agroptima-design-system 0.29.2-beta.4 → 0.29.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 +1 -1
- package/src/atoms/Button/Button.tsx +5 -6
- package/src/atoms/Button/FloatingButton.tsx +8 -9
- package/src/atoms/Button/IconButton.tsx +7 -3
- package/src/atoms/DatePicker/DateRangePicker.tsx +12 -17
- package/src/atoms/DatePicker/translations.ts +1 -3
- package/src/atoms/Select.tsx +0 -2
- package/src/stories/Button.stories.ts +2 -1
- package/src/stories/Changelog.mdx +4 -0
- package/src/stories/DatePicker.stories.ts +0 -6
- package/src/stories/FloatingButton.stories.ts +4 -0
- package/src/stories/IconButton.stories.ts +4 -0
- package/tests/DateRangePicker.spec.tsx +0 -1
package/package.json
CHANGED
|
@@ -45,21 +45,20 @@ export function Button({
|
|
|
45
45
|
disabled,
|
|
46
46
|
variant = 'primary',
|
|
47
47
|
loading = false,
|
|
48
|
+
className,
|
|
48
49
|
...props
|
|
49
50
|
}: ButtonProps) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
const cssClasses = classNames(props.className, 'button', variant)
|
|
51
|
+
const leftIconName = loading ? 'Loading' : leftIcon
|
|
52
|
+
const cssClasses = classNames(className, 'button', variant)
|
|
54
53
|
|
|
55
54
|
return (
|
|
56
55
|
<BaseButton
|
|
57
56
|
disabled={loading || disabled}
|
|
58
57
|
aria-label={accessibilityLabel || label}
|
|
59
|
-
{...props}
|
|
60
58
|
className={cssClasses}
|
|
59
|
+
{...props}
|
|
61
60
|
>
|
|
62
|
-
{
|
|
61
|
+
{leftIconName && <Icon name={leftIconName} size="3" />}
|
|
63
62
|
{label}
|
|
64
63
|
{rightIcon && <Icon name={rightIcon} size="3" />}
|
|
65
64
|
</BaseButton>
|
|
@@ -15,6 +15,7 @@ interface CustomProps {
|
|
|
15
15
|
disabled?: boolean
|
|
16
16
|
accessibilityLabel: string
|
|
17
17
|
shape?: Shape
|
|
18
|
+
loading?: boolean
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export type FloatingButtonProps = CustomProps & BaseButtonProps
|
|
@@ -25,23 +26,21 @@ export function FloatingButton({
|
|
|
25
26
|
disabled,
|
|
26
27
|
variant = 'primary',
|
|
27
28
|
shape = 'rounded-square',
|
|
29
|
+
loading = false,
|
|
30
|
+
className,
|
|
28
31
|
...props
|
|
29
32
|
}: FloatingButtonProps) {
|
|
30
|
-
const cssClasses = classNames(
|
|
31
|
-
|
|
32
|
-
variant,
|
|
33
|
-
props.className,
|
|
34
|
-
shape,
|
|
35
|
-
)
|
|
33
|
+
const cssClasses = classNames('floating-button', variant, className, shape)
|
|
34
|
+
const iconName = loading ? 'Loading' : icon
|
|
36
35
|
|
|
37
36
|
return (
|
|
38
37
|
<BaseButton
|
|
39
|
-
disabled={disabled}
|
|
38
|
+
disabled={loading || disabled}
|
|
40
39
|
aria-label={accessibilityLabel}
|
|
41
|
-
{...props}
|
|
42
40
|
className={cssClasses}
|
|
41
|
+
{...props}
|
|
43
42
|
>
|
|
44
|
-
<Icon name={
|
|
43
|
+
<Icon name={iconName} />
|
|
45
44
|
</BaseButton>
|
|
46
45
|
)
|
|
47
46
|
}
|
|
@@ -12,6 +12,7 @@ interface CustomProps {
|
|
|
12
12
|
variant?: Variant
|
|
13
13
|
disabled?: boolean
|
|
14
14
|
accessibilityLabel: string
|
|
15
|
+
loading?: boolean
|
|
15
16
|
size?: IconSize
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -22,17 +23,20 @@ export function IconButton({
|
|
|
22
23
|
icon,
|
|
23
24
|
disabled,
|
|
24
25
|
variant = 'primary',
|
|
26
|
+
loading = false,
|
|
25
27
|
size,
|
|
28
|
+
className,
|
|
26
29
|
...props
|
|
27
30
|
}: IconButtonProps) {
|
|
31
|
+
const iconName = loading ? 'Loading' : icon
|
|
28
32
|
return (
|
|
29
33
|
<BaseButton
|
|
30
|
-
disabled={disabled}
|
|
34
|
+
disabled={loading || disabled}
|
|
31
35
|
aria-label={accessibilityLabel}
|
|
36
|
+
className={classNames(className, 'icon-button', variant)}
|
|
32
37
|
{...props}
|
|
33
|
-
className={classNames(props.className, 'icon-button', variant)}
|
|
34
38
|
>
|
|
35
|
-
<Icon title={accessibilityLabel} name={
|
|
39
|
+
<Icon title={accessibilityLabel} name={iconName} size={size} />
|
|
36
40
|
</BaseButton>
|
|
37
41
|
)
|
|
38
42
|
}
|
|
@@ -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,8 +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
|
-
required?: boolean
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
export function DateRangePicker({
|
|
@@ -42,22 +39,22 @@ export function DateRangePicker({
|
|
|
42
39
|
onSelect = () => {},
|
|
43
40
|
selected: preselected,
|
|
44
41
|
lng,
|
|
45
|
-
type,
|
|
46
|
-
required = false,
|
|
47
42
|
}: DateRangePickerProps): React.JSX.Element {
|
|
48
43
|
const manageFooterText = (): string => {
|
|
49
44
|
const hasDatesFilter = selected && selected.from && selected.to
|
|
45
|
+
const isExactDate =
|
|
46
|
+
formatDatePickerParamsDate(selected?.from) ===
|
|
47
|
+
formatDatePickerParamsDate(selected?.to)
|
|
50
48
|
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
49
|
+
if (!hasDatesFilter) return translations[lng].pickDate
|
|
50
|
+
|
|
51
|
+
if (isExactDate) {
|
|
55
52
|
return translations[lng].selectedDate.replace(
|
|
56
53
|
'${date}',
|
|
57
54
|
formatDatePickerFooterDate(selected.from, lng as string),
|
|
58
55
|
)
|
|
59
56
|
}
|
|
60
|
-
|
|
57
|
+
|
|
61
58
|
return translations[lng].selectedRangeOfDates
|
|
62
59
|
.replace(
|
|
63
60
|
'${from}',
|
|
@@ -79,11 +76,11 @@ export function DateRangePicker({
|
|
|
79
76
|
}, [preselected])
|
|
80
77
|
|
|
81
78
|
function selectDate(dateRange: DateRange | undefined) {
|
|
82
|
-
|
|
79
|
+
const isSingleDaySelection = dateRange && !dateRange.to
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
if (isSingleDaySelection) {
|
|
82
|
+
dateRange.to = dateRange.from
|
|
83
|
+
}
|
|
87
84
|
|
|
88
85
|
setSelected(dateRange)
|
|
89
86
|
onSelect(dateRange)
|
|
@@ -95,10 +92,8 @@ export function DateRangePicker({
|
|
|
95
92
|
locale={availableLocales[lng]}
|
|
96
93
|
mode="range"
|
|
97
94
|
min={1}
|
|
98
|
-
max={type === 'single' ? 1 : undefined}
|
|
99
|
-
required={required}
|
|
100
95
|
selected={selected}
|
|
101
|
-
onSelect={
|
|
96
|
+
onSelect={(dateRange) => selectDate(dateRange)}
|
|
102
97
|
footer={footer}
|
|
103
98
|
defaultMonth={selected?.from}
|
|
104
99
|
/>
|
|
@@ -5,13 +5,11 @@ interface Translation {
|
|
|
5
5
|
export const translations: Translation = {
|
|
6
6
|
en: {
|
|
7
7
|
pickDate: 'Pick a day or a range of dates',
|
|
8
|
-
pickDay: 'Pick a day',
|
|
9
8
|
selectedDate: 'Selected date: ${date}',
|
|
10
9
|
selectedRangeOfDates: 'Selected dates range: from ${from} to ${to}',
|
|
11
10
|
},
|
|
12
11
|
es: {
|
|
13
|
-
|
|
14
|
-
pickDay: 'Selecciona un día',
|
|
12
|
+
pickDate: 'Selecciona un día o un rango de fechas',
|
|
15
13
|
selectedDate: 'Fecha seleccionada: ${date}',
|
|
16
14
|
selectedRangeOfDates: 'Rango de fechas seleccionado: desde ${from} a ${to}',
|
|
17
15
|
},
|
package/src/atoms/Select.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
'use client'
|
|
2
1
|
import './Select.scss'
|
|
3
2
|
import React, { useRef, useState } from 'react'
|
|
4
3
|
import { useOpen } from '../hooks/useOpen'
|
|
@@ -161,7 +160,6 @@ function OptionList({
|
|
|
161
160
|
searchLabel,
|
|
162
161
|
}: OptionListProps) {
|
|
163
162
|
const { findItems, search } = useSearch(options, 'label')
|
|
164
|
-
|
|
165
163
|
return (
|
|
166
164
|
<div className="select-options">
|
|
167
165
|
{isSearchable && (
|
|
@@ -24,6 +24,7 @@ const meta = {
|
|
|
24
24
|
},
|
|
25
25
|
loading: {
|
|
26
26
|
description: 'Is the button in loading state?',
|
|
27
|
+
control: { type: 'boolean', default: false },
|
|
27
28
|
},
|
|
28
29
|
leftIcon: {
|
|
29
30
|
description: 'Button left icon from a list of values',
|
|
@@ -39,7 +40,7 @@ const meta = {
|
|
|
39
40
|
},
|
|
40
41
|
visible: {
|
|
41
42
|
description: 'Is the button visible?',
|
|
42
|
-
control: { type: 'boolean'
|
|
43
|
+
control: { type: 'boolean' },
|
|
43
44
|
},
|
|
44
45
|
},
|
|
45
46
|
}
|
|
@@ -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
|
}
|