agroptima-design-system 0.32.3 → 0.33.0-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/package.json +1 -1
- package/src/atoms/Input.scss +1 -3
- package/src/atoms/Select/Select.tsx +1 -0
- package/src/atoms/Select/SelectTrigger.tsx +2 -7
- package/src/atoms/TabMenu/TabLink.tsx +38 -0
- package/src/atoms/TabMenu/TabMenu.scss +67 -0
- package/src/atoms/TabMenu/TabMenu.tsx +27 -0
- package/src/atoms/TabMenu/index.ts +4 -0
- package/src/stories/Changelog.mdx +2 -9
- package/src/stories/TabMenu.stories.js +53 -0
- package/tests/Multiselect.spec.tsx +2 -44
- package/tests/Select.spec.tsx +1 -43
- package/tests/TabMenu.spec.tsx +24 -0
package/package.json
CHANGED
package/src/atoms/Input.scss
CHANGED
|
@@ -87,9 +87,7 @@
|
|
|
87
87
|
&:has(textarea:disabled) {
|
|
88
88
|
border: 1px solid color_alias.$neutral-color-400;
|
|
89
89
|
background: color_alias.$neutral-color-50;
|
|
90
|
-
|
|
91
|
-
color: color_alias.$neutral-color-400;
|
|
92
|
-
}
|
|
90
|
+
color: color_alias.$neutral-color-400;
|
|
93
91
|
|
|
94
92
|
input::placeholder,
|
|
95
93
|
textarea::placeholder {
|
|
@@ -27,10 +27,6 @@ export function SelectTrigger({
|
|
|
27
27
|
isEmpty,
|
|
28
28
|
children,
|
|
29
29
|
}: SelectTriggerProps) {
|
|
30
|
-
const handleClear = (event: React.MouseEvent) => {
|
|
31
|
-
if (disabled) return
|
|
32
|
-
onClear(event)
|
|
33
|
-
}
|
|
34
30
|
return (
|
|
35
31
|
<div className="select-container">
|
|
36
32
|
<button
|
|
@@ -55,12 +51,11 @@ export function SelectTrigger({
|
|
|
55
51
|
/>
|
|
56
52
|
</button>
|
|
57
53
|
<IconButton
|
|
58
|
-
type="button"
|
|
59
54
|
size="3"
|
|
60
55
|
icon="Close"
|
|
61
56
|
className="clear-button"
|
|
62
|
-
accessibilityLabel="
|
|
63
|
-
onClick={
|
|
57
|
+
accessibilityLabel="close"
|
|
58
|
+
onClick={onClear}
|
|
64
59
|
visible={!isEmpty}
|
|
65
60
|
/>
|
|
66
61
|
</div>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import './TabMenu.scss'
|
|
2
|
+
import Link, { type LinkProps } from 'next/link'
|
|
3
|
+
import React, { type AnchorHTMLAttributes } from 'react'
|
|
4
|
+
import { classNames } from '../../utils/classNames'
|
|
5
|
+
|
|
6
|
+
export type Variant = 'primary'
|
|
7
|
+
|
|
8
|
+
type AnchorProps = AnchorHTMLAttributes<HTMLAnchorElement> & LinkProps
|
|
9
|
+
|
|
10
|
+
export interface TabLinkProps extends AnchorProps {
|
|
11
|
+
title: string
|
|
12
|
+
variant?: Variant
|
|
13
|
+
isActive?: boolean
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function TabLink({
|
|
18
|
+
variant = 'primary',
|
|
19
|
+
isActive = false,
|
|
20
|
+
disabled = false,
|
|
21
|
+
className,
|
|
22
|
+
title,
|
|
23
|
+
prefetch = false,
|
|
24
|
+
...props
|
|
25
|
+
}: TabLinkProps): React.JSX.Element {
|
|
26
|
+
const cssClasses = classNames('tabmenu-item', variant, className, {
|
|
27
|
+
active: isActive,
|
|
28
|
+
disabled,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<li tabIndex={0} role="menuitem">
|
|
33
|
+
<Link {...props} prefetch={prefetch} className={cssClasses}>
|
|
34
|
+
<span className="title">{title}</span>
|
|
35
|
+
</Link>
|
|
36
|
+
</li>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
@use '../../settings/color_alias';
|
|
2
|
+
@use '../../settings/typography/content' as typography;
|
|
3
|
+
@use '../../settings/config';
|
|
4
|
+
@use '../../settings/depth';
|
|
5
|
+
|
|
6
|
+
.tabmenu-container {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
justify-content: flex-end;
|
|
10
|
+
|
|
11
|
+
.tabmenu {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 0px;
|
|
14
|
+
z-index: 999;
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: row;
|
|
17
|
+
list-style-type: none;
|
|
18
|
+
align-items: flex-start;
|
|
19
|
+
gap: config.$space-5x;
|
|
20
|
+
padding: 0;
|
|
21
|
+
|
|
22
|
+
&-item {
|
|
23
|
+
display: flex;
|
|
24
|
+
text-decoration: none;
|
|
25
|
+
color: inherit;
|
|
26
|
+
cursor: default;
|
|
27
|
+
padding-bottom: config.$space-1x;
|
|
28
|
+
|
|
29
|
+
.title {
|
|
30
|
+
flex: 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&.primary {
|
|
34
|
+
@include typography.body-regular-primary;
|
|
35
|
+
border-bottom: 2px solid color_alias.$neutral-color-200;
|
|
36
|
+
|
|
37
|
+
&:hover {
|
|
38
|
+
color: color_alias.$primary-color-600;
|
|
39
|
+
border-bottom: 2px solid color_alias.$primary-color-600;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&.active {
|
|
43
|
+
color: color_alias.$primary-color-600;
|
|
44
|
+
border-bottom: 2px solid color_alias.$primary-color-600;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.disabled {
|
|
48
|
+
color: color_alias.$neutral-color-400;
|
|
49
|
+
border-bottom: 2px solid color_alias.$neutral-color-200;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.tabmenu-item::-webkit-details-marker {
|
|
55
|
+
display: none;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.tabmenu-divider {
|
|
60
|
+
z-index: 1;
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 28px;
|
|
63
|
+
width: 100%;
|
|
64
|
+
height: config.$space-halfx;
|
|
65
|
+
background-color: color_alias.$neutral-color-200;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import './TabMenu.scss'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { classNames } from '../../utils/classNames'
|
|
4
|
+
|
|
5
|
+
export type Variant = 'primary'
|
|
6
|
+
|
|
7
|
+
export interface TabMenuProps extends React.ComponentPropsWithoutRef<'ul'> {
|
|
8
|
+
variant?: Variant
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function TabMenu({
|
|
12
|
+
variant = 'primary',
|
|
13
|
+
className,
|
|
14
|
+
children,
|
|
15
|
+
...props
|
|
16
|
+
}: TabMenuProps): React.JSX.Element {
|
|
17
|
+
const cssClasses = classNames('tabmenu', variant, className)
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className="tabmenu-container">
|
|
21
|
+
<ul className={cssClasses} role="menu" {...props}>
|
|
22
|
+
{children}
|
|
23
|
+
</ul>
|
|
24
|
+
<div className="tabmenu-divider" />
|
|
25
|
+
</div>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -4,22 +4,15 @@ import { Meta } from "@storybook/blocks";
|
|
|
4
4
|
|
|
5
5
|
# Changelog
|
|
6
6
|
|
|
7
|
-
## 0.
|
|
8
|
-
|
|
9
|
-
* Fix send form when click on deselect button in Select component
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## 0.32.2
|
|
13
|
-
|
|
14
|
-
* Fix disabled color input
|
|
7
|
+
## 0.33.0
|
|
15
8
|
|
|
9
|
+
* Add TabMenu component
|
|
16
10
|
|
|
17
11
|
## 0.32.1
|
|
18
12
|
|
|
19
13
|
* Add reason icon
|
|
20
14
|
* Add credit note icon
|
|
21
15
|
|
|
22
|
-
|
|
23
16
|
## 0.32.0
|
|
24
17
|
|
|
25
18
|
* Make more accessible Select component.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TabLink, TabMenu } from '../atoms/TabMenu'
|
|
2
|
+
|
|
3
|
+
const figmaPrimaryDesign = {
|
|
4
|
+
design: {
|
|
5
|
+
type: 'figma',
|
|
6
|
+
url: 'https://www.figma.com/design/DN2ova21vWqCRvPspBXgI1/Design-System?node-id=4124-74&t=he01I8TeGSN2aYXP-4',
|
|
7
|
+
},
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const meta = {
|
|
11
|
+
title: 'Design System/Atoms/TabMenu',
|
|
12
|
+
component: TabMenu,
|
|
13
|
+
parameters: {
|
|
14
|
+
docs: {
|
|
15
|
+
description: {
|
|
16
|
+
component:
|
|
17
|
+
'<h2>Usage guidelines</h2><p>The TabMenu component can be used as an extra navigational hierarchy complementing the main navbar.</p><ul><li>Use concise & descriptive titles in order to ensure simplicity</li></ul>',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
figmaPrimaryDesign,
|
|
21
|
+
},
|
|
22
|
+
tags: ['autodocs'],
|
|
23
|
+
argTypes: {
|
|
24
|
+
variant: {
|
|
25
|
+
description: 'Component variant used',
|
|
26
|
+
},
|
|
27
|
+
title: {
|
|
28
|
+
description: 'Component title text',
|
|
29
|
+
},
|
|
30
|
+
isActive: {
|
|
31
|
+
description: 'Is the element active?',
|
|
32
|
+
},
|
|
33
|
+
href: {
|
|
34
|
+
description: 'Link to the page',
|
|
35
|
+
},
|
|
36
|
+
disabled: {
|
|
37
|
+
description: 'Is the TabLink disabled?',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default meta
|
|
43
|
+
|
|
44
|
+
export const Tabs = {
|
|
45
|
+
render: () => (
|
|
46
|
+
<TabMenu>
|
|
47
|
+
<TabLink title="Videogames" href="some-link" />
|
|
48
|
+
<TabLink title="Books" href="some-link" isActive />
|
|
49
|
+
<TabLink title="Cinema" href="some-link" />
|
|
50
|
+
<TabLink title="Graphic Novels" href="some-link" disabled />
|
|
51
|
+
</TabMenu>
|
|
52
|
+
),
|
|
53
|
+
}
|
|
@@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react'
|
|
|
2
2
|
import userEvent from '@testing-library/user-event'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import { Multiselect } from '../src/atoms/Multiselect'
|
|
5
|
-
import {
|
|
5
|
+
import type { Option } from '../src/atoms/Select'
|
|
6
6
|
|
|
7
7
|
const zelda = {
|
|
8
8
|
id: '1',
|
|
@@ -112,7 +112,7 @@ describe('Multiselect', () => {
|
|
|
112
112
|
/>,
|
|
113
113
|
)
|
|
114
114
|
|
|
115
|
-
await user.click(screen.getByRole('button', { name: /
|
|
115
|
+
await user.click(screen.getByRole('button', { name: /close/i }))
|
|
116
116
|
|
|
117
117
|
expect(getByText(placeholder)).toBeInTheDocument()
|
|
118
118
|
expect(mockChange).toHaveBeenCalledWith([])
|
|
@@ -143,46 +143,4 @@ describe('Multiselect', () => {
|
|
|
143
143
|
expect(queryByText('Spyro the Dragon')).not.toBeInTheDocument()
|
|
144
144
|
expect(queryByText('Halo')).not.toBeInTheDocument()
|
|
145
145
|
})
|
|
146
|
-
|
|
147
|
-
it('deselects when click on deselect button', async () => {
|
|
148
|
-
const user = userEvent.setup()
|
|
149
|
-
const placeholder = 'Select your favourite gaming system...'
|
|
150
|
-
const handleSubmit = jest.fn()
|
|
151
|
-
|
|
152
|
-
render(
|
|
153
|
-
<form onSubmit={handleSubmit}>
|
|
154
|
-
<Multiselect
|
|
155
|
-
label="Videogames"
|
|
156
|
-
name="select-videogames"
|
|
157
|
-
placeholder="Select your favourite gaming system..."
|
|
158
|
-
defaultValue={[zelda.id]}
|
|
159
|
-
options={OPTIONS}
|
|
160
|
-
/>
|
|
161
|
-
</form>,
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
await user.click(screen.getByLabelText(/clear/i))
|
|
165
|
-
|
|
166
|
-
expect(screen.getByLabelText('Videogames')).toHaveTextContent(placeholder)
|
|
167
|
-
expect(handleSubmit).toHaveBeenCalledTimes(0)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('disables deselect button when is disabled', async () => {
|
|
171
|
-
const user = userEvent.setup()
|
|
172
|
-
render(
|
|
173
|
-
<Multiselect
|
|
174
|
-
disabled
|
|
175
|
-
label="Videogames"
|
|
176
|
-
name="select-videogames"
|
|
177
|
-
defaultValue={[zelda.id]}
|
|
178
|
-
options={OPTIONS}
|
|
179
|
-
/>,
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
await user.click(screen.getByLabelText(/clear/i))
|
|
183
|
-
|
|
184
|
-
expect(screen.getByLabelText('Videogames')).toHaveTextContent(
|
|
185
|
-
/1 items selected/i,
|
|
186
|
-
)
|
|
187
|
-
})
|
|
188
146
|
})
|
package/tests/Select.spec.tsx
CHANGED
|
@@ -100,7 +100,7 @@ describe('Select', () => {
|
|
|
100
100
|
/>,
|
|
101
101
|
)
|
|
102
102
|
|
|
103
|
-
await user.click(screen.getByRole('button', { name: /
|
|
103
|
+
await user.click(screen.getByRole('button', { name: /close/i }))
|
|
104
104
|
|
|
105
105
|
expect(getByText(placeholder)).toBeInTheDocument()
|
|
106
106
|
expect(mockChange).toHaveBeenCalledWith('')
|
|
@@ -124,46 +124,4 @@ describe('Select', () => {
|
|
|
124
124
|
expect(queryByText('Nintendo Switch')).not.toBeInTheDocument()
|
|
125
125
|
expect(queryByText('Xbox Series S/X')).not.toBeInTheDocument()
|
|
126
126
|
})
|
|
127
|
-
it('deselects when click on deselect button', async () => {
|
|
128
|
-
const user = userEvent.setup()
|
|
129
|
-
const placeholder = 'Select your favourite gaming system...'
|
|
130
|
-
const handleSubmit = jest.fn()
|
|
131
|
-
|
|
132
|
-
render(
|
|
133
|
-
<form onSubmit={handleSubmit}>
|
|
134
|
-
<Select
|
|
135
|
-
label="Videogames"
|
|
136
|
-
name="select-videogames"
|
|
137
|
-
isSearchable
|
|
138
|
-
placeholder={placeholder}
|
|
139
|
-
defaultValue={playstation5.id}
|
|
140
|
-
options={OPTIONS}
|
|
141
|
-
/>
|
|
142
|
-
</form>,
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
await user.click(screen.getByLabelText(/clear/i))
|
|
146
|
-
|
|
147
|
-
expect(screen.getByLabelText('Videogames')).toHaveTextContent(placeholder)
|
|
148
|
-
expect(handleSubmit).toHaveBeenCalledTimes(0)
|
|
149
|
-
})
|
|
150
|
-
it('disables deselect button when is disabled', async () => {
|
|
151
|
-
const user = userEvent.setup()
|
|
152
|
-
render(
|
|
153
|
-
<Select
|
|
154
|
-
label="Videogames"
|
|
155
|
-
name="select-videogames"
|
|
156
|
-
isSearchable
|
|
157
|
-
disabled
|
|
158
|
-
defaultValue={playstation5.id}
|
|
159
|
-
options={OPTIONS}
|
|
160
|
-
/>,
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
await user.click(screen.getByLabelText(/clear/i))
|
|
164
|
-
|
|
165
|
-
expect(screen.getByLabelText('Videogames')).toHaveTextContent(
|
|
166
|
-
playstation5.label,
|
|
167
|
-
)
|
|
168
|
-
})
|
|
169
127
|
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { TabLink, TabMenu } from '../src/atoms/TabMenu'
|
|
4
|
+
|
|
5
|
+
describe('TabMenu', () => {
|
|
6
|
+
it('renders tabs menu', () => {
|
|
7
|
+
const { getByRole, getByText } = render(
|
|
8
|
+
<TabMenu>
|
|
9
|
+
<TabLink title="Videogames" href="some-link" />
|
|
10
|
+
<TabLink title="Books" href="some-link" isActive />
|
|
11
|
+
<TabLink title="Cinema" href="some-link" />
|
|
12
|
+
<TabLink title="Graphic Novels" href="some-link" disabled />
|
|
13
|
+
</TabMenu>,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
expect(getByRole('menu')).toHaveClass(`tabmenu primary`)
|
|
17
|
+
expect(getByRole('link', { name: 'Books' })).toHaveClass(`active`)
|
|
18
|
+
expect(getByRole('link', { name: 'Graphic Novels' })).toHaveClass(
|
|
19
|
+
`disabled`,
|
|
20
|
+
)
|
|
21
|
+
expect(getByText(/Videogames/i)).toBeInTheDocument()
|
|
22
|
+
expect(getByText(/Cinema/i)).toBeInTheDocument()
|
|
23
|
+
})
|
|
24
|
+
})
|