12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- /* eslint-disable no-nested-ternary */
- import React, { PureComponent } from 'react';
- import classnames from 'classnames';
- import PropTypes from 'prop-types';
- import { noop } from 'lodash';
- import { checkboxClasses as css } from '@douyinfe/semi-foundation/checkbox/constants';
- import { Context } from './context';
- import { IconCheckboxTick, IconCheckboxIndeterminate } from '@douyinfe/semi-icons';
- export interface CheckboxInnerProps {
- indeterminate?: boolean;
- checked?: boolean;
- disabled?: boolean;
- prefixCls?: string;
- name?: string;
- isPureCardType?: boolean;
- ref?: React.MutableRefObject<CheckboxInner> | ((ref: CheckboxInner) => void);
- addonId?: string;
- extraId?: string;
- }
- class CheckboxInner extends PureComponent<CheckboxInnerProps> {
- static contextType = Context;
- static propTypes = {
- 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,
- };
- static defaultProps = {
- onChange: noop,
- };
- inputEntity: HTMLInputElement;
- blur() {
- this.inputEntity.blur();
- }
- focus() {
- this.inputEntity.focus();
- }
- render() {
- const { indeterminate, checked, disabled, prefixCls, name, isPureCardType, addonId, extraId } = 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,
- });
- const icon = checked ? (
- <IconCheckboxTick />
- ) : indeterminate ? (
- <IconCheckboxIndeterminate />
- ) : null;
- return (
- <span className={wrapper}>
- <input
- aria-hidden={true}
- tabIndex={-1}
- ref={ref => {
- this.inputEntity = ref;
- }}
- type="checkbox"
- className={css.INPUT}
- onChange={noop}
- checked={checked}
- disabled={disabled}
- name={name}
- />
- <span className={inner}>{icon}</span>
- </span>
- );
- }
- }
- export default CheckboxInner;
|