agroptima-design-system 0.30.1 → 0.30.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": "0.30.1",
3
+ "version": "0.30.2",
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,10 @@ import { Meta } from "@storybook/blocks";
4
4
 
5
5
  # Changelog
6
6
 
7
+ ## 0.30.2
8
+
9
+ * Update QuantitySelector decrement & increment logic management
10
+
7
11
  ## 0.30.1
8
12
 
9
13
  * 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
  }
@@ -8,12 +8,9 @@ describe('QuantitySelector', () => {
8
8
  label="Quantity"
9
9
  accessibilityLabel="Quantity of items to wishlist"
10
10
  id="quantity"
11
- onDecrement={() => alert('decrement')}
12
- onIncrement={() => alert('increment')}
13
11
  name="quantity"
14
12
  value={1}
15
13
  onChange={() => alert('onChange')}
16
- type="number"
17
14
  max={10}
18
15
  step={0.0001}
19
16
  min={1}