agroptima-design-system 1.2.38-beta.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agroptima-design-system",
3
- "version": "1.2.38-beta.1",
3
+ "version": "1.2.38-beta.2",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ import { CheckboxWithDivider } from './CheckboxWithDivider'
2
+
3
+ export type { CheckboxWithDividerProps } from './CheckboxWithDivider'
4
+ export { CheckboxWithDivider }
@@ -19,10 +19,6 @@ $border-line: 1px solid var(--neutral-color-200);
19
19
  &-title {
20
20
  display: flex;
21
21
  align-items: center;
22
-
23
- .checkbox-group {
24
- margin-right: config.$space-2x;
25
- }
26
22
  }
27
23
 
28
24
  .short {
@@ -1,26 +1,17 @@
1
1
  import './Divider.scss'
2
2
  import type { ComponentPropsWithoutRef } from 'react'
3
3
  import { classNames } from '../utils/classNames'
4
- import { Checkbox } from './Checkbox'
5
4
  import type { IconType } from './Icon'
6
5
  import { Icon } from './Icon'
7
6
 
8
7
  type DividerIconTypes = IconType | 'Line'
9
8
 
10
- export interface DividerCheckboxProps {
11
- name: string
12
- checked: boolean
13
- indeterminate?: boolean
14
- onChange: () => void
15
- }
16
-
17
9
  export interface DividerProps extends ComponentPropsWithoutRef<'div'> {
18
10
  title?: string
19
11
  variant?: string
20
12
  icon?: DividerIconTypes
21
13
  iconButton?: IconType
22
14
  hasAction?: boolean
23
- checkbox?: DividerCheckboxProps
24
15
  onClick?: () => void
25
16
  }
26
17
 
@@ -28,7 +19,6 @@ export function Divider({
28
19
  title,
29
20
  variant = 'primary',
30
21
  icon,
31
- checkbox,
32
22
  hasAction,
33
23
  className,
34
24
  children,
@@ -39,27 +29,12 @@ export function Divider({
39
29
  return (
40
30
  <div className="divider-container">
41
31
  <div role="separator" className={cssClasses}>
42
- {(title || checkbox) && (
32
+ {title && (
43
33
  <div className="divider-title">
44
- {checkbox ? (
45
- <Checkbox
46
- name={checkbox.name}
47
- checked={checkbox.checked}
48
- indeterminate={checkbox.indeterminate}
49
- onChange={checkbox.onChange}
50
- hideLabel
51
- />
52
- ) : (
53
- <DividerIcon icon={icon} />
54
- )}
55
- {title && (
56
- <span
57
- onClick={onClick}
58
- className={classNames({ link: hasAction })}
59
- >
60
- {title}
61
- </span>
62
- )}
34
+ <DividerIcon icon={icon} />
35
+ <span onClick={onClick} className={classNames({ link: hasAction })}>
36
+ {title}
37
+ </span>
63
38
  </div>
64
39
  )}
65
40
  <div className="long line"></div>
@@ -6,7 +6,7 @@ import { Meta } from "@storybook/addon-docs/blocks";
6
6
 
7
7
  ## 1.2.38
8
8
 
9
- * Add `checkbox` variant to Divider component
9
+ * Add CheckboxWithDivider component
10
10
 
11
11
  ## 1.2.37
12
12
 
@@ -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
+ }
@@ -93,15 +93,3 @@ export const NoIcon: Story = {
93
93
  export const NoTitle: Story = {
94
94
  parameters: figmaPrimaryDesign,
95
95
  }
96
-
97
- export const WithCheckbox: Story = {
98
- args: {
99
- title: '19/01/2025 - My gaming diary',
100
- checkbox: {
101
- name: 'select-all',
102
- checked: false,
103
- onChange: () => alert('change'),
104
- },
105
- },
106
- parameters: figmaPrimaryDesign,
107
- }
@@ -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
+ })
@@ -50,43 +50,4 @@ describe('Divider', () => {
50
50
  expect(getByRole('separator')).toHaveClass('divider primary')
51
51
  expect(container.querySelector('.long.line')).toBeInTheDocument()
52
52
  })
53
-
54
- it('renders with checkbox', async () => {
55
- const user = userEvent.setup()
56
- const handleChange = jest.fn()
57
-
58
- const { getByRole, getByText } = render(
59
- <Divider
60
- title="A title divider with checkbox"
61
- checkbox={{
62
- name: 'select-all',
63
- checked: false,
64
- onChange: handleChange,
65
- }}
66
- />,
67
- )
68
-
69
- expect(getByRole('checkbox')).toBeInTheDocument()
70
- expect(getByText('A title divider with checkbox')).toBeInTheDocument()
71
-
72
- await user.click(getByRole('checkbox'))
73
-
74
- expect(handleChange).toHaveBeenCalledTimes(1)
75
- })
76
-
77
- it('renders checkbox as indeterminate', () => {
78
- const { getByRole } = render(
79
- <Divider
80
- title="Indeterminate divider"
81
- checkbox={{
82
- name: 'select-all',
83
- checked: true,
84
- indeterminate: true,
85
- onChange: () => {},
86
- }}
87
- />,
88
- )
89
-
90
- expect(getByRole('checkbox')).toBeChecked()
91
- })
92
53
  })