diff --git a/src/frontend/src/primitives/Field.tsx b/src/frontend/src/primitives/Field.tsx index 6f54953d..273cf276 100644 --- a/src/frontend/src/primitives/Field.tsx +++ b/src/frontend/src/primitives/Field.tsx @@ -20,6 +20,7 @@ import { Checkbox } from './Checkbox' import { Select } from './Select' import { Text } from './Text' import { Div } from './Div' +import { Switch, type SwitchProps } from './Switch' import { css } from '@/styled-system/css' const FieldWrapper = styled('div', { @@ -67,6 +68,7 @@ type PartialSelectProps = Omit< SelectProps, OmittedRACProps > +type PartialSwitchProps = Omit type FieldProps = ( | ({ type: 'text' @@ -101,6 +103,11 @@ type FieldProps = ( validate?: (value: T) => ReactNode | ReactNode[] | true | null | undefined } & Items & PartialSelectProps) + | ({ + type: 'switch' + items?: never + validate?: never + } & PartialSwitchProps) ) & { label: string description?: string @@ -250,6 +257,34 @@ export const Field = ({ ) } + + if (type === 'switch') { + return ( + +
+ {label} + +
+ {description && ( + + {description} + + )} +
+ ) + } } const FieldItem = ({ diff --git a/src/frontend/src/primitives/Switch.tsx b/src/frontend/src/primitives/Switch.tsx index 7f031385..2f55b182 100644 --- a/src/frontend/src/primitives/Switch.tsx +++ b/src/frontend/src/primitives/Switch.tsx @@ -4,7 +4,6 @@ import { } from 'react-aria-components' import { styled } from '@/styled-system/jsx' import { StyledVariantProps } from '@/styled-system/types' -import { ReactNode } from 'react' export const StyledSwitch = styled(RACSwitch, { base: { @@ -100,21 +99,25 @@ export const StyledSwitch = styled(RACSwitch, { }) export type SwitchProps = StyledVariantProps & - RACSwitchProps & { children: ReactNode } + RACSwitchProps /** * Styled RAC Switch. */ export const Switch = ({ children, ...props }: SwitchProps) => ( -
- - -
- {children} + {(renderProps) => ( + <> +
+ + +
+ {typeof children === 'function' ? children(renderProps) : children} + + )}
)