Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Fieldset, Switch, Radio, Checkbox): ✨ Add large size #841

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions packages/react/src/components/form/Fieldset/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import { PadlockLockedFillIcon } from '@navikt/aksel-icons';

import { Label, Paragraph, ErrorMessage } from '../../Typography';
import utilityclasses from '../../../utils/utility.module.css';
import type { FormFieldProps } from '../useFormField';

import { useFieldset } from './useFieldset';
import classes from './Fieldset.module.css';

export type FieldsetContextType = {
error?: ReactNode;
errorId?: string;
disabled?: boolean;
readOnly?: boolean;
size?: 'xsmall' | 'small' | 'medium';
};
export type FieldsetContextType = Pick<
FormFieldProps,
'error' | 'errorId' | 'disabled' | 'readOnly' | 'size'
>;

export const FieldsetContext = createContext<FieldsetContextType | null>(null);

Expand All @@ -28,14 +26,13 @@ export type FieldsetProps = {
error?: ReactNode;
/** The legend of the fieldset. */
legend?: ReactNode;
/** The size of the fieldset. */
size?: 'xsmall' | 'small' | 'medium';
/** Toggle `readOnly` on fieldset context.
* @note This does not prevent fieldset values from being submited */
readOnly?: boolean;
/** Visually hide `legend` and `description` (still available for screen readers) */
hideLegend?: boolean;
} & FieldsetHTMLAttributes<HTMLFieldSetElement>;
} & Pick<FormFieldProps, 'size'> &
FieldsetHTMLAttributes<HTMLFieldSetElement>;

export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
(props, ref) => {
Expand Down
6 changes: 2 additions & 4 deletions packages/react/src/components/form/useFormField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type FormFieldProps = {
/** Toggle `readOnly` */
readOnly?: boolean;
/** Changes field size and paddings */
size?: 'xsmall' | 'small' | 'medium';
size?: 'xsmall' | 'small' | 'medium' | 'large';
} & Pick<HTMLAttributes<HTMLElement>, 'aria-describedby'>;

export type FormField = {
Expand All @@ -31,9 +31,7 @@ export type FormField = {
InputHTMLAttributes<HTMLInputElement>,
'id' | 'disabled' | 'aria-invalid' | 'aria-describedby'
>;
readOnly?: boolean;
size?: 'xsmall' | 'small' | 'medium';
};
} & Pick<FormFieldProps, 'size' | 'readOnly'>;

/**
* Handles props and their state for various form-fields in context with Fieldset
Expand Down
Loading