@rockshin/tao-ui 0.0.26 → 0.0.28
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/components/date-picker/date-picker.d.ts +1 -1
- package/dist/components/date-picker/date-picker.js +57 -43
- package/dist/components/date-picker/range-picker.js +68 -23
- package/dist/components/select/mobile-select.js +9 -20
- package/dist/components/select/select-model.d.ts +7 -1
- package/dist/components/select/select-model.js +30 -7
- package/dist/components/select/select.js +48 -37
- package/dist/components/sonner/sonner.d.ts +2 -1
- package/dist/components/sonner/sonner.js +74 -81
- package/dist/components/textarea/textarea.css +81 -79
- package/dist/docs/component-docs.js +11 -1
- package/package.json +1 -1
|
@@ -34,4 +34,4 @@ export interface DatePickerProps {
|
|
|
34
34
|
classNames?: SemanticClassNames<DatePickerSemanticPart>;
|
|
35
35
|
styles?: SemanticStyles<DatePickerSemanticPart>;
|
|
36
36
|
}
|
|
37
|
-
export declare function DatePicker({ value, onChange, picker, showTime, format: formatProp, disabledDate, minDate, maxDate, presets, placeholder, size, variant, disabled, allowClear, prefix, suffixIcon, status, mobile, open: controlledOpen, onOpenChange, className, style, classNames, styles, ref, }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare function DatePicker({ value, defaultValue, onChange, picker, showTime, format: formatProp, disabledDate, minDate, maxDate, presets, placeholder, size, variant, disabled, allowClear, prefix, suffixIcon, status, mobile, open: controlledOpen, onOpenChange, className, style, classNames, styles, ref, }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,9 +4,9 @@ import dayjs from "dayjs";
|
|
|
4
4
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
5
5
|
import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
|
|
7
|
+
import { useIsMobile } from "../../utils/breakpoint.js";
|
|
7
8
|
import { cx } from "../../utils/semantic.js";
|
|
8
9
|
import { Drawer } from "../drawer/drawer.js";
|
|
9
|
-
import { useIsMobile } from "../../utils/breakpoint.js";
|
|
10
10
|
import { CalendarGrid } from "./calendar/calendar-grid.js";
|
|
11
11
|
import { CalendarHeader } from "./calendar/calendar-header.js";
|
|
12
12
|
import { MonthGrid } from "./calendar/month-grid.js";
|
|
@@ -17,7 +17,7 @@ import { Presets } from "./presets.js";
|
|
|
17
17
|
import { getDefaultFormat } from "./types.js";
|
|
18
18
|
import * as __rspack_external__radix_ui_react_popover_c8444160 from "@radix-ui/react-popover";
|
|
19
19
|
dayjs.extend(customParseFormat);
|
|
20
|
-
function DatePicker({ value, onChange, picker = 'date', showTime, format: formatProp, disabledDate, minDate, maxDate, presets, placeholder, size, variant, disabled, allowClear = true, prefix, suffixIcon, status, mobile, open: controlledOpen, onOpenChange, className, style, classNames, styles, ref }) {
|
|
20
|
+
function DatePicker({ value, defaultValue, onChange, picker = 'date', showTime, format: formatProp, disabledDate, minDate, maxDate, presets, placeholder, size, variant, disabled, allowClear = true, prefix, suffixIcon, status, mobile, open: controlledOpen, onOpenChange, className, style, classNames, styles, ref }) {
|
|
21
21
|
const ctx = useTaoConfig();
|
|
22
22
|
const resolvedSize = size ?? ctx.size;
|
|
23
23
|
const resolvedVariant = variant ?? ctx.variant;
|
|
@@ -41,8 +41,18 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
41
41
|
const fmt = formatProp ?? getDefaultFormat(picker, showTime);
|
|
42
42
|
const defaultPlaceholder = placeholder ?? fmt;
|
|
43
43
|
const drawerTitle = showTime ? 'Date & Time' : defaultPlaceholder;
|
|
44
|
+
const isValueControlled = void 0 !== value;
|
|
45
|
+
const [internalValue, setInternalValue] = useState(defaultValue ?? null);
|
|
46
|
+
const resolvedValue = isValueControlled ? value : internalValue;
|
|
47
|
+
const emitChange = useCallback((next, dateString)=>{
|
|
48
|
+
if (!isValueControlled) setInternalValue(next);
|
|
49
|
+
onChange?.(next, dateString);
|
|
50
|
+
}, [
|
|
51
|
+
isValueControlled,
|
|
52
|
+
onChange
|
|
53
|
+
]);
|
|
44
54
|
const [internalOpen, setInternalOpen] = useState(false);
|
|
45
|
-
const displayValue =
|
|
55
|
+
const displayValue = resolvedValue ? resolvedValue.format(fmt) : '';
|
|
46
56
|
const [inputValue, setInputValue] = useState(displayValue);
|
|
47
57
|
const isOpen = controlledOpen ?? internalOpen;
|
|
48
58
|
const setOpen = useCallback((v)=>{
|
|
@@ -56,45 +66,45 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
56
66
|
}, [
|
|
57
67
|
displayValue
|
|
58
68
|
]);
|
|
59
|
-
const [viewDate, setViewDate] = useState(()=>
|
|
69
|
+
const [viewDate, setViewDate] = useState(()=>resolvedValue ?? dayjs());
|
|
60
70
|
const [panelMode, setPanelMode] = useState('year' === picker ? 'year' : 'month' === picker ? 'month' : 'date');
|
|
61
71
|
const [timeScrollKey, setTimeScrollKey] = useState(0);
|
|
62
72
|
useEffect(()=>{
|
|
63
73
|
if (isOpen) {
|
|
64
|
-
setViewDate(
|
|
74
|
+
setViewDate(resolvedValue ?? dayjs());
|
|
65
75
|
setPanelMode('year' === picker ? 'year' : 'month' === picker ? 'month' : 'date');
|
|
66
76
|
setTimeScrollKey((k)=>k + 1);
|
|
67
77
|
}
|
|
68
78
|
}, [
|
|
69
79
|
isOpen,
|
|
70
80
|
picker,
|
|
71
|
-
|
|
81
|
+
resolvedValue
|
|
72
82
|
]);
|
|
73
83
|
const timeValue = useMemo(()=>({
|
|
74
|
-
hour:
|
|
75
|
-
minute:
|
|
76
|
-
second:
|
|
84
|
+
hour: resolvedValue?.hour() ?? 0,
|
|
85
|
+
minute: resolvedValue?.minute() ?? 0,
|
|
86
|
+
second: resolvedValue?.second() ?? 0
|
|
77
87
|
}), [
|
|
78
|
-
|
|
88
|
+
resolvedValue
|
|
79
89
|
]);
|
|
80
90
|
const handleDateSelect = useCallback((date)=>{
|
|
81
91
|
let result = date;
|
|
82
|
-
if (showTime &&
|
|
83
|
-
if (showTime)
|
|
92
|
+
if (showTime && resolvedValue) result = date.hour(resolvedValue.hour()).minute(resolvedValue.minute()).second(resolvedValue.second());
|
|
93
|
+
if (showTime) emitChange(result, result.format(fmt));
|
|
84
94
|
else {
|
|
85
|
-
|
|
95
|
+
emitChange(result, result.format(fmt));
|
|
86
96
|
setOpen(false);
|
|
87
97
|
}
|
|
88
98
|
}, [
|
|
89
|
-
|
|
99
|
+
emitChange,
|
|
90
100
|
fmt,
|
|
91
101
|
showTime,
|
|
92
|
-
|
|
102
|
+
resolvedValue,
|
|
93
103
|
setOpen
|
|
94
104
|
]);
|
|
95
105
|
const handleMonthSelect = useCallback((date_0)=>{
|
|
96
106
|
if ('month' === picker) {
|
|
97
|
-
|
|
107
|
+
emitChange(date_0, date_0.format(fmt));
|
|
98
108
|
setOpen(false);
|
|
99
109
|
} else {
|
|
100
110
|
setViewDate(date_0);
|
|
@@ -102,13 +112,13 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
102
112
|
}
|
|
103
113
|
}, [
|
|
104
114
|
picker,
|
|
105
|
-
|
|
115
|
+
emitChange,
|
|
106
116
|
fmt,
|
|
107
117
|
setOpen
|
|
108
118
|
]);
|
|
109
119
|
const handleYearSelect = useCallback((date_1)=>{
|
|
110
120
|
if ('year' === picker) {
|
|
111
|
-
|
|
121
|
+
emitChange(date_1, date_1.format(fmt));
|
|
112
122
|
setOpen(false);
|
|
113
123
|
} else {
|
|
114
124
|
setViewDate(date_1);
|
|
@@ -116,31 +126,31 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
116
126
|
}
|
|
117
127
|
}, [
|
|
118
128
|
picker,
|
|
119
|
-
|
|
129
|
+
emitChange,
|
|
120
130
|
fmt,
|
|
121
131
|
setOpen
|
|
122
132
|
]);
|
|
123
133
|
const handleTimeChange = useCallback((h, m, s)=>{
|
|
124
|
-
const base =
|
|
134
|
+
const base = resolvedValue ?? dayjs();
|
|
125
135
|
const result_0 = base.hour(h).minute(m).second(s);
|
|
126
|
-
|
|
136
|
+
emitChange(result_0, result_0.format(fmt));
|
|
127
137
|
}, [
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
resolvedValue,
|
|
139
|
+
emitChange,
|
|
130
140
|
fmt
|
|
131
141
|
]);
|
|
132
142
|
const handleClear = useCallback((e)=>{
|
|
133
143
|
e.stopPropagation();
|
|
134
|
-
|
|
144
|
+
emitChange(null, '');
|
|
135
145
|
}, [
|
|
136
|
-
|
|
146
|
+
emitChange
|
|
137
147
|
]);
|
|
138
148
|
const handlePresetSelect = useCallback((val)=>{
|
|
139
149
|
const d = val;
|
|
140
|
-
|
|
150
|
+
emitChange(d, d.format(fmt));
|
|
141
151
|
setOpen(false);
|
|
142
152
|
}, [
|
|
143
|
-
|
|
153
|
+
emitChange,
|
|
144
154
|
fmt,
|
|
145
155
|
setOpen
|
|
146
156
|
]);
|
|
@@ -151,20 +161,20 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
151
161
|
]);
|
|
152
162
|
const handleNow = useCallback(()=>{
|
|
153
163
|
const now = dayjs();
|
|
154
|
-
|
|
164
|
+
emitChange(now, now.format(fmt));
|
|
155
165
|
setViewDate(now);
|
|
156
166
|
setPanelMode('date');
|
|
157
167
|
setTimeScrollKey((k_0)=>k_0 + 1);
|
|
158
168
|
}, [
|
|
159
|
-
|
|
169
|
+
emitChange,
|
|
160
170
|
fmt
|
|
161
171
|
]);
|
|
162
|
-
const showClearBtn = allowClear &&
|
|
172
|
+
const showClearBtn = allowClear && resolvedValue && !resolvedDisabled;
|
|
163
173
|
const commitInputValue = useCallback(()=>{
|
|
164
174
|
const text = inputValue.trim();
|
|
165
175
|
if (!text) {
|
|
166
|
-
|
|
167
|
-
setInputValue('');
|
|
176
|
+
if (displayValue) emitChange(null, '');
|
|
177
|
+
setInputValue(isValueControlled ? displayValue : '');
|
|
168
178
|
setOpen(false);
|
|
169
179
|
return;
|
|
170
180
|
}
|
|
@@ -172,18 +182,19 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
172
182
|
const isBlocked = !parsed.isValid() || disabledDate?.(parsed) || null != minDate && parsed.isBefore(minDate, 'day') || null != maxDate && parsed.isAfter(maxDate, 'day');
|
|
173
183
|
if (isBlocked) return void setInputValue(displayValue);
|
|
174
184
|
const formatted = parsed.format(fmt);
|
|
175
|
-
setInputValue(formatted);
|
|
185
|
+
setInputValue(isValueControlled ? displayValue : formatted);
|
|
176
186
|
setViewDate(parsed);
|
|
177
|
-
|
|
187
|
+
if (formatted !== displayValue) emitChange(parsed, formatted);
|
|
178
188
|
setOpen(false);
|
|
179
189
|
}, [
|
|
180
190
|
disabledDate,
|
|
181
191
|
displayValue,
|
|
182
192
|
fmt,
|
|
183
193
|
inputValue,
|
|
194
|
+
isValueControlled,
|
|
184
195
|
maxDate,
|
|
185
196
|
minDate,
|
|
186
|
-
|
|
197
|
+
emitChange,
|
|
187
198
|
setOpen
|
|
188
199
|
]);
|
|
189
200
|
const showTimePanel = !!(showTime && 'date' === panelMode);
|
|
@@ -200,7 +211,7 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
200
211
|
children: [
|
|
201
212
|
'date' === panelMode && /*#__PURE__*/ jsx(CalendarGrid, {
|
|
202
213
|
viewDate: viewDate,
|
|
203
|
-
value:
|
|
214
|
+
value: resolvedValue,
|
|
204
215
|
onSelect: handleDateSelect,
|
|
205
216
|
onViewDateChange: setViewDate,
|
|
206
217
|
disabledDate: disabledDate,
|
|
@@ -213,13 +224,13 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
213
224
|
}),
|
|
214
225
|
'month' === panelMode && /*#__PURE__*/ jsx(MonthGrid, {
|
|
215
226
|
viewDate: viewDate,
|
|
216
|
-
value:
|
|
227
|
+
value: resolvedValue,
|
|
217
228
|
onSelect: handleMonthSelect,
|
|
218
229
|
disabledDate: disabledDate
|
|
219
230
|
}),
|
|
220
231
|
('year' === panelMode || 'decade' === panelMode) && /*#__PURE__*/ jsx(YearGrid, {
|
|
221
232
|
viewDate: viewDate,
|
|
222
|
-
value:
|
|
233
|
+
value: resolvedValue,
|
|
223
234
|
onSelect: handleYearSelect,
|
|
224
235
|
disabledDate: disabledDate
|
|
225
236
|
})
|
|
@@ -378,12 +389,15 @@ function DatePicker({ value, onChange, picker = 'date', showTime, format: format
|
|
|
378
389
|
disabled: resolvedDisabled,
|
|
379
390
|
"aria-invalid": 'error' === status || void 0,
|
|
380
391
|
onChange: (event_1)=>setInputValue(event_1.target.value),
|
|
381
|
-
onBlur:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
392
|
+
onBlur: (event_2)=>{
|
|
393
|
+
if (event_2.relatedTarget instanceof HTMLElement && event_2.relatedTarget.closest('[data-tao-picker-dropdown]')) return;
|
|
394
|
+
commitInputValue();
|
|
395
|
+
},
|
|
396
|
+
onKeyDown: (event_3)=>{
|
|
397
|
+
if ('Enter' === event_3.key) {
|
|
398
|
+
event_3.preventDefault();
|
|
385
399
|
commitInputValue();
|
|
386
|
-
} else if ('Escape' ===
|
|
400
|
+
} else if ('Escape' === event_3.key) {
|
|
387
401
|
setInputValue(displayValue);
|
|
388
402
|
setOpen(false);
|
|
389
403
|
}
|
|
@@ -4,9 +4,9 @@ import dayjs from "dayjs";
|
|
|
4
4
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
5
5
|
import { useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
6
6
|
import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
|
|
7
|
+
import { useIsMobile } from "../../utils/breakpoint.js";
|
|
7
8
|
import { cx } from "../../utils/semantic.js";
|
|
8
9
|
import { Drawer } from "../drawer/drawer.js";
|
|
9
|
-
import { useIsMobile } from "../../utils/breakpoint.js";
|
|
10
10
|
import { CalendarGrid } from "./calendar/calendar-grid.js";
|
|
11
11
|
import "./date-picker.css";
|
|
12
12
|
import { Presets } from "./presets.js";
|
|
@@ -53,25 +53,53 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
53
53
|
]);
|
|
54
54
|
const [internalOpen, setInternalOpen] = useState(false);
|
|
55
55
|
const isOpen = controlledOpen ?? internalOpen;
|
|
56
|
+
const [interaction, setInteraction] = useState({
|
|
57
|
+
phase: 'idle',
|
|
58
|
+
activeInput: 'start'
|
|
59
|
+
});
|
|
60
|
+
const controlledValueKey = isValueControlled ? `${resolvedValue?.[0]?.valueOf() ?? 'null'}:${resolvedValue?.[1]?.valueOf() ?? 'null'}` : void 0;
|
|
56
61
|
const setOpen = useCallback((v)=>{
|
|
57
62
|
setInternalOpen(v);
|
|
58
63
|
onOpenChange?.(v);
|
|
59
64
|
}, [
|
|
60
65
|
onOpenChange
|
|
61
66
|
]);
|
|
67
|
+
useEffect(()=>{
|
|
68
|
+
if (!isOpen) setInteraction({
|
|
69
|
+
phase: 'idle',
|
|
70
|
+
activeInput: 'start'
|
|
71
|
+
});
|
|
72
|
+
}, [
|
|
73
|
+
isOpen
|
|
74
|
+
]);
|
|
75
|
+
useEffect(()=>{
|
|
76
|
+
if (void 0 !== controlledValueKey) setInteraction({
|
|
77
|
+
phase: 'idle',
|
|
78
|
+
activeInput: 'start'
|
|
79
|
+
});
|
|
80
|
+
}, [
|
|
81
|
+
controlledValueKey
|
|
82
|
+
]);
|
|
62
83
|
const [viewDateStart, setViewDateStart] = useState(()=>resolvedValue?.[0] ?? dayjs());
|
|
63
84
|
const viewDateEnd = viewDateStart.add(1, 'month');
|
|
64
|
-
const
|
|
65
|
-
const [
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
85
|
+
const rangeStart = 'pickingEnd' === interaction.phase ? interaction.start : resolvedValue?.[0] ?? null;
|
|
86
|
+
const rangeEnd = 'pickingEnd' === interaction.phase ? null : resolvedValue?.[1] ?? null;
|
|
87
|
+
const hoverDate = 'pickingEnd' === interaction.phase ? interaction.hover : null;
|
|
88
|
+
const setHoverDate = useCallback((hover)=>{
|
|
89
|
+
setInteraction((current)=>'pickingEnd' === current.phase ? {
|
|
90
|
+
...current,
|
|
91
|
+
hover
|
|
92
|
+
} : current);
|
|
93
|
+
}, []);
|
|
69
94
|
const handleDateSelect = useCallback((date)=>{
|
|
70
|
-
if ('start' ===
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
95
|
+
if ('idle' === interaction.phase && 'start' === interaction.activeInput) setInteraction({
|
|
96
|
+
phase: 'pickingEnd',
|
|
97
|
+
activeInput: 'end',
|
|
98
|
+
start: date,
|
|
99
|
+
hover: null
|
|
100
|
+
});
|
|
101
|
+
else {
|
|
102
|
+
let start = 'pickingEnd' === interaction.phase ? interaction.start : rangeStart;
|
|
75
103
|
let end = date;
|
|
76
104
|
if (start && date.isBefore(start)) [start, end] = [
|
|
77
105
|
date,
|
|
@@ -84,14 +112,14 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
84
112
|
start?.format(fmt) ?? '',
|
|
85
113
|
end.format(fmt)
|
|
86
114
|
]);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
115
|
+
setInteraction({
|
|
116
|
+
phase: 'idle',
|
|
117
|
+
activeInput: 'start'
|
|
118
|
+
});
|
|
90
119
|
if (!showTime) setOpen(false);
|
|
91
120
|
}
|
|
92
121
|
}, [
|
|
93
|
-
|
|
94
|
-
pendingStart,
|
|
122
|
+
interaction,
|
|
95
123
|
rangeStart,
|
|
96
124
|
emitChange,
|
|
97
125
|
fmt,
|
|
@@ -104,6 +132,10 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
104
132
|
'',
|
|
105
133
|
''
|
|
106
134
|
]);
|
|
135
|
+
setInteraction({
|
|
136
|
+
phase: 'idle',
|
|
137
|
+
activeInput: 'start'
|
|
138
|
+
});
|
|
107
139
|
}, [
|
|
108
140
|
emitChange
|
|
109
141
|
]);
|
|
@@ -116,6 +148,10 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
116
148
|
s.format(fmt),
|
|
117
149
|
e_0.format(fmt)
|
|
118
150
|
]);
|
|
151
|
+
setInteraction({
|
|
152
|
+
phase: 'idle',
|
|
153
|
+
activeInput: 'start'
|
|
154
|
+
});
|
|
119
155
|
setOpen(false);
|
|
120
156
|
}, [
|
|
121
157
|
emitChange,
|
|
@@ -152,7 +188,10 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
152
188
|
nextStart,
|
|
153
189
|
nextEnd
|
|
154
190
|
] : null, nextStrings);
|
|
155
|
-
|
|
191
|
+
setInteraction({
|
|
192
|
+
phase: 'idle',
|
|
193
|
+
activeInput: position_0
|
|
194
|
+
});
|
|
156
195
|
if (parsed) setViewDateStart(parsed);
|
|
157
196
|
if ('start' === position_0) setInputStart(nextStrings[0]);
|
|
158
197
|
else setInputEnd(nextStrings[1]);
|
|
@@ -334,7 +373,7 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
334
373
|
children: [
|
|
335
374
|
/*#__PURE__*/ jsx("span", {
|
|
336
375
|
"data-tao-range-input": "",
|
|
337
|
-
"data-tao-active": 'start' ===
|
|
376
|
+
"data-tao-active": 'start' === interaction.activeInput && isOpen || void 0,
|
|
338
377
|
className: classNames?.input,
|
|
339
378
|
style: styles?.input,
|
|
340
379
|
children: displayStart || /*#__PURE__*/ jsx("span", {
|
|
@@ -350,7 +389,7 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
350
389
|
}),
|
|
351
390
|
/*#__PURE__*/ jsx("span", {
|
|
352
391
|
"data-tao-range-input": "",
|
|
353
|
-
"data-tao-active": 'end' ===
|
|
392
|
+
"data-tao-active": 'end' === interaction.activeInput && isOpen || void 0,
|
|
354
393
|
className: classNames?.input,
|
|
355
394
|
style: styles?.input,
|
|
356
395
|
children: displayEnd || /*#__PURE__*/ jsx("span", {
|
|
@@ -377,7 +416,7 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
377
416
|
/*#__PURE__*/ jsx("input", {
|
|
378
417
|
ref: startInputRef,
|
|
379
418
|
"data-tao-range-input": "",
|
|
380
|
-
"data-tao-active": 'start' ===
|
|
419
|
+
"data-tao-active": 'start' === interaction.activeInput && isOpen || void 0,
|
|
381
420
|
className: classNames?.input,
|
|
382
421
|
style: styles?.input,
|
|
383
422
|
value: inputStart,
|
|
@@ -385,7 +424,10 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
385
424
|
disabled: resolvedDisabled,
|
|
386
425
|
"aria-invalid": 'error' === status || void 0,
|
|
387
426
|
onFocus: ()=>{
|
|
388
|
-
|
|
427
|
+
setInteraction({
|
|
428
|
+
phase: 'idle',
|
|
429
|
+
activeInput: 'start'
|
|
430
|
+
});
|
|
389
431
|
},
|
|
390
432
|
onChange: (event_1)=>setInputStart(event_1.target.value),
|
|
391
433
|
onBlur: ()=>commitInputValue('start'),
|
|
@@ -408,7 +450,7 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
408
450
|
/*#__PURE__*/ jsx("input", {
|
|
409
451
|
ref: endInputRef,
|
|
410
452
|
"data-tao-range-input": "",
|
|
411
|
-
"data-tao-active": 'end' ===
|
|
453
|
+
"data-tao-active": 'end' === interaction.activeInput && isOpen || void 0,
|
|
412
454
|
className: classNames?.input,
|
|
413
455
|
style: styles?.input,
|
|
414
456
|
value: inputEnd,
|
|
@@ -416,7 +458,10 @@ function RangePicker({ value, defaultValue, onChange, picker = 'date', showTime,
|
|
|
416
458
|
disabled: resolvedDisabled,
|
|
417
459
|
"aria-invalid": 'error' === status || void 0,
|
|
418
460
|
onFocus: ()=>{
|
|
419
|
-
|
|
461
|
+
setInteraction({
|
|
462
|
+
phase: 'idle',
|
|
463
|
+
activeInput: 'end'
|
|
464
|
+
});
|
|
420
465
|
},
|
|
421
466
|
onChange: (event_3)=>setInputEnd(event_3.target.value),
|
|
422
467
|
onBlur: ()=>commitInputValue('end'),
|
|
@@ -3,25 +3,8 @@ import { c } from "react/compiler-runtime";
|
|
|
3
3
|
import { useCallback, useMemo, useState } from "react";
|
|
4
4
|
import { Drawer } from "../drawer/drawer.js";
|
|
5
5
|
import { SearchIcon } from "./select-icons.js";
|
|
6
|
+
import { countLeafOptions, defaultFilter, filterTree } from "./select-model.js";
|
|
6
7
|
import "./mobile-select.css";
|
|
7
|
-
const defaultFilter = (input, option)=>{
|
|
8
|
-
const label = 'string' == typeof option.label ? option.label : String(option.label);
|
|
9
|
-
return label.toLowerCase().includes(input.toLowerCase());
|
|
10
|
-
};
|
|
11
|
-
function filterTree(options, fn, input) {
|
|
12
|
-
const result = [];
|
|
13
|
-
for (const o of options)if (o.options) {
|
|
14
|
-
const kids = filterTree(o.options, fn, input);
|
|
15
|
-
if (kids.length) result.push({
|
|
16
|
-
...o,
|
|
17
|
-
options: kids
|
|
18
|
-
});
|
|
19
|
-
} else if (fn(input, o)) result.push(o);
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
function countLeaves(options) {
|
|
23
|
-
return options.reduce((n, o)=>n + (o.options ? countLeaves(o.options) : 1), 0);
|
|
24
|
-
}
|
|
25
8
|
function MobileSelectContentInner({ options, value, onChange, onMultiChange, showSearch, filterOption, notFoundContent = 'No results', optionRender, onClose, multiple }) {
|
|
26
9
|
const [search, setSearch] = useState('');
|
|
27
10
|
const valueArray = useMemo(()=>{
|
|
@@ -34,6 +17,9 @@ function MobileSelectContentInner({ options, value, onChange, onMultiChange, sho
|
|
|
34
17
|
value
|
|
35
18
|
]);
|
|
36
19
|
const [draft, setDraft] = useState(valueArray);
|
|
20
|
+
const draftSet = useMemo(()=>new Set(draft), [
|
|
21
|
+
draft
|
|
22
|
+
]);
|
|
37
23
|
const filteredOptions = useMemo(()=>{
|
|
38
24
|
if (!showSearch || !search) return options;
|
|
39
25
|
const fn = filterOption ?? defaultFilter;
|
|
@@ -44,6 +30,9 @@ function MobileSelectContentInner({ options, value, onChange, onMultiChange, sho
|
|
|
44
30
|
showSearch,
|
|
45
31
|
filterOption
|
|
46
32
|
]);
|
|
33
|
+
const resultCount = useMemo(()=>countLeafOptions(filteredOptions), [
|
|
34
|
+
filteredOptions
|
|
35
|
+
]);
|
|
47
36
|
const handleSelect = useCallback((optValue)=>{
|
|
48
37
|
if (multiple) setDraft((prev)=>prev.includes(optValue) ? prev.filter((v)=>v !== optValue) : [
|
|
49
38
|
...prev,
|
|
@@ -69,7 +58,7 @@ function MobileSelectContentInner({ options, value, onChange, onMultiChange, sho
|
|
|
69
58
|
let optIndex = 0;
|
|
70
59
|
const renderItem = (opt)=>{
|
|
71
60
|
const index = optIndex++;
|
|
72
|
-
const isSelected = multiple ?
|
|
61
|
+
const isSelected = multiple ? draftSet.has(opt.value) : opt.value === value;
|
|
73
62
|
return /*#__PURE__*/ jsxs("button", {
|
|
74
63
|
type: "button",
|
|
75
64
|
"data-tao-sheet-item": "",
|
|
@@ -137,7 +126,7 @@ function MobileSelectContentInner({ options, value, onChange, onMultiChange, sho
|
|
|
137
126
|
}),
|
|
138
127
|
/*#__PURE__*/ jsx("div", {
|
|
139
128
|
"data-tao-sheet-list": "",
|
|
140
|
-
children:
|
|
129
|
+
children: resultCount > 0 ? renderTree(filteredOptions) : /*#__PURE__*/ jsx("div", {
|
|
141
130
|
"data-tao-sheet-empty": "",
|
|
142
131
|
children: notFoundContent
|
|
143
132
|
})
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { SelectOption } from './select-types';
|
|
2
|
+
export interface SelectIndex {
|
|
3
|
+
optionByValue: Map<string, SelectOption>;
|
|
4
|
+
optionByToken: Map<string, SelectOption>;
|
|
5
|
+
}
|
|
6
|
+
export declare function buildSelectIndex(options: SelectOption[]): SelectIndex;
|
|
7
|
+
export declare function flattenLeafOptions(options: SelectOption[]): SelectOption[];
|
|
8
|
+
export declare function countLeafOptions(options: SelectOption[]): number;
|
|
2
9
|
export declare function defaultFilter(input: string, option: SelectOption): boolean;
|
|
3
|
-
export declare function flattenOptions(options: SelectOption[]): SelectOption[];
|
|
4
10
|
export declare function filterTree(options: SelectOption[], filter: (input: string, option: SelectOption) => boolean, input: string): SelectOption[];
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
function forEachLeafOption(options, visit) {
|
|
2
|
+
for (const option of options)if (option.options) forEachLeafOption(option.options, visit);
|
|
3
|
+
else visit(option);
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function buildSelectIndex(options) {
|
|
6
|
+
const optionByValue = new Map();
|
|
7
|
+
const optionByToken = new Map();
|
|
8
|
+
forEachLeafOption(options, (option)=>{
|
|
9
|
+
if (!optionByValue.has(option.value)) optionByValue.set(option.value, option);
|
|
10
|
+
if (!optionByToken.has(option.value)) optionByToken.set(option.value, option);
|
|
11
|
+
if ('string' == typeof option.label && !optionByToken.has(option.label)) optionByToken.set(option.label, option);
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
optionByValue,
|
|
15
|
+
optionByToken
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function flattenLeafOptions(options) {
|
|
6
19
|
const result = [];
|
|
7
|
-
|
|
8
|
-
else result.push(option);
|
|
20
|
+
forEachLeafOption(options, (option)=>result.push(option));
|
|
9
21
|
return result;
|
|
10
22
|
}
|
|
23
|
+
function countLeafOptions(options) {
|
|
24
|
+
let count = 0;
|
|
25
|
+
forEachLeafOption(options, ()=>{
|
|
26
|
+
count += 1;
|
|
27
|
+
});
|
|
28
|
+
return count;
|
|
29
|
+
}
|
|
30
|
+
function defaultFilter(input, option) {
|
|
31
|
+
const label = 'string' == typeof option.label ? option.label : String(option.label);
|
|
32
|
+
return label.toLowerCase().includes(input.toLowerCase());
|
|
33
|
+
}
|
|
11
34
|
function filterTree(options, filter, input) {
|
|
12
35
|
const result = [];
|
|
13
36
|
for (const option of options)if (option.options) {
|
|
@@ -19,4 +42,4 @@ function filterTree(options, filter, input) {
|
|
|
19
42
|
} else if (filter(input, option)) result.push(option);
|
|
20
43
|
return result;
|
|
21
44
|
}
|
|
22
|
-
export { defaultFilter, filterTree,
|
|
45
|
+
export { buildSelectIndex, countLeafOptions, defaultFilter, filterTree, flattenLeafOptions };
|