(front) add customization to Field

We want to be able to provide some custom attributes to the FieldWrapper
and its label too to manage width, alignment.
This commit is contained in:
Nathan Vasse
2025-01-16 14:54:17 +01:00
committed by NathanVss
parent 994f335266
commit eac9158734

View File

@@ -25,11 +25,31 @@ const FieldWrapper = styled('div', {
marginBottom: 'textfield', marginBottom: 'textfield',
minWidth: 0, minWidth: 0,
}, },
variants: {
noMargin: {
true: {
marginBottom: 0,
},
},
fullWidth: {
true: {
width: '100%',
},
},
},
}) })
const StyledLabel = styled(Label, { const StyledLabel = styled(Label, {
base: { base: {
display: 'block', display: 'block',
fontSize: '12px',
},
variants: {
center: {
true: {
textAlign: 'center',
},
},
}, },
}) })
@@ -80,6 +100,8 @@ type FieldProps<T extends object> = (
) & { ) & {
label: string label: string
description?: string description?: string
wrapperProps?: React.ComponentProps<typeof FieldWrapper>
labelProps?: React.ComponentProps<typeof StyledLabel>
} }
/** /**
@@ -104,7 +126,7 @@ export const Field = <T extends object>({
}: FieldProps<T>) => { }: FieldProps<T>) => {
const LabelAndDescription = ( const LabelAndDescription = (
<> <>
<StyledLabel>{label}</StyledLabel> <StyledLabel {...props.labelProps}>{label}</StyledLabel>
<FieldDescription slot="description">{description}</FieldDescription> <FieldDescription slot="description">{description}</FieldDescription>
</> </>
) )
@@ -118,7 +140,7 @@ export const Field = <T extends object>({
if (type === 'text') { if (type === 'text') {
return ( return (
<FieldWrapper> <FieldWrapper {...props.wrapperProps}>
<RACTextField <RACTextField
validate={validate as unknown as TextFieldProps['validate']} validate={validate as unknown as TextFieldProps['validate']}
{...(props as PartialTextFieldProps)} {...(props as PartialTextFieldProps)}
@@ -133,7 +155,7 @@ export const Field = <T extends object>({
if (type === 'checkbox') { if (type === 'checkbox') {
return ( return (
<FieldWrapper> <FieldWrapper {...props.wrapperProps}>
<Checkbox <Checkbox
validate={validate as unknown as CheckboxProps['validate']} validate={validate as unknown as CheckboxProps['validate']}
description={description} description={description}
@@ -147,7 +169,7 @@ export const Field = <T extends object>({
if (type === 'checkboxGroup') { if (type === 'checkboxGroup') {
return ( return (
<FieldWrapper> <FieldWrapper {...props.wrapperProps}>
<CheckboxGroup <CheckboxGroup
validate={validate as unknown as CheckboxGroupProps['validate']} validate={validate as unknown as CheckboxGroupProps['validate']}
{...(props as PartialCheckboxGroupProps)} {...(props as PartialCheckboxGroupProps)}
@@ -170,7 +192,7 @@ export const Field = <T extends object>({
if (type === 'radioGroup') { if (type === 'radioGroup') {
return ( return (
<FieldWrapper> <FieldWrapper {...props.wrapperProps}>
<RadioGroup <RadioGroup
validate={validate as unknown as RadioGroupProps['validate']} validate={validate as unknown as RadioGroupProps['validate']}
{...(props as PartialRadioGroupProps)} {...(props as PartialRadioGroupProps)}
@@ -189,7 +211,7 @@ export const Field = <T extends object>({
if (type === 'select') { if (type === 'select') {
return ( return (
<FieldWrapper> <FieldWrapper {...props.wrapperProps}>
<Select <Select
validate={validate as unknown as SelectProps<T>['validate']} validate={validate as unknown as SelectProps<T>['validate']}
{...(props as PartialSelectProps<T>)} {...(props as PartialSelectProps<T>)}