@eml-payments/ui-kit 1.2.8 → 1.3.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/dist/src/components/DatePicker/DatePicker.d.ts +4 -4
- package/dist/src/components/DatePicker/DatePicker.js +17 -6
- package/dist/src/components/DatePicker/DatePicker.stories.d.ts +1 -0
- package/dist/src/components/DatePicker/DatePicker.stories.js +31 -0
- package/dist/src/components/index.d.ts +3 -0
- package/dist/src/components/index.js +3 -0
- package/dist/src/utils/dayjs.js +4 -0
- package/package.json +1 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type FC } from 'react';
|
|
2
2
|
import { type InputProps } from '../Input';
|
|
3
|
-
|
|
3
|
+
export type DatePickerProps = Omit<InputProps, 'value' | 'variant' | 'onChange' | 'error'> & {
|
|
4
4
|
currentDate?: Date;
|
|
5
5
|
dateFormat?: string;
|
|
6
6
|
maxDate?: Date;
|
|
7
7
|
minDate?: Date;
|
|
8
|
+
error?: string;
|
|
8
9
|
onChangeDate?: (date: Date | undefined) => void;
|
|
9
|
-
}
|
|
10
|
-
export declare const DatePicker: FC<
|
|
11
|
-
export {};
|
|
10
|
+
};
|
|
11
|
+
export declare const DatePicker: FC<DatePickerProps>;
|
|
@@ -8,15 +8,15 @@ import { Input } from '../Input';
|
|
|
8
8
|
const formatDate = (date, format) => {
|
|
9
9
|
return date ? dayjs(date).format(format) : '';
|
|
10
10
|
};
|
|
11
|
-
export const DatePicker = ({ placeholder = 'DD/MM/YYYY', dateFormat = 'DD/MM/YYYY', currentDate, minDate, maxDate, onChangeDate, ...inputProps }) => {
|
|
11
|
+
export const DatePicker = ({ placeholder = 'DD/MM/YYYY', dateFormat = 'DD/MM/YYYY', currentDate, minDate, maxDate, error, onChangeDate, ...inputProps }) => {
|
|
12
12
|
const [date, setDate] = useState(currentDate);
|
|
13
13
|
const [value, setValue] = useState(formatDate(currentDate, dateFormat));
|
|
14
|
-
const [
|
|
14
|
+
const [defaultError, setDefaultError] = useState('');
|
|
15
15
|
const [open, setOpen] = useState(false);
|
|
16
16
|
const onUpdateDate = (selectedDate) => {
|
|
17
17
|
setDate(selectedDate);
|
|
18
18
|
onChangeDate === null || onChangeDate === void 0 ? void 0 : onChangeDate(selectedDate);
|
|
19
|
-
|
|
19
|
+
setDefaultError('');
|
|
20
20
|
};
|
|
21
21
|
const handleChangeDate = (selectedDate) => {
|
|
22
22
|
onUpdateDate(selectedDate);
|
|
@@ -25,13 +25,24 @@ export const DatePicker = ({ placeholder = 'DD/MM/YYYY', dateFormat = 'DD/MM/YYY
|
|
|
25
25
|
};
|
|
26
26
|
const handleChangeInputValue = (e) => {
|
|
27
27
|
setValue(e.target.value);
|
|
28
|
+
if (e.target.value === '') {
|
|
29
|
+
onUpdateDate(undefined);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
28
32
|
const parsedDate = dayjs(e.target.value, dateFormat, true);
|
|
29
|
-
|
|
33
|
+
onChangeDate === null || onChangeDate === void 0 ? void 0 : onChangeDate(parsedDate.toDate());
|
|
34
|
+
if (!parsedDate.isValid()) {
|
|
35
|
+
setDefaultError('Invalid date format');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const isWithinRange = (!minDate || parsedDate.isSameOrAfter(dayjs(minDate), 'day')) &&
|
|
39
|
+
(!maxDate || parsedDate.isSameOrBefore(dayjs(maxDate), 'day'));
|
|
40
|
+
if (isWithinRange) {
|
|
30
41
|
onUpdateDate(parsedDate.toDate());
|
|
31
42
|
}
|
|
32
43
|
else {
|
|
33
|
-
|
|
44
|
+
setDefaultError('Date is out of range');
|
|
34
45
|
}
|
|
35
46
|
};
|
|
36
|
-
return (_jsx("div", { className: "relative", children: _jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverAnchor, { children: _jsx(Input, { type: "text", value: value, placeholder: placeholder, error: error
|
|
47
|
+
return (_jsx("div", { className: "relative", children: _jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverAnchor, { children: _jsx(Input, { type: "text", value: value, placeholder: placeholder, error: error !== null && error !== void 0 ? error : defaultError, onChange: handleChangeInputValue, endAdornment: _jsx(PopoverTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "p-1.5 hover:bg-gray-100 rounded-full transition-colors cursor-pointer flex items-center justify-center", "aria-label": "Open calendar", children: _jsx(CalendarIcon, { size: 16, className: "text-gray-500" }) }) }), ...inputProps }) }), _jsx(PopoverContent, { className: "w-auto p-0", align: "center", sideOffset: 0, children: _jsx(Calendar, { mode: "single", captionLayout: "dropdown", selected: date, startMonth: minDate, endMonth: maxDate, onSelect: handleChangeDate }) })] }) }));
|
|
37
48
|
};
|
|
@@ -11,6 +11,15 @@ const meta = {
|
|
|
11
11
|
},
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
|
+
render: (args) => {
|
|
15
|
+
const convertedArgs = {
|
|
16
|
+
...args,
|
|
17
|
+
currentDate: args.currentDate ? new Date(args.currentDate) : undefined,
|
|
18
|
+
minDate: args.minDate ? new Date(args.minDate) : undefined,
|
|
19
|
+
maxDate: args.maxDate ? new Date(args.maxDate) : undefined,
|
|
20
|
+
};
|
|
21
|
+
return _jsx(DatePicker, { ...convertedArgs });
|
|
22
|
+
},
|
|
14
23
|
argTypes: {
|
|
15
24
|
placeholder: {
|
|
16
25
|
control: 'text',
|
|
@@ -29,6 +38,14 @@ const meta = {
|
|
|
29
38
|
control: 'date',
|
|
30
39
|
description: 'Initial date value',
|
|
31
40
|
},
|
|
41
|
+
minDate: {
|
|
42
|
+
control: 'date',
|
|
43
|
+
description: 'Minimum selectable date',
|
|
44
|
+
},
|
|
45
|
+
maxDate: {
|
|
46
|
+
control: 'date',
|
|
47
|
+
description: 'Maximum selectable date',
|
|
48
|
+
},
|
|
32
49
|
onChangeDate: {
|
|
33
50
|
action: 'dateChanged',
|
|
34
51
|
description: 'Callback fired when date changes',
|
|
@@ -73,3 +90,17 @@ export const WithError = {
|
|
|
73
90
|
},
|
|
74
91
|
},
|
|
75
92
|
};
|
|
93
|
+
export const WithDateRange = {
|
|
94
|
+
args: {
|
|
95
|
+
label: 'Select Date (Limited Range)',
|
|
96
|
+
minDate: new Date(2024, 0, 1),
|
|
97
|
+
maxDate: new Date(2025, 11, 31),
|
|
98
|
+
},
|
|
99
|
+
parameters: {
|
|
100
|
+
docs: {
|
|
101
|
+
description: {
|
|
102
|
+
story: 'Date picker with minimum and maximum date constraints. Users can only select dates within the specified range.',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
package/dist/src/utils/dayjs.js
CHANGED
|
@@ -4,9 +4,13 @@ import utc from 'dayjs/plugin/utc';
|
|
|
4
4
|
import timezone from 'dayjs/plugin/timezone';
|
|
5
5
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
6
6
|
import duration from 'dayjs/plugin/duration';
|
|
7
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
8
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
7
9
|
dayjs.extend(customParseFormat);
|
|
8
10
|
dayjs.extend(utc);
|
|
9
11
|
dayjs.extend(timezone);
|
|
10
12
|
dayjs.extend(relativeTime);
|
|
11
13
|
dayjs.extend(duration);
|
|
14
|
+
dayjs.extend(isSameOrAfter);
|
|
15
|
+
dayjs.extend(isSameOrBefore);
|
|
12
16
|
export { dayjs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eml-payments/ui-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ARLO UIKit",
|
|
6
6
|
"homepage": "https://github.com/EML-Payments/arlo.npm.uikit#readme",
|
|
@@ -66,7 +66,6 @@
|
|
|
66
66
|
"@tanstack/react-virtual": "^3.13.13",
|
|
67
67
|
"class-variance-authority": "^0.7.1",
|
|
68
68
|
"clsx": "^2.1.1",
|
|
69
|
-
"date-fns": "^4.1.0",
|
|
70
69
|
"dayjs": "^1.11.19",
|
|
71
70
|
"lucide-react": "^0.562.0",
|
|
72
71
|
"prettier": "^3.6.2",
|