UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

99 lines 3.07 kB
import _noop from "lodash/noop"; import React, { PureComponent } from 'react'; import classnames from 'classnames'; import PropTypes from 'prop-types'; import { checkboxClasses as css } from '@douyinfe/semi-foundation/lib/es/checkbox/constants'; import { Context } from './context'; import { IconCheckboxTick, IconCheckboxIndeterminate } from '@douyinfe/semi-icons'; class CheckboxInner extends PureComponent { blur() { this.inputEntity.blur(); } focus() { const { preventScroll } = this.props; this.inputEntity.focus({ preventScroll }); } render() { const { indeterminate, checked, disabled, prefixCls, name, isPureCardType, addonId, extraId, focusInner, onInputFocus, onInputBlur } = this.props; const prefix = prefixCls || css.PREFIX; const wrapper = classnames({ [`${prefix}-inner`]: true, [`${prefix}-inner-checked`]: Boolean(checked), [`${prefix}-inner-pureCardType`]: isPureCardType }, css.WRAPPER); const inner = classnames({ [`${prefix}-inner-display`]: true, [`${prefix}-focus`]: focusInner, [`${prefix}-focus-border`]: focusInner && !checked }); const icon = checked ? (/*#__PURE__*/React.createElement(IconCheckboxTick, null)) : indeterminate ? (/*#__PURE__*/React.createElement(IconCheckboxIndeterminate, null)) : null; const inputProps = { type: "checkbox", 'aria-label': this.props['aria-label'], 'aria-disabled': disabled, 'aria-checked': checked, 'aria-labelledby': addonId, 'aria-describedby': extraId || this.props['aria-describedby'], 'aria-invalid': this.props['aria-invalid'], 'aria-errormessage': this.props['aria-errormessage'], 'aria-required': this.props['aria-required'], className: css.INPUT, onChange: _noop, checked: checked, disabled: disabled, onFocus: onInputFocus, onBlur: onInputBlur }; name && (inputProps['name'] = name); return /*#__PURE__*/React.createElement("span", { className: wrapper }, /*#__PURE__*/React.createElement("input", Object.assign({}, inputProps, { ref: ref => { this.inputEntity = ref; } })), /*#__PURE__*/React.createElement("span", { className: inner }, icon)); } } CheckboxInner.contextType = Context; CheckboxInner.propTypes = { 'aria-describedby': PropTypes.string, 'aria-errormessage': PropTypes.string, 'aria-invalid': PropTypes.bool, 'aria-labelledby': PropTypes.string, 'aria-required': PropTypes.bool, checked: PropTypes.bool, disabled: PropTypes.bool, onChange: PropTypes.func, children: PropTypes.node, grouped: PropTypes.bool, value: PropTypes.any, isPureCardType: PropTypes.bool, addonId: PropTypes.string, extraId: PropTypes.string, focusInner: PropTypes.bool, onInputFocus: PropTypes.func, onInputBlur: PropTypes.func, preventScroll: PropTypes.bool }; CheckboxInner.defaultProps = { onChange: _noop }; export default CheckboxInner;