agroptima-design-system 0.29.2 → 0.29.3-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 +1 -1
- package/src/atoms/Button/Button.tsx +6 -5
- package/src/atoms/Button/FloatingButton.tsx +9 -8
- package/src/atoms/Button/IconButton.tsx +3 -7
- package/src/atoms/DateSinglePicker/DateSinglePicker.scss +15 -0
- package/src/atoms/DateSinglePicker/DateSinglePicker.tsx +82 -0
- package/src/atoms/DateSinglePicker/translations.ts +14 -0
- package/src/atoms/Select.tsx +2 -0
- package/src/stories/Button.stories.ts +1 -2
- package/src/stories/Changelog.mdx +0 -4
- package/src/stories/DateSinglePicker.stories.ts +57 -0
- package/src/stories/FloatingButton.stories.ts +0 -4
- package/src/stories/IconButton.stories.ts +0 -4
package/package.json
CHANGED
|
@@ -45,20 +45,21 @@ export function Button({
|
|
|
45
45
|
disabled,
|
|
46
46
|
variant = 'primary',
|
|
47
47
|
loading = false,
|
|
48
|
-
className,
|
|
49
48
|
...props
|
|
50
49
|
}: ButtonProps) {
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (loading) {
|
|
51
|
+
leftIcon = 'Loading'
|
|
52
|
+
}
|
|
53
|
+
const cssClasses = classNames(props.className, 'button', variant)
|
|
53
54
|
|
|
54
55
|
return (
|
|
55
56
|
<BaseButton
|
|
56
57
|
disabled={loading || disabled}
|
|
57
58
|
aria-label={accessibilityLabel || label}
|
|
58
|
-
className={cssClasses}
|
|
59
59
|
{...props}
|
|
60
|
+
className={cssClasses}
|
|
60
61
|
>
|
|
61
|
-
{
|
|
62
|
+
{leftIcon && <Icon name={leftIcon} size="3" />}
|
|
62
63
|
{label}
|
|
63
64
|
{rightIcon && <Icon name={rightIcon} size="3" />}
|
|
64
65
|
</BaseButton>
|
|
@@ -15,7 +15,6 @@ interface CustomProps {
|
|
|
15
15
|
disabled?: boolean
|
|
16
16
|
accessibilityLabel: string
|
|
17
17
|
shape?: Shape
|
|
18
|
-
loading?: boolean
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
export type FloatingButtonProps = CustomProps & BaseButtonProps
|
|
@@ -26,21 +25,23 @@ export function FloatingButton({
|
|
|
26
25
|
disabled,
|
|
27
26
|
variant = 'primary',
|
|
28
27
|
shape = 'rounded-square',
|
|
29
|
-
loading = false,
|
|
30
|
-
className,
|
|
31
28
|
...props
|
|
32
29
|
}: FloatingButtonProps) {
|
|
33
|
-
const cssClasses = classNames(
|
|
34
|
-
|
|
30
|
+
const cssClasses = classNames(
|
|
31
|
+
'floating-button',
|
|
32
|
+
variant,
|
|
33
|
+
props.className,
|
|
34
|
+
shape,
|
|
35
|
+
)
|
|
35
36
|
|
|
36
37
|
return (
|
|
37
38
|
<BaseButton
|
|
38
|
-
disabled={
|
|
39
|
+
disabled={disabled}
|
|
39
40
|
aria-label={accessibilityLabel}
|
|
40
|
-
className={cssClasses}
|
|
41
41
|
{...props}
|
|
42
|
+
className={cssClasses}
|
|
42
43
|
>
|
|
43
|
-
<Icon name={
|
|
44
|
+
<Icon name={icon} />
|
|
44
45
|
</BaseButton>
|
|
45
46
|
)
|
|
46
47
|
}
|
|
@@ -12,7 +12,6 @@ interface CustomProps {
|
|
|
12
12
|
variant?: Variant
|
|
13
13
|
disabled?: boolean
|
|
14
14
|
accessibilityLabel: string
|
|
15
|
-
loading?: boolean
|
|
16
15
|
size?: IconSize
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -23,20 +22,17 @@ export function IconButton({
|
|
|
23
22
|
icon,
|
|
24
23
|
disabled,
|
|
25
24
|
variant = 'primary',
|
|
26
|
-
loading = false,
|
|
27
25
|
size,
|
|
28
|
-
className,
|
|
29
26
|
...props
|
|
30
27
|
}: IconButtonProps) {
|
|
31
|
-
const iconName = loading ? 'Loading' : icon
|
|
32
28
|
return (
|
|
33
29
|
<BaseButton
|
|
34
|
-
disabled={
|
|
30
|
+
disabled={disabled}
|
|
35
31
|
aria-label={accessibilityLabel}
|
|
36
|
-
className={classNames(className, 'icon-button', variant)}
|
|
37
32
|
{...props}
|
|
33
|
+
className={classNames(props.className, 'icon-button', variant)}
|
|
38
34
|
>
|
|
39
|
-
<Icon title={accessibilityLabel} name={
|
|
35
|
+
<Icon title={accessibilityLabel} name={icon} size={size} />
|
|
40
36
|
</BaseButton>
|
|
41
37
|
)
|
|
42
38
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@use '../../settings/color_alias';
|
|
2
|
+
@use '../../settings/typography/content' as typography;
|
|
3
|
+
@use '../../settings/config';
|
|
4
|
+
@use '../../settings/depth';
|
|
5
|
+
@use '../../settings/breakpoints';
|
|
6
|
+
|
|
7
|
+
// Interpolation applied: https://sass-lang.com/documentation/breaking-changes/css-vars/
|
|
8
|
+
|
|
9
|
+
.date-picker {
|
|
10
|
+
.rdp-root {
|
|
11
|
+
width: 309px;
|
|
12
|
+
--rdp-accent-color: #{color_alias.$primary-color-600};
|
|
13
|
+
--rdp-accent-background-color: #{color_alias.$primary-color-50};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import 'react-day-picker/style.css'
|
|
2
|
+
import './DateSinglePicker.scss'
|
|
3
|
+
import { useEffect, useState } from 'react'
|
|
4
|
+
import { 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
|
+
type DivPropsWithoutOnSelect = Omit<
|
|
16
|
+
React.ComponentPropsWithoutRef<'div'>,
|
|
17
|
+
'onSelect'
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
interface AvailableLocale {
|
|
21
|
+
[index: string]: Locale
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const availableLocales: AvailableLocale = {
|
|
25
|
+
es: es,
|
|
26
|
+
en: enGB,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface DateSinglePickerProps extends DivPropsWithoutOnSelect {
|
|
30
|
+
variant?: Variant
|
|
31
|
+
onSelect: (date: Date | undefined) => void
|
|
32
|
+
selected?: Date
|
|
33
|
+
lng: keyof typeof availableLocales
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function DateSinglePicker({
|
|
37
|
+
className,
|
|
38
|
+
variant = 'primary',
|
|
39
|
+
onSelect = () => {},
|
|
40
|
+
selected: preselected,
|
|
41
|
+
lng,
|
|
42
|
+
}: DateSinglePickerProps): React.JSX.Element {
|
|
43
|
+
const manageFooterText = (): string => {
|
|
44
|
+
if (!selected) return translations[lng].pickDate
|
|
45
|
+
|
|
46
|
+
return translations[lng].selectedDate.replace(
|
|
47
|
+
'${date}',
|
|
48
|
+
formatDatePickerFooterDate(selected, lng as string),
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const [selected, setSelected] = useState<Date | undefined>(preselected)
|
|
53
|
+
const [footer, setFooter] = useState<string>(() => {
|
|
54
|
+
return manageFooterText()
|
|
55
|
+
})
|
|
56
|
+
const cssClasses = classNames('date-picker', variant, className)
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
setSelected(preselected)
|
|
60
|
+
setFooter(manageFooterText())
|
|
61
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
+
}, [preselected])
|
|
63
|
+
|
|
64
|
+
function selectDate(date: Date | undefined) {
|
|
65
|
+
setSelected(date)
|
|
66
|
+
onSelect(date)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div className={cssClasses}>
|
|
71
|
+
<DayPicker
|
|
72
|
+
locale={availableLocales[lng]}
|
|
73
|
+
mode="single"
|
|
74
|
+
selected={selected}
|
|
75
|
+
onSelect={(date) => selectDate(date)}
|
|
76
|
+
footer={footer}
|
|
77
|
+
required
|
|
78
|
+
defaultMonth={selected}
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface Translation {
|
|
2
|
+
[index: string]: { [index: string]: string }
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const translations: Translation = {
|
|
6
|
+
en: {
|
|
7
|
+
pickDate: 'Pick a date',
|
|
8
|
+
selectedDate: 'Selected date: ${date}',
|
|
9
|
+
},
|
|
10
|
+
es: {
|
|
11
|
+
pickDate: 'Selecciona una fecha',
|
|
12
|
+
selectedDate: 'Fecha seleccionada: ${date}',
|
|
13
|
+
},
|
|
14
|
+
}
|
package/src/atoms/Select.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import './Select.scss'
|
|
2
3
|
import React, { useRef, useState } from 'react'
|
|
3
4
|
import { useOpen } from '../hooks/useOpen'
|
|
@@ -160,6 +161,7 @@ function OptionList({
|
|
|
160
161
|
searchLabel,
|
|
161
162
|
}: OptionListProps) {
|
|
162
163
|
const { findItems, search } = useSearch(options, 'label')
|
|
164
|
+
|
|
163
165
|
return (
|
|
164
166
|
<div className="select-options">
|
|
165
167
|
{isSearchable && (
|
|
@@ -24,7 +24,6 @@ const meta = {
|
|
|
24
24
|
},
|
|
25
25
|
loading: {
|
|
26
26
|
description: 'Is the button in loading state?',
|
|
27
|
-
control: { type: 'boolean', default: false },
|
|
28
27
|
},
|
|
29
28
|
leftIcon: {
|
|
30
29
|
description: 'Button left icon from a list of values',
|
|
@@ -40,7 +39,7 @@ const meta = {
|
|
|
40
39
|
},
|
|
41
40
|
visible: {
|
|
42
41
|
description: 'Is the button visible?',
|
|
43
|
-
control: { type: 'boolean' },
|
|
42
|
+
control: { type: 'boolean', default: true },
|
|
44
43
|
},
|
|
45
44
|
},
|
|
46
45
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react'
|
|
2
|
+
import { DateSinglePicker } from '../atoms/DateSinglePicker/DateSinglePicker'
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Design System/Atoms/DateSinglePicker',
|
|
6
|
+
component: DateSinglePicker,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
argTypes: {
|
|
9
|
+
footer: {
|
|
10
|
+
description: 'Text for the footer',
|
|
11
|
+
},
|
|
12
|
+
variant: {
|
|
13
|
+
description: 'Component variant used',
|
|
14
|
+
},
|
|
15
|
+
onSelect: {
|
|
16
|
+
description: 'Component onSelect callback',
|
|
17
|
+
},
|
|
18
|
+
selected: {
|
|
19
|
+
description: 'Selected date or date range',
|
|
20
|
+
},
|
|
21
|
+
lng: {
|
|
22
|
+
description: 'String with the locale to be used on the translations',
|
|
23
|
+
},
|
|
24
|
+
required: {
|
|
25
|
+
description: 'Parameter to disallow calendar without selected day',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const figmaPrimaryDesign = {
|
|
31
|
+
design: {
|
|
32
|
+
type: 'figma',
|
|
33
|
+
url: 'https://www.figma.com/design/DN2ova21vWqCRvPspBXgI1/Design-System?node-id=3665-571&m=dev',
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default meta
|
|
38
|
+
type Story = StoryObj<typeof meta>
|
|
39
|
+
|
|
40
|
+
export const Primary: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
variant: 'primary',
|
|
43
|
+
onSelect: (date) => console.log('onSelect date:', date),
|
|
44
|
+
lng: 'en',
|
|
45
|
+
},
|
|
46
|
+
parameters: figmaPrimaryDesign,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const WithSingleDaySelected: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
variant: 'primary',
|
|
52
|
+
onSelect: (date) => console.log('onSelect date:', date),
|
|
53
|
+
selected: new Date(2024, 1, 2),
|
|
54
|
+
lng: 'en',
|
|
55
|
+
},
|
|
56
|
+
parameters: figmaPrimaryDesign,
|
|
57
|
+
}
|