1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 5× 1× 4× 4× 1× 1× 1× 6× 6× 78× 6× 1× 1× 1× 4× 4× 1× 6× 6× 6× 1× 1× 1× 1× 6× 6× 6× 6× 6× 6× 6× 1× 1× 1× 1× 1× | 'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _uxcoreSwitch = require('uxcore-switch'); var _uxcoreSwitch2 = _interopRequireDefault(_uxcoreSwitch); var _uxcoreFormField = require('uxcore-form-field'); var _uxcoreFormField2 = _interopRequireDefault(_uxcoreFormField); var _objectAssign = require('object-assign'); var _objectAssign2 = _interopRequireDefault(_objectAssign); var _uxcoreConst = require('uxcore-const'); var _uxcoreConst2 = _interopRequireDefault(_uxcoreConst); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { Iif (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { Iif (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } /** * SwitchFormField Component for uxcore * @author eternalsky * * Copyright 2015-2016, Uxcore Team, Alinw. * All rights reserved. */ var switchPropKeys = Object.keys(_uxcoreSwitch2['default'].propTypes); function getSwitchProps(formFieldProps) { var ret = {}; switchPropKeys.filter(function (key) { return formFieldProps.hasOwnProperty(key); }).forEach(function (key) { ret[key] = props[key]; }); return ret; } var SwitchFormField = function (_FormField) { _inherits(SwitchFormField, _FormField); function SwitchFormField() { _classCallCheck(this, SwitchFormField); return _possibleConstructorReturn(this, _FormField.apply(this, arguments)); } SwitchFormField.prototype.addSpecificClass = function addSpecificClass() { var me = this; Eif (me.props.jsxprefixCls === "kuma-uxform-field") { return me.props.jsxprefixCls + ' kuma-switch-uxform-field'; } return me.props.jsxprefixCls; }; SwitchFormField.prototype.handleChange = function handleChange(checked) { var me = this; me.handleDataChange(checked); }; SwitchFormField.prototype.renderField = function renderField() { var me = this; var props = me.props, state = me.state; var switchProps = getSwitchProps(props); var mode = props.jsxmode || props.mode; var checkedChildren = props.checkedChildren, unCheckedChildren = props.unCheckedChildren; Eif (mode === _uxcoreConst2['default'].MODE.EDIT) { return _react2['default'].createElement(_uxcoreSwitch2['default'], _extends({}, switchProps, { checked: state.value, onChange: me.handleChange.bind(me), style: {}, className: '' })); } return _react2['default'].createElement( 'span', null, state.value ? checkedChildren : unCheckedChildren ); }; return SwitchFormField; }(_uxcoreFormField2['default']); SwitchFormField.defaultProps = (0, _objectAssign2['default'])({}, _uxcoreFormField2['default'].defaultProps); // http://facebook.github.io/react/docs/reusable-components.html SwitchFormField.propTypes = (0, _objectAssign2['default'])({}, _uxcoreFormField2['default'].propTypes); SwitchFormField.displayName = 'SwitchFormField'; module.exports = SwitchFormField; |