/** @jsxRuntime classic */ /** @jsx jsx */ /** * TODO: * * - This component needs to be brought into line with either buttons (including support for tones) * or better represented in the theme. * - Needs proper tokens and styling functions * - Needs size support * - Needs focus support * - Needs disabled support * - Needs a label wrapper like radio and checkbox * - Should this be stateful like a checkbox? check react-aria */ import { type ButtonHTMLAttributes, forwardRef, type ReactNode } from 'react' import { jsx, useTheme, VisuallyHidden } from '@keystone-ui/core' import { ControlLabel } from './components/ControlLabel' type SwitchProps = { /** The switch label content. */ children: ReactNode } & SwitchControlProps export const Switch = forwardRef( ({ children, className, ...props }, ref) => { return ( }> {children} ) } ) type ButtonProps = ButtonHTMLAttributes type SwitchControlProps = { /** Optionally pass in "On" and "Off" label text for screen readers */ a11yLabels?: { on: string, off: string } /** The current checked state. */ checked?: boolean /** Handle change events. */ onChange?: (checked: boolean) => void } & Omit export const SwitchControl = forwardRef( ({ a11yLabels = { on: 'On', off: 'Off' }, checked = false, onChange, ...props }, ref) => { const onClick = () => { if (onChange) { onChange(!checked) } } return ( ) } ) const Button = forwardRef((props, ref) => { const { animation, fields, sizing } = useTheme() const gutter = 3 const trackHeight = sizing.xsmall + gutter const trackWidth = trackHeight * 2 - 2 * gutter const handleSize = trackHeight - gutter * 2 return (