UNPKG

acud

Version:

acg react 组件库

156 lines • 5.64 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _extends from "@babel/runtime/helpers/esm/extends"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _isNativeReflectConstruct from "@babel/runtime/helpers/esm/isNativeReflectConstruct"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; import classNames from 'classnames'; import OutlinedCheckSmall from "acud-icon/es/icons/OutlinedCheckSmall"; var BaseCheckbox = /*#__PURE__*/function (_React$Component) { function BaseCheckbox(props) { var _this; _classCallCheck(this, BaseCheckbox); _this = _callSuper(this, BaseCheckbox, [props]); _this.handleChange = function (e) { var _this$props = _this.props, disabled = _this$props.disabled, onChange = _this$props.onChange; if (disabled) { return; } if (!('checked' in _this.props)) { _this.setState({ checked: e.target.checked }); } if (onChange) { onChange({ target: _extends(_extends({}, _this.props), { checked: e.target.checked }), stopPropagation: function stopPropagation() { e.stopPropagation(); }, preventDefault: function preventDefault() { e.preventDefault(); }, nativeEvent: e.nativeEvent }); } }; _this.saveInput = function (node) { _this.input = node; }; var checked = 'checked' in props ? props.checked : props.defaultChecked; _this.state = { checked: checked }; return _this; } _inherits(BaseCheckbox, _React$Component); return _createClass(BaseCheckbox, [{ key: "focus", value: function focus() { this.input.focus(); } }, { key: "blur", value: function blur() { this.input.blur(); } }, { key: "render", value: function render() { var _a = this.props, prefixCls = _a.prefixCls, className = _a.className, style = _a.style, name = _a.name, id = _a.id, type = _a.type, disabled = _a.disabled, readOnly = _a.readOnly, tabIndex = _a.tabIndex, onClick = _a.onClick, onFocus = _a.onFocus, onBlur = _a.onBlur, onKeyDown = _a.onKeyDown, onKeyPress = _a.onKeyPress, onKeyUp = _a.onKeyUp, autoFocus = _a.autoFocus, value = _a.value, required = _a.required, others = __rest(_a, ["prefixCls", "className", "style", "name", "id", "type", "disabled", "readOnly", "tabIndex", "onClick", "onFocus", "onBlur", "onKeyDown", "onKeyPress", "onKeyUp", "autoFocus", "value", "required"]); var globalProps = Object.keys(others).reduce(function (prev, key) { if (key.substr(0, 5) === 'aria-' || key.substr(0, 5) === 'data-' || key === 'role') { // eslint-disable-next-line no-param-reassign prev[key] = others[key]; } return prev; }, {}); var checked = this.state.checked; var classString = classNames(prefixCls, className, _defineProperty(_defineProperty({}, "".concat(prefixCls, "-checked"), checked), "".concat(prefixCls, "-disabled"), disabled)); return /*#__PURE__*/React.createElement("span", { className: classString, style: style }, /*#__PURE__*/React.createElement("input", _extends({ name: name, id: id, type: type, required: required, readOnly: readOnly, disabled: disabled, tabIndex: tabIndex, className: "".concat(prefixCls, "-input"), checked: !!checked, onClick: onClick, onFocus: onFocus, onBlur: onBlur, onKeyUp: onKeyUp, onKeyDown: onKeyDown, onKeyPress: onKeyPress, onChange: this.handleChange, autoFocus: autoFocus, ref: this.saveInput, value: value }, globalProps)), /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-inner") }, checked && /*#__PURE__*/React.createElement(OutlinedCheckSmall, { width: "14px", height: "14px", className: "checkbox-check-icon" }))); } }], [{ key: "getDerivedStateFromProps", value: function getDerivedStateFromProps(props, state) { if ('checked' in props) { return _extends(_extends({}, state), { checked: props.checked }); } return null; } }]); }(React.Component); BaseCheckbox.defaultProps = { prefixCls: 'acud-checkbox', className: '', style: {}, type: 'checkbox', optionType: 'default', defaultChecked: false }; export default BaseCheckbox;