Skip to content

Commit

Permalink
feat: remove severity colors from default 'data-color' type
Browse files Browse the repository at this point in the history
  • Loading branch information
unekinn committed Feb 26, 2025
1 parent 1b1cc24 commit 01f90fd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
18 changes: 11 additions & 7 deletions packages/react/src/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ export interface MainAndSupportColors {}
* otherwise return the arbitrary string type.
*/
type ColorWithFallback<T> = MainAndSupportColors extends EmptyObject
? string & {}
? string
: T;

export type SeverityColors = 'info' | 'success' | 'warning' | 'danger';
export type SeverityInfo = 'info';
export type SeveritySuccess = 'success';
export type SeverityWarning = 'warning';
export type SeverityDanger = 'danger';
export type SeverityColors =
| SeverityInfo
| SeveritySuccess
| SeverityWarning
| SeverityDanger;

export type CustomColors = ColorWithFallback<
'neutral' | keyof MainAndSupportColors
>;

export type Color = CustomColors | ColorWithFallback<SeverityColors>;
export type Color = ColorWithFallback<'neutral' | keyof MainAndSupportColors>;
8 changes: 8 additions & 0 deletions packages/react/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type {
Color,
SeverityColors,
} from '@digdir/designsystemet-react/colors';
import cl from 'clsx/lite';
import { type HTMLAttributes, forwardRef } from 'react';
import type { DefaultProps } from '../../types';
Expand All @@ -20,6 +24,10 @@ export type BadgeProps = MergeRight<
* @default 'base'
*/
'data-variant'?: 'base' | 'tinted';
/**
* Change the color scheme of the badge
*/
'data-color'?: Color | SeverityColors;
children?: never;
}
>;
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type {
Color,
SeverityDanger,
} from '@digdir/designsystemet-react/colors';
import { Slot, Slottable } from '@radix-ui/react-slot';
import cl from 'clsx/lite';
import { forwardRef } from 'react';
Expand All @@ -14,6 +18,10 @@ export type ButtonProps = MergeRight<
* @default 'primary'
*/
variant?: 'primary' | 'secondary' | 'tertiary';
/**
* Change the color scheme of the button
*/
'data-color'?: Color | SeverityDanger;
/**
* Toggle icon only styling, pass icon as children
* @default false
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type {
Color,
SeverityColors,
} from '@digdir/designsystemet-react/colors';
import {
autoUpdate,
computePosition,
Expand Down Expand Up @@ -54,6 +58,10 @@ export type PopoverProps = MergeRight<
* @default 'default'
*/
'data-variant'?: 'default' | 'tinted';
/**
* Change the color scheme of the popover
*/
'data-color'?: Color | SeverityColors;
/**
* Callback when the popover wants to open.
*/
Expand Down
15 changes: 14 additions & 1 deletion packages/react/src/components/Tag/Tag.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import type {
Color,
SeverityColors,
} from '@digdir/designsystemet-react/colors';
import cl from 'clsx/lite';
import type { HTMLAttributes } from 'react';
import { forwardRef } from 'react';
import type { DefaultProps } from '../../types';
import type { MergeRight } from '../../utilities';

export type TagProps = DefaultProps & HTMLAttributes<HTMLSpanElement>;
export type TagProps = MergeRight<
DefaultProps & HTMLAttributes<HTMLSpanElement>,
{
/**
* Change the color scheme of the tag
*/
'data-color'?: Color | SeverityColors;
}
>;

/**
* Use `Tag` to display categories or statuses.
Expand Down

0 comments on commit 01f90fd

Please sign in to comment.