agroptima-design-system 0.30.1 → 0.30.2-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agroptima-design-system",
3
- "version": "0.30.1",
3
+ "version": "0.30.2-beta.0",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -2,13 +2,13 @@ import './Input.scss'
2
2
  import React, { useState } from 'react'
3
3
  import { buildHelpText } from '../utils/buildHelpText'
4
4
  import { classNames } from '../utils/classNames'
5
- import { IconButton } from './Button/IconButton'
5
+ import { IconButton } from './Button'
6
6
  import type { IconType } from './Icon'
7
7
  import { Icon } from './Icon'
8
8
 
9
9
  export type InputVariant = 'primary'
10
10
 
11
- export interface InputProps extends React.ComponentPropsWithoutRef<'input'> {
11
+ export interface InputProps extends React.ComponentPropsWithRef<'input'> {
12
12
  label: string
13
13
  accessibilityLabel?: string
14
14
  hideLabel?: boolean
@@ -1,5 +1,5 @@
1
1
  import './QuantitySelector.scss'
2
- import React from 'react'
2
+ import React, { useRef } from 'react'
3
3
  import { classNames } from '../utils/classNames'
4
4
  import { Button } from './Button'
5
5
  import type { InputProps } from './Input'
@@ -7,28 +7,38 @@ import { Input } from './Input'
7
7
 
8
8
  export type Variant = 'primary'
9
9
 
10
- export interface QuantitySelectorProps extends InputProps {
10
+ export interface QuantitySelectorProps extends Omit<InputProps, 'type'> {
11
11
  label: string
12
12
  accessibilityLabel?: string
13
13
  hideLabel?: boolean
14
14
  id?: string
15
15
  variant?: Variant
16
- onDecrement: () => void
17
- onIncrement: () => void
18
16
  }
19
17
 
20
18
  export function QuantitySelector({
21
19
  id,
22
- onDecrement,
23
- onIncrement,
24
20
  label,
25
21
  accessibilityLabel,
26
22
  className,
23
+ disabled,
27
24
  hideLabel = false,
28
25
  variant = 'primary',
29
- disabled,
30
26
  ...props
31
27
  }: QuantitySelectorProps): React.JSX.Element {
28
+ const inputRef = useRef<HTMLInputElement>(null)
29
+ const handleIncrement = () => {
30
+ if (inputRef.current) {
31
+ inputRef.current.stepUp()
32
+ inputRef.current.dispatchEvent(new Event('input', { bubbles: true }))
33
+ }
34
+ }
35
+
36
+ const handleDecrement = () => {
37
+ if (inputRef.current) {
38
+ inputRef.current.stepDown()
39
+ inputRef.current.dispatchEvent(new Event('input', { bubbles: true }))
40
+ }
41
+ }
32
42
  return (
33
43
  <div className={classNames('quantity-selector-group', variant, className)}>
34
44
  {!hideLabel && (
@@ -49,13 +59,15 @@ export function QuantitySelector({
49
59
  leftIcon="Minus"
50
60
  className="decrement-button"
51
61
  disabled={disabled}
52
- onClick={onDecrement}
62
+ onClick={handleDecrement}
53
63
  />
54
64
  <Input
55
65
  id={id}
66
+ ref={inputRef}
56
67
  label={label}
57
68
  accessibilityLabel={accessibilityLabel}
58
69
  disabled={disabled}
70
+ type="number"
59
71
  {...props}
60
72
  hideLabel={true}
61
73
  />
@@ -66,7 +78,7 @@ export function QuantitySelector({
66
78
  type="button"
67
79
  className="increment-button"
68
80
  disabled={disabled}
69
- onClick={onIncrement}
81
+ onClick={handleIncrement}
70
82
  />
71
83
  </div>
72
84
  </div>
@@ -4,6 +4,14 @@ import { Meta } from "@storybook/blocks";
4
4
 
5
5
  # Changelog
6
6
 
7
+ ## 0.30.2
8
+
9
+ * Use native increment and decrement buttons on QuantitySelector component.
10
+
11
+ BREAKING CHANGES
12
+
13
+ * Remove onIncrement and onDecrement props from QuantitySelector component.
14
+
7
15
  ## 0.30.1
8
16
 
9
17
  * Add components documentation
@@ -62,15 +62,11 @@ export const Primary: Story = {
62
62
  id: 'quantity',
63
63
  hideLabel: true,
64
64
  name: 'quantity',
65
- value: 1,
66
- onChange: () => alert('onChange'),
67
- type: 'number',
68
65
  max: 10,
69
66
  step: 0.0001,
70
67
  min: 1,
71
68
  required: true,
72
- onDecrement: () => alert('decrement'),
73
- onIncrement: () => alert('increment'),
69
+ defaultValue: 1,
74
70
  },
75
71
  parameters: figmaPrimaryDesign,
76
72
  }
@@ -81,16 +77,13 @@ export const Disabled: Story = {
81
77
  accessibilityLabel: 'Quantity of items to wishlist',
82
78
  id: 'quantity',
83
79
  name: 'quantity',
84
- value: 1,
80
+ defaultValue: 1,
85
81
  onChange: () => alert('onChange'),
86
- type: 'number',
87
82
  max: 10,
88
83
  step: 0.0001,
89
84
  min: 1,
90
85
  required: true,
91
86
  disabled: true,
92
- onDecrement: () => alert('decrement'),
93
- onIncrement: () => alert('increment'),
94
87
  },
95
88
  parameters: figmaPrimaryDesign,
96
89
  }
@@ -1,4 +1,5 @@
1
1
  import { render } from '@testing-library/react'
2
+ import userEvent from '@testing-library/user-event'
2
3
  import { QuantitySelector } from '../src/atoms/QuantitySelector'
3
4
 
4
5
  describe('QuantitySelector', () => {
@@ -8,12 +9,9 @@ describe('QuantitySelector', () => {
8
9
  label="Quantity"
9
10
  accessibilityLabel="Quantity of items to wishlist"
10
11
  id="quantity"
11
- onDecrement={() => alert('decrement')}
12
- onIncrement={() => alert('increment')}
13
12
  name="quantity"
14
13
  value={1}
15
14
  onChange={() => alert('onChange')}
16
- type="number"
17
15
  max={10}
18
16
  step={0.0001}
19
17
  min={1}
@@ -30,4 +28,34 @@ describe('QuantitySelector', () => {
30
28
  )
31
29
  expect(getByRole('spinbutton')).toHaveValue(1)
32
30
  })
31
+ it('add one step when press on increment button', async () => {
32
+ const user = userEvent.setup()
33
+ const { getByRole } = render(
34
+ <QuantitySelector
35
+ label="Quantity"
36
+ name="quantity"
37
+ defaultValue={5}
38
+ step={1}
39
+ />,
40
+ )
41
+
42
+ await user.click(getByRole('button', { name: '+' }))
43
+
44
+ expect(getByRole('spinbutton')).toHaveValue(6)
45
+ })
46
+ it('remove one step when press on increment button', async () => {
47
+ const user = userEvent.setup()
48
+ const { getByRole } = render(
49
+ <QuantitySelector
50
+ label="Quantity"
51
+ name="quantity"
52
+ defaultValue={5}
53
+ step={1}
54
+ />,
55
+ )
56
+
57
+ await user.click(getByRole('button', { name: '-' }))
58
+
59
+ expect(getByRole('spinbutton')).toHaveValue(4)
60
+ })
33
61
  })