@scripso-homepad/ui 0.4.31 → 0.4.34
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/index.cjs +101 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +101 -67
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Calendar.tsx +2 -5
- package/src/components/DatePicker.tsx +55 -11
- package/src/theme/calendar.ts +9 -1
package/dist/index.d.cts
CHANGED
|
@@ -231,6 +231,10 @@ type DatePickerFieldProps = {
|
|
|
231
231
|
hintClassName?: string;
|
|
232
232
|
/** Opens the calendar popup on mount (useful for Storybook previews). */
|
|
233
233
|
defaultOpen?: boolean;
|
|
234
|
+
/** Controlled open state for the calendar popup. */
|
|
235
|
+
open?: boolean;
|
|
236
|
+
/** Called when the calendar popup opens or closes. */
|
|
237
|
+
onOpenChange?: (open: boolean) => void;
|
|
234
238
|
/** Closes the popup after a complete range is selected. Defaults to true in range mode. */
|
|
235
239
|
closeOnRangeComplete?: boolean;
|
|
236
240
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -231,6 +231,10 @@ type DatePickerFieldProps = {
|
|
|
231
231
|
hintClassName?: string;
|
|
232
232
|
/** Opens the calendar popup on mount (useful for Storybook previews). */
|
|
233
233
|
defaultOpen?: boolean;
|
|
234
|
+
/** Controlled open state for the calendar popup. */
|
|
235
|
+
open?: boolean;
|
|
236
|
+
/** Called when the calendar popup opens or closes. */
|
|
237
|
+
onOpenChange?: (open: boolean) => void;
|
|
234
238
|
/** Closes the popup after a complete range is selected. Defaults to true in range mode. */
|
|
235
239
|
closeOnRangeComplete?: boolean;
|
|
236
240
|
};
|
package/dist/index.js
CHANGED
|
@@ -1476,7 +1476,7 @@ var calendarDropdownMetrics = StyleSheet.create({
|
|
|
1476
1476
|
boxSizing: "border-box"
|
|
1477
1477
|
} : null
|
|
1478
1478
|
},
|
|
1479
|
-
|
|
1479
|
+
dayCellDisabled: {
|
|
1480
1480
|
backgroundColor: colors.stormGray50
|
|
1481
1481
|
},
|
|
1482
1482
|
dayCellSelected: {
|
|
@@ -1599,6 +1599,10 @@ function resolveCalendarDropdownLeft(anchor, panelWidth = CALENDAR_PANEL_WIDTH)
|
|
|
1599
1599
|
const maxLeft = Math.max(0, windowWidth - panelWidth);
|
|
1600
1600
|
return Math.max(0, Math.min(anchor.x, maxLeft));
|
|
1601
1601
|
}
|
|
1602
|
+
function resolveCalendarDropdownLeftCentered(panelWidth = CALENDAR_PANEL_WIDTH) {
|
|
1603
|
+
const windowWidth = Dimensions.get("window").width;
|
|
1604
|
+
return Math.max(0, (windowWidth - panelWidth) / 2);
|
|
1605
|
+
}
|
|
1602
1606
|
var calendarFieldMetrics = StyleSheet.create({
|
|
1603
1607
|
container: {
|
|
1604
1608
|
flexDirection: "row",
|
|
@@ -2015,10 +2019,9 @@ function resolveDayCellStyle(day) {
|
|
|
2015
2019
|
if (day.isSelected) {
|
|
2016
2020
|
return [calendarDropdownMetrics.dayCell, calendarDropdownMetrics.dayCellSelected];
|
|
2017
2021
|
}
|
|
2018
|
-
const useMutedBackground = day.inCurrentMonth && !day.isToday && (day.isPast || day.isDisabled);
|
|
2019
2022
|
return [
|
|
2020
2023
|
calendarDropdownMetrics.dayCell,
|
|
2021
|
-
|
|
2024
|
+
day.isDisabled ? calendarDropdownMetrics.dayCellDisabled : null
|
|
2022
2025
|
];
|
|
2023
2026
|
}
|
|
2024
2027
|
function resolveDayLabelStyle(day) {
|
|
@@ -2031,7 +2034,7 @@ function resolveDayLabelStyle(day) {
|
|
|
2031
2034
|
if (day.isToday) {
|
|
2032
2035
|
return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelToday];
|
|
2033
2036
|
}
|
|
2034
|
-
if (day.
|
|
2037
|
+
if (day.isDisabled) {
|
|
2035
2038
|
return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelMuted];
|
|
2036
2039
|
}
|
|
2037
2040
|
return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelFuture];
|
|
@@ -2309,6 +2312,7 @@ function CalendarIcon({
|
|
|
2309
2312
|
}
|
|
2310
2313
|
) });
|
|
2311
2314
|
}
|
|
2315
|
+
var isDesktopCalendar = Platform.OS === "web";
|
|
2312
2316
|
function DatePicker(props) {
|
|
2313
2317
|
const {
|
|
2314
2318
|
label,
|
|
@@ -2334,7 +2338,9 @@ function DatePicker(props) {
|
|
|
2334
2338
|
labelClassName,
|
|
2335
2339
|
errorClassName,
|
|
2336
2340
|
hintClassName,
|
|
2337
|
-
defaultOpen = false
|
|
2341
|
+
defaultOpen = false,
|
|
2342
|
+
open: controlledOpen,
|
|
2343
|
+
onOpenChange
|
|
2338
2344
|
} = props;
|
|
2339
2345
|
const mode = props.mode ?? "single";
|
|
2340
2346
|
const closeOnRangeComplete = props.mode === "range" ? props.closeOnRangeComplete ?? true : false;
|
|
@@ -2344,11 +2350,18 @@ function DatePicker(props) {
|
|
|
2344
2350
|
const wrapperRef = useRef(null);
|
|
2345
2351
|
const triggerRef = useRef(null);
|
|
2346
2352
|
const helperRef = useRef(null);
|
|
2347
|
-
const
|
|
2353
|
+
const isControlled = controlledOpen !== void 0;
|
|
2354
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
|
|
2355
|
+
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
2348
2356
|
const [anchor, setAnchor] = useState(null);
|
|
2349
2357
|
useApplyWebClassName(wrapperRef, className);
|
|
2350
2358
|
useApplyWebClassName(triggerRef, fieldClassName);
|
|
2351
2359
|
useApplyWebClassName(helperRef, error ? errorClassName : hintClassName);
|
|
2360
|
+
useEffect(() => {
|
|
2361
|
+
if (!open) {
|
|
2362
|
+
setAnchor(null);
|
|
2363
|
+
}
|
|
2364
|
+
}, [open]);
|
|
2352
2365
|
useEffect(() => {
|
|
2353
2366
|
if (!defaultOpen || disabled) {
|
|
2354
2367
|
return;
|
|
@@ -2356,7 +2369,7 @@ function DatePicker(props) {
|
|
|
2356
2369
|
const frame = requestAnimationFrame(() => {
|
|
2357
2370
|
triggerRef.current?.measureInWindow((x, y, width, height) => {
|
|
2358
2371
|
setAnchor({ x, y, width, height });
|
|
2359
|
-
|
|
2372
|
+
setOpenState(true);
|
|
2360
2373
|
});
|
|
2361
2374
|
});
|
|
2362
2375
|
return () => cancelAnimationFrame(frame);
|
|
@@ -2391,11 +2404,16 @@ function DatePicker(props) {
|
|
|
2391
2404
|
};
|
|
2392
2405
|
const helperMessage = error ?? hint;
|
|
2393
2406
|
const panelWidth = CALENDAR_PANEL_WIDTH;
|
|
2394
|
-
const panelLeft = anchor ? resolveCalendarDropdownLeft(anchor, panelWidth) : 0;
|
|
2407
|
+
const panelLeft = anchor ? isDesktopCalendar ? resolveCalendarDropdownLeft(anchor, panelWidth) : resolveCalendarDropdownLeftCentered(panelWidth) : 0;
|
|
2395
2408
|
const dropdownTop = anchor ? resolveCalendarDropdownTop(anchor) : 0;
|
|
2396
|
-
|
|
2409
|
+
function setOpenState(next) {
|
|
2410
|
+
if (!isControlled) {
|
|
2411
|
+
setUncontrolledOpen(next);
|
|
2412
|
+
}
|
|
2413
|
+
onOpenChange?.(next);
|
|
2414
|
+
}
|
|
2397
2415
|
function closePicker() {
|
|
2398
|
-
|
|
2416
|
+
setOpenState(false);
|
|
2399
2417
|
setAnchor(null);
|
|
2400
2418
|
}
|
|
2401
2419
|
function openPicker() {
|
|
@@ -2404,9 +2422,10 @@ function DatePicker(props) {
|
|
|
2404
2422
|
}
|
|
2405
2423
|
triggerRef.current?.measureInWindow((x, y, width, height) => {
|
|
2406
2424
|
setAnchor({ x, y, width, height });
|
|
2407
|
-
|
|
2425
|
+
setOpenState(true);
|
|
2408
2426
|
});
|
|
2409
2427
|
}
|
|
2428
|
+
const resolvedDefaultViewDate = defaultViewDate ?? (props.mode === "range" ? props.value?.start : props.value) ?? today;
|
|
2410
2429
|
function handleSingleSelect(date) {
|
|
2411
2430
|
if (props.mode === "range") {
|
|
2412
2431
|
return;
|
|
@@ -2476,64 +2495,76 @@ function DatePicker(props) {
|
|
|
2476
2495
|
}
|
|
2477
2496
|
),
|
|
2478
2497
|
helperMessage ? /* @__PURE__ */ jsx(Text, { ref: helperRef, style: error ? styles5.error : styles5.hint, children: helperMessage }) : null,
|
|
2479
|
-
/* @__PURE__ */ jsx(
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
{
|
|
2492
|
-
style: [
|
|
2493
|
-
styles5.panelPosition,
|
|
2494
|
-
{
|
|
2495
|
-
top: dropdownTop,
|
|
2496
|
-
left: panelLeft,
|
|
2497
|
-
width: panelWidth,
|
|
2498
|
-
height: CALENDAR_PANEL_HEIGHT
|
|
2499
|
-
}
|
|
2500
|
-
],
|
|
2501
|
-
children: props.mode === "range" ? /* @__PURE__ */ jsx(
|
|
2502
|
-
Calendar,
|
|
2498
|
+
/* @__PURE__ */ jsx(
|
|
2499
|
+
Modal,
|
|
2500
|
+
{
|
|
2501
|
+
visible: open,
|
|
2502
|
+
transparent: true,
|
|
2503
|
+
animationType: "fade",
|
|
2504
|
+
onRequestClose: closePicker,
|
|
2505
|
+
statusBarTranslucent: true,
|
|
2506
|
+
...Platform.OS === "ios" ? { presentationStyle: "overFullScreen" } : null,
|
|
2507
|
+
children: /* @__PURE__ */ jsxs(View, { style: styles5.modalRoot, children: [
|
|
2508
|
+
/* @__PURE__ */ jsx(
|
|
2509
|
+
Pressable,
|
|
2503
2510
|
{
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
defaultViewDate: resolvedDefaultViewDate,
|
|
2509
|
-
onViewDateChange,
|
|
2510
|
-
locale: resolvedLocale,
|
|
2511
|
-
labels,
|
|
2512
|
-
minDate,
|
|
2513
|
-
maxDate,
|
|
2514
|
-
today,
|
|
2515
|
-
className: panelClassName
|
|
2511
|
+
style: styles5.backdrop,
|
|
2512
|
+
onPress: closePicker,
|
|
2513
|
+
accessibilityRole: "button",
|
|
2514
|
+
accessibilityLabel: labels?.closeCalendar ?? translations.closeCalendar
|
|
2516
2515
|
}
|
|
2517
|
-
)
|
|
2518
|
-
|
|
2516
|
+
),
|
|
2517
|
+
anchor ? /* @__PURE__ */ jsx(
|
|
2518
|
+
View,
|
|
2519
2519
|
{
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2520
|
+
pointerEvents: "box-none",
|
|
2521
|
+
style: [
|
|
2522
|
+
styles5.panelPosition,
|
|
2523
|
+
{
|
|
2524
|
+
top: dropdownTop,
|
|
2525
|
+
left: panelLeft,
|
|
2526
|
+
width: panelWidth,
|
|
2527
|
+
height: CALENDAR_PANEL_HEIGHT
|
|
2528
|
+
}
|
|
2529
|
+
],
|
|
2530
|
+
children: /* @__PURE__ */ jsx(View, { pointerEvents: "auto", children: props.mode === "range" ? /* @__PURE__ */ jsx(
|
|
2531
|
+
Calendar,
|
|
2532
|
+
{
|
|
2533
|
+
mode: "range",
|
|
2534
|
+
value: props.value,
|
|
2535
|
+
onChange: handleRangeSelect,
|
|
2536
|
+
viewDate,
|
|
2537
|
+
defaultViewDate: resolvedDefaultViewDate,
|
|
2538
|
+
onViewDateChange,
|
|
2539
|
+
locale: resolvedLocale,
|
|
2540
|
+
labels,
|
|
2541
|
+
minDate,
|
|
2542
|
+
maxDate,
|
|
2543
|
+
today,
|
|
2544
|
+
className: panelClassName
|
|
2545
|
+
}
|
|
2546
|
+
) : /* @__PURE__ */ jsx(
|
|
2547
|
+
Calendar,
|
|
2548
|
+
{
|
|
2549
|
+
mode: "single",
|
|
2550
|
+
value: props.value,
|
|
2551
|
+
onChange: handleSingleSelect,
|
|
2552
|
+
viewDate,
|
|
2553
|
+
defaultViewDate: resolvedDefaultViewDate,
|
|
2554
|
+
onViewDateChange,
|
|
2555
|
+
locale: resolvedLocale,
|
|
2556
|
+
labels,
|
|
2557
|
+
minDate,
|
|
2558
|
+
maxDate,
|
|
2559
|
+
today,
|
|
2560
|
+
className: panelClassName
|
|
2561
|
+
}
|
|
2562
|
+
) })
|
|
2532
2563
|
}
|
|
2533
|
-
)
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
|
|
2564
|
+
) : null
|
|
2565
|
+
] })
|
|
2566
|
+
}
|
|
2567
|
+
)
|
|
2537
2568
|
]
|
|
2538
2569
|
}
|
|
2539
2570
|
);
|
|
@@ -2573,11 +2604,14 @@ var styles5 = StyleSheet.create({
|
|
|
2573
2604
|
flexShrink: 0
|
|
2574
2605
|
},
|
|
2575
2606
|
modalRoot: {
|
|
2576
|
-
flex: 1
|
|
2607
|
+
flex: 1,
|
|
2608
|
+
width: "100%",
|
|
2609
|
+
height: "100%"
|
|
2577
2610
|
},
|
|
2578
2611
|
backdrop: {
|
|
2579
2612
|
...StyleSheet.absoluteFillObject,
|
|
2580
|
-
backgroundColor:
|
|
2613
|
+
backgroundColor: "rgba(0, 0, 0, 0.35)",
|
|
2614
|
+
zIndex: 0
|
|
2581
2615
|
},
|
|
2582
2616
|
panelPosition: {
|
|
2583
2617
|
position: "absolute",
|