agroptima-design-system 1.2.38-beta.0 → 1.2.38-beta.2
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/CheckboxWithDivider/CheckboxWithDivider.scss +17 -0
- package/src/atoms/CheckboxWithDivider/CheckboxWithDivider.tsx +31 -0
- package/src/atoms/CheckboxWithDivider/index.ts +4 -0
- package/src/atoms/Modal/ModalDialog.tsx +1 -3
- package/src/stories/Changelog.mdx +4 -0
- package/src/stories/CheckboxWithDivider.stories.tsx +48 -0
- package/src/stories/Modal.stories.tsx +1 -1
- package/tests/CheckboxWithDivider.spec.tsx +64 -0
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
@use '../../settings/typography/content' as typography;
|
|
2
|
+
@use '../../settings/config';
|
|
3
|
+
|
|
4
|
+
.checkbox-with-divider {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
gap: config.$space-3x;
|
|
8
|
+
|
|
9
|
+
.form-label {
|
|
10
|
+
@include typography.body-bold;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.long.line {
|
|
14
|
+
flex: 1;
|
|
15
|
+
border: 1px solid var(--neutral-color-200);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import './CheckboxWithDivider.scss'
|
|
2
|
+
import type { CheckboxProps } from '../Checkbox'
|
|
3
|
+
import { Checkbox } from '../Checkbox'
|
|
4
|
+
|
|
5
|
+
export interface CheckboxWithDividerProps extends Omit<
|
|
6
|
+
CheckboxProps,
|
|
7
|
+
'checked'
|
|
8
|
+
> {
|
|
9
|
+
title: string
|
|
10
|
+
checked: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function CheckboxWithDivider({
|
|
14
|
+
title,
|
|
15
|
+
accessibilityLabel,
|
|
16
|
+
className,
|
|
17
|
+
...props
|
|
18
|
+
}: CheckboxWithDividerProps) {
|
|
19
|
+
return (
|
|
20
|
+
<div className="checkbox-with-divider">
|
|
21
|
+
<Checkbox
|
|
22
|
+
accessibilityLabel={accessibilityLabel || title}
|
|
23
|
+
className={className}
|
|
24
|
+
{...props}
|
|
25
|
+
>
|
|
26
|
+
{title}
|
|
27
|
+
</Checkbox>
|
|
28
|
+
<div className="long line" />
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -29,8 +29,6 @@ export function ModalDialog({
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
useEffect(() => {
|
|
32
|
-
if (!isOpen) return
|
|
33
|
-
|
|
34
32
|
keepScrollbarSpace()
|
|
35
33
|
window.addEventListener('resize', keepScrollbarSpace)
|
|
36
34
|
|
|
@@ -38,7 +36,7 @@ export function ModalDialog({
|
|
|
38
36
|
removeScrollbarSpace()
|
|
39
37
|
window.removeEventListener('resize', keepScrollbarSpace)
|
|
40
38
|
}
|
|
41
|
-
}, [
|
|
39
|
+
}, [])
|
|
42
40
|
|
|
43
41
|
useEffect(() => {
|
|
44
42
|
const dialog = dialogRef.current
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/nextjs'
|
|
2
|
+
import { CheckboxWithDivider } from '../atoms/CheckboxWithDivider'
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Design System/Atoms/CheckboxWithDivider',
|
|
6
|
+
component: CheckboxWithDivider,
|
|
7
|
+
parameters: {
|
|
8
|
+
docs: {
|
|
9
|
+
description: {
|
|
10
|
+
component:
|
|
11
|
+
'<h2>Usage guidelines</h2>' +
|
|
12
|
+
'<p>A CheckboxWithDivider combines a Checkbox with a divider line, used as a selectable group header (e.g. "select all" on a list of items).</p>',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
tags: ['autodocs', 'Layout components'],
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default meta
|
|
20
|
+
type Story = StoryObj<typeof meta>
|
|
21
|
+
|
|
22
|
+
export const Default: Story = {
|
|
23
|
+
args: {
|
|
24
|
+
title: '19/01/2025 - My gaming diary',
|
|
25
|
+
name: 'select-all',
|
|
26
|
+
checked: false,
|
|
27
|
+
onChange: () => console.log('change'),
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const Checked: Story = {
|
|
32
|
+
args: {
|
|
33
|
+
title: '19/01/2025 - My gaming diary',
|
|
34
|
+
name: 'select-all',
|
|
35
|
+
checked: true,
|
|
36
|
+
onChange: () => console.log('change'),
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const Indeterminate: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
title: '19/01/2025 - My gaming diary',
|
|
43
|
+
name: 'select-all',
|
|
44
|
+
checked: true,
|
|
45
|
+
indeterminate: true,
|
|
46
|
+
onChange: () => console.log('change'),
|
|
47
|
+
},
|
|
48
|
+
}
|
|
@@ -37,7 +37,7 @@ const meta = {
|
|
|
37
37
|
' <li>Require a response from the user</li>' +
|
|
38
38
|
' <li>Notify the user of any related information</li>' +
|
|
39
39
|
' <li>Confirm a user decision</li>' +
|
|
40
|
-
" <li>It's opened/closed through `isOpen` prop
|
|
40
|
+
" <li>It's opened/closed through `isOpen` prop. If we don't want it to be part of the DOM, we can also add a conditional render on the frontend project.</li>" +
|
|
41
41
|
' <li>Natively, focus is set on the first nested focusable element and explicitly indicated by default by the browser</li>' +
|
|
42
42
|
" <li>When nesting a Form inside Modal component, remember to add `type='button'` to all Cancel buttons to not to be considered as submitable</li>" +
|
|
43
43
|
'</ul>',
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import userEvent from '@testing-library/user-event'
|
|
3
|
+
import { CheckboxWithDivider } from '../src/atoms/CheckboxWithDivider'
|
|
4
|
+
|
|
5
|
+
describe('CheckboxWithDivider', () => {
|
|
6
|
+
it('renders the title and a divider line', () => {
|
|
7
|
+
const { getByRole, getByText, container } = render(
|
|
8
|
+
<CheckboxWithDivider
|
|
9
|
+
title="19/01/2025 - My gaming diary"
|
|
10
|
+
name="select-all"
|
|
11
|
+
checked={false}
|
|
12
|
+
/>,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
expect(getByRole('checkbox')).toBeInTheDocument()
|
|
16
|
+
expect(getByText('19/01/2025 - My gaming diary')).toBeInTheDocument()
|
|
17
|
+
expect(container.querySelector('.long.line')).toBeInTheDocument()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('toggles when clicking the title, thanks to the native label', async () => {
|
|
21
|
+
const user = userEvent.setup()
|
|
22
|
+
const handleChange = jest.fn()
|
|
23
|
+
|
|
24
|
+
const { getByText } = render(
|
|
25
|
+
<CheckboxWithDivider
|
|
26
|
+
title="19/01/2025 - My gaming diary"
|
|
27
|
+
name="select-all"
|
|
28
|
+
checked={false}
|
|
29
|
+
onChange={handleChange}
|
|
30
|
+
/>,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
await user.click(getByText('19/01/2025 - My gaming diary'))
|
|
34
|
+
|
|
35
|
+
expect(handleChange).toHaveBeenCalledTimes(1)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('renders as indeterminate', () => {
|
|
39
|
+
const { getByRole } = render(
|
|
40
|
+
<CheckboxWithDivider
|
|
41
|
+
title="19/01/2025 - My gaming diary"
|
|
42
|
+
name="select-all"
|
|
43
|
+
checked
|
|
44
|
+
indeterminate
|
|
45
|
+
/>,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
expect(getByRole('checkbox')).toBeChecked()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('falls back to the title as the accessible name', () => {
|
|
52
|
+
const { getByRole } = render(
|
|
53
|
+
<CheckboxWithDivider
|
|
54
|
+
title="19/01/2025 - My gaming diary"
|
|
55
|
+
name="select-all"
|
|
56
|
+
checked={false}
|
|
57
|
+
/>,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
expect(
|
|
61
|
+
getByRole('checkbox', { name: '19/01/2025 - My gaming diary' }),
|
|
62
|
+
).toBeInTheDocument()
|
|
63
|
+
})
|
|
64
|
+
})
|