@scaleflex/ui-tw 0.0.59 → 0.0.61
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/date-picker/date-picker.component.d.ts +1 -1
- package/date-picker/date-picker.component.js +29 -13
- package/date-picker/date-picker.constants.d.ts +6 -0
- package/date-picker/date-picker.constants.js +69 -1
- package/date-picker/date-picker.types.d.ts +7 -0
- package/date-picker/index.d.ts +1 -0
- package/date-picker/index.js +2 -1
- package/input-tags/input-tags.component.js +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DatePickerProps } from './date-picker.types';
|
|
3
|
-
declare function DatePicker({ minDate, maxDate, readOnly, defaultDate, size, invalidDateText, disabled, onChange, popoverClassName, defaultOpen, popoverContentProps, onKeyDown, onBlur, ...rest }: DatePickerProps): React.JSX.Element;
|
|
3
|
+
declare function DatePicker({ minDate, maxDate, readOnly, defaultDate, size, invalidDateText, disabled, onChange, popoverClassName, defaultOpen, popoverContentProps, onKeyDown, onBlur, placeholder, format: dateFormat, locale, calendarProps, ...rest }: DatePickerProps): React.JSX.Element;
|
|
4
4
|
export { DatePicker };
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["minDate", "maxDate", "readOnly", "defaultDate", "size", "invalidDateText", "disabled", "onChange", "popoverClassName", "defaultOpen", "popoverContentProps", "onKeyDown", "onBlur"];
|
|
5
|
+
var _excluded = ["minDate", "maxDate", "readOnly", "defaultDate", "size", "invalidDateText", "disabled", "onChange", "popoverClassName", "defaultOpen", "popoverContentProps", "onKeyDown", "onBlur", "placeholder", "format", "locale", "calendarProps"];
|
|
6
6
|
import { Button } from '@scaleflex/ui-tw/button';
|
|
7
7
|
import { Calendar } from '@scaleflex/ui-tw/calendar';
|
|
8
8
|
import { Input } from '@scaleflex/ui-tw/input';
|
|
@@ -12,10 +12,11 @@ import { getBaseSelectClassNames, selectReadOnlyClassNames } from '@scaleflex/ui
|
|
|
12
12
|
import { getBaseInputClasses } from '@scaleflex/ui-tw/styles/shared-classes';
|
|
13
13
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
14
14
|
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
15
|
+
import { format, isValid, parse } from 'date-fns';
|
|
16
|
+
import { enGB } from 'date-fns/locale';
|
|
15
17
|
import { CalendarIcon } from 'lucide-react';
|
|
16
18
|
import React, { useRef, useState } from 'react';
|
|
17
19
|
import { buttonSizeInTriggerOptions, iconSizeInTriggerOptions } from './date-picker.constants';
|
|
18
|
-
import { parseDateString, toHtmlDateString } from './date-picker.utils';
|
|
19
20
|
function DatePicker(_ref) {
|
|
20
21
|
var minDate = _ref.minDate,
|
|
21
22
|
maxDate = _ref.maxDate,
|
|
@@ -33,6 +34,12 @@ function DatePicker(_ref) {
|
|
|
33
34
|
popoverContentProps = _ref.popoverContentProps,
|
|
34
35
|
onKeyDown = _ref.onKeyDown,
|
|
35
36
|
onBlur = _ref.onBlur,
|
|
37
|
+
placeholder = _ref.placeholder,
|
|
38
|
+
_ref$format = _ref.format,
|
|
39
|
+
dateFormat = _ref$format === void 0 ? 'dd/MM/yyyy' : _ref$format,
|
|
40
|
+
_ref$locale = _ref.locale,
|
|
41
|
+
locale = _ref$locale === void 0 ? enGB : _ref$locale,
|
|
42
|
+
calendarProps = _ref.calendarProps,
|
|
36
43
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
37
44
|
var inputRef = useRef(null);
|
|
38
45
|
var isEscapeBlur = useRef(false);
|
|
@@ -40,7 +47,9 @@ function DatePicker(_ref) {
|
|
|
40
47
|
_useState2 = _slicedToArray(_useState, 2),
|
|
41
48
|
open = _useState2[0],
|
|
42
49
|
setOpen = _useState2[1];
|
|
43
|
-
var _useState3 = useState(
|
|
50
|
+
var _useState3 = useState(defaultDate ? format(defaultDate, dateFormat, {
|
|
51
|
+
locale: locale
|
|
52
|
+
}) : ''),
|
|
44
53
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
45
54
|
inputValue = _useState4[0],
|
|
46
55
|
setInputValue = _useState4[1];
|
|
@@ -52,13 +61,17 @@ function DatePicker(_ref) {
|
|
|
52
61
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
53
62
|
calendarMonth = _useState8[0],
|
|
54
63
|
setCalendarMonth = _useState8[1];
|
|
55
|
-
var parsedDate = inputValue
|
|
56
|
-
|
|
64
|
+
var parsedDate = inputValue ? parse(inputValue, dateFormat, new Date(), {
|
|
65
|
+
locale: locale
|
|
66
|
+
}) : undefined;
|
|
67
|
+
var isInputValid = !inputValue || parsedDate && isValid(parsedDate);
|
|
57
68
|
var handleInputChange = function handleInputChange(e) {
|
|
58
69
|
var value = e.target.value;
|
|
59
70
|
setInputValue(value);
|
|
60
|
-
var parsed =
|
|
61
|
-
|
|
71
|
+
var parsed = parse(value, dateFormat, new Date(), {
|
|
72
|
+
locale: locale
|
|
73
|
+
});
|
|
74
|
+
if (isValid(parsed)) {
|
|
62
75
|
setSelectedDate(parsed);
|
|
63
76
|
setCalendarMonth(parsed);
|
|
64
77
|
}
|
|
@@ -67,7 +80,9 @@ function DatePicker(_ref) {
|
|
|
67
80
|
if (date) {
|
|
68
81
|
var _inputRef$current;
|
|
69
82
|
setSelectedDate(date);
|
|
70
|
-
setInputValue(
|
|
83
|
+
setInputValue(format(date, dateFormat, {
|
|
84
|
+
locale: locale
|
|
85
|
+
}));
|
|
71
86
|
setCalendarMonth(date);
|
|
72
87
|
setOpen(false);
|
|
73
88
|
onChange === null || onChange === void 0 || onChange(date);
|
|
@@ -108,7 +123,7 @@ function DatePicker(_ref) {
|
|
|
108
123
|
inputMode: "numeric",
|
|
109
124
|
autoComplete: "off",
|
|
110
125
|
pattern: "\\d{2}/\\d{2}/\\d{4}",
|
|
111
|
-
placeholder:
|
|
126
|
+
placeholder: placeholder || dateFormat,
|
|
112
127
|
value: inputValue,
|
|
113
128
|
disabled: disabled,
|
|
114
129
|
className: cn.apply(void 0, _toConsumableArray(getBaseSelectClassNames()).concat(_toConsumableArray(getBaseInputClasses()), ['hover:border-secondary-foreground/50', selectTriggerVariants({
|
|
@@ -143,7 +158,7 @@ function DatePicker(_ref) {
|
|
|
143
158
|
align: "end",
|
|
144
159
|
alignOffset: -8,
|
|
145
160
|
sideOffset: 10
|
|
146
|
-
}, popoverContentProps), /*#__PURE__*/React.createElement(Calendar, {
|
|
161
|
+
}, popoverContentProps), /*#__PURE__*/React.createElement(Calendar, _extends({
|
|
147
162
|
mode: "single",
|
|
148
163
|
selected: selectedDate,
|
|
149
164
|
captionLayout: "dropdown",
|
|
@@ -154,9 +169,10 @@ function DatePicker(_ref) {
|
|
|
154
169
|
before: minDate
|
|
155
170
|
}, maxDate && {
|
|
156
171
|
after: maxDate
|
|
157
|
-
}].filter(Boolean)
|
|
158
|
-
|
|
172
|
+
}].filter(Boolean),
|
|
173
|
+
locale: locale
|
|
174
|
+
}, calendarProps))))), !isInputValid && /*#__PURE__*/React.createElement("span", {
|
|
159
175
|
className: "px-1 text-xs text-red-500"
|
|
160
|
-
}, invalidDateText !== null && invalidDateText !== void 0 ? invalidDateText :
|
|
176
|
+
}, invalidDateText !== null && invalidDateText !== void 0 ? invalidDateText : "Invalid date. Use ".concat(placeholder || dateFormat)));
|
|
161
177
|
}
|
|
162
178
|
export { DatePicker };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Locale } from 'date-fns';
|
|
1
2
|
export declare const iconSizeInTriggerOptions: {
|
|
2
3
|
sm: string;
|
|
3
4
|
md: string;
|
|
@@ -8,3 +9,8 @@ export declare const buttonSizeInTriggerOptions: {
|
|
|
8
9
|
md: string;
|
|
9
10
|
lg: string;
|
|
10
11
|
};
|
|
12
|
+
export declare const SUPPORTED_DATE_LOCALES: Record<string, {
|
|
13
|
+
label: string;
|
|
14
|
+
locale: Locale;
|
|
15
|
+
format: string;
|
|
16
|
+
}>;
|
|
@@ -1,4 +1,72 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
3
|
+
import { de, enGB, enUS, es, fr, id, it, ja, nl, pl, pt, ro, zhCN } from 'date-fns/locale';
|
|
3
4
|
export var iconSizeInTriggerOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'size-3'), FormSize.Md, 'size-4'), FormSize.Lg, 'size-5');
|
|
4
|
-
export var buttonSizeInTriggerOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'icon-xs'), FormSize.Md, 'icon-sm'), FormSize.Lg, 'icon-md');
|
|
5
|
+
export var buttonSizeInTriggerOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'icon-xs'), FormSize.Md, 'icon-sm'), FormSize.Lg, 'icon-md');
|
|
6
|
+
export var SUPPORTED_DATE_LOCALES = {
|
|
7
|
+
en: {
|
|
8
|
+
label: 'English (US)',
|
|
9
|
+
locale: enUS,
|
|
10
|
+
format: 'MM/dd/yyyy'
|
|
11
|
+
},
|
|
12
|
+
enGB: {
|
|
13
|
+
label: 'English (UK)',
|
|
14
|
+
locale: enGB,
|
|
15
|
+
format: 'dd/MM/yyyy'
|
|
16
|
+
},
|
|
17
|
+
de: {
|
|
18
|
+
label: 'German',
|
|
19
|
+
locale: de,
|
|
20
|
+
format: 'dd.MM.yyyy'
|
|
21
|
+
},
|
|
22
|
+
es: {
|
|
23
|
+
label: 'Spanish',
|
|
24
|
+
locale: es,
|
|
25
|
+
format: 'dd/MM/yyyy'
|
|
26
|
+
},
|
|
27
|
+
fr: {
|
|
28
|
+
label: 'French',
|
|
29
|
+
locale: fr,
|
|
30
|
+
format: 'dd/MM/yyyy'
|
|
31
|
+
},
|
|
32
|
+
id: {
|
|
33
|
+
label: 'Indonesian',
|
|
34
|
+
locale: id,
|
|
35
|
+
format: 'dd/MM/yyyy'
|
|
36
|
+
},
|
|
37
|
+
it: {
|
|
38
|
+
label: 'Italian',
|
|
39
|
+
locale: it,
|
|
40
|
+
format: 'dd/MM/yyyy'
|
|
41
|
+
},
|
|
42
|
+
ja: {
|
|
43
|
+
label: 'Japanese',
|
|
44
|
+
locale: ja,
|
|
45
|
+
format: 'yyyy/MM/dd'
|
|
46
|
+
},
|
|
47
|
+
nl: {
|
|
48
|
+
label: 'Dutch',
|
|
49
|
+
locale: nl,
|
|
50
|
+
format: 'dd-MM-yyyy'
|
|
51
|
+
},
|
|
52
|
+
pl: {
|
|
53
|
+
label: 'Polish',
|
|
54
|
+
locale: pl,
|
|
55
|
+
format: 'dd.MM.yyyy'
|
|
56
|
+
},
|
|
57
|
+
pt: {
|
|
58
|
+
label: 'Portuguese',
|
|
59
|
+
locale: pt,
|
|
60
|
+
format: 'dd/MM/yyyy'
|
|
61
|
+
},
|
|
62
|
+
ro: {
|
|
63
|
+
label: 'Romanian',
|
|
64
|
+
locale: ro,
|
|
65
|
+
format: 'dd.MM.yyyy'
|
|
66
|
+
},
|
|
67
|
+
zh: {
|
|
68
|
+
label: 'Chinese',
|
|
69
|
+
locale: zhCN,
|
|
70
|
+
format: 'yyyy/MM/dd'
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
2
2
|
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
3
|
+
import type { Locale } from 'date-fns';
|
|
3
4
|
import type { ComponentProps, FocusEvent, KeyboardEvent } from 'react';
|
|
5
|
+
import { DayPicker } from 'react-day-picker';
|
|
4
6
|
export type DatePickerProps = {
|
|
5
7
|
minDate?: Date;
|
|
6
8
|
maxDate?: Date;
|
|
@@ -15,4 +17,9 @@ export type DatePickerProps = {
|
|
|
15
17
|
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
|
16
18
|
onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
|
|
17
19
|
popoverContentProps?: ComponentProps<typeof PopoverPrimitive.Content>;
|
|
20
|
+
calendarProps?: Omit<ComponentProps<typeof DayPicker>, 'selected' | 'onSelect' | 'month' | 'mode' | 'captionLayout' | 'onMonthChange' | 'disabled'>;
|
|
21
|
+
pattern?: string;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
format?: string;
|
|
24
|
+
locale?: Locale;
|
|
18
25
|
};
|
package/date-picker/index.d.ts
CHANGED
package/date-picker/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { DatePicker } from './date-picker.component';
|
|
1
|
+
export { DatePicker } from './date-picker.component';
|
|
2
|
+
export { SUPPORTED_DATE_LOCALES } from './date-picker.constants';
|
|
@@ -139,7 +139,7 @@ export function InputTags(_ref) {
|
|
|
139
139
|
return !disabled && setOpen(true);
|
|
140
140
|
}
|
|
141
141
|
}, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
142
|
-
className: cn('flex w-full flex-wrap gap-2', inputTagsVariants({
|
|
142
|
+
className: cn('flex w-full flex-wrap gap-2 overflow-y-auto', inputTagsVariants({
|
|
143
143
|
size: size
|
|
144
144
|
}), 'min-h-auto')
|
|
145
145
|
}, value.length === 0 ? /*#__PURE__*/React.createElement("span", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/ui-tw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"author": "scaleflex",
|
|
5
5
|
"repository": "github:scaleflex/ui",
|
|
6
6
|
"homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@radix-ui/react-slot": "^1.1.2",
|
|
24
24
|
"@radix-ui/react-switch": "^1.0.1",
|
|
25
25
|
"@radix-ui/react-tooltip": "^1.2.6",
|
|
26
|
-
"@scaleflex/icons-tw": "^0.0.
|
|
26
|
+
"@scaleflex/icons-tw": "^0.0.61",
|
|
27
27
|
"@tanstack/react-table": "^8.21.3",
|
|
28
28
|
"@types/lodash.merge": "^4.6.9",
|
|
29
29
|
"class-variance-authority": "^0.7.1",
|