refactor: radio button group value generic
This commit is contained in:
@@ -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)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -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 />}
|
||||||
|
|||||||
Reference in New Issue
Block a user