agroptima-design-system 0.27.0-beta.2 → 0.27.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agroptima-design-system",
3
- "version": "0.27.0-beta.2",
3
+ "version": "0.27.0",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -34,7 +34,7 @@ export function CheckableTag({
34
34
  <span
35
35
  className={cssClasses}
36
36
  role="checkbox"
37
- aria-checked={false}
37
+ aria-checked={isChecked}
38
38
  tabIndex={0}
39
39
  aria-label={props['aria-label']}
40
40
  onClick={() => onSelect(label)}
@@ -3,66 +3,43 @@
3
3
  @use '../settings/config';
4
4
 
5
5
  .checkbox-group {
6
- .checkbox-label-container {
7
- display: flex;
8
- justify-content: flex-start;
9
- align-items: center;
10
- gap: config.$space-1x;
11
-
12
- .background-icon {
13
- width: config.$icon-size-4x;
14
- height: config.$icon-size-4x;
15
- }
6
+ @include typography.checkbox-label;
7
+ display: flex;
8
+ justify-content: flex-start;
9
+ align-items: center;
10
+ gap: config.$space-1x;
11
+
12
+ .checkbox {
13
+ -webkit-appearance: none;
14
+ -moz-appearance: none;
15
+ appearance: none;
16
+ width: config.$icon-size-4x;
17
+ height: config.$icon-size-4x;
18
+ min-width: config.$icon-size-4x;
19
+ }
16
20
 
17
- .label {
18
- @include typography.checkbox-label;
19
- }
21
+ &.disabled {
22
+ @include typography.checkbox-disabled-label;
20
23
  }
21
24
 
22
25
  &.primary {
23
- input[type='checkbox'] {
24
- display: none;
25
- }
26
-
27
- input[type='checkbox'] + .checkbox-label-container .background-icon {
26
+ .checkbox {
28
27
  background: url('../icons/checkbox-primary-inactive.svg') left top
29
28
  no-repeat;
30
29
  }
31
-
32
- input[type='checkbox']:checked
33
- + .checkbox-label-container
34
- .background-icon {
30
+ .checkbox:checked {
35
31
  background: url('../icons/checkbox-primary-active.svg') left top no-repeat;
36
32
  }
37
-
38
- // Disabled
39
- input[type='checkbox']
40
- + .checkbox-label-container.disabled
41
- .background-icon {
33
+ .checkbox:disabled {
42
34
  background: url('../icons/checkbox-disabled-inactive.svg') left top
43
35
  no-repeat;
44
36
  }
45
-
46
- input[type='checkbox']:checked
47
- + .checkbox-label-container.disabled
48
- .background-icon {
37
+ .checkbox:checked:disabled {
49
38
  background: url('../icons/checkbox-disabled-active.svg') left top
50
39
  no-repeat;
51
40
  }
52
-
53
- .checkbox-label-container {
54
- &.disabled {
55
- .label {
56
- @include typography.checkbox-disabled-label;
57
- }
58
- }
59
- }
60
-
61
- // Hover
62
41
  &:hover {
63
- input[type='checkbox']:not(:checked)
64
- + .checkbox-label-container:not(.disabled)
65
- .background-icon {
42
+ .checkbox:not(:checked):not(.disabled) {
66
43
  background: url('../icons/checkbox-primary-hover-inactive.svg') left top
67
44
  no-repeat;
68
45
  }
@@ -4,45 +4,42 @@ import './Checkbox.scss'
4
4
  export type Variant = 'primary'
5
5
 
6
6
  export interface CheckboxProps extends React.ComponentPropsWithoutRef<'input'> {
7
- label?: string
7
+ label: string
8
+ accessibilityLabel?: string
8
9
  hideLabel?: boolean
9
10
  variant?: Variant
10
11
  id?: string
11
- accessibilityLabel: string
12
12
  }
13
13
 
14
14
  export function Checkbox({
15
- accessibilityLabel,
16
15
  label,
17
- hideLabel,
16
+ accessibilityLabel,
17
+ hideLabel = false,
18
18
  disabled,
19
19
  variant = 'primary',
20
20
  id,
21
21
  name,
22
+ className,
22
23
  ...props
23
24
  }: CheckboxProps) {
24
25
  const identifier = id || name
25
- const inputCss = classNames('checkbox', variant)
26
- const labelCss = classNames('checkbox-label-container', {
27
- disabled: disabled,
28
- })
29
26
 
30
27
  return (
31
- <div className={`checkbox-group ${variant}`}>
28
+ <div
29
+ className={classNames('checkbox-group', variant, className, {
30
+ disabled: disabled,
31
+ })}
32
+ >
32
33
  <input
33
34
  id={identifier}
34
35
  name={name}
35
36
  type="checkbox"
36
- className={inputCss}
37
+ className="checkbox"
37
38
  disabled={disabled}
38
- aria-label={accessibilityLabel}
39
+ aria-label={accessibilityLabel || label}
39
40
  {...props}
40
41
  />
41
-
42
- <label className={labelCss} htmlFor={identifier}>
43
- <span className="background-icon"></span>
44
- {!hideLabel && <span className="label">{label}</span>}
45
- </label>
42
+ {!hideLabel && <label htmlFor={identifier}>{label}</label>}
46
43
  </div>
47
44
  )
48
45
  }
@@ -15,6 +15,11 @@
15
15
 
16
16
  .input-label {
17
17
  @include typography.form-label;
18
+
19
+ &.is-required::after {
20
+ content: '*';
21
+ color: color_alias.$primary-color-600;
22
+ }
18
23
  }
19
24
 
20
25
  &.invalid .input-help-text {
@@ -146,4 +151,5 @@
146
151
  }
147
152
  }
148
153
  }
154
+
149
155
  }
@@ -18,6 +18,7 @@ export interface InputProps extends React.ComponentPropsWithoutRef<'input'> {
18
18
  id?: string
19
19
  suffix?: string
20
20
  errors?: string[]
21
+ required?: boolean
21
22
  }
22
23
 
23
24
  export function Input({
@@ -34,6 +35,7 @@ export function Input({
34
35
  name,
35
36
  id,
36
37
  errors,
38
+ required = false,
37
39
  ...props
38
40
  }: InputProps): React.JSX.Element {
39
41
  const identifier = id || name
@@ -62,10 +64,14 @@ export function Input({
62
64
  })}
63
65
  >
64
66
  {!hideLabel && (
65
- <label className="input-label" htmlFor={identifier}>
67
+ <label
68
+ className={classNames('input-label', required ? 'is-required' : '')}
69
+ htmlFor={identifier}
70
+ >
66
71
  {label}
67
72
  </label>
68
73
  )}
74
+
69
75
  <div className="input-container">
70
76
  {icon && <Icon className="left-icon" name={icon} />}
71
77
  <input
@@ -74,7 +80,10 @@ export function Input({
74
80
  type={handleInputType()}
75
81
  name={name}
76
82
  aria-label={accessibilityLabel || label}
77
- className={classNames({ 'primary-outlined': type === 'file' })}
83
+ required={required}
84
+ className={classNames({
85
+ 'primary-outlined': type === 'file',
86
+ })}
78
87
  {...props}
79
88
  />
80
89
  {suffix && <span className="input-suffix">{suffix}</span>}
@@ -4,12 +4,29 @@ import { Meta } from "@storybook/blocks";
4
4
 
5
5
  # Changelog
6
6
 
7
+
7
8
  # 0.27.0
8
9
 
9
10
  * Add RadioButton component.
10
11
  * Add `vertically` prop to CardsTable component in order to display the data vertically both on desktop and mobile.
11
12
  * Add `singleLine` prop to DetailItem component in order to display the data on a single line.
12
13
 
14
+ # 0.26.10
15
+
16
+ * Add required property for input
17
+
18
+ # 0.26.9
19
+
20
+ * Update Checkbox component to use input and not span
21
+
22
+ BREAKING CHANGES
23
+
24
+ * Checkbox component make label mandatory and accessibilityLabel optional
25
+
26
+ # 0.26.8
27
+
28
+ * Set check value in CheckableTag
29
+
13
30
  # 0.26.7
14
31
 
15
32
  * Fix Collapsible header padding-bottom.
@@ -15,7 +15,7 @@ describe('Checkbox', () => {
15
15
  />,
16
16
  )
17
17
  expect(getAllByRole('generic')[1]).toHaveClass(`checkbox-group ${variant}`)
18
- expect(getByRole('checkbox')).toHaveClass(`checkbox ${variant}`)
18
+ expect(getByRole('checkbox')).toHaveClass('checkbox')
19
19
  expect(getByText(/Do you like videogames/i)).toBeInTheDocument()
20
20
  })
21
21
  })
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { render, screen } from '@testing-library/react'
2
+ import { getByText, render, screen } from '@testing-library/react'
3
3
  import userEvent from '@testing-library/user-event'
4
4
  import { Input } from '@/atoms/Input'
5
5
 
@@ -87,4 +87,17 @@ describe('Input', () => {
87
87
  expect(getByRole('spinbutton')).toBeInTheDocument()
88
88
  expect(getByText('€/Bottle')).toBeInTheDocument()
89
89
  })
90
+ it('renders required input', () => {
91
+ const { getByText } = render(
92
+ <Input
93
+ helpText="This text can help you"
94
+ label="Required input"
95
+ name="input"
96
+ type="text"
97
+ required
98
+ />,
99
+ )
100
+
101
+ expect(getByText('Required input')).toHaveClass('input-label is-required')
102
+ })
90
103
  })