import { Switch, SwitchProps } from 'antd'; import cx from 'classnames'; import React from 'react'; import type { StdCallback } from './types'; const CLASS_NAME = 'ac-switch'; export type AcSwitchProps = { className?: string; value?: boolean; onChange?: StdCallback; } & SwitchProps; export class AcSwitch extends React.Component { static displayName = CLASS_NAME; static formSchema = CLASS_NAME; static defaultProps = {}; state = { value: Boolean(this.props.value), }; shouldComponentUpdate(nextProps: Readonly): boolean { const { value } = nextProps; if (value !== this.props.value) this.setState({ value }); return true; } handleChange = (value) => { const { onChange } = this.props; const target = { value }; this.setState(target, () => onChange?.({ target })); }; render() { const { className, value, onChange, ...props } = this.props; const _value = this.state.value; return ( ); } } export const AcSwitchFc = React.forwardRef((props, ref) => { return ; });