import { RtToggleProps } from './rt-toggle.types'; import styles from './styles/rt-toggle.module.css'; import config from './styles/toggle-config.module.css'; import className from 'classnames/bind'; import { RtBaseProps, useRtBaseProps } from '@dpa/react-hoc'; import { RtFrame } from '@dpa/react-frame-intro'; import { ChangeEvent, useRef } from 'react'; import { RtSpinner } from '@dpa/react-loaders'; const cn = className.bind(styles); export function RtToggle(props: RtToggleProps & RtBaseProps) { const { size = 'md', activeUse = 'success', radius = 'primary', width = 'min-content', height = 'min-content', isActive = false, isLoading, disabled, } = props; const baseProps = useRtBaseProps(props, '0.2.2'); const inputRef = useRef(null); const surfaceState = disabled ? 'disabled' : isLoading ? 'loading' : undefined; function handleChange(event: ChangeEvent) { props.onChange?.({ event, value: event.target.checked, name: props.name }); } function handleClick() { setTimeout(() => { inputRef.current?.blur(); }, 0); } return ( { if (e.code === 'Space') inputRef.current?.click(); }} > {!!isLoading && ( )} { e.stopPropagation(); }} aria-label={props.ariaLabel} aria-labelledby={props.ariaLabelledBy} /> ); } RtToggle.displayName = 'RtToggle';