= ({
{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('', () => {
rerender();
expect(label.classList.contains('ffe-form-label--block')).toBe(true);
});
+
+ it('ads the on colored on-colored-bg modifier', () => {
+ render();
+ const label = screen.getByText('label text');
+ expect(label.classList.contains('ffe-form-label')).toBe(true);
+ expect(label.classList.contains('ffe-form-label--on-colored-bg')).toBe(
+ true,
+ );
+ });
});
diff --git a/packages/ffe-form-react/src/Label.tsx b/packages/ffe-form-react/src/Label.tsx
index 2b3b6d4ee4..5a05e4b123 100644
--- a/packages/ffe-form-react/src/Label.tsx
+++ b/packages/ffe-form-react/src/Label.tsx
@@ -7,6 +7,8 @@ export interface LabelProps extends React.ComponentPropsWithoutRef<'label'> {
* Set this to `true` if you don't use tooltips and need the label to be `display: block;`.
*/
block?: boolean;
+ /** Adds alternative styling for better contrast on certain backgrounds */
+ onColoredBg?: boolean;
}
export const Label: React.FC = ({
@@ -14,11 +16,13 @@ export const Label: React.FC = ({
children,
className,
htmlFor,
+ onColoredBg,
...rest
}) => (
= ({
className,
inline,
+ onColoredBg,
...rest
}) => {
return (
;
selectedValue?: boolean | string | number | null;
+ onColoredBg?: boolean;
}) => React.ReactNode;
/** Additional class names applied to the fieldset */
className?: string;
@@ -30,7 +31,10 @@ export interface RadioButtonInputGroupProps
*/
extraMargin?: boolean;
/** String or ErrorFieldMessage component with message */
- fieldMessage?: React.ReactNode;
+ fieldMessage?:
+ | string
+ | React.ReactElement<{ onColoredBg?: boolean }>
+ | null;
/**
* Indicates whether the radio buttons inside this radio button group is
* rendered inline or as a block.
@@ -53,6 +57,8 @@ export interface RadioButtonInputGroupProps
* set
* */
tooltip?: React.ReactNode;
+ /** Adds alternative styling for better contrast on certain backgrounds */
+ onColoredBg?: boolean;
}
export const RadioButtonInputGroup: React.FC = ({
@@ -67,6 +73,7 @@ export const RadioButtonInputGroup: React.FC = ({
selectedValue,
tooltip,
onChange,
+ onColoredBg,
...rest
}) => {
if (tooltip && description) {
@@ -81,6 +88,7 @@ export const RadioButtonInputGroup: React.FC = ({
aria-labelledby={id}
className={classNames(
'ffe-input-group',
+ { 'ffe-input-group--on-colored-bg': onColoredBg },
{ 'ffe-input-group--no-extra-margin': !extraMargin },
{ 'ffe-input-group--message': !!fieldMessage },
className,
@@ -93,22 +101,22 @@ export const RadioButtonInputGroup: React.FC = ({
className={classNames(
'ffe-form-label',
'ffe-form-label--block',
+ { 'ffe-form-label--on-colored-bg': onColoredBg },
)}
>
{label}
{typeof tooltip === 'string' && (
- {tooltip}
+ {tooltip}
)}
{React.isValidElement(tooltip) && tooltip}
)}
- {typeof description === 'string' ? (
- {description}
- ) : (
- description
+ {description && (
+
+ {description}
+
)}
-
{children({
inline,
name,
@@ -116,12 +124,18 @@ export const RadioButtonInputGroup: React.FC = ({
onChange?.(e);
},
selectedValue,
+ onColoredBg,
})}
{typeof fieldMessage === 'string' ? (
- {fieldMessage}
+
+ {fieldMessage}
+
) : (
- fieldMessage
+ React.isValidElement(fieldMessage) &&
+ React.cloneElement(fieldMessage, {
+ onColoredBg,
+ })
)}
);
diff --git a/packages/ffe-form-react/src/Tooltip.spec.tsx b/packages/ffe-form-react/src/Tooltip.spec.tsx
index 5d9808cefa..d938a92342 100644
--- a/packages/ffe-form-react/src/Tooltip.spec.tsx
+++ b/packages/ffe-form-react/src/Tooltip.spec.tsx
@@ -75,4 +75,13 @@ describe('', () => {
expect(button.getAttribute('aria-controls')).toBe(tipId);
});
+
+ it('ads the on colored on-colored-bg modifier', () => {
+ const { container } = renderTooltip({ onColoredBg: true });
+ const tooltip = container.querySelector('.ffe-tooltip');
+ expect(tooltip?.classList.contains('ffe-tooltip')).toBeTruthy();
+ expect(
+ tooltip?.classList.contains('ffe-tooltip--on-colored-bg'),
+ ).toBeTruthy();
+ });
});
diff --git a/packages/ffe-form-react/src/Tooltip.tsx b/packages/ffe-form-react/src/Tooltip.tsx
index ad82963fde..92ad142e1c 100644
--- a/packages/ffe-form-react/src/Tooltip.tsx
+++ b/packages/ffe-form-react/src/Tooltip.tsx
@@ -15,6 +15,8 @@ export interface TooltipProps
> {
containerProps?: React.ComponentPropsWithoutRef<'div'>;
isOpen?: boolean;
+ /** Adds alternative styling for better contrast on certain backgrounds */
+ onColoredBg?: boolean;
}
export const Tooltip = React.forwardRef(
@@ -28,6 +30,7 @@ export const Tooltip = React.forwardRef(
onClick,
tabIndex,
containerProps,
+ onColoredBg,
},
ref,
) => {
@@ -50,6 +53,7 @@ export const Tooltip = React.forwardRef(
{...containerProps}
className={classNames('ffe-tooltip', {
'ffe-tooltip--open': isOpen,
+ 'ffe-tooltip--on-colored-bg': onColoredBg,
})}
>