@dloizides/ui-forms 1.42.0 → 1.42.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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2389,7 +2389,7 @@ function PickerDialog({ testID, sheet, onDismiss, children }) {
|
|
|
2389
2389
|
event.preventDefault();
|
|
2390
2390
|
(event.shiftKey ? last : first).focus();
|
|
2391
2391
|
};
|
|
2392
|
-
const shape = sheet ? { borderTopLeftRadius: SHEET_RADIUS, borderTopRightRadius: SHEET_RADIUS, maxHeight: SHEET_MAX_HEIGHT, overflowY: "auto" } : { borderRadius: RADIUS, boxShadow: `0 12px 32px ${colors.border}` };
|
|
2392
|
+
const shape = sheet ? { borderTopLeftRadius: SHEET_RADIUS, borderTopRightRadius: SHEET_RADIUS, width: "100%", maxHeight: SHEET_MAX_HEIGHT, overflowY: "auto" } : { borderRadius: RADIUS, boxShadow: `0 12px 32px ${colors.border}` };
|
|
2393
2393
|
const style = { boxSizing: "border-box", padding: PAD, background: colors.surface, color: colors.text, border: `1px solid ${colors.border}`, fontFamily: "inherit", ...shape };
|
|
2394
2394
|
return /* @__PURE__ */ jsx("div", { ref, "data-testid": testID, "data-variant": sheet ? "sheet" : "popover", style, onKeyDown, children });
|
|
2395
2395
|
}
|
|
@@ -2416,23 +2416,26 @@ function placeDropdown(anchor, panelHeight, viewportHeight) {
|
|
|
2416
2416
|
if (roomBelow >= panelHeight) return "below" /* Below */;
|
|
2417
2417
|
return anchor.y > roomBelow ? "above" /* Above */ : "below" /* Below */;
|
|
2418
2418
|
}
|
|
2419
|
-
function
|
|
2420
|
-
|
|
2419
|
+
function clampTop(top, panelHeight, viewportHeight) {
|
|
2420
|
+
return Math.max(EDGE, Math.min(top, viewportHeight - panelHeight - EDGE));
|
|
2421
|
+
}
|
|
2422
|
+
function dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow = false) {
|
|
2423
|
+
const placement = preferBelow ? "below" /* Below */ : placeDropdown(anchor, panelHeight, viewportHeight);
|
|
2421
2424
|
const base = { placement, left: anchor.x, width: anchor.width };
|
|
2422
|
-
if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - anchor.y };
|
|
2423
|
-
return { ...base, top: anchor.y + anchor.height };
|
|
2425
|
+
if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - clampTop(anchor.y - panelHeight, panelHeight, viewportHeight) - panelHeight };
|
|
2426
|
+
return { ...base, top: clampTop(anchor.y + anchor.height, panelHeight, viewportHeight) };
|
|
2424
2427
|
}
|
|
2425
2428
|
function fitDropdownWidth(frame, viewportWidth, minWidth = MIN_PANEL_WIDTH) {
|
|
2426
2429
|
const width = Math.max(frame.width, Math.min(minWidth, viewportWidth - EDGE - EDGE));
|
|
2427
2430
|
const left = Math.max(EDGE, Math.min(frame.left, viewportWidth - width - EDGE));
|
|
2428
2431
|
return { ...frame, width, left: frame.width >= width ? frame.left : left };
|
|
2429
2432
|
}
|
|
2430
|
-
function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children, minWidth, scale, accessibilityLabel }) {
|
|
2433
|
+
function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children, minWidth, scale, accessibilityLabel, preferBelow = false }) {
|
|
2431
2434
|
const { height: viewportHeight, width: viewportWidth } = useWindowDimensions();
|
|
2432
2435
|
const anchor = useAnchorRect2(anchorRef);
|
|
2433
2436
|
const [panelHeight, setPanelHeight] = useState(0);
|
|
2434
2437
|
const onLayout = useCallback((event) => setPanelHeight(event.nativeEvent.layout.height), []);
|
|
2435
|
-
const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight), viewportWidth, minWidth);
|
|
2438
|
+
const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow), viewportWidth, minWidth);
|
|
2436
2439
|
const place = frame === null ? null : { left: frame.left, width: frame.width, top: frame.top, bottom: frame.bottom };
|
|
2437
2440
|
return /* @__PURE__ */ jsxs(Modal, { transparent: true, visible: true, animationType: "none", "aria-label": accessibilityLabel, onRequestClose: onDismiss, children: [
|
|
2438
2441
|
/* @__PURE__ */ jsx(Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
|
|
@@ -2446,11 +2449,12 @@ var styles15 = StyleSheet.create({
|
|
|
2446
2449
|
function SheetSurface({ translateY, onDismiss, closeLabel, closeHint, testID, children, progress, scale, accessibilityLabel }) {
|
|
2447
2450
|
return /* @__PURE__ */ jsx(Modal, { transparent: true, visible: true, animationType: "none", "aria-label": accessibilityLabel, onRequestClose: onDismiss, children: /* @__PURE__ */ jsxs(View, { style: styles16.backdrop, children: [
|
|
2448
2451
|
/* @__PURE__ */ jsx(Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
|
|
2449
|
-
/* @__PURE__ */ jsx(Animated.View, { style: [{ transform: scale === void 0 ? [{ translateY }] : [{ translateY }, { scale }] }, progress === void 0 ? null : { opacity: progress }], children })
|
|
2452
|
+
/* @__PURE__ */ jsx(Animated.View, { testID: `${testID}-sheet`, style: [styles16.sheet, { transform: scale === void 0 ? [{ translateY }] : [{ translateY }, { scale }] }, progress === void 0 ? null : { opacity: progress }], children })
|
|
2450
2453
|
] }) });
|
|
2451
2454
|
}
|
|
2452
2455
|
var styles16 = StyleSheet.create({
|
|
2453
|
-
backdrop: { flex: 1, justifyContent: "flex-end" }
|
|
2456
|
+
backdrop: { flex: 1, justifyContent: "flex-end" },
|
|
2457
|
+
sheet: { width: "100%", alignSelf: "stretch" }
|
|
2454
2458
|
});
|
|
2455
2459
|
function useReducedMotion() {
|
|
2456
2460
|
const [reduced, setReduced] = useState(false);
|
|
@@ -2632,9 +2636,9 @@ function PickerSurface({ anchorRef, phone, minWidth, label, testID, onDismiss, c
|
|
|
2632
2636
|
const { progress, scale, still } = useOpenProgress();
|
|
2633
2637
|
const body = /* @__PURE__ */ jsx(PickerDialog, { sheet: phone, testID, onDismiss, children });
|
|
2634
2638
|
if (phone) {
|
|
2635
|
-
return /* @__PURE__ */ jsx(SheetSurface, { accessibilityLabel: label, closeHint: labels.cancelHint, closeLabel: labels.cancel, progress,
|
|
2639
|
+
return /* @__PURE__ */ jsx(SheetSurface, { accessibilityLabel: label, closeHint: labels.cancelHint, closeLabel: labels.cancel, progress, testID, translateY: still, onDismiss, children: body });
|
|
2636
2640
|
}
|
|
2637
|
-
return /* @__PURE__ */ jsx(DropdownSurface, { accessibilityLabel: label, anchorRef, closeHint: labels.cancelHint, closeLabel: labels.cancel, minWidth, progress, scale, testID, translateY: still, onDismiss, children: body });
|
|
2641
|
+
return /* @__PURE__ */ jsx(DropdownSurface, { accessibilityLabel: label, anchorRef, closeHint: labels.cancelHint, closeLabel: labels.cancel, minWidth, preferBelow: true, progress, scale, testID, translateY: still, onDismiss, children: body });
|
|
2638
2642
|
}
|
|
2639
2643
|
|
|
2640
2644
|
// src/DatePicker/utils/calendarKeys.ts
|
|
@@ -2699,7 +2703,7 @@ var REGULAR = 400;
|
|
|
2699
2703
|
function DayCell({ iso, state, testID, label, hint, onPick, onKey }) {
|
|
2700
2704
|
const colors = usePickerColors();
|
|
2701
2705
|
const { inRange, isEnd, isToday, enabled, focusable } = state;
|
|
2702
|
-
const cellStyle = { width: DAY_CELL_PX, height: DAY_CELL_PX, background: inRange && !isEnd ? colors.tint : "transparent" };
|
|
2706
|
+
const cellStyle = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0, background: inRange && !isEnd ? colors.tint : "transparent" };
|
|
2703
2707
|
const textColor = isEnd ? colors.onBrand : enabled ? colors.text : colors.textSecondary;
|
|
2704
2708
|
const buttonStyle = {
|
|
2705
2709
|
width: DAY_CELL_PX,
|
|
@@ -2822,7 +2826,7 @@ var CAPTION_FONT = 15;
|
|
|
2822
2826
|
var WEEKDAY_FONT = 12;
|
|
2823
2827
|
var BOLD2 = 700;
|
|
2824
2828
|
var ROW = { display: "flex" };
|
|
2825
|
-
var EMPTY = { width: DAY_CELL_PX, height: DAY_CELL_PX };
|
|
2829
|
+
var EMPTY = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0 };
|
|
2826
2830
|
var FALLBACK = { year: 1970, month: 1};
|
|
2827
2831
|
function MonthGrid({ month, selection, focusedDay, bounds, testID, onPick, onKey, showCaption = false, motion }) {
|
|
2828
2832
|
const { labels, locale, today, firstDay } = useDatePickerConfig();
|
|
@@ -2939,8 +2943,11 @@ function useIsPhone() {
|
|
|
2939
2943
|
function useReturnFocus(open, target) {
|
|
2940
2944
|
const wasOpen = useRef(open);
|
|
2941
2945
|
useEffect(() => {
|
|
2942
|
-
|
|
2946
|
+
const closed = wasOpen.current && !open;
|
|
2943
2947
|
wasOpen.current = open;
|
|
2948
|
+
if (!closed) return void 0;
|
|
2949
|
+
const timer = setTimeout(() => target.current?.focus(), 0);
|
|
2950
|
+
return () => clearTimeout(timer);
|
|
2944
2951
|
}, [open, target]);
|
|
2945
2952
|
}
|
|
2946
2953
|
function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }) {
|
|
@@ -2993,6 +3000,17 @@ function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }
|
|
|
2993
3000
|
isReady
|
|
2994
3001
|
};
|
|
2995
3002
|
}
|
|
3003
|
+
|
|
3004
|
+
// src/DatePicker/utils/fieldWidth.ts
|
|
3005
|
+
var FONT_PX = 14;
|
|
3006
|
+
var GLYPH_EM = 0.62;
|
|
3007
|
+
var PAD_INLINE = 12;
|
|
3008
|
+
var BORDER = 1;
|
|
3009
|
+
var PLACEHOLDER_CHARS = 15;
|
|
3010
|
+
function closedFieldMinWidth(text, iconRoom) {
|
|
3011
|
+
const chars = Math.max(text.length, PLACEHOLDER_CHARS);
|
|
3012
|
+
return Math.ceil(chars * FONT_PX * GLYPH_EM) + PAD_INLINE + iconRoom + BORDER + BORDER;
|
|
3013
|
+
}
|
|
2996
3014
|
var SINGLE_PICKER_WIDTH = 340;
|
|
2997
3015
|
var ICON_ROOM = 48;
|
|
2998
3016
|
var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "flex", alignItems: "center" };
|
|
@@ -3026,7 +3044,7 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3026
3044
|
event.preventDefault();
|
|
3027
3045
|
if (typed.isReady()) onSubmit();
|
|
3028
3046
|
};
|
|
3029
|
-
return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: anchorStyles.wrap, children: [
|
|
3047
|
+
return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: [anchorStyles.wrap, { minWidth: closedFieldMinWidth(typed.display, ICON_ROOM) }], testID: `${testID}-anchor`, children: [
|
|
3030
3048
|
/* @__PURE__ */ jsx(
|
|
3031
3049
|
"input",
|
|
3032
3050
|
{
|