agroptima-design-system 0.7.0 → 0.8.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/package.json +1 -1
- package/src/atoms/Badge.scss +61 -0
- package/src/atoms/Badge.tsx +37 -0
- package/src/atoms/Button.scss +1 -0
- package/src/atoms/IconButton.scss +1 -0
- package/src/stories/Badge.stories.ts +56 -0
- package/src/stories/Changelog.stories.mdx +5 -0
- package/tests/Badge.spec.tsx +31 -0
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
@use '../settings/color_alias';
|
|
2
|
+
@use '../settings/typography/content' as typography;
|
|
3
|
+
@use '../settings/config';
|
|
4
|
+
@use '../settings/depth';
|
|
5
|
+
|
|
6
|
+
.badge {
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
align-items: center;
|
|
10
|
+
padding: 0 config.$space-2x 0.063rem config.$space-2x;
|
|
11
|
+
border: 1px solid transparent;
|
|
12
|
+
border-radius: config.$corner-radius-xxl;
|
|
13
|
+
width: fit-content;
|
|
14
|
+
text-align: center;
|
|
15
|
+
|
|
16
|
+
@include typography.footnote-primary;
|
|
17
|
+
|
|
18
|
+
&.info {
|
|
19
|
+
background: color_alias.$info-color-600;
|
|
20
|
+
color: color_alias.$neutral-white;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.success {
|
|
24
|
+
background: color_alias.$success-color-1000;
|
|
25
|
+
color: color_alias.$neutral-color-900;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&.warning {
|
|
29
|
+
background: color_alias.$warning-color-1000;
|
|
30
|
+
color: color_alias.$neutral-color-900;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&.error {
|
|
34
|
+
background: color_alias.$error-color-600;
|
|
35
|
+
color: color_alias.$neutral-white;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&.info-outlined {
|
|
39
|
+
background: color_alias.$info-color-50;
|
|
40
|
+
color: color_alias.$neutral-color-1000;
|
|
41
|
+
border: 1px solid color_alias.$info-color-1000;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.success-outlined {
|
|
45
|
+
background: color_alias.$success-color-50;
|
|
46
|
+
color: color_alias.$neutral-color-1000;
|
|
47
|
+
border: 1px solid color_alias.$success-color-300;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&.warning-outlined {
|
|
51
|
+
background: color_alias.$warning-color-50;
|
|
52
|
+
color: color_alias.$neutral-color-1000;
|
|
53
|
+
border: 1px solid color_alias.$warning-color-1000;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&.error-outlined {
|
|
57
|
+
background: color_alias.$error-color-50;
|
|
58
|
+
color: color_alias.$neutral-color-1000;
|
|
59
|
+
border: 1px solid color_alias.$error-color-1000;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import './Badge.scss'
|
|
2
|
+
|
|
3
|
+
export type Variant =
|
|
4
|
+
| 'info'
|
|
5
|
+
| 'success'
|
|
6
|
+
| 'warning'
|
|
7
|
+
| 'error'
|
|
8
|
+
| 'info-outlined'
|
|
9
|
+
| 'success-outlined'
|
|
10
|
+
| 'warning-outlined'
|
|
11
|
+
| 'error-outlined'
|
|
12
|
+
|
|
13
|
+
export interface BadgeProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
14
|
+
variant?: Variant
|
|
15
|
+
text: string
|
|
16
|
+
accessibilityLabel: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Badge({
|
|
20
|
+
variant = 'info',
|
|
21
|
+
text,
|
|
22
|
+
accessibilityLabel,
|
|
23
|
+
...props
|
|
24
|
+
}: BadgeProps): React.JSX.Element {
|
|
25
|
+
const cssClasses = ['badge', variant].join(' ')
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<span
|
|
29
|
+
className={cssClasses}
|
|
30
|
+
role="status"
|
|
31
|
+
aria-label={accessibilityLabel}
|
|
32
|
+
{...props}
|
|
33
|
+
>
|
|
34
|
+
{text}
|
|
35
|
+
</span>
|
|
36
|
+
)
|
|
37
|
+
}
|
package/src/atoms/Button.scss
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react'
|
|
2
|
+
import { Badge } from '../atoms/Badge'
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Design System/Atoms/Badge',
|
|
6
|
+
component: Badge,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
argTypes: {
|
|
9
|
+
variant: {
|
|
10
|
+
description: 'Component variant used',
|
|
11
|
+
},
|
|
12
|
+
text: {
|
|
13
|
+
description: 'Component text',
|
|
14
|
+
},
|
|
15
|
+
accessibilityLabel: {
|
|
16
|
+
description: 'Describes the component purpose',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default meta
|
|
22
|
+
type Story = StoryObj<typeof meta>
|
|
23
|
+
|
|
24
|
+
const figmaPrimaryDesign = {
|
|
25
|
+
design: {
|
|
26
|
+
type: 'figma',
|
|
27
|
+
url: 'https://www.figma.com/file/DN2ova21vWqCRvPspBXgI1/Design-System?type=design&node-id=2137-1803&mode=dev',
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const BadgeWithText: Story = {
|
|
32
|
+
args: {
|
|
33
|
+
variant: 'error',
|
|
34
|
+
text: 'Game over',
|
|
35
|
+
accessibilityLabel: 'You have lost the game',
|
|
36
|
+
},
|
|
37
|
+
parameters: figmaPrimaryDesign,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const BadgeWithNumber: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
variant: 'warning',
|
|
43
|
+
text: '1',
|
|
44
|
+
accessibilityLabel: 'There is one item to review',
|
|
45
|
+
},
|
|
46
|
+
parameters: figmaPrimaryDesign,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const BadgeWithNumbers: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
variant: 'success-outlined',
|
|
52
|
+
text: '88',
|
|
53
|
+
accessibilityLabel: 'You have earned 88 points',
|
|
54
|
+
},
|
|
55
|
+
parameters: figmaPrimaryDesign,
|
|
56
|
+
}
|
|
@@ -3,6 +3,11 @@ import { Meta } from "@storybook/addon-docs";
|
|
|
3
3
|
<Meta title="Changelog" />
|
|
4
4
|
# Changelog
|
|
5
5
|
|
|
6
|
+
## 0.8.0
|
|
7
|
+
|
|
8
|
+
- Badge component is added to Storybook.
|
|
9
|
+
- IconButton and Button have the default cursor on both link and button versions.
|
|
10
|
+
|
|
6
11
|
## 0.7.0
|
|
7
12
|
|
|
8
13
|
- Modal component is added to Storybook.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render } from '@testing-library/react'
|
|
3
|
+
import { Badge, Variant } from '@/atoms/Badge'
|
|
4
|
+
|
|
5
|
+
describe('Badge', () => {
|
|
6
|
+
const variants = [
|
|
7
|
+
'info',
|
|
8
|
+
'success',
|
|
9
|
+
'warning',
|
|
10
|
+
'error',
|
|
11
|
+
'info-outlined',
|
|
12
|
+
'succes-outlined',
|
|
13
|
+
'warning-outlined',
|
|
14
|
+
'error-outlined',
|
|
15
|
+
]
|
|
16
|
+
it.each(variants)('renders the %s variant with text', (variant) => {
|
|
17
|
+
const text = `${variant} badge text`
|
|
18
|
+
const accessibilityLabel = `${variant} badge label`
|
|
19
|
+
|
|
20
|
+
const { getByRole, getByText } = render(
|
|
21
|
+
<Badge
|
|
22
|
+
id={`${variant}-badge`}
|
|
23
|
+
accessibilityLabel={accessibilityLabel}
|
|
24
|
+
text={text}
|
|
25
|
+
variant={variant as Variant}
|
|
26
|
+
/>,
|
|
27
|
+
)
|
|
28
|
+
expect(getByText(text)).toBeInTheDocument()
|
|
29
|
+
expect(getByRole('status')).toHaveClass(`badge ${variant}`)
|
|
30
|
+
})
|
|
31
|
+
})
|