agroptima-design-system 0.16.2 → 0.17.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.16.2",
3
+ "version": "0.17.0",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -0,0 +1,97 @@
1
+ @use '../settings/color_alias';
2
+ @use '../settings/typography/form' as form-typography;
3
+ @use '../settings/typography/content' as typography;
4
+ @use '../settings/config';
5
+
6
+ .quantity-selector-group {
7
+ display: flex;
8
+ flex-direction: column;
9
+ gap: config.$space-2x;
10
+
11
+ .quantity-selector {
12
+ display: flex;
13
+ align-items: flex-start;
14
+
15
+ .input-group {
16
+ width: 100%;
17
+ }
18
+ }
19
+
20
+ &.primary {
21
+ .quantity-selector {
22
+ .input-container {
23
+ // Remove default arrows
24
+ /* Chrome, Safari, Edge, Opera */
25
+ input::-webkit-outer-spin-button,
26
+ input::-webkit-inner-spin-button {
27
+ -webkit-appearance: none;
28
+ margin: 0;
29
+ }
30
+
31
+ /* Firefox */
32
+ input[type='number'] {
33
+ -moz-appearance: textfield;
34
+ }
35
+ .input {
36
+ border-radius: 0;
37
+ border-right: 0;
38
+ border-left: 0;
39
+ background: color_alias.$neutral-white;
40
+ text-align: center;
41
+
42
+ @include form-typography.input-text;
43
+
44
+ &::placeholder {
45
+ @include form-typography.input-placeholder-text;
46
+ }
47
+
48
+ &:focus {
49
+ outline: color_alias.$primary-color-600;
50
+ border: 1px solid color_alias.$primary-color-600;
51
+ }
52
+
53
+ &:disabled {
54
+ border: 1px solid color_alias.$neutral-color-400;
55
+ background: color_alias.$neutral-color-50;
56
+ color: color_alias.$neutral-color-400;
57
+
58
+ &::placeholder {
59
+ color: color_alias.$neutral-color-400;
60
+ }
61
+ }
62
+ }
63
+ }
64
+ .button {
65
+ @include typography.body-regular-primary;
66
+ color: color_alias.$neutral-white;
67
+ height: 42px;
68
+
69
+ &:disabled {
70
+ border: 1px solid color_alias.$neutral-color-400;
71
+ color: color_alias.$neutral-color-400;
72
+ }
73
+ }
74
+ .decrement-button {
75
+ border-top-right-radius: 0;
76
+ border-bottom-right-radius: 0;
77
+
78
+ &:disabled {
79
+ border-right: 0;
80
+ }
81
+ }
82
+
83
+ .increment-button {
84
+ border-top-left-radius: 0;
85
+ border-bottom-left-radius: 0;
86
+
87
+ &:disabled {
88
+ border-left: 0;
89
+ }
90
+ }
91
+ }
92
+
93
+ .quantity-selector-label {
94
+ @include form-typography.form-label;
95
+ }
96
+ }
97
+ }
@@ -0,0 +1,54 @@
1
+ import React, { useState } from 'react'
2
+ import { Icon } from './Icon'
3
+ import { classNames } from '../utils/classNames'
4
+ import './QuantitySelector.scss'
5
+ import { Input, InputProps } from './Input'
6
+ import { Button, ButtonProps } from './Button'
7
+
8
+ export type Variant = 'primary'
9
+
10
+ export interface QuantitySelectorProps
11
+ extends React.ComponentPropsWithoutRef<'div'> {
12
+ label: string
13
+ accessibilityLabel?: string
14
+ hideLabel?: boolean
15
+ id?: string
16
+ variant?: Variant
17
+ decrementButton: ButtonProps
18
+ incrementButton: ButtonProps
19
+ quantityInput: InputProps
20
+ }
21
+
22
+ export function QuantitySelector({
23
+ decrementButton,
24
+ incrementButton,
25
+ quantityInput,
26
+ label,
27
+ accessibilityLabel,
28
+ id,
29
+ className,
30
+ hideLabel = false,
31
+ variant = 'primary',
32
+ ...props
33
+ }: QuantitySelectorProps): React.JSX.Element {
34
+ const cssClasses = classNames('quantity-selector', className)
35
+
36
+ return (
37
+ <div className={`quantity-selector-group ${variant}`} {...props}>
38
+ {!hideLabel && (
39
+ <label className="quantity-selector-label" htmlFor={id}>
40
+ {label}
41
+ </label>
42
+ )}
43
+ <div className={cssClasses}>
44
+ <Button className="decrement-button" {...decrementButton} />
45
+ <Input
46
+ {...quantityInput}
47
+ label={label}
48
+ accessibilityLabel={accessibilityLabel}
49
+ />
50
+ <Button className="increment-button" {...incrementButton} />
51
+ </div>
52
+ </div>
53
+ )
54
+ }
@@ -25,6 +25,7 @@ import Import from './import.svg'
25
25
  import Info from './info.svg'
26
26
  import Loading from './loading.svg'
27
27
  import Logout from './logout.svg'
28
+ import Minus from './minus.svg'
28
29
  import Product from './product.svg'
29
30
  import Salesman from './salesman.svg'
30
31
  import Search from './search.svg'
@@ -62,6 +63,7 @@ export {
62
63
  Info,
63
64
  Loading,
64
65
  Logout,
66
+ Minus,
65
67
  Product,
66
68
  Salesman,
67
69
  Search,
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 11H0V8h20v3Z" fill="#444"/></svg>
@@ -3,6 +3,9 @@ import { Meta } from "@storybook/addon-docs";
3
3
  <Meta title="Changelog" />
4
4
  # Changelog
5
5
 
6
+ ## 0.17.0
7
+ - Added QuantitySelector component to Storybook
8
+
6
9
  ## 0.16.2
7
10
  - Fixed some icons missing ViewBox
8
11
 
@@ -0,0 +1,113 @@
1
+ import { QuantitySelector } from '../atoms/QuantitySelector'
2
+ import { StoryObj } from '@storybook/react'
3
+
4
+ const meta = {
5
+ title: 'Design System/Atoms/QuantitySelector',
6
+ component: QuantitySelector,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ label: {
10
+ description: 'Label for the component',
11
+ },
12
+ accessibilityLabel: {
13
+ description:
14
+ 'Describes the component purpose. If empty, label content will be used',
15
+ },
16
+ variant: {
17
+ description: 'Component variant used',
18
+ },
19
+ disabled: {
20
+ description: 'Is the input in disabled state?',
21
+ },
22
+ name: {
23
+ description: 'Component name property',
24
+ },
25
+ id: {
26
+ description: 'Value needed for the label relation',
27
+ },
28
+ decrementButton: {
29
+ description: 'Button component props for decrementButton',
30
+ },
31
+ incrementButton: {
32
+ description: 'Button component props for incrementButton',
33
+ },
34
+ quantityInput: {
35
+ description: 'Input component props for quantityInput',
36
+ },
37
+ },
38
+ }
39
+
40
+ const figmaPrimaryDesign = {
41
+ design: {
42
+ type: 'figma',
43
+ url: 'https://www.figma.com/design/DN2ova21vWqCRvPspBXgI1/Design-System?node-id=2701-275&m=dev',
44
+ },
45
+ }
46
+
47
+ export default meta
48
+ type Story = StoryObj<typeof meta>
49
+
50
+ export const Primary: Story = {
51
+ args: {
52
+ label: 'Quantity',
53
+ accessibilityLabel: 'Quantity of items to wishlist',
54
+ id: 'quantity-selector',
55
+ decrementButton: {
56
+ label: '',
57
+ leftIcon: 'Minus',
58
+ onClick: () => alert('decrement'),
59
+ },
60
+ incrementButton: {
61
+ label: '',
62
+ leftIcon: 'Add',
63
+ onClick: () => alert('increment'),
64
+ },
65
+ quantityInput: {
66
+ label: 'Quantity input',
67
+ hideLabel: true,
68
+ name: 'quantity',
69
+ value: 1,
70
+ onChange: () => alert('onChange'),
71
+ type: 'number',
72
+ max: 10,
73
+ step: 0.0001,
74
+ min: 1,
75
+ required: true,
76
+ },
77
+ },
78
+ parameters: figmaPrimaryDesign,
79
+ }
80
+
81
+ export const Disabled: Story = {
82
+ args: {
83
+ label: 'Quantity',
84
+ accessibilityLabel: 'Quantity of items to wishlist',
85
+ id: 'quantity-selector',
86
+ decrementButton: {
87
+ label: '',
88
+ leftIcon: 'Minus',
89
+ onClick: () => alert('decrement'),
90
+ disabled: true,
91
+ },
92
+ incrementButton: {
93
+ label: '',
94
+ leftIcon: 'Add',
95
+ onClick: () => alert('increment'),
96
+ disabled: true,
97
+ },
98
+ quantityInput: {
99
+ label: 'Quantity input',
100
+ hideLabel: true,
101
+ name: 'quantity',
102
+ value: 1,
103
+ onChange: () => alert('onChange'),
104
+ type: 'number',
105
+ max: 10,
106
+ step: 0.0001,
107
+ min: 1,
108
+ required: true,
109
+ disabled: true,
110
+ },
111
+ },
112
+ parameters: figmaPrimaryDesign,
113
+ }
@@ -0,0 +1,44 @@
1
+ import React from 'react'
2
+ import { screen, render } from '@testing-library/react'
3
+ import { QuantitySelector } from '@/atoms/QuantitySelector'
4
+
5
+ describe('QuantitySelector', () => {
6
+ it('renders', () => {
7
+ const { getByRole, getByText, getAllByRole } = render(
8
+ <QuantitySelector
9
+ label="Quantity"
10
+ accessibilityLabel="Quantity of items to wishlist"
11
+ id="quantity-selector"
12
+ decrementButton={{
13
+ label: '-',
14
+ onClick: () => alert('decrement'),
15
+ }}
16
+ incrementButton={{
17
+ label: '+',
18
+ onClick: () => alert('increment'),
19
+ }}
20
+ quantityInput={{
21
+ label: 'Quantity input',
22
+ hideLabel: true,
23
+ name: 'quantity',
24
+ value: 1,
25
+ onChange: () => alert('onChange'),
26
+ type: 'number',
27
+ max: 10,
28
+ step: 0.0001,
29
+ min: 1,
30
+ required: true,
31
+ }}
32
+ />,
33
+ )
34
+
35
+ expect(getByText(/Quantity/i)).toBeInTheDocument()
36
+ expect(getAllByRole('button')[0]).toHaveClass(
37
+ `button primary decrement-button`,
38
+ )
39
+ expect(getAllByRole('button')[1]).toHaveClass(
40
+ `button primary increment-button`,
41
+ )
42
+ expect(getByRole('spinbutton')).toHaveValue(1)
43
+ })
44
+ })