diff options
Diffstat (limited to 'packages/excalidraw/components/Switch.tsx')
| -rw-r--r-- | packages/excalidraw/components/Switch.tsx | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/excalidraw/components/Switch.tsx b/packages/excalidraw/components/Switch.tsx new file mode 100644 index 0000000..431c644 --- /dev/null +++ b/packages/excalidraw/components/Switch.tsx @@ -0,0 +1,38 @@ +import clsx from "clsx"; + +import "./Switch.scss"; + +export type SwitchProps = { + name: string; + checked: boolean; + title?: string; + onChange: (value: boolean) => void; + disabled?: boolean; +}; + +export const Switch = ({ + title, + name, + checked, + onChange, + disabled = false, +}: SwitchProps) => { + return ( + <div className={clsx("Switch", { toggled: checked, disabled })}> + <input + name={name} + id={name} + title={title} + type="checkbox" + checked={checked} + disabled={disabled} + onChange={() => onChange(!checked)} + onKeyDown={(event) => { + if (event.key === " ") { + onChange(!checked); + } + }} + /> + </div> + ); +}; |
