agroptima-design-system 0.34.8 → 0.34.9
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
CHANGED
package/src/atoms/Divider.scss
CHANGED
|
@@ -10,21 +10,27 @@ $border-line: 1px solid color_alias.$neutral-color-200;
|
|
|
10
10
|
@include typography.body_bold;
|
|
11
11
|
display: flex;
|
|
12
12
|
align-items: center;
|
|
13
|
+
gap: config.$space-3x;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
&-title {
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
.long {
|
|
19
|
-
flex: 1;
|
|
20
|
-
margin-left: config.$space-3x;
|
|
21
|
-
}
|
|
22
20
|
|
|
23
21
|
.short {
|
|
24
22
|
width: config.$space-6x;
|
|
25
23
|
margin-right: config.$space-3x;
|
|
26
24
|
}
|
|
27
25
|
|
|
26
|
+
.line {
|
|
27
|
+
border: $border-line;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.long {
|
|
31
|
+
flex: 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
.icon {
|
|
29
35
|
margin-right: config.$space-2x;
|
|
30
36
|
}
|
|
@@ -34,4 +40,8 @@ $border-line: 1px solid color_alias.$neutral-color-200;
|
|
|
34
40
|
text-decoration-line: underline;
|
|
35
41
|
cursor: default;
|
|
36
42
|
}
|
|
43
|
+
|
|
44
|
+
.iconButton {
|
|
45
|
+
margin-left: config.$space-3x;
|
|
46
|
+
}
|
|
37
47
|
}
|
package/src/atoms/Divider.tsx
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import './Divider.scss'
|
|
2
|
-
import
|
|
2
|
+
import type { ComponentPropsWithoutRef } from 'react'
|
|
3
3
|
import { classNames } from '../utils/classNames'
|
|
4
4
|
import type { IconType } from './Icon'
|
|
5
5
|
import { Icon } from './Icon'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
type DividerIconTypes = IconType | 'Line'
|
|
8
|
+
|
|
9
|
+
export interface DividerProps extends ComponentPropsWithoutRef<'div'> {
|
|
8
10
|
title: string
|
|
9
11
|
variant?: string
|
|
10
|
-
icon?:
|
|
12
|
+
icon?: DividerIconTypes
|
|
13
|
+
iconButton?: IconType
|
|
11
14
|
hasAction?: boolean
|
|
12
15
|
onClick?: () => void
|
|
13
16
|
}
|
|
@@ -18,21 +21,27 @@ export function Divider({
|
|
|
18
21
|
icon,
|
|
19
22
|
hasAction,
|
|
20
23
|
className,
|
|
24
|
+
children,
|
|
21
25
|
onClick = () => {},
|
|
22
26
|
}: DividerProps) {
|
|
23
27
|
const cssClasses = classNames('divider', variant, className)
|
|
24
28
|
|
|
25
29
|
return (
|
|
26
30
|
<div role="separator" className={cssClasses}>
|
|
27
|
-
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{title}
|
|
34
|
-
</span>
|
|
31
|
+
<div className="divider-title">
|
|
32
|
+
<DividerIcon icon={icon} />
|
|
33
|
+
<span onClick={onClick} className={classNames({ link: hasAction })}>
|
|
34
|
+
{title}
|
|
35
|
+
</span>
|
|
36
|
+
</div>
|
|
35
37
|
<div className="long line"></div>
|
|
38
|
+
{children}
|
|
36
39
|
</div>
|
|
37
40
|
)
|
|
38
41
|
}
|
|
42
|
+
|
|
43
|
+
function DividerIcon({ icon }: { icon?: DividerIconTypes }) {
|
|
44
|
+
if (!icon) return null
|
|
45
|
+
if (icon === 'Line') return <div className="short line" />
|
|
46
|
+
return <Icon className="icon" name={icon} size="3" />
|
|
47
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StoryObj } from '@storybook/react'
|
|
2
|
+
import { IconButton } from '../atoms/Button'
|
|
2
3
|
import { Divider } from '../atoms/Divider'
|
|
3
4
|
|
|
4
5
|
const meta = {
|
|
@@ -38,6 +39,15 @@ export const Primary: Story = {
|
|
|
38
39
|
args: {
|
|
39
40
|
title: '19/01/2025 - My gaming diary',
|
|
40
41
|
variant: 'primary',
|
|
42
|
+
icon: 'DeliveryNote',
|
|
43
|
+
},
|
|
44
|
+
parameters: figmaPrimaryDesign,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const WithLine: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
title: '19/01/2025 - My gaming diary',
|
|
50
|
+
icon: 'Line',
|
|
41
51
|
},
|
|
42
52
|
parameters: figmaPrimaryDesign,
|
|
43
53
|
}
|
|
@@ -46,7 +56,6 @@ export const WithIcon: Story = {
|
|
|
46
56
|
args: {
|
|
47
57
|
title: '19/01/2025 - My gaming diary',
|
|
48
58
|
icon: 'DeliveryNote',
|
|
49
|
-
variant: 'primary',
|
|
50
59
|
},
|
|
51
60
|
parameters: figmaPrimaryDesign,
|
|
52
61
|
}
|
|
@@ -60,3 +69,19 @@ export const WithLink: Story = {
|
|
|
60
69
|
},
|
|
61
70
|
parameters: figmaPrimaryDesign,
|
|
62
71
|
}
|
|
72
|
+
|
|
73
|
+
export const WithButton: Story = {
|
|
74
|
+
args: {
|
|
75
|
+
title: '19/01/2025 - My gaming diary',
|
|
76
|
+
icon: 'Delete',
|
|
77
|
+
children: <IconButton icon="Delete" accessibilityLabel="Delete" />,
|
|
78
|
+
},
|
|
79
|
+
parameters: figmaPrimaryDesign,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const NoIcon: Story = {
|
|
83
|
+
args: {
|
|
84
|
+
title: '19/01/2025 - My gaming diary',
|
|
85
|
+
},
|
|
86
|
+
parameters: figmaPrimaryDesign,
|
|
87
|
+
}
|
package/tests/Divider.spec.tsx
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
1
|
import { render } from '@testing-library/react'
|
|
2
|
+
import userEvent from '@testing-library/user-event'
|
|
3
|
+
import { IconButton } from '../src/atoms/Button'
|
|
2
4
|
import { Divider } from '../src/atoms/Divider'
|
|
3
5
|
|
|
4
6
|
describe('Divider', () => {
|
|
5
7
|
it('renders', () => {
|
|
6
|
-
const { getByRole,
|
|
7
|
-
<Divider title="A title divider" />,
|
|
8
|
+
const { getByRole, getByText, container } = render(
|
|
9
|
+
<Divider title="A title divider" icon="Line" />,
|
|
8
10
|
)
|
|
9
11
|
expect(getByRole('separator')).toHaveClass('divider primary')
|
|
10
|
-
expect(
|
|
11
|
-
expect(
|
|
12
|
+
expect(container.querySelector('.short.line')).toBeInTheDocument()
|
|
13
|
+
expect(container.querySelector('.long.line')).toBeInTheDocument()
|
|
12
14
|
expect(getByText('A title divider')).toBeInTheDocument()
|
|
13
15
|
})
|
|
14
16
|
|
|
15
17
|
it('renders with icon', () => {
|
|
16
|
-
const { getByRole,
|
|
18
|
+
const { getByRole, container, getByText } = render(
|
|
17
19
|
<Divider title="A title divider with icon" icon="DeliveryNote" />,
|
|
18
20
|
)
|
|
19
21
|
expect(getByRole('img')).toHaveClass(/icon/i)
|
|
20
|
-
expect(
|
|
22
|
+
expect(container.querySelector('.long.line')).toBeInTheDocument()
|
|
21
23
|
expect(getByText('A title divider with icon')).toBeInTheDocument()
|
|
22
24
|
})
|
|
25
|
+
|
|
26
|
+
it('renders with button', async () => {
|
|
27
|
+
const user = userEvent.setup()
|
|
28
|
+
const handleClick = jest.fn()
|
|
29
|
+
|
|
30
|
+
const { getByRole, container, getByText } = render(
|
|
31
|
+
<Divider title="A title divider with button" icon="DeliveryNote">
|
|
32
|
+
<IconButton
|
|
33
|
+
icon="Delete"
|
|
34
|
+
accessibilityLabel="Delete"
|
|
35
|
+
type="button"
|
|
36
|
+
onClick={handleClick}
|
|
37
|
+
/>
|
|
38
|
+
</Divider>,
|
|
39
|
+
)
|
|
40
|
+
await user.click(getByRole('button', { name: 'Delete' }))
|
|
41
|
+
|
|
42
|
+
expect(getByRole('img', { name: 'DeliveryNote' })).toBeInTheDocument()
|
|
43
|
+
expect(container.querySelector('.long.line')).toBeInTheDocument()
|
|
44
|
+
expect(getByText('A title divider with button')).toBeInTheDocument()
|
|
45
|
+
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
46
|
+
})
|
|
23
47
|
})
|