refactor: radio button group value generic

This commit is contained in:
Aman Harwara
2023-09-13 15:59:57 +05:30
parent 7c9cc821a2
commit a07fa23c70
2 changed files with 7 additions and 7 deletions

View File

@@ -1,19 +1,19 @@
import { VisuallyHidden, Radio, RadioGroup, useRadioStore } from '@ariakit/react' import { VisuallyHidden, Radio, RadioGroup, useRadioStore } from '@ariakit/react'
import { classNames } from '@standardnotes/utils' import { classNames } from '@standardnotes/utils'
type Props = { type Props<Value extends string> = {
items: { label: string; value: string }[] items: { label: string; value: Value }[]
value: string value: Value
onChange: (value: string) => void onChange: (value: Value) => void
className?: string className?: string
} }
const RadioButtonGroup = ({ value, items, onChange, className }: Props) => { function RadioButtonGroup<Value extends string>({ value, items, onChange, className }: Props<Value>) {
const radio = useRadioStore({ const radio = useRadioStore({
value, value,
orientation: 'horizontal', orientation: 'horizontal',
setValue(value) { setValue(value) {
onChange(value as string) onChange(value as Value)
}, },
}) })

View File

@@ -35,7 +35,7 @@ const VaultSelectionMenu = () => {
{ label: 'One', value: 'single' }, { label: 'One', value: 'single' },
]} ]}
value={mode} value={mode}
onChange={(value) => changeSelectionMode(value as SettingsMode)} onChange={(value) => changeSelectionMode(value)}
className="m-3 mt-1" className="m-3 mt-1"
/> />
{mode === 'many' && <ManyVaultSelectionMenu />} {mode === 'many' && <ManyVaultSelectionMenu />}