x-ui-design 1.0.30 → 1.0.31-gamma.1
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/README.md +1 -22
- package/dist/{esm/types/components → components}/DatePicker/DatePicker.d.ts +1 -2
- package/dist/{esm/types/components → components}/DatePicker/RangePicker/RangePicker.d.ts +1 -2
- package/dist/{esm/types/components → components}/Dropdown/Dropdown.d.ts +1 -2
- package/dist/{esm/types/components → components}/Empty/Empty.d.ts +1 -2
- package/dist/{esm/types/components → components}/Form/Item/Item.d.ts +1 -2
- package/dist/components/Icons/Icons.d.ts +18 -0
- package/dist/components/Input/Input.d.ts +11 -0
- package/dist/{esm/types/components → components}/Input/Textarea/Textarea.d.ts +1 -2
- package/dist/{esm/types/components → components}/Popover/Popover.d.ts +1 -2
- package/dist/{esm/types/components → components}/Radio/Button/Button.d.ts +1 -2
- package/dist/{esm/types/components → components}/Radio/Group/Group.d.ts +1 -2
- package/dist/{esm/types/components → components}/Radio/Radio.d.ts +1 -2
- package/dist/{esm/types/components → components}/Result/Result.d.ts +1 -2
- package/dist/{esm/types/components → components}/Switch/Switch.d.ts +1 -2
- package/dist/{esm/types/components → components}/Upload/Upload.d.ts +1 -2
- package/dist/esm/types/index.d.ts +0 -56
- package/dist/index.d.ts +1 -150
- package/dist/index.esm.js +3433 -3863
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3395 -3825
- package/dist/index.js.map +1 -1
- package/package.json +22 -20
- package/.github/workflows/x-ui-design.yml +0 -14
- package/compile.sh +0 -15
- package/dist/esm/types/components/Icons/Icons.d.ts +0 -19
- package/dist/esm/types/components/Input/Input.d.ts +0 -16
- package/eslint.config.mjs +0 -16
- package/lib/components/Button/Button.tsx +0 -136
- package/lib/components/Button/index.ts +0 -1
- package/lib/components/Button/style.css +0 -197
- package/lib/components/Checkbox/Checkbox.tsx +0 -131
- package/lib/components/Checkbox/index.ts +0 -1
- package/lib/components/Checkbox/style.css +0 -95
- package/lib/components/ConditionalWrapper/index.tsx +0 -12
- package/lib/components/DatePicker/DatePicker.tsx +0 -526
- package/lib/components/DatePicker/RangePicker/RangePicker.tsx +0 -500
- package/lib/components/DatePicker/RangePicker/index.ts +0 -1
- package/lib/components/DatePicker/RangePicker/style.css +0 -434
- package/lib/components/DatePicker/TimePicker/TimePicker.tsx +0 -497
- package/lib/components/DatePicker/TimePicker/index.ts +0 -1
- package/lib/components/DatePicker/TimePicker/style.css +0 -197
- package/lib/components/DatePicker/index.ts +0 -1
- package/lib/components/DatePicker/style.css +0 -318
- package/lib/components/Dropdown/Dropdown.tsx +0 -234
- package/lib/components/Dropdown/index.ts +0 -1
- package/lib/components/Dropdown/style.css +0 -124
- package/lib/components/Empty/Empty.tsx +0 -45
- package/lib/components/Empty/index.ts +0 -1
- package/lib/components/Empty/style.css +0 -13
- package/lib/components/Form/Form.tsx +0 -130
- package/lib/components/Form/Item/Item.tsx +0 -294
- package/lib/components/Form/Item/index.ts +0 -1
- package/lib/components/Form/Item/style.css +0 -61
- package/lib/components/Form/index.ts +0 -1
- package/lib/components/Icons/Icons.tsx +0 -433
- package/lib/components/Icons/index.ts +0 -15
- package/lib/components/Input/Input.tsx +0 -228
- package/lib/components/Input/Textarea/Textarea.tsx +0 -110
- package/lib/components/Input/Textarea/index.ts +0 -1
- package/lib/components/Input/Textarea/style.css +0 -104
- package/lib/components/Input/index.ts +0 -1
- package/lib/components/Input/style.css +0 -137
- package/lib/components/Menu/Item/Item.tsx +0 -65
- package/lib/components/Menu/Menu.tsx +0 -261
- package/lib/components/Menu/SubMenu/SubMenu.tsx +0 -68
- package/lib/components/Menu/index.css +0 -145
- package/lib/components/Menu/index.ts +0 -1
- package/lib/components/Popover/Popover.tsx +0 -135
- package/lib/components/Popover/index.ts +0 -1
- package/lib/components/Popover/style.css +0 -82
- package/lib/components/Radio/Button/Button.tsx +0 -42
- package/lib/components/Radio/Button/index.ts +0 -1
- package/lib/components/Radio/Button/style.css +0 -43
- package/lib/components/Radio/Group/Group.tsx +0 -105
- package/lib/components/Radio/Group/index.ts +0 -1
- package/lib/components/Radio/Group/style.css +0 -53
- package/lib/components/Radio/Radio.tsx +0 -83
- package/lib/components/Radio/index.ts +0 -1
- package/lib/components/Radio/style.css +0 -73
- package/lib/components/Result/Result.tsx +0 -39
- package/lib/components/Result/index.ts +0 -1
- package/lib/components/Result/style.css +0 -173
- package/lib/components/Select/Option/Option.tsx +0 -49
- package/lib/components/Select/Option/index.ts +0 -1
- package/lib/components/Select/Option/style.css +0 -50
- package/lib/components/Select/Select.tsx +0 -935
- package/lib/components/Select/Tag/Tag.tsx +0 -43
- package/lib/components/Select/Tag/index.ts +0 -1
- package/lib/components/Select/Tag/style.css +0 -87
- package/lib/components/Select/index.ts +0 -1
- package/lib/components/Select/style.css +0 -186
- package/lib/components/Skeleton/Avatar/Avatar.tsx +0 -61
- package/lib/components/Skeleton/Avatar/index.ts +0 -1
- package/lib/components/Skeleton/Avatar/style.css +0 -27
- package/lib/components/Skeleton/Button/Button.tsx +0 -44
- package/lib/components/Skeleton/Button/index.ts +0 -1
- package/lib/components/Skeleton/Button/style.css +0 -50
- package/lib/components/Skeleton/Image/Image.tsx +0 -45
- package/lib/components/Skeleton/Image/index.ts +0 -1
- package/lib/components/Skeleton/Image/style.css +0 -23
- package/lib/components/Skeleton/Input/Input.tsx +0 -42
- package/lib/components/Skeleton/Input/index.ts +0 -1
- package/lib/components/Skeleton/Input/style.css +0 -56
- package/lib/components/Skeleton/Skeleton.tsx +0 -97
- package/lib/components/Skeleton/index.ts +0 -1
- package/lib/components/Skeleton/style.css +0 -84
- package/lib/components/Switch/Switch.tsx +0 -68
- package/lib/components/Switch/index.css +0 -50
- package/lib/components/Switch/index.ts +0 -1
- package/lib/components/Upload/Upload.tsx +0 -291
- package/lib/components/Upload/index.ts +0 -1
- package/lib/components/Upload/style.css +0 -151
- package/lib/global.d.ts +0 -1
- package/lib/helpers/flatten.ts +0 -26
- package/lib/helpers/index.ts +0 -52
- package/lib/helpers/mask.ts +0 -52
- package/lib/hooks/useForm.ts +0 -548
- package/lib/hooks/usePosition.ts +0 -206
- package/lib/hooks/useWatch.ts +0 -41
- package/lib/hooks/useWatchError.ts +0 -20
- package/lib/index.ts +0 -184
- package/lib/styles/global.css +0 -57
- package/lib/types/button.ts +0 -83
- package/lib/types/checkbox.ts +0 -32
- package/lib/types/datepicker.ts +0 -165
- package/lib/types/dropdown.ts +0 -41
- package/lib/types/empty.ts +0 -8
- package/lib/types/form.ts +0 -179
- package/lib/types/index.ts +0 -38
- package/lib/types/input.ts +0 -72
- package/lib/types/menu.ts +0 -55
- package/lib/types/popover.ts +0 -16
- package/lib/types/radio.ts +0 -69
- package/lib/types/result.ts +0 -22
- package/lib/types/select.ts +0 -126
- package/lib/types/skeleton.ts +0 -62
- package/lib/types/switch.ts +0 -22
- package/lib/types/upload.ts +0 -67
- package/lib/utils/index.ts +0 -37
- package/lib/utils/lazy.ts +0 -17
- package/next.config.ts +0 -7
- package/rollup.config.js +0 -71
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +0 -48
- package/src/app/layout.d.ts +0 -5
- package/src/app/layout.tsx +0 -16
- package/src/app/page.d.ts +0 -1
- package/src/app/page.tsx +0 -21
- package/tsconfig.json +0 -46
- /package/dist/{esm/types/components → components}/Button/Button.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Button/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Checkbox/Checkbox.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Checkbox/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/ConditionalWrapper/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/RangePicker/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/TimePicker/TimePicker.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/TimePicker/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Dropdown/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Empty/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Form/Form.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Form/Item/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Form/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Icons/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Input/Textarea/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Input/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/Item/Item.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/Menu.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/SubMenu/SubMenu.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Popover/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Radio/Button/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Radio/Group/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Radio/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Result/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Option/Option.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Option/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Select.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Tag/Tag.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Tag/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Avatar/Avatar.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Avatar/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Button/Button.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Button/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Image/Image.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Image/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Input/Input.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Input/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Skeleton.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Switch/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Upload/index.d.ts +0 -0
- /package/dist/{esm/types/helpers → helpers}/flatten.d.ts +0 -0
- /package/dist/{esm/types/helpers → helpers}/index.d.ts +0 -0
- /package/dist/{esm/types/helpers → helpers}/mask.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/useForm.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/usePosition.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/useWatch.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/useWatchError.d.ts +0 -0
- /package/dist/{esm/types/types → types}/button.d.ts +0 -0
- /package/dist/{esm/types/types → types}/checkbox.d.ts +0 -0
- /package/dist/{esm/types/types → types}/datepicker.d.ts +0 -0
- /package/dist/{esm/types/types → types}/dropdown.d.ts +0 -0
- /package/dist/{esm/types/types → types}/empty.d.ts +0 -0
- /package/dist/{esm/types/types → types}/form.d.ts +0 -0
- /package/dist/{esm/types/types → types}/index.d.ts +0 -0
- /package/dist/{esm/types/types → types}/input.d.ts +0 -0
- /package/dist/{esm/types/types → types}/menu.d.ts +0 -0
- /package/dist/{esm/types/types → types}/popover.d.ts +0 -0
- /package/dist/{esm/types/types → types}/radio.d.ts +0 -0
- /package/dist/{esm/types/types → types}/result.d.ts +0 -0
- /package/dist/{esm/types/types → types}/select.d.ts +0 -0
- /package/dist/{esm/types/types → types}/skeleton.d.ts +0 -0
- /package/dist/{esm/types/types → types}/switch.d.ts +0 -0
- /package/dist/{esm/types/types → types}/upload.d.ts +0 -0
- /package/dist/{esm/types/utils → utils}/index.d.ts +0 -0
- /package/dist/{esm/types/utils → utils}/lazy.d.ts +0 -0
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
.xUi-checkbox-wrapper {
|
|
2
|
-
cursor: pointer;
|
|
3
|
-
font-size: var(--xui-font-size-md);
|
|
4
|
-
align-items: center;
|
|
5
|
-
display: inline-flex;
|
|
6
|
-
color: var(--xui-main-color);
|
|
7
|
-
margin: 16px 0;
|
|
8
|
-
|
|
9
|
-
&:has([tabindex="0"]:focus-visible) {
|
|
10
|
-
border-color: var(--xui-primary-color);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.xUi-checkbox {
|
|
15
|
-
width: 14px;
|
|
16
|
-
height: 14px;
|
|
17
|
-
position: relative;
|
|
18
|
-
border-radius: var(--xui-border-radius-sm);
|
|
19
|
-
transition: all 0.3s;
|
|
20
|
-
display: inline-block;
|
|
21
|
-
background-color: transparent;
|
|
22
|
-
border: 1px solid var(--xui-border-color);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.xUi-checkbox.xUi-checkbox-checked {
|
|
26
|
-
border-color: var(--xui-primary-color);
|
|
27
|
-
background-color: #f0f5ff;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.xUi-checkbox input {
|
|
31
|
-
inset: 0;
|
|
32
|
-
opacity: 0;
|
|
33
|
-
cursor: pointer;
|
|
34
|
-
position: absolute;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.xUi-checkbox-inner {
|
|
38
|
-
top: 50%;
|
|
39
|
-
left: 50%;
|
|
40
|
-
width: 10px;
|
|
41
|
-
height: 6px;
|
|
42
|
-
border-top: 0;
|
|
43
|
-
border-left: 0;
|
|
44
|
-
position: absolute;
|
|
45
|
-
border: 2px solid var(--xui-background-color);
|
|
46
|
-
transform: rotate(45deg) scale(0);
|
|
47
|
-
transition: transform 0.2s ease-in-out;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.xUi-checkbox-check {
|
|
51
|
-
width: 100%;
|
|
52
|
-
height: 100%;
|
|
53
|
-
display: block;
|
|
54
|
-
position: relative;
|
|
55
|
-
transition: 0.1s ease;
|
|
56
|
-
border-color: var(--xui-primary-color);
|
|
57
|
-
background-color: var(--xui-primary-color);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.xUi-checkbox-check::after {
|
|
61
|
-
top: 1px;
|
|
62
|
-
left: 3px;
|
|
63
|
-
width: 5px;
|
|
64
|
-
height: 8px;
|
|
65
|
-
content: "";
|
|
66
|
-
position: absolute;
|
|
67
|
-
border: solid white;
|
|
68
|
-
transform: rotate(45deg);
|
|
69
|
-
border-width: 0 2px 2px 0;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.xUi-checkbox-disabled,
|
|
73
|
-
.xUi-checkbox-disabled .xUi-checkbox-check {
|
|
74
|
-
opacity: 0.5;
|
|
75
|
-
cursor: not-allowed;
|
|
76
|
-
background-color: var(--xui-color-disabled);
|
|
77
|
-
border-color: var(--xui-border-color) !important;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.xUi-checkbox-label {
|
|
81
|
-
margin-left: 8px;
|
|
82
|
-
user-select: none;
|
|
83
|
-
font-size: 14px;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.xUi-checkbox:hover:not(.disabled),
|
|
87
|
-
.xUi-checkbox:focus:not(.disabled) {
|
|
88
|
-
border-color: var(--xui-primary-color);
|
|
89
|
-
cursor: pointer;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.xUi-checkbox.disabled {
|
|
93
|
-
opacity: 0.5;
|
|
94
|
-
cursor: not-allowed;
|
|
95
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FC, PropsWithChildren, ReactElement } from 'react';
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
condition: boolean;
|
|
5
|
-
wrapper: (children: PropsWithChildren['children']) => ReactElement;
|
|
6
|
-
} & PropsWithChildren;
|
|
7
|
-
|
|
8
|
-
export const ConditionalWrapper: FC<Props> = ({
|
|
9
|
-
condition,
|
|
10
|
-
wrapper,
|
|
11
|
-
children
|
|
12
|
-
}) => (condition ? wrapper(children) : children);
|
|
@@ -1,526 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
4
|
-
import { clsx } from '../../helpers';
|
|
5
|
-
import { TDatePickerProps } from '../../types/datepicker';
|
|
6
|
-
import { prefixClsDatePicker } from '../../utils';
|
|
7
|
-
import { CalendarIcon, ClearIcon, ErrorIcon } from '../Icons/Icons';
|
|
8
|
-
import { ConditionalWrapper } from '../ConditionalWrapper';
|
|
9
|
-
import { createPortal } from 'react-dom';
|
|
10
|
-
import { usePosition } from '../../hooks/usePosition';
|
|
11
|
-
import './style.css';
|
|
12
|
-
|
|
13
|
-
const INPUT_SIZE = 12;
|
|
14
|
-
export const NUMBER_SIX = 6;
|
|
15
|
-
export const MONTH_LENGTH = 11;
|
|
16
|
-
export const NEXT_DAYS_COUNT_AS_CURRENT_MUNTH = 35;
|
|
17
|
-
|
|
18
|
-
const monthNames = [
|
|
19
|
-
'Jan',
|
|
20
|
-
'Feb',
|
|
21
|
-
'Mar',
|
|
22
|
-
'Apr',
|
|
23
|
-
'May',
|
|
24
|
-
'Jun',
|
|
25
|
-
'Jul',
|
|
26
|
-
'Aug',
|
|
27
|
-
'Sep',
|
|
28
|
-
'Oct',
|
|
29
|
-
'Nov',
|
|
30
|
-
'Dec'
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
const DatePicker = ({
|
|
34
|
-
value,
|
|
35
|
-
onChange,
|
|
36
|
-
onCalendarChange,
|
|
37
|
-
disabled,
|
|
38
|
-
error,
|
|
39
|
-
placeholder = 'Select date',
|
|
40
|
-
prefixCls = prefixClsDatePicker,
|
|
41
|
-
noStyle,
|
|
42
|
-
feedbackIcons,
|
|
43
|
-
locale,
|
|
44
|
-
className = '',
|
|
45
|
-
placement = 'bottomLeft',
|
|
46
|
-
defaultValue,
|
|
47
|
-
size = 'large',
|
|
48
|
-
format = 'YYYY-MM-DD',
|
|
49
|
-
getPopupContainer,
|
|
50
|
-
showToday = true,
|
|
51
|
-
allowClear = false,
|
|
52
|
-
disabledDate,
|
|
53
|
-
suffixIcon,
|
|
54
|
-
picker = 'date',
|
|
55
|
-
prefix,
|
|
56
|
-
defaultOpen = false,
|
|
57
|
-
inputReadOnly = false,
|
|
58
|
-
bordered = true,
|
|
59
|
-
defaultPickerValue
|
|
60
|
-
}: TDatePickerProps) => {
|
|
61
|
-
const triggerRef = useRef<HTMLDivElement>(null);
|
|
62
|
-
const initialDate = value || defaultValue;
|
|
63
|
-
const initialPickerDate = defaultPickerValue || initialDate;
|
|
64
|
-
|
|
65
|
-
const popupRef = useRef<HTMLDivElement>(null);
|
|
66
|
-
const popuptriggerRef = useRef<HTMLElement | null>(null);
|
|
67
|
-
|
|
68
|
-
const DateNow = new Date();
|
|
69
|
-
|
|
70
|
-
const [selectedDate, setSelectedDate] = useState<Date | undefined>(
|
|
71
|
-
initialDate
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const [selectedDatePlaceholder, setSelectedDatePlaceholder] = useState<
|
|
75
|
-
string | undefined
|
|
76
|
-
>(initialDate ? formatDate(initialDate, format as string) : undefined);
|
|
77
|
-
|
|
78
|
-
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
79
|
-
const [currentYear, setCurrentYear] = useState(
|
|
80
|
-
initialPickerDate ? new Date(initialPickerDate).getFullYear() : DateNow.getFullYear()
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const [currentMonth, setCurrentMonth] = useState(
|
|
84
|
-
initialPickerDate ? new Date(initialPickerDate).getMonth() : DateNow.getMonth()
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const [viewMode, setViewMode] = useState<'day' | 'month' | 'year'>(
|
|
88
|
-
picker === 'month' ? 'month' : picker === 'year' ? 'year' : 'day'
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const localeMonths =
|
|
92
|
-
locale?.shortMonths ||
|
|
93
|
-
Array.from({ length: 12 }, (_, i) =>
|
|
94
|
-
new Date(0, i).toLocaleString(locale?.locale || 'default', {
|
|
95
|
-
month: 'short'
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const localeWeekdays = locale?.shortWeekDays || [
|
|
100
|
-
'Su',
|
|
101
|
-
'Mo',
|
|
102
|
-
'Tu',
|
|
103
|
-
'We',
|
|
104
|
-
'Th',
|
|
105
|
-
'Fr',
|
|
106
|
-
'Sa'
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
const { dropdownPosition } = usePosition({
|
|
110
|
-
isOpen,
|
|
111
|
-
popupRef,
|
|
112
|
-
placement,
|
|
113
|
-
triggerRef,
|
|
114
|
-
getPopupContainer: getPopupContainer?.(triggerRef.current as HTMLElement)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
const _date = value || defaultValue;
|
|
119
|
-
|
|
120
|
-
setSelectedDate(_date);
|
|
121
|
-
setSelectedDatePlaceholder(_date ? formatDate(_date, format as string) : undefined);
|
|
122
|
-
}, [value])
|
|
123
|
-
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
const handleClickOutside = (event: MouseEvent) => {
|
|
126
|
-
if (
|
|
127
|
-
popupRef.current &&
|
|
128
|
-
!popupRef.current.contains(event.target as Node) &&
|
|
129
|
-
triggerRef.current &&
|
|
130
|
-
!triggerRef.current.contains(event.target as Node)
|
|
131
|
-
) {
|
|
132
|
-
setIsOpen(false);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const controller = new AbortController();
|
|
137
|
-
|
|
138
|
-
if (isOpen) {
|
|
139
|
-
document.addEventListener('mousedown', handleClickOutside, {
|
|
140
|
-
signal: controller.signal
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return () => {
|
|
145
|
-
controller.abort();
|
|
146
|
-
};
|
|
147
|
-
}, [isOpen]);
|
|
148
|
-
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
if (getPopupContainer && triggerRef.current) {
|
|
151
|
-
popuptriggerRef.current = getPopupContainer(triggerRef.current);
|
|
152
|
-
}
|
|
153
|
-
}, [getPopupContainer]);
|
|
154
|
-
|
|
155
|
-
const daysInMonth = (year: number, month: number) =>
|
|
156
|
-
new Date(year, month + 1, 0).getDate();
|
|
157
|
-
|
|
158
|
-
const firstDayOfMonth = (year: number, month: number) =>
|
|
159
|
-
new Date(year, month, 1).getDay();
|
|
160
|
-
|
|
161
|
-
function formatDate(date: Date, format?: string | ((d: Date) => string)): string {
|
|
162
|
-
if (typeof format === 'function') {
|
|
163
|
-
return format(date);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (typeof format === 'string') {
|
|
167
|
-
date = new Date(date);
|
|
168
|
-
|
|
169
|
-
return format
|
|
170
|
-
.replace(/YYYY/, date.getFullYear().toString())
|
|
171
|
-
.replace(/MMM/, monthNames[date.getMonth()])
|
|
172
|
-
.replace(/MM/, (date.getMonth() + 1).toString().padStart(2, '0'))
|
|
173
|
-
.replace(/DD/, date.getDate().toString().padStart(2, '0'));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return `${date.getFullYear()}-${(date.getMonth() + 1)
|
|
177
|
-
.toString()
|
|
178
|
-
.padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const handleSelect = (day: number, month: number, year: number) => {
|
|
183
|
-
if (disabled) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const date = new Date(year, month, day);
|
|
188
|
-
|
|
189
|
-
if (disabledDate?.(date, { from: undefined, to: undefined })) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
setCurrentMonth(month);
|
|
194
|
-
setCurrentYear(year);
|
|
195
|
-
setSelectedDate(date);
|
|
196
|
-
|
|
197
|
-
const formatted = formatDate(date, format as string);
|
|
198
|
-
setSelectedDatePlaceholder(formatted);
|
|
199
|
-
onChange?.(date.toUTCString(), formatted);
|
|
200
|
-
onCalendarChange?.(date.toUTCString(), formatted, { range: undefined });
|
|
201
|
-
setIsOpen(false);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const clearSelection = () => {
|
|
205
|
-
setSelectedDate(undefined);
|
|
206
|
-
setSelectedDatePlaceholder(undefined);
|
|
207
|
-
onChange?.(null, '');
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const isMonthDisabled = (month: number) => {
|
|
211
|
-
const date = new Date(currentYear, month + 1, 1);
|
|
212
|
-
|
|
213
|
-
return disabledDate?.(date, { from: undefined, to: undefined });
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const isYearDisabled = (year: number) => {
|
|
217
|
-
const date = new Date(year + 1, currentMonth, 1);
|
|
218
|
-
|
|
219
|
-
return disabledDate?.(date, { from: undefined, to: undefined });
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const prevMonth = currentMonth === 0 ? MONTH_LENGTH : currentMonth - 1;
|
|
223
|
-
const nextMonth = currentMonth === MONTH_LENGTH ? 0 : currentMonth + 1;
|
|
224
|
-
const prevMonthYear = currentMonth === 0 ? currentYear - 1 : currentYear;
|
|
225
|
-
const nextMonthYear =
|
|
226
|
-
currentMonth === MONTH_LENGTH ? currentYear + 1 : currentYear;
|
|
227
|
-
|
|
228
|
-
const totalDays = daysInMonth(currentYear, currentMonth);
|
|
229
|
-
const firstDay = firstDayOfMonth(currentYear, currentMonth);
|
|
230
|
-
const prevMonthDays = daysInMonth(prevMonthYear, prevMonth);
|
|
231
|
-
const nextDaysCount =
|
|
232
|
-
NEXT_DAYS_COUNT_AS_CURRENT_MUNTH - (firstDay + totalDays);
|
|
233
|
-
|
|
234
|
-
const days = [
|
|
235
|
-
...Array.from({ length: firstDay }, (_, i) => ({
|
|
236
|
-
day: prevMonthDays - firstDay + i + 1,
|
|
237
|
-
current: false,
|
|
238
|
-
month: prevMonth,
|
|
239
|
-
year: prevMonthYear
|
|
240
|
-
})),
|
|
241
|
-
...Array.from({ length: totalDays }, (_, i) => ({
|
|
242
|
-
day: i + 1,
|
|
243
|
-
current: true,
|
|
244
|
-
month: currentMonth,
|
|
245
|
-
year: currentYear
|
|
246
|
-
})),
|
|
247
|
-
...Array.from({ length: nextDaysCount }, (_, i) => ({
|
|
248
|
-
day: i + 1,
|
|
249
|
-
current: false,
|
|
250
|
-
month: nextMonth,
|
|
251
|
-
year: nextMonthYear
|
|
252
|
-
}))
|
|
253
|
-
];
|
|
254
|
-
|
|
255
|
-
return (
|
|
256
|
-
<div
|
|
257
|
-
|
|
258
|
-
className={clsx([
|
|
259
|
-
`${prefixCls}-container`,
|
|
260
|
-
{
|
|
261
|
-
noStyle,
|
|
262
|
-
[`${prefixCls}-${size}`]: size
|
|
263
|
-
}
|
|
264
|
-
])}
|
|
265
|
-
>
|
|
266
|
-
<div className={`${prefixCls}-input-wrapper`} ref={triggerRef}>
|
|
267
|
-
<button
|
|
268
|
-
type="button"
|
|
269
|
-
className={clsx([
|
|
270
|
-
`${prefixCls}-input ${className}`,
|
|
271
|
-
{
|
|
272
|
-
noBordered: !bordered,
|
|
273
|
-
[`${prefixCls}-error`]: error,
|
|
274
|
-
[`${prefixCls}-${size}`]: size,
|
|
275
|
-
[`${prefixCls}-disabled`]: disabled
|
|
276
|
-
}
|
|
277
|
-
])}
|
|
278
|
-
disabled={disabled}
|
|
279
|
-
onClick={(e) => {
|
|
280
|
-
e.preventDefault();
|
|
281
|
-
e.stopPropagation();
|
|
282
|
-
setIsOpen(!isOpen)
|
|
283
|
-
}}
|
|
284
|
-
>
|
|
285
|
-
{prefix || null}
|
|
286
|
-
<input
|
|
287
|
-
key={selectedDate?.toString()}
|
|
288
|
-
size={INPUT_SIZE}
|
|
289
|
-
disabled={disabled}
|
|
290
|
-
readOnly={inputReadOnly}
|
|
291
|
-
className={`${prefixCls}-selected-date globalEllipsis`}
|
|
292
|
-
placeholder={placeholder}
|
|
293
|
-
style={{ opacity: isOpen ? '0.6' : 1 }}
|
|
294
|
-
defaultValue={selectedDatePlaceholder}
|
|
295
|
-
/>
|
|
296
|
-
<span className={`${prefixCls}-icon`}>
|
|
297
|
-
{allowClear && selectedDate ? (
|
|
298
|
-
<span className={`${prefixCls}-clear`} onClick={clearSelection}>
|
|
299
|
-
{typeof allowClear === 'object' && allowClear.clearIcon ? (
|
|
300
|
-
allowClear.clearIcon
|
|
301
|
-
) : (
|
|
302
|
-
<ClearIcon />
|
|
303
|
-
)}
|
|
304
|
-
</span>
|
|
305
|
-
) : (
|
|
306
|
-
suffixIcon || <CalendarIcon />
|
|
307
|
-
)}
|
|
308
|
-
{error && feedbackIcons ? <ErrorIcon /> : null}
|
|
309
|
-
</span>
|
|
310
|
-
</button>
|
|
311
|
-
</div>
|
|
312
|
-
|
|
313
|
-
{isOpen && (
|
|
314
|
-
<ConditionalWrapper
|
|
315
|
-
condition={getPopupContainer !== undefined}
|
|
316
|
-
wrapper={(element) => getPopupContainer ? createPortal(element, getPopupContainer(popupRef.current as HTMLElement)) : <>{element}</>}>
|
|
317
|
-
<div
|
|
318
|
-
ref={popupRef}
|
|
319
|
-
className={`${prefixCls}-dropdown-wrapper`}
|
|
320
|
-
style={dropdownPosition}
|
|
321
|
-
>
|
|
322
|
-
<div className={`${prefixCls}-dropdown`}>
|
|
323
|
-
<div className={`${prefixCls}-header`}>
|
|
324
|
-
<div className={`${prefixCls}-nav-buttons`}>
|
|
325
|
-
<button onClick={(e) => {
|
|
326
|
-
e.preventDefault();
|
|
327
|
-
e.stopPropagation();
|
|
328
|
-
|
|
329
|
-
setCurrentYear((y: number) => y - 1)
|
|
330
|
-
}}>
|
|
331
|
-
«
|
|
332
|
-
</button>
|
|
333
|
-
<button
|
|
334
|
-
onClick={(e) => {
|
|
335
|
-
e.preventDefault();
|
|
336
|
-
e.stopPropagation();
|
|
337
|
-
|
|
338
|
-
setCurrentMonth((m: number) =>
|
|
339
|
-
m === 0
|
|
340
|
-
? (setCurrentYear((y: number) => y - 1), MONTH_LENGTH)
|
|
341
|
-
: m - 1
|
|
342
|
-
)
|
|
343
|
-
}}
|
|
344
|
-
>
|
|
345
|
-
‹
|
|
346
|
-
</button>
|
|
347
|
-
</div>
|
|
348
|
-
<div className={`${prefixCls}-dropdown-selects`}>
|
|
349
|
-
<button
|
|
350
|
-
type="button"
|
|
351
|
-
className={`${prefixCls}-select`}
|
|
352
|
-
onClick={(e) => {
|
|
353
|
-
e.preventDefault();
|
|
354
|
-
e.stopPropagation();
|
|
355
|
-
|
|
356
|
-
setViewMode('year')
|
|
357
|
-
}}
|
|
358
|
-
>
|
|
359
|
-
{currentYear}
|
|
360
|
-
</button>
|
|
361
|
-
<button
|
|
362
|
-
type="button"
|
|
363
|
-
className={`${prefixCls}-select`}
|
|
364
|
-
onClick={(e) => {
|
|
365
|
-
e.preventDefault();
|
|
366
|
-
e.stopPropagation();
|
|
367
|
-
|
|
368
|
-
setViewMode('month')
|
|
369
|
-
}}
|
|
370
|
-
>
|
|
371
|
-
{localeMonths[currentMonth]}
|
|
372
|
-
</button>
|
|
373
|
-
</div>
|
|
374
|
-
<div className={`${prefixCls}-nav-buttons`}>
|
|
375
|
-
<button
|
|
376
|
-
onClick={(e) => {
|
|
377
|
-
e.preventDefault();
|
|
378
|
-
e.stopPropagation();
|
|
379
|
-
|
|
380
|
-
setCurrentMonth((m: number) =>
|
|
381
|
-
m === MONTH_LENGTH
|
|
382
|
-
? (setCurrentYear((y: number) => y + 1), 0)
|
|
383
|
-
: m + 1
|
|
384
|
-
)
|
|
385
|
-
}}
|
|
386
|
-
>
|
|
387
|
-
›
|
|
388
|
-
</button>
|
|
389
|
-
<button onClick={(e) => {
|
|
390
|
-
e.preventDefault();
|
|
391
|
-
e.stopPropagation();
|
|
392
|
-
|
|
393
|
-
setCurrentYear((y: number) => y + 1)
|
|
394
|
-
}}>
|
|
395
|
-
»
|
|
396
|
-
</button>
|
|
397
|
-
</div>
|
|
398
|
-
</div>
|
|
399
|
-
|
|
400
|
-
{viewMode === 'day' && (
|
|
401
|
-
<div className={`${prefixCls}-grid day`}>
|
|
402
|
-
{localeWeekdays.map(day => (
|
|
403
|
-
<div key={day} className={`${prefixCls}-day-header`}>
|
|
404
|
-
{day}
|
|
405
|
-
</div>
|
|
406
|
-
))}
|
|
407
|
-
{days.map(({ day, current, month, year }, idx) => {
|
|
408
|
-
const isSelected =
|
|
409
|
-
selectedDate &&
|
|
410
|
-
selectedDate.getDate() === day &&
|
|
411
|
-
selectedDate.getMonth() === month &&
|
|
412
|
-
selectedDate.getFullYear() === year;
|
|
413
|
-
|
|
414
|
-
return (
|
|
415
|
-
<button
|
|
416
|
-
key={`${year}-${month}-${day}-${idx}`}
|
|
417
|
-
className={clsx([
|
|
418
|
-
`${prefixCls}-day`,
|
|
419
|
-
{
|
|
420
|
-
[`${prefixCls}-selected`]: isSelected,
|
|
421
|
-
[`${prefixCls}-other-month`]: !current
|
|
422
|
-
}
|
|
423
|
-
])}
|
|
424
|
-
onClick={(e) => {
|
|
425
|
-
e.preventDefault();
|
|
426
|
-
e.stopPropagation();
|
|
427
|
-
|
|
428
|
-
handleSelect(day, month, year)
|
|
429
|
-
}}
|
|
430
|
-
disabled={disabledDate?.(new Date(year, month, day), {
|
|
431
|
-
from: undefined,
|
|
432
|
-
to: undefined
|
|
433
|
-
})}
|
|
434
|
-
>
|
|
435
|
-
{day}
|
|
436
|
-
</button>
|
|
437
|
-
);
|
|
438
|
-
})}
|
|
439
|
-
</div>
|
|
440
|
-
)}
|
|
441
|
-
|
|
442
|
-
{viewMode === 'month' && (
|
|
443
|
-
<div className={`${prefixCls}-grid`}>
|
|
444
|
-
{localeMonths.map((m, i) => (
|
|
445
|
-
<button
|
|
446
|
-
key={i}
|
|
447
|
-
className={`${prefixCls}-month`}
|
|
448
|
-
onClick={(e) => {
|
|
449
|
-
e.preventDefault();
|
|
450
|
-
e.stopPropagation();
|
|
451
|
-
|
|
452
|
-
setCurrentMonth(i);
|
|
453
|
-
setViewMode('day');
|
|
454
|
-
}}
|
|
455
|
-
disabled={isMonthDisabled(i)}
|
|
456
|
-
>
|
|
457
|
-
{m}
|
|
458
|
-
</button>
|
|
459
|
-
))}
|
|
460
|
-
</div>
|
|
461
|
-
)}
|
|
462
|
-
|
|
463
|
-
{viewMode === 'year' && (
|
|
464
|
-
<div className={`${prefixCls}-grid`}>
|
|
465
|
-
{Array.from({ length: 12 }, (_, i) => {
|
|
466
|
-
const year = currentYear - NUMBER_SIX + i;
|
|
467
|
-
|
|
468
|
-
return (
|
|
469
|
-
<button
|
|
470
|
-
key={year}
|
|
471
|
-
className={`${prefixCls}-year`}
|
|
472
|
-
disabled={isYearDisabled(year)}
|
|
473
|
-
onClick={(e) => {
|
|
474
|
-
e.preventDefault();
|
|
475
|
-
e.stopPropagation();
|
|
476
|
-
|
|
477
|
-
setCurrentYear(year);
|
|
478
|
-
setViewMode('month');
|
|
479
|
-
}}
|
|
480
|
-
>
|
|
481
|
-
{year}
|
|
482
|
-
</button>
|
|
483
|
-
);
|
|
484
|
-
})}
|
|
485
|
-
</div>
|
|
486
|
-
)}
|
|
487
|
-
|
|
488
|
-
{showToday && (
|
|
489
|
-
<div
|
|
490
|
-
className={`${prefixCls}-day-footer`}
|
|
491
|
-
style={{ gridColumn: 'span 7' }}
|
|
492
|
-
>
|
|
493
|
-
<button
|
|
494
|
-
className={`${prefixCls}-select`}
|
|
495
|
-
disabled={disabledDate?.(
|
|
496
|
-
new Date(
|
|
497
|
-
DateNow.getDate(),
|
|
498
|
-
DateNow.getMonth(),
|
|
499
|
-
DateNow.getFullYear()
|
|
500
|
-
),
|
|
501
|
-
{ from: undefined, to: undefined }
|
|
502
|
-
)}
|
|
503
|
-
onClick={(e) => {
|
|
504
|
-
e.preventDefault();
|
|
505
|
-
e.stopPropagation();
|
|
506
|
-
|
|
507
|
-
handleSelect(
|
|
508
|
-
DateNow.getDate(),
|
|
509
|
-
DateNow.getMonth(),
|
|
510
|
-
DateNow.getFullYear()
|
|
511
|
-
);
|
|
512
|
-
}}
|
|
513
|
-
>
|
|
514
|
-
{locale?.today || 'Today'}
|
|
515
|
-
</button>
|
|
516
|
-
</div>
|
|
517
|
-
)}
|
|
518
|
-
</div>
|
|
519
|
-
</div>
|
|
520
|
-
</ConditionalWrapper>
|
|
521
|
-
)}
|
|
522
|
-
</div>
|
|
523
|
-
);
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
export default DatePicker;
|