hensei-web/components/common/Switch/index.tsx
Justin Edmund 4c5fb3c28d Rename all files and fix imports
* Renaming index.scss files to index.module.scss
* Changing `import from` to `import styles from`
2023-06-23 13:19:38 -07:00

47 lines
1,022 B
TypeScript

import React from 'react'
import * as RadixSwitch from '@radix-ui/react-switch'
import classNames from 'classnames'
import styles from './index.module.scss'
interface Props
extends React.DetailedHTMLProps<
React.InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
> {
thumbClass?: string
onCheckedChange: (checked: boolean) => void
}
const Switch = (props: Props) => {
const {
checked,
className,
disabled,
name,
onCheckedChange,
required,
thumbClass,
value,
} = props
const mainClasses = classNames({ Switch: true }, className)
const thumbClasses = classNames({ SwitchThumb: true }, thumbClass)
return (
<RadixSwitch.Root
className={mainClasses}
checked={checked}
name={name}
disabled={disabled}
required={required}
value={value}
tabIndex={props.tabIndex}
onCheckedChange={onCheckedChange}
>
<RadixSwitch.Thumb className={thumbClasses} />
</RadixSwitch.Root>
)
}
export default Switch