agroptima-design-system 1.2.37 → 1.2.38-beta.1

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.37",
3
+ "version": "1.2.38-beta.1",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -19,6 +19,10 @@ $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
+ }
22
26
  }
23
27
 
24
28
  .short {
@@ -1,17 +1,26 @@
1
1
  import './Divider.scss'
2
2
  import type { ComponentPropsWithoutRef } from 'react'
3
3
  import { classNames } from '../utils/classNames'
4
+ import { Checkbox } from './Checkbox'
4
5
  import type { IconType } from './Icon'
5
6
  import { Icon } from './Icon'
6
7
 
7
8
  type DividerIconTypes = IconType | 'Line'
8
9
 
10
+ export interface DividerCheckboxProps {
11
+ name: string
12
+ checked: boolean
13
+ indeterminate?: boolean
14
+ onChange: () => void
15
+ }
16
+
9
17
  export interface DividerProps extends ComponentPropsWithoutRef<'div'> {
10
18
  title?: string
11
19
  variant?: string
12
20
  icon?: DividerIconTypes
13
21
  iconButton?: IconType
14
22
  hasAction?: boolean
23
+ checkbox?: DividerCheckboxProps
15
24
  onClick?: () => void
16
25
  }
17
26
 
@@ -19,6 +28,7 @@ export function Divider({
19
28
  title,
20
29
  variant = 'primary',
21
30
  icon,
31
+ checkbox,
22
32
  hasAction,
23
33
  className,
24
34
  children,
@@ -29,12 +39,27 @@ export function Divider({
29
39
  return (
30
40
  <div className="divider-container">
31
41
  <div role="separator" className={cssClasses}>
32
- {title && (
42
+ {(title || checkbox) && (
33
43
  <div className="divider-title">
34
- <DividerIcon icon={icon} />
35
- <span onClick={onClick} className={classNames({ link: hasAction })}>
36
- {title}
37
- </span>
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
+ )}
38
63
  </div>
39
64
  )}
40
65
  <div className="long line"></div>
@@ -4,6 +4,10 @@ import { Meta } from "@storybook/addon-docs/blocks";
4
4
 
5
5
  # Changelog
6
6
 
7
+ ## 1.2.38
8
+
9
+ * Add `checkbox` variant to Divider component
10
+
7
11
  ## 1.2.37
8
12
 
9
13
  * Add mobile-cell-label and mobile-cell-highlight styles to CardsTable. Add a new related story as an example.
@@ -93,3 +93,15 @@ 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
+ }
@@ -50,4 +50,43 @@ 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
+ })
53
92
  })