@hyphen/hyphen-components 7.4.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/index.css +21 -1
- package/dist/css/utilities.css +73 -1
- package/dist/css/variables.css +26 -2
- package/dist/hyphen-components.cjs.development.js +2 -2
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +2 -2
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +2 -2
- package/dist/hyphen-components.esm.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/Badge/Badge.mdx +33 -28
- package/src/components/Badge/Badge.module.scss +25 -1
- package/src/components/Badge/Badge.stories.tsx +39 -3
- package/src/components/Badge/Badge.test.tsx +14 -1
- package/src/components/Badge/Badge.tsx +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -411,7 +411,7 @@ declare const Box: FC<BoxProps>;
|
|
|
411
411
|
declare const boxPropsKeys: (keyof Pick<BoxProps, KnownKeys<BoxProps>>)[];
|
|
412
412
|
|
|
413
413
|
type BadgeSize = 'sm' | 'md' | 'lg';
|
|
414
|
-
type BadgeVariant = 'light-grey' | 'dark-grey' | 'inverse' | 'green' | 'yellow' | 'blue' | 'red' | 'purple' | 'orange' | 'hyphen';
|
|
414
|
+
type BadgeVariant = 'default' | 'secondary' | 'danger' | 'outline' | 'light-grey' | 'dark-grey' | 'inverse' | 'green' | 'yellow' | 'blue' | 'red' | 'purple' | 'orange' | 'hyphen';
|
|
415
415
|
interface BadgeProps extends BoxProps {
|
|
416
416
|
/**
|
|
417
417
|
* @deprecated Use children instead. The text message or ReactNode to be rendered in the badge.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyphen/hyphen-components",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "@hyphen"
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@emotion/react": "^11.14.0",
|
|
61
|
-
"@hyphen/hyphen-design-tokens": "^7.
|
|
61
|
+
"@hyphen/hyphen-design-tokens": "^7.5.1",
|
|
62
62
|
"@radix-ui/react-aspect-ratio": "^1.1.8",
|
|
63
63
|
"@radix-ui/react-collapsible": "^1.1.12",
|
|
64
64
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import { Canvas, Meta, ArgTypes } from '@storybook/addon-docs/blocks';
|
|
2
|
-
import { Badge } from './Badge';
|
|
3
|
-
import * as Stories from './Badge.stories';
|
|
4
|
-
|
|
5
|
-
<Meta of={Stories} />
|
|
6
|
-
|
|
7
|
-
# Badge
|
|
8
|
-
|
|
9
|
-
Badges are used to display the status of an object or of an action that’s been taken.
|
|
10
|
-
|
|
11
|
-
<Canvas of={Stories.Overview} />
|
|
12
|
-
|
|
13
|
-
## Props
|
|
14
|
-
|
|
15
|
-
<ArgTypes of={Badge} />
|
|
16
|
-
|
|
17
|
-
## Variants
|
|
18
|
-
|
|
19
|
-
Badges come in different variants based on the kind of message being delivered to the user.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { Canvas, Meta, ArgTypes } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import { Badge } from './Badge';
|
|
3
|
+
import * as Stories from './Badge.stories';
|
|
4
|
+
|
|
5
|
+
<Meta of={Stories} />
|
|
6
|
+
|
|
7
|
+
# Badge
|
|
8
|
+
|
|
9
|
+
Badges are used to display the status of an object or of an action that’s been taken.
|
|
10
|
+
|
|
11
|
+
<Canvas of={Stories.Overview} />
|
|
12
|
+
|
|
13
|
+
## Props
|
|
14
|
+
|
|
15
|
+
<ArgTypes of={Badge} />
|
|
16
|
+
|
|
17
|
+
## Variants
|
|
18
|
+
|
|
19
|
+
Badges come in different variants based on the kind of message being delivered to the user.
|
|
20
|
+
If the `variant` prop is omitted, the badge uses the theme-aware `default` variant.
|
|
21
|
+
|
|
22
|
+
<Canvas of={Stories.Variants} />
|
|
23
|
+
|
|
24
|
+
Fixed-color badge variants remain available when you want the same color treatment regardless of theme.
|
|
25
|
+
|
|
26
|
+
<Canvas of={Stories.FixedColorVariants} />
|
|
27
|
+
|
|
28
|
+
## Sizes
|
|
29
|
+
|
|
30
|
+
Set the size of the badge to `sm`, `md`, or `lg`. `md` is the default size. A `ResponsiveProp` object may also be used
|
|
31
|
+
so the badge can be a different size per breakpoint.
|
|
32
|
+
|
|
33
|
+
<Canvas of={Stories.Sizes} />
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
.badge {
|
|
43
43
|
border-style: solid;
|
|
44
44
|
border-width: var(--size-border-width-sm);
|
|
45
|
-
font-weight: var(--size-font-weight-
|
|
45
|
+
font-weight: var(--size-font-weight-medium);
|
|
46
46
|
line-height: var(--size-line-height-base);
|
|
47
47
|
|
|
48
48
|
&.inverse {
|
|
@@ -51,6 +51,30 @@
|
|
|
51
51
|
color: var(--color-font-inverse);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
&.default {
|
|
55
|
+
background-color: var(--color-background-badge-default);
|
|
56
|
+
border-color: var(--color-border-badge-default);
|
|
57
|
+
color: var(--color-font-badge-default);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
&.secondary {
|
|
61
|
+
background-color: var(--color-background-badge-secondary);
|
|
62
|
+
border-color: var(--color-border-badge-secondary);
|
|
63
|
+
color: var(--color-font-badge-secondary);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&.danger {
|
|
67
|
+
background-color: var(--color-background-badge-danger);
|
|
68
|
+
border-color: var(--color-border-badge-danger);
|
|
69
|
+
color: var(--color-font-badge-danger);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
&.outline {
|
|
73
|
+
background-color: var(--color-background-badge-outline);
|
|
74
|
+
border-color: var(--color-border-badge-outline);
|
|
75
|
+
color: var(--color-font-badge-outline);
|
|
76
|
+
}
|
|
77
|
+
|
|
54
78
|
&.purple {
|
|
55
79
|
background-color: var(--color-base-purple-500);
|
|
56
80
|
border-color: var(--color-base-purple-600);
|
|
@@ -2,8 +2,16 @@ import { Badge, BadgeVariant } from './Badge';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Box } from '../Box/Box';
|
|
4
4
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
5
|
+
import { allModes } from '../../modes';
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const SEMANTIC_BADGE_VARIANTS: BadgeVariant[] = [
|
|
8
|
+
'default',
|
|
9
|
+
'secondary',
|
|
10
|
+
'danger',
|
|
11
|
+
'outline',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const FIXED_COLOR_BADGE_VARIANTS: BadgeVariant[] = [
|
|
7
15
|
'light-grey',
|
|
8
16
|
'dark-grey',
|
|
9
17
|
'inverse',
|
|
@@ -16,6 +24,11 @@ const BADGE_VARIANTS: BadgeVariant[] = [
|
|
|
16
24
|
'hyphen',
|
|
17
25
|
];
|
|
18
26
|
|
|
27
|
+
const BADGE_VARIANTS: BadgeVariant[] = [
|
|
28
|
+
...SEMANTIC_BADGE_VARIANTS,
|
|
29
|
+
...FIXED_COLOR_BADGE_VARIANTS,
|
|
30
|
+
];
|
|
31
|
+
|
|
19
32
|
const BADGE_SIZES = ['sm', 'md', 'lg'];
|
|
20
33
|
|
|
21
34
|
const meta: Meta<typeof Badge> = {
|
|
@@ -47,12 +60,20 @@ const meta: Meta<typeof Badge> = {
|
|
|
47
60
|
},
|
|
48
61
|
},
|
|
49
62
|
args: {
|
|
50
|
-
variant: '
|
|
63
|
+
variant: 'default',
|
|
51
64
|
size: 'md',
|
|
52
65
|
message: '',
|
|
53
66
|
className: '',
|
|
54
67
|
children: undefined,
|
|
55
68
|
},
|
|
69
|
+
parameters: {
|
|
70
|
+
chromatic: {
|
|
71
|
+
modes: {
|
|
72
|
+
light: allModes['light'],
|
|
73
|
+
dark: allModes['dark'],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
56
77
|
};
|
|
57
78
|
|
|
58
79
|
export default meta;
|
|
@@ -68,7 +89,22 @@ export const Overview: Story = {
|
|
|
68
89
|
export const Variants: Story = {
|
|
69
90
|
render: () => (
|
|
70
91
|
<Box direction="row" gap="sm">
|
|
71
|
-
{
|
|
92
|
+
{SEMANTIC_BADGE_VARIANTS.map((variant) => (
|
|
93
|
+
<Badge variant={variant} key={variant}>
|
|
94
|
+
{variant}
|
|
95
|
+
</Badge>
|
|
96
|
+
))}
|
|
97
|
+
</Box>
|
|
98
|
+
),
|
|
99
|
+
parameters: {
|
|
100
|
+
controls: { disable: true },
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const FixedColorVariants: Story = {
|
|
105
|
+
render: () => (
|
|
106
|
+
<Box direction="row" gap="sm" flexWrap="wrap">
|
|
107
|
+
{FIXED_COLOR_BADGE_VARIANTS.map((variant) => (
|
|
72
108
|
<Badge variant={variant} key={variant}>
|
|
73
109
|
{variant}
|
|
74
110
|
</Badge>
|
|
@@ -3,6 +3,10 @@ import { render, screen } from '@testing-library/react';
|
|
|
3
3
|
import { Badge, BadgeSize, BadgeVariant } from './Badge';
|
|
4
4
|
|
|
5
5
|
export const BADGE_VARIANTS: BadgeVariant[] = [
|
|
6
|
+
'default',
|
|
7
|
+
'secondary',
|
|
8
|
+
'danger',
|
|
9
|
+
'outline',
|
|
6
10
|
'light-grey',
|
|
7
11
|
'dark-grey',
|
|
8
12
|
'inverse',
|
|
@@ -18,10 +22,19 @@ export const BADGE_VARIANTS: BadgeVariant[] = [
|
|
|
18
22
|
export const BADGE_SIZES: BadgeSize[] = ['sm', 'md', 'lg'];
|
|
19
23
|
|
|
20
24
|
describe('Badge', () => {
|
|
21
|
-
test('
|
|
25
|
+
test('Badge correctly renders with base props', () => {
|
|
22
26
|
render(<Badge message="hello" />);
|
|
23
27
|
const badge = screen.getByText('hello');
|
|
24
28
|
expect(badge).toBeInTheDocument();
|
|
29
|
+
expect(badge.getAttribute('class')).toContain('default');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('it applies the default variant when none is provided', () => {
|
|
33
|
+
render(<Badge>Badge</Badge>);
|
|
34
|
+
const badge = screen.getByText('Badge');
|
|
35
|
+
|
|
36
|
+
expect(badge.getAttribute('class')).toContain('default');
|
|
37
|
+
expect(badge.getAttribute('class')).not.toContain('light-grey');
|
|
25
38
|
});
|
|
26
39
|
|
|
27
40
|
describe('Variants', () => {
|
|
@@ -8,6 +8,10 @@ import { Box, BoxProps } from '../Box/Box';
|
|
|
8
8
|
export type BadgeSize = 'sm' | 'md' | 'lg';
|
|
9
9
|
|
|
10
10
|
export type BadgeVariant =
|
|
11
|
+
| 'default'
|
|
12
|
+
| 'secondary'
|
|
13
|
+
| 'danger'
|
|
14
|
+
| 'outline'
|
|
11
15
|
| 'light-grey'
|
|
12
16
|
| 'dark-grey'
|
|
13
17
|
| 'inverse'
|
|
@@ -39,7 +43,7 @@ export const Badge = forwardRef<HTMLDivElement, BadgeProps>(
|
|
|
39
43
|
{
|
|
40
44
|
className = '',
|
|
41
45
|
message = '',
|
|
42
|
-
variant = '
|
|
46
|
+
variant = 'default',
|
|
43
47
|
size = 'md',
|
|
44
48
|
children,
|
|
45
49
|
...restProps
|