Files
web/packages/design-system/lib/components/Form/PaymentOption/PaymentOptionsGroup.tsx
Rasmus Langvad d0546926a9 Merged in fix/3697-prettier-configs (pull request #3396)
fix(SW-3691): Setup one prettier config for whole repo

* Setup prettierrc in root and remove other configs


Approved-by: Joakim Jäderberg
Approved-by: Linus Flood
2026-01-07 12:45:50 +00:00

54 lines
1.1 KiB
TypeScript

"use client"
import { Label, RadioGroup } from "react-aria-components"
import { useController, useFormContext } from "react-hook-form"
import type { ReactNode } from "react"
import { Typography } from "../../../components/Typography"
interface PaymentOptionsGroupProps {
name: string
label?: string
children: ReactNode
className?: string
initalValue?: string
onChange?: (newValue: string) => void
}
export function PaymentOptionsGroup({
name,
label,
children,
className,
onChange,
initalValue,
}: PaymentOptionsGroupProps) {
const { control } = useFormContext()
const {
field: { value, onChange: formOnChange },
} = useController({
name,
control,
})
const handleChange = (newValue: string) => {
formOnChange(newValue)
onChange?.(newValue)
}
return (
<RadioGroup
value={initalValue || value}
onChange={handleChange}
className={className}
>
{label ? (
<Typography variant="Title/Overline/sm">
<Label>{label}</Label>
</Typography>
) : null}
{children}
</RadioGroup>
)
}