agroptima-design-system 0.29.2-beta.1 → 0.29.2-beta.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.29.2-beta.1",
3
+ "version": "0.29.2-beta.2",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -1,20 +1,13 @@
1
1
  @use '../../settings/color_alias';
2
2
  @use '../../settings/typography/content' as typography;
3
3
  @use '../../settings/config';
4
+ @use '../../settings/mixins';
4
5
 
5
6
  @mixin button-style($main-color, $secondary-color, $hover-color) {
7
+ @include mixins.icon-color($secondary-color);
6
8
  background: $main-color;
7
9
  color: $secondary-color;
8
10
 
9
- > .icon {
10
- > svg {
11
- fill: $secondary-color;
12
- path {
13
- fill: $secondary-color;
14
- }
15
- }
16
- }
17
-
18
11
  &:not(:disabled):hover,
19
12
  &:not(:disabled):active {
20
13
  background: $hover-color;
@@ -39,10 +32,6 @@
39
32
  margin-top: 2px;
40
33
  width: config.$icon-size-3x;
41
34
  height: config.$icon-size-3x;
42
- > svg {
43
- width: 100%;
44
- height: 100%;
45
- }
46
35
  }
47
36
 
48
37
  &.primary {
@@ -11,7 +11,6 @@ import {
11
11
  import { translations } from './translations'
12
12
 
13
13
  export type Variant = 'primary'
14
- export type DateType = 'single' | 'range' | 'multiple'
15
14
 
16
15
  type DivPropsWithoutOnSelect = Omit<
17
16
  React.ComponentPropsWithoutRef<'div'>,
@@ -32,7 +31,6 @@ export interface DateRangePickerProps extends DivPropsWithoutOnSelect {
32
31
  onSelect: (dateRange: DateRange | undefined) => void
33
32
  selected?: DateRange
34
33
  lng: keyof typeof availableLocales
35
- type: DateType
36
34
  }
37
35
 
38
36
  export function DateRangePicker({
@@ -41,7 +39,6 @@ export function DateRangePicker({
41
39
  onSelect = () => {},
42
40
  selected: preselected,
43
41
  lng,
44
- type,
45
42
  }: DateRangePickerProps): React.JSX.Element {
46
43
  const manageFooterText = (): string => {
47
44
  const hasDatesFilter = selected && selected.from && selected.to
@@ -95,7 +92,6 @@ export function DateRangePicker({
95
92
  locale={availableLocales[lng]}
96
93
  mode="range"
97
94
  min={1}
98
- max={type === 'single' ? 1 : undefined}
99
95
  selected={selected}
100
96
  onSelect={(dateRange) => selectDate(dateRange)}
101
97
  footer={footer}
@@ -2,6 +2,10 @@
2
2
  @use '../settings/typography/form' as typography;
3
3
  @use '../settings/config';
4
4
  @use '../settings/depth';
5
+ @use '../settings/mixins';
6
+
7
+ $selected-option-padding: config.$space-2x config.$space-3x;
8
+ $selected-option-height: config.$space-10x;
5
9
 
6
10
  .select-group {
7
11
  display: flex;
@@ -34,15 +38,7 @@
34
38
  border: 1px solid color_alias.$neutral-color-600;
35
39
  background: color_alias.$neutral-white;
36
40
  @include typography.select-text;
37
-
38
- > .icon {
39
- > svg {
40
- fill: color_alias.$primary-color-600;
41
- path {
42
- fill: color_alias.$primary-color-600;
43
- }
44
- }
45
- }
41
+ @include mixins.icon-color(color_alias.$primary-color-600);
46
42
 
47
43
  &.filled {
48
44
  @include typography.select-option-text;
@@ -61,15 +57,7 @@
61
57
  border: 1px solid color_alias.$neutral-color-400;
62
58
  background: color_alias.$neutral-color-50;
63
59
  color: color_alias.$neutral-color-400;
64
-
65
- > .icon {
66
- > svg {
67
- fill: color_alias.$neutral-color-400;
68
- path {
69
- fill: color_alias.$neutral-color-400;
70
- }
71
- }
72
- }
60
+ @include mixins.icon-color(color_alias.$neutral-color-400);
73
61
  }
74
62
  }
75
63
 
@@ -117,6 +105,7 @@
117
105
  }
118
106
 
119
107
  .selected-option {
108
+ min-height: $selected-option-height;
120
109
  display: flex;
121
110
  justify-content: space-between;
122
111
  align-items: center;
@@ -128,7 +117,7 @@
128
117
  height: config.$icon-size-3x;
129
118
  }
130
119
  }
131
-
120
+
132
121
  .select-options {
133
122
  max-height: 256px;
134
123
  overflow-y: auto;
@@ -141,7 +130,7 @@
141
130
  width: 100%;
142
131
 
143
132
  .search {
144
- margin: config.$space-2x config.$space-3x;
133
+ margin: $selected-option-padding;
145
134
  }
146
135
 
147
136
  ul {
@@ -149,13 +138,13 @@
149
138
  margin: 0;
150
139
  padding: 0;
151
140
  }
152
-
141
+
153
142
  .option {
154
143
  display: flex;
155
144
  align-items: center;
156
145
  cursor: default;
157
146
  list-style-type: none;
158
- padding: config.$space-2x config.$space-3x;
147
+ padding: $selected-option-padding;
159
148
 
160
149
  > .icon {
161
150
  width: config.$icon-size-4x;
@@ -163,5 +152,13 @@
163
152
  margin-right: config.$space-1x;
164
153
  }
165
154
  }
166
- }
155
+ }
156
+ }
157
+
158
+ .select-loader {
159
+ position: absolute;
160
+ padding: $selected-option-padding;
161
+ min-height: $selected-option-height;
162
+ display: flex;
163
+ align-items: center;
167
164
  }
@@ -31,6 +31,7 @@ export interface SelectProps extends InputPropsWithoutOnChange {
31
31
  required?: boolean
32
32
  isSearchable?: boolean
33
33
  searchLabel?: string
34
+ loading?: boolean
34
35
  }
35
36
 
36
37
  const EMPTY_OPTION = { id: '', label: '' }
@@ -51,6 +52,7 @@ export function Select({
51
52
  defaultValue,
52
53
  required = false,
53
54
  isSearchable = false,
55
+ loading = false,
54
56
  searchLabel = 'Search',
55
57
  ...props
56
58
  }: SelectProps): React.JSX.Element {
@@ -62,6 +64,7 @@ export function Select({
62
64
  const isEmpty = selectedOption.id === EMPTY_OPTION.id
63
65
  const selectRef = useRef(null)
64
66
  useOutsideClick(selectRef, close)
67
+ const displayedValue = loading ? '' : selectedOption.label || placeholder
65
68
 
66
69
  const cssClasses = classNames('selected-option', {
67
70
  open: isOpen,
@@ -98,6 +101,11 @@ export function Select({
98
101
  )}
99
102
 
100
103
  <div className="select-container" ref={selectRef}>
104
+ {loading && (
105
+ <div className="select-loader">
106
+ <Icon name="Loading" />
107
+ </div>
108
+ )}
101
109
  <div
102
110
  className={cssClasses}
103
111
  tabIndex={0}
@@ -106,7 +114,7 @@ export function Select({
106
114
  aria-live="assertive"
107
115
  role="alert"
108
116
  >
109
- <span>{selectedOption.label || placeholder}</span>
117
+ <span>{displayedValue}</span>
110
118
  <Icon name={isOpen ? 'AngleUp' : 'AngleDown'} visible={isEmpty} />
111
119
  <IconButton
112
120
  icon="Close"
@@ -116,7 +124,7 @@ export function Select({
116
124
  visible={!isEmpty}
117
125
  />
118
126
  </div>
119
- {isOpen && (
127
+ {isOpen && options.length > 0 && (
120
128
  <OptionList
121
129
  options={options}
122
130
  selectedOption={selectedOption}
@@ -18,9 +18,6 @@ const meta = {
18
18
  selected: {
19
19
  description: 'Selected date or date range',
20
20
  },
21
- type: {
22
- description: 'Type of date picker',
23
- },
24
21
  lng: {
25
22
  description: 'String with the locale to be used on the translations',
26
23
  },
@@ -42,7 +39,6 @@ export const Primary: Story = {
42
39
  variant: 'primary',
43
40
  onSelect: (date) => console.log('onSelect date:', date),
44
41
  lng: 'en',
45
- type: 'range',
46
42
  },
47
43
  parameters: figmaPrimaryDesign,
48
44
  }
@@ -53,7 +49,6 @@ export const WithDateRangeSelected: Story = {
53
49
  onSelect: (date) => console.log('onSelect date:', date),
54
50
  selected: { from: new Date(2024, 1, 2), to: new Date(2024, 1, 15) },
55
51
  lng: 'en',
56
- type: 'range',
57
52
  },
58
53
  parameters: figmaPrimaryDesign,
59
54
  }
@@ -64,7 +59,6 @@ export const WithSingleDaySelected: Story = {
64
59
  onSelect: (date) => console.log('onSelect date:', date),
65
60
  selected: { from: new Date(2024, 1, 2), to: new Date(2024, 1, 2) },
66
61
  lng: 'en',
67
- type: 'single',
68
62
  },
69
63
  parameters: figmaPrimaryDesign,
70
64
  }
@@ -8,7 +8,6 @@ describe('DateRangePicker', () => {
8
8
  <DateRangePicker
9
9
  selected={{ from: new Date(2025, 0, 1), to: new Date(2025, 0, 15) }}
10
10
  onSelect={() => jest.fn()}
11
- type="range"
12
11
  lng={'es'}
13
12
  />,
14
13
  )
@@ -1,81 +0,0 @@
1
- import 'react-day-picker/style.css'
2
- import './DateRangePicker.scss'
3
- import { useEffect, useState } from 'react'
4
- import { type DateRange, DayPicker, type Locale } from 'react-day-picker'
5
- import { enGB, es } from 'react-day-picker/locale'
6
- import { classNames } from '../../utils/classNames'
7
- import {
8
- formatDatePickerFooterDate,
9
- formatDatePickerParamsDate,
10
- } from '../../utils/dateHelpers'
11
- import { translations } from './translations'
12
-
13
- export type Variant = 'primary'
14
-
15
- export type DateType = 'single' | 'range' | 'multiple'
16
-
17
- type DivPropsWithoutOnSelect = Omit<
18
- React.ComponentPropsWithoutRef<'div'>,
19
- 'onSelect'
20
- >
21
-
22
- interface AvailableLocale {
23
- [index: string]: Locale
24
- }
25
-
26
- const availableLocales: AvailableLocale = {
27
- es: es,
28
- en: enGB,
29
- }
30
-
31
- export interface DateSinglePickerProps extends DivPropsWithoutOnSelect {
32
- variant?: Variant
33
- onSelect: (date: Date | undefined) => void
34
- selected?: Date
35
- lng: keyof typeof availableLocales
36
- }
37
-
38
- export function DateSinglePicker({
39
- onSelect = () => {},
40
- selected: preselected,
41
- lng,
42
- }: DateSinglePickerProps): React.JSX.Element {
43
- const manageFooterText = (): string => {
44
- return translations[lng].selectedDate.replace(
45
- '${date}',
46
- formatDatePickerFooterDate(singleSelected, lng as string),
47
- )
48
- }
49
-
50
- const [singleSelected, setSingleSelected] = useState<Date | undefined>(
51
- preselected,
52
- )
53
-
54
- const [footer, setFooter] = useState<string>(() => {
55
- return manageFooterText()
56
- })
57
-
58
- useEffect(() => {
59
- setSingleSelected(preselected)
60
- setFooter(manageFooterText())
61
- // eslint-disable-next-line react-hooks/exhaustive-deps
62
- }, [preselected])
63
-
64
- function selectDate(date: Date | undefined) {
65
- setSingleSelected(date)
66
- onSelect(date)
67
- }
68
-
69
- return (
70
- <>
71
- <DayPicker
72
- locale={availableLocales[lng]}
73
- mode="single"
74
- selected={singleSelected}
75
- onSelect={(date) => selectDate(date)}
76
- footer={footer}
77
- defaultMonth={singleSelected}
78
- />
79
- </>
80
- )
81
- }