agroptima-design-system 1.2.29 → 1.2.30-beta.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/.claude/settings.local.json +7 -0
- package/.github/workflows/publish-package-to-npmjs.yml +1 -1
- package/package.json +1 -1
- package/src/atoms/Collapsible/Collapsible.tsx +3 -2
- package/src/atoms/Icon.tsx +5 -3
- package/src/icons/index.tsx +2 -2
- package/src/stories/Changelog.mdx +0 -4
- package/src/stories/Icons.mdx +2 -2
- package/tests/Collapsible.spec.tsx +1 -48
package/package.json
CHANGED
|
@@ -27,7 +27,8 @@ export function Collapsible({
|
|
|
27
27
|
onToggle,
|
|
28
28
|
...props
|
|
29
29
|
}: CollapsibleProps) {
|
|
30
|
-
const [
|
|
30
|
+
const [expanded, setExpanded] = useState(false)
|
|
31
|
+
const isOpen = controlledOpen !== undefined ? controlledOpen : expanded
|
|
31
32
|
|
|
32
33
|
const cssClasses = classNames('collapsible', variant, className, {
|
|
33
34
|
open: isOpen,
|
|
@@ -45,7 +46,7 @@ export function Collapsible({
|
|
|
45
46
|
className={cssClasses}
|
|
46
47
|
aria-label={title}
|
|
47
48
|
onToggle={(e) => {
|
|
48
|
-
|
|
49
|
+
if (controlledOpen === undefined) setExpanded(e.currentTarget.open)
|
|
49
50
|
onToggle?.(e)
|
|
50
51
|
}}
|
|
51
52
|
{...props}
|
package/src/atoms/Icon.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './Icon.scss'
|
|
2
2
|
import type { ReactNode } from 'react'
|
|
3
|
-
import
|
|
3
|
+
import { icons } from '../icons'
|
|
4
4
|
import { classNames } from '../utils/classNames'
|
|
5
5
|
export type IconType = keyof typeof icons
|
|
6
6
|
|
|
@@ -33,10 +33,12 @@ export const Icon: React.FC<IconProps> = ({
|
|
|
33
33
|
rotate: name === 'Loading',
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
+
const IconComponent = icons[name]
|
|
37
|
+
|
|
36
38
|
if (decorative) {
|
|
37
39
|
return (
|
|
38
40
|
<span aria-hidden="true" className={cssClasses}>
|
|
39
|
-
{
|
|
41
|
+
{IconComponent ? ((<IconComponent {...props} />) as ReactNode) : null}
|
|
40
42
|
</span>
|
|
41
43
|
)
|
|
42
44
|
}
|
|
@@ -48,7 +50,7 @@ export const Icon: React.FC<IconProps> = ({
|
|
|
48
50
|
title={accessibilityLabel || name}
|
|
49
51
|
className={cssClasses}
|
|
50
52
|
>
|
|
51
|
-
{
|
|
53
|
+
{IconComponent ? ((<IconComponent {...props} />) as ReactNode) : null}
|
|
52
54
|
</span>
|
|
53
55
|
)
|
|
54
56
|
}
|
package/src/icons/index.tsx
CHANGED
|
@@ -73,7 +73,7 @@ import UserMenu from './user-menu.svg'
|
|
|
73
73
|
import ValidateInvoice from './validate-invoice.svg'
|
|
74
74
|
import Warning from './warning.svg'
|
|
75
75
|
|
|
76
|
-
export {
|
|
76
|
+
export const icons = {
|
|
77
77
|
Add,
|
|
78
78
|
AddCircle,
|
|
79
79
|
AngleDown,
|
|
@@ -148,4 +148,4 @@ export {
|
|
|
148
148
|
UserMenu,
|
|
149
149
|
ValidateInvoice,
|
|
150
150
|
Warning,
|
|
151
|
-
}
|
|
151
|
+
} as const
|
package/src/stories/Icons.mdx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Meta, Title, IconGallery, IconItem } from '@storybook/addon-docs/blocks'
|
|
2
|
-
import
|
|
2
|
+
import { icons } from '../icons'
|
|
3
3
|
|
|
4
4
|
<Meta title="Design System/Styles/Icons" tags={['Styles', 'Documentation','!Components']} />
|
|
5
5
|
|
|
@@ -11,7 +11,7 @@ import * as Icons from '../icons'
|
|
|
11
11
|
|
|
12
12
|
<IconGallery>
|
|
13
13
|
{
|
|
14
|
-
Object.values(
|
|
14
|
+
Object.values(icons).map((Icon) => {
|
|
15
15
|
return(
|
|
16
16
|
<IconItem name={Icon['name'].substring(3)}>
|
|
17
17
|
<Icon />
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { render
|
|
2
|
-
import userEvent from '@testing-library/user-event'
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
3
2
|
import React from 'react'
|
|
4
3
|
import { Collapsible } from '../src/atoms/Collapsible'
|
|
5
4
|
import { Input } from '../src/atoms/Input'
|
|
@@ -25,50 +24,4 @@ describe('Collapsible', () => {
|
|
|
25
24
|
expect(getByRole('textbox')).toBeInTheDocument()
|
|
26
25
|
expect(getByRole('group')).toHaveClass(`collapsible primary open`)
|
|
27
26
|
})
|
|
28
|
-
|
|
29
|
-
it('removes the open styles when a default-open collapsible is closed', async () => {
|
|
30
|
-
const user = userEvent.setup()
|
|
31
|
-
const { getByRole } = render(
|
|
32
|
-
<Collapsible title="My personal data" name="personal-data" open>
|
|
33
|
-
<Input
|
|
34
|
-
accessibilityLabel="Fill the form name"
|
|
35
|
-
id="name_input"
|
|
36
|
-
label="Name"
|
|
37
|
-
name="name"
|
|
38
|
-
type="name"
|
|
39
|
-
variant="primary"
|
|
40
|
-
/>
|
|
41
|
-
</Collapsible>,
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
const group = getByRole('group')
|
|
45
|
-
expect(group).toHaveClass('open')
|
|
46
|
-
|
|
47
|
-
await user.click(group.querySelector('summary')!)
|
|
48
|
-
|
|
49
|
-
await waitFor(() => expect(group).not.toHaveClass('open'))
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('adds the open styles when a closed collapsible is opened', async () => {
|
|
53
|
-
const user = userEvent.setup()
|
|
54
|
-
const { getByRole } = render(
|
|
55
|
-
<Collapsible title="My personal data" name="personal-data">
|
|
56
|
-
<Input
|
|
57
|
-
accessibilityLabel="Fill the form name"
|
|
58
|
-
id="name_input"
|
|
59
|
-
label="Name"
|
|
60
|
-
name="name"
|
|
61
|
-
type="name"
|
|
62
|
-
variant="primary"
|
|
63
|
-
/>
|
|
64
|
-
</Collapsible>,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
const group = getByRole('group')
|
|
68
|
-
expect(group).not.toHaveClass('open')
|
|
69
|
-
|
|
70
|
-
await user.click(group.querySelector('summary')!)
|
|
71
|
-
|
|
72
|
-
await waitFor(() => expect(group).toHaveClass('open'))
|
|
73
|
-
})
|
|
74
27
|
})
|