diff --git a/packages/ffe-form-react/src/Checkbox.spec.tsx b/packages/ffe-form-react/src/Checkbox.spec.tsx index 9fdd6c48ab..4f98ae0d0f 100644 --- a/packages/ffe-form-react/src/Checkbox.spec.tsx +++ b/packages/ffe-form-react/src/Checkbox.spec.tsx @@ -111,4 +111,20 @@ describe('', () => { expect(labelContent?.innerHTML).toBe('children'); expect(input?.getAttribute('aria-label')).toBe('I am label'); }); + + it('ads the on colored on-colored-bg modifier', () => { + const { container } = render( + + {({ htmlFor, className }) => ( + + )} + , + ); + const label = container.querySelector('label'); + expect( + label?.classList.contains('ffe-checkbox--on-colored-bg'), + ).toBeTruthy(); + }); }); diff --git a/packages/ffe-form-react/src/Checkbox.tsx b/packages/ffe-form-react/src/Checkbox.tsx index ced14bba7e..5d89830611 100644 --- a/packages/ffe-form-react/src/Checkbox.tsx +++ b/packages/ffe-form-react/src/Checkbox.tsx @@ -15,10 +15,23 @@ export interface CheckboxProps className: string; htmlFor: string; }) => React.ReactNode); + /** Adds alternative styling for better contrast on certain backgrounds */ + onColoredBg?: boolean; } export const Checkbox = React.forwardRef( - ({ children, hiddenLabel, inline = true, noMargins, id, ...rest }, ref) => { + ( + { + children, + hiddenLabel, + inline = true, + noMargins, + id, + onColoredBg, + ...rest + }, + ref, + ) => { const generatedId = useRef(id ?? `checkbox-${uuid()}`).current; const labelProps = { className: classNames({ @@ -26,6 +39,7 @@ export const Checkbox = React.forwardRef( 'ffe-checkbox--inline': inline, 'ffe-checkbox--no-margin': noMargins, 'ffe-checkbox--hidden-label': hiddenLabel, + 'ffe-checkbox--on-colored-bg': onColoredBg, }), htmlFor: generatedId, }; diff --git a/packages/ffe-form-react/src/InputGroup.tsx b/packages/ffe-form-react/src/InputGroup.tsx index 2e713b3b2b..ad1b16d08c 100644 --- a/packages/ffe-form-react/src/InputGroup.tsx +++ b/packages/ffe-form-react/src/InputGroup.tsx @@ -9,6 +9,7 @@ type ChildrenExtraProps = { id: string; 'aria-invalid': 'true' | 'false'; 'aria-describedby': string | undefined; + onColoredBg?: boolean; }; export interface InputGroupProps @@ -27,14 +28,25 @@ export interface InputGroupProps */ extraMargin?: boolean; /** Use the ErrorFieldMessage component if you need more flexibility in how the content is rendered. */ - fieldMessage?: string | React.ReactElement<{ id: string }> | null; + fieldMessage?: + | string + | React.ReactElement<{ id: string; onColoredBg?: boolean }> + | null; /** To just render a static, always visible tooltip, use this. */ description?: string; /** Use the Label component if you need more flexibility in how the content is rendered. */ - label?: string | React.ReactElement<{ id: string; htmlFor: string }>; + label?: + | string + | React.ReactElement<{ + id: string; + htmlFor: string; + onColoredBg?: boolean; + }>; onTooltipToggle?: TooltipProps['onClick']; /** Use the Tooltip component if you need more flexibility in how the content is rendered. */ tooltip?: React.ReactNode; + /** Adds alternative styling for better contrast on certain backgrounds */ + onColoredBg?: boolean; } const getChildrenWithExtraProps = ( children: InputGroupProps['children'], @@ -59,6 +71,7 @@ export const InputGroup: React.FC = ({ tooltip, onTooltipToggle, labelId, + onColoredBg, ...rest }) => { const id = useRef(inputId ? inputId : `input-${uuid()}`).current; @@ -114,6 +127,7 @@ export const InputGroup: React.FC = ({ id, 'aria-invalid': isInvalid ? 'true' : 'false', 'aria-describedby': ariaDescribedBy, + onColoredBg, } as const; const modifiedChildren = getChildrenWithExtraProps(children, extraProps); @@ -122,14 +136,17 @@ export const InputGroup: React.FC = ({
{typeof label === 'string' ? ( -
); diff --git a/packages/ffe-form-react/src/Label.spec.tsx b/packages/ffe-form-react/src/Label.spec.tsx index d1c23729c8..c56984053f 100644 --- a/packages/ffe-form-react/src/Label.spec.tsx +++ b/packages/ffe-form-react/src/Label.spec.tsx @@ -34,4 +34,13 @@ describe('