import React, { HTMLAttributes, useRef, useState } from 'react'; import classNames from 'classnames'; import './index.scss'; export interface SwitchProps extends HTMLAttributes { defaultChecked?: boolean; onColor?: string; offColor?: string; callback?: (checked: boolean) => void; children?: React.ReactNode; } const Switch: React.FC = (props) => { const { children, onColor, offColor, defaultChecked, callback, ...rest } = props; const [selected, setSelected] = useState(defaultChecked!); const wrapRef = useRef(null); const innerRef = useRef(null); const selectedChange = () => { callback!(!selected); setSelected(!selected); }; return (
); }; Switch.defaultProps = { defaultChecked: false, onColor: '#1890ff', offColor: '#dcdfe6', callback: () => {}, children: '' }; export default Switch;