@fluixi-ui/date-picker 0.3.0-alpha.12 → 0.3.0-alpha.14
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/date-picker.d.ts +9 -0
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +122 -194
- package/dist/date-range-picker.d.ts +9 -0
- package/dist/date-range-picker.d.ts.map +1 -1
- package/dist/date-range-picker.js +126 -208
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +6 -5
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { createSignal, untrack, createRenderEffect, createMemo, createEffect } from "@fluixi/reactive/signal";
|
|
2
1
|
import { createComponent, splitProps, mergeProps, createNativeElement, spread, insert, templateNode, handleRef, delegateEvents } from "@fluixi/dom";
|
|
2
|
+
import { createSignal, untrack, createRenderEffect, createMemo, createEffect } from "@fluixi/reactive/signal";
|
|
3
|
+
import { fxProps } from "@fluixi-ui/fx";
|
|
3
4
|
import { useRef, Show } from "@fluixi/core";
|
|
4
5
|
import { createControllableSignal, createControllableBooleanSignal, createId, composeId, composeEventHandlers, createSafeContext } from "@fluixi-ui/kit";
|
|
5
6
|
import { Portal, createFloatingPosition, createDismissableLayer, createFocusScope } from "@fluixi-ui/primitives";
|
|
6
7
|
import { DateField, DateInput } from "@fluixi-ui/date-field";
|
|
7
8
|
import { RangeCalendar, CalendarHeader, CalendarPrevButton, CalendarHeading, CalendarNextButton, CalendarGrid } from "@fluixi-ui/calendar";
|
|
8
|
-
const
|
|
9
|
-
delegateEvents(["change", "
|
|
9
|
+
const _fxTmpl$0 = '<span aria-hidden="true" data-date-range-separator="">–</span>';
|
|
10
|
+
delegateEvents(["change", "keydown", "click"]);
|
|
10
11
|
const [DateRangePickerProvider, useDateRangePickerContext] = createSafeContext("DateRangePicker");
|
|
11
12
|
function DateRangePicker(props) {
|
|
12
13
|
const [value, setValue] = createControllableSignal({
|
|
@@ -31,10 +32,7 @@ function DateRangePicker(props) {
|
|
|
31
32
|
const commit = () => {
|
|
32
33
|
const s = start();
|
|
33
34
|
const e = end();
|
|
34
|
-
setValue(s && e ? {
|
|
35
|
-
start: s,
|
|
36
|
-
end: e
|
|
37
|
-
} : null);
|
|
35
|
+
setValue(s && e ? { start: s, end: e } : null);
|
|
38
36
|
};
|
|
39
37
|
const baseId = createId("date-range-picker");
|
|
40
38
|
const [triggerRef, setTriggerRef] = createSignal(void 0);
|
|
@@ -57,10 +55,7 @@ function DateRangePicker(props) {
|
|
|
57
55
|
},
|
|
58
56
|
isOpen,
|
|
59
57
|
setOpen: (o) => setOpen(o),
|
|
60
|
-
ids: {
|
|
61
|
-
label: composeId(baseId, "label"),
|
|
62
|
-
content: composeId(baseId, "content")
|
|
63
|
-
},
|
|
58
|
+
ids: { label: composeId(baseId, "label"), content: composeId(baseId, "content") },
|
|
64
59
|
triggerRef,
|
|
65
60
|
setTriggerRef,
|
|
66
61
|
placement: props.placement ?? "bottom-start",
|
|
@@ -74,177 +69,129 @@ function DateRangePicker(props) {
|
|
|
74
69
|
isReadOnly: () => props.isReadOnly ?? false,
|
|
75
70
|
isDateUnavailable: props.isDateUnavailable
|
|
76
71
|
};
|
|
77
|
-
return createMemo(() => createComponent(DateRangePickerProvider, {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return props.children;
|
|
83
|
-
}
|
|
84
|
-
}));
|
|
72
|
+
return createMemo(() => createComponent(DateRangePickerProvider, { get value() {
|
|
73
|
+
return ctx;
|
|
74
|
+
}, get children() {
|
|
75
|
+
return props.children;
|
|
76
|
+
} }));
|
|
85
77
|
}
|
|
86
78
|
function DateRangePickerLabel(props) {
|
|
87
79
|
const ctx = useDateRangePickerContext();
|
|
88
|
-
const [local, others] = splitProps(props, ["children"]);
|
|
80
|
+
const [local, others] = splitProps(props, ["children", "fx", "style"]);
|
|
89
81
|
return (() => {
|
|
90
82
|
const _el$ = createNativeElement("span");
|
|
91
|
-
spread({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"data-date-picker-label": ""
|
|
96
|
-
})
|
|
97
|
-
});
|
|
83
|
+
spread({ element: _el$, props: mergeProps(fxProps(
|
|
84
|
+
() => local.fx,
|
|
85
|
+
() => local.style
|
|
86
|
+
), others, { id: () => ctx.ids.label, "data-date-picker-label": "" }) });
|
|
98
87
|
insert(_el$, local.children);
|
|
99
88
|
return _el$;
|
|
100
89
|
})();
|
|
101
90
|
}
|
|
102
91
|
function EndpointField(props) {
|
|
103
92
|
const ctx = useDateRangePickerContext();
|
|
104
|
-
return createMemo(() => createComponent(DateField, {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
get
|
|
124
|
-
return ctx.
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
get isReadOnly() {
|
|
130
|
-
return ctx.isReadOnly;
|
|
131
|
-
},
|
|
132
|
-
get children() {
|
|
133
|
-
return createMemo(() => createComponent(DateInput, {
|
|
134
|
-
get "aria-labelledby"() {
|
|
135
|
-
return ctx.ids.label;
|
|
136
|
-
},
|
|
137
|
-
get "data-date-picker-input"() {
|
|
138
|
-
return "";
|
|
139
|
-
}
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
}));
|
|
93
|
+
return createMemo(() => createComponent(DateField, { get value() {
|
|
94
|
+
return props.value;
|
|
95
|
+
}, get onChange() {
|
|
96
|
+
return props.onChange;
|
|
97
|
+
}, get locale() {
|
|
98
|
+
return ctx.locale;
|
|
99
|
+
}, get granularity() {
|
|
100
|
+
return ctx.granularity;
|
|
101
|
+
}, get hourCycle() {
|
|
102
|
+
return ctx.hourCycle;
|
|
103
|
+
}, get minValue() {
|
|
104
|
+
return ctx.minValue;
|
|
105
|
+
}, get maxValue() {
|
|
106
|
+
return ctx.maxValue;
|
|
107
|
+
}, get isDisabled() {
|
|
108
|
+
return ctx.isDisabled;
|
|
109
|
+
}, get isReadOnly() {
|
|
110
|
+
return ctx.isReadOnly;
|
|
111
|
+
}, get children() {
|
|
112
|
+
return createMemo(() => createComponent(DateInput, { get "aria-labelledby"() {
|
|
113
|
+
return ctx.ids.label;
|
|
114
|
+
}, get "data-date-picker-input"() {
|
|
115
|
+
return "";
|
|
116
|
+
} }));
|
|
117
|
+
} }));
|
|
143
118
|
}
|
|
144
119
|
function DateRangePickerField(props) {
|
|
145
120
|
const ctx = useDateRangePickerContext();
|
|
146
|
-
const [local, others] = splitProps(props, ["ref", "children"]);
|
|
121
|
+
const [local, others] = splitProps(props, ["ref", "children", "fx", "style"]);
|
|
147
122
|
const setRef = (node) => {
|
|
148
123
|
ctx.setTriggerRef(node);
|
|
149
124
|
handleRef(local.ref, node);
|
|
150
125
|
};
|
|
151
126
|
return (() => {
|
|
152
127
|
const _el$ = createNativeElement("div");
|
|
153
|
-
spread({
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
insert(_el$, createMemo(() => createComponent(EndpointField, {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return ctx.setStart;
|
|
169
|
-
}
|
|
170
|
-
})), null);
|
|
171
|
-
insert(_el$, templateNode(_tmpl$0, "span"));
|
|
172
|
-
insert(_el$, createMemo(() => createComponent(EndpointField, {
|
|
173
|
-
get value() {
|
|
174
|
-
return ctx.end;
|
|
175
|
-
},
|
|
176
|
-
get onChange() {
|
|
177
|
-
return ctx.setEnd;
|
|
178
|
-
}
|
|
179
|
-
})), null);
|
|
128
|
+
spread({ element: _el$, props: mergeProps(fxProps(
|
|
129
|
+
() => local.fx,
|
|
130
|
+
() => local.style
|
|
131
|
+
), others, { ref: setRef, role: "group", "aria-labelledby": () => ctx.ids.label, "data-date-picker-control": "", "data-date-range": "" }) });
|
|
132
|
+
insert(_el$, createMemo(() => createComponent(EndpointField, { get value() {
|
|
133
|
+
return ctx.start;
|
|
134
|
+
}, get onChange() {
|
|
135
|
+
return ctx.setStart;
|
|
136
|
+
} })), null);
|
|
137
|
+
insert(_el$, templateNode(_fxTmpl$0, "span"));
|
|
138
|
+
insert(_el$, createMemo(() => createComponent(EndpointField, { get value() {
|
|
139
|
+
return ctx.end;
|
|
140
|
+
}, get onChange() {
|
|
141
|
+
return ctx.setEnd;
|
|
142
|
+
} })), null);
|
|
180
143
|
insert(_el$, local.children ?? createMemo(() => createComponent(DateRangePickerTrigger, {})));
|
|
181
144
|
return _el$;
|
|
182
145
|
})();
|
|
183
146
|
}
|
|
184
147
|
function DateRangePickerTrigger(props) {
|
|
185
148
|
const ctx = useDateRangePickerContext();
|
|
186
|
-
const [local, others] = splitProps(props, ["onClick", "children"]);
|
|
149
|
+
const [local, others] = splitProps(props, ["onClick", "children", "fx", "style"]);
|
|
187
150
|
return (() => {
|
|
188
151
|
const _el$ = createNativeElement("button");
|
|
189
|
-
spread({
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
onClick: composeEventHandlers([local.onClick, () => {
|
|
200
|
-
if (ctx.isDisabled() || ctx.isReadOnly()) return;
|
|
201
|
-
ctx.setOpen(!ctx.isOpen());
|
|
202
|
-
}])
|
|
203
|
-
})
|
|
204
|
-
});
|
|
152
|
+
spread({ element: _el$, props: mergeProps(fxProps(
|
|
153
|
+
() => local.fx,
|
|
154
|
+
() => local.style
|
|
155
|
+
), others, { type: "button", "aria-haspopup": "dialog", "aria-expanded": (() => ctx.isOpen() ? "true" : "false"), "aria-controls": () => ctx.ids.content, "aria-label": "Open calendar", disabled: (() => ctx.isDisabled()), "data-date-picker-trigger": "", onClick: composeEventHandlers([
|
|
156
|
+
local.onClick,
|
|
157
|
+
() => {
|
|
158
|
+
if (ctx.isDisabled() || ctx.isReadOnly()) return;
|
|
159
|
+
ctx.setOpen(!ctx.isOpen());
|
|
160
|
+
}
|
|
161
|
+
]) }) });
|
|
205
162
|
insert(_el$, local.children ?? "📅");
|
|
206
163
|
return _el$;
|
|
207
164
|
})();
|
|
208
165
|
}
|
|
209
166
|
function DateRangePickerContent(props) {
|
|
210
167
|
const ctx = useDateRangePickerContext();
|
|
211
|
-
const [local, others] = splitProps(props, ["ref", "children", "style"]);
|
|
168
|
+
const [local, others] = splitProps(props, ["ref", "children", "style", "fx", "style"]);
|
|
212
169
|
const [element, setElement] = createSignal(void 0);
|
|
213
170
|
const portalRef = useRef(null);
|
|
214
171
|
createEffect(() => {
|
|
215
172
|
if (!ctx.isOpen() && portalRef.current) portalRef.current.remove();
|
|
216
173
|
});
|
|
217
|
-
return createMemo(() => createComponent(Show, {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return local.style;
|
|
239
|
-
},
|
|
240
|
-
get children() {
|
|
241
|
-
return local.children ?? createMemo(() => createComponent(DateRangePickerCalendar, {}));
|
|
242
|
-
}
|
|
243
|
-
})));
|
|
244
|
-
}
|
|
245
|
-
}));
|
|
246
|
-
}
|
|
247
|
-
}));
|
|
174
|
+
return createMemo(() => createComponent(Show, { get when() {
|
|
175
|
+
return ctx.isOpen();
|
|
176
|
+
}, get children() {
|
|
177
|
+
return createMemo(() => createComponent(Portal, { get ref() {
|
|
178
|
+
return portalRef;
|
|
179
|
+
}, get children() {
|
|
180
|
+
return createMemo(() => createComponent(FloatingPanel, mergeProps(others, { get setElement() {
|
|
181
|
+
return setElement;
|
|
182
|
+
}, get element() {
|
|
183
|
+
return element;
|
|
184
|
+
}, get forwardRef() {
|
|
185
|
+
return local.ref;
|
|
186
|
+
}, get fx() {
|
|
187
|
+
return local.fx;
|
|
188
|
+
}, get style() {
|
|
189
|
+
return local.style;
|
|
190
|
+
}, get children() {
|
|
191
|
+
return local.children ?? createMemo(() => createComponent(DateRangePickerCalendar, {}));
|
|
192
|
+
} })));
|
|
193
|
+
} }));
|
|
194
|
+
} }));
|
|
248
195
|
}
|
|
249
196
|
function FloatingPanel(props) {
|
|
250
197
|
const ctx = useDateRangePickerContext();
|
|
@@ -259,11 +206,7 @@ function FloatingPanel(props) {
|
|
|
259
206
|
},
|
|
260
207
|
onDismiss: () => ctx.setOpen(false)
|
|
261
208
|
});
|
|
262
|
-
createFocusScope(props.element, {
|
|
263
|
-
trap: false,
|
|
264
|
-
autoFocus: true,
|
|
265
|
-
restoreFocus: true
|
|
266
|
-
});
|
|
209
|
+
createFocusScope(props.element, { trap: false, autoFocus: true, restoreFocus: true });
|
|
267
210
|
createRenderEffect(() => {
|
|
268
211
|
const el = props.element();
|
|
269
212
|
if (!el) return;
|
|
@@ -277,73 +220,48 @@ function FloatingPanel(props) {
|
|
|
277
220
|
};
|
|
278
221
|
return (() => {
|
|
279
222
|
const _el$ = createNativeElement("div");
|
|
280
|
-
spread({
|
|
281
|
-
|
|
282
|
-
props
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
"data-date-picker-
|
|
288
|
-
"data-placement": () => position.placement(),
|
|
289
|
-
style: () => props.style,
|
|
290
|
-
tabindex: -1,
|
|
291
|
-
onKeyDown: (e) => {
|
|
292
|
-
if (e.key === "Escape") {
|
|
293
|
-
e.stopPropagation();
|
|
294
|
-
ctx.setOpen(false);
|
|
295
|
-
ctx.triggerRef()?.querySelector("[data-date-picker-trigger]")?.focus();
|
|
296
|
-
}
|
|
297
|
-
}
|
|
223
|
+
spread({ element: _el$, props: mergeProps(fxProps(
|
|
224
|
+
() => props.fx,
|
|
225
|
+
() => props.style
|
|
226
|
+
), { ref: setRef, role: "dialog", id: () => ctx.ids.content, "aria-label": "Calendar", "data-date-picker-content": "", "data-placement": (() => position.placement()), tabindex: -1, onKeyDown: ((e) => {
|
|
227
|
+
if (e.key === "Escape") {
|
|
228
|
+
e.stopPropagation();
|
|
229
|
+
ctx.setOpen(false);
|
|
230
|
+
ctx.triggerRef()?.querySelector("[data-date-picker-trigger]")?.focus();
|
|
298
231
|
}
|
|
299
|
-
});
|
|
232
|
+
}) }) });
|
|
300
233
|
insert(_el$, props.children);
|
|
301
234
|
return _el$;
|
|
302
235
|
})();
|
|
303
236
|
}
|
|
304
237
|
function DateRangePickerCalendar() {
|
|
305
238
|
const ctx = useDateRangePickerContext();
|
|
306
|
-
return createMemo(() => createComponent(RangeCalendar, {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
return [createMemo(() => createComponent(CalendarHeader, {
|
|
333
|
-
get children() {
|
|
334
|
-
return [createMemo(() => createComponent(CalendarPrevButton, {
|
|
335
|
-
get children() {
|
|
336
|
-
return "‹";
|
|
337
|
-
}
|
|
338
|
-
})), createMemo(() => createComponent(CalendarHeading, {})), createMemo(() => createComponent(CalendarNextButton, {
|
|
339
|
-
get children() {
|
|
340
|
-
return "›";
|
|
341
|
-
}
|
|
342
|
-
}))];
|
|
343
|
-
}
|
|
344
|
-
})), createMemo(() => createComponent(CalendarGrid, {}))];
|
|
345
|
-
}
|
|
346
|
-
}));
|
|
239
|
+
return createMemo(() => createComponent(RangeCalendar, { get value() {
|
|
240
|
+
return ctx.value;
|
|
241
|
+
}, get onChange() {
|
|
242
|
+
return ((range) => {
|
|
243
|
+
ctx.selectRange(range);
|
|
244
|
+
if (range) ctx.setOpen(false);
|
|
245
|
+
});
|
|
246
|
+
}, get locale() {
|
|
247
|
+
return ctx.locale;
|
|
248
|
+
}, get minValue() {
|
|
249
|
+
return ctx.minValue;
|
|
250
|
+
}, get maxValue() {
|
|
251
|
+
return ctx.maxValue;
|
|
252
|
+
}, get isDateUnavailable() {
|
|
253
|
+
return ctx.isDateUnavailable;
|
|
254
|
+
}, get "data-date-picker-calendar"() {
|
|
255
|
+
return "";
|
|
256
|
+
}, get children() {
|
|
257
|
+
return [createMemo(() => createComponent(CalendarHeader, { get children() {
|
|
258
|
+
return [createMemo(() => createComponent(CalendarPrevButton, { get children() {
|
|
259
|
+
return "‹";
|
|
260
|
+
} })), createMemo(() => createComponent(CalendarHeading, {})), createMemo(() => createComponent(CalendarNextButton, { get children() {
|
|
261
|
+
return "›";
|
|
262
|
+
} }))];
|
|
263
|
+
} })), createMemo(() => createComponent(CalendarGrid, {}))];
|
|
264
|
+
} }));
|
|
347
265
|
}
|
|
348
266
|
export {
|
|
349
267
|
DateRangePicker,
|