@dloizides/ui-layout 1.10.0 → 1.12.0
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/CHANGELOG.md +60 -6
- package/README.md +22 -1
- package/dist/index.d.mts +123 -2
- package/dist/index.d.ts +123 -2
- package/dist/index.js +170 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40,6 +40,34 @@ var LAYOUT_TEST_IDS = {
|
|
|
40
40
|
accordion: "accordion"
|
|
41
41
|
};
|
|
42
42
|
var DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
43
|
+
var LAYOUT_I18N = {
|
|
44
|
+
/** Placeholder shown by `ModalDropdown` when no option matches the current value. */
|
|
45
|
+
selectPlaceholder: "common.selectPlaceholder",
|
|
46
|
+
/** Accessible name + hint of the modal-variant dropdown's dismiss backdrop. */
|
|
47
|
+
dismissDropdown: "common.dismissDropdown",
|
|
48
|
+
dismissDropdownHint: "common.dismissDropdownHint",
|
|
49
|
+
/** Accessible hint on a single dropdown option row. */
|
|
50
|
+
selectOptionHint: "common.selectOptionHint",
|
|
51
|
+
/** Default accessible hint on an `AccordionItem` header when the caller supplies none. */
|
|
52
|
+
accordionToggleHint: "common.accordionToggleHint",
|
|
53
|
+
/** Default accessible hint on a `StatusBadge` when the caller supplies none. */
|
|
54
|
+
statusBadgeHint: "common.statusBadgeHint",
|
|
55
|
+
/** `ModalShell`: accessible name of the dialog when its title is not a plain string. */
|
|
56
|
+
dialog: "common.dialog",
|
|
57
|
+
/** `ModalShell`: accessible hint on the close button. */
|
|
58
|
+
closeDialogHint: "common.closeDialogHint",
|
|
59
|
+
/** `ModalShell`: accessible name of the close button. */
|
|
60
|
+
close: "quizTemplates.cancel",
|
|
61
|
+
/** `ModalShell`: heading fallback when no title is supplied. */
|
|
62
|
+
closeHeading: "close",
|
|
63
|
+
upgradePromptTitle: "settings.billing.upgradePrompt.title",
|
|
64
|
+
/** Body copy, parameterised: "…requires {{p1}}, you are on {{p2}}." */
|
|
65
|
+
upgradePromptMessage: "settings.billing.upgradePrompt.message",
|
|
66
|
+
upgradePromptCta: "settings.billing.upgradePrompt.cta",
|
|
67
|
+
upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint",
|
|
68
|
+
upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss",
|
|
69
|
+
upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint"
|
|
70
|
+
};
|
|
43
71
|
var styles2 = reactNative.StyleSheet.create({
|
|
44
72
|
heading: {
|
|
45
73
|
fontWeight: "700",
|
|
@@ -84,7 +112,7 @@ var StatusBadge = ({
|
|
|
84
112
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
85
113
|
reactNative.View,
|
|
86
114
|
{
|
|
87
|
-
accessibilityHint: accessibilityHint ?? t(
|
|
115
|
+
accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.statusBadgeHint),
|
|
88
116
|
accessibilityLabel: accessibilityLabel ?? label,
|
|
89
117
|
style: [styles3.badge, dynamicBadge],
|
|
90
118
|
testID,
|
|
@@ -216,30 +244,30 @@ var UpgradePrompt = ({
|
|
|
216
244
|
style: [styles5.container, { borderColor: primary, backgroundColor: colors.surface }],
|
|
217
245
|
testID: LAYOUT_TEST_IDS.upgradePrompt,
|
|
218
246
|
children: [
|
|
219
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.title, { color: colors.text }], children: t(
|
|
220
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.message, { color: colors.textSecondary }], children: t(
|
|
247
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.title, { color: colors.text }], children: t(LAYOUT_I18N.upgradePromptTitle) }),
|
|
248
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.message, { color: colors.textSecondary }], children: t(LAYOUT_I18N.upgradePromptMessage, requiredTier, currentTier) }),
|
|
221
249
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
222
250
|
reactNative.TouchableOpacity,
|
|
223
251
|
{
|
|
224
|
-
accessibilityHint: t(
|
|
225
|
-
accessibilityLabel: t(
|
|
252
|
+
accessibilityHint: t(LAYOUT_I18N.upgradePromptCtaHint),
|
|
253
|
+
accessibilityLabel: t(LAYOUT_I18N.upgradePromptCta),
|
|
226
254
|
accessibilityRole: "button",
|
|
227
255
|
style: [styles5.cta, { backgroundColor: primary }],
|
|
228
256
|
testID: LAYOUT_TEST_IDS.upgradePromptCta,
|
|
229
257
|
onPress: handleUpgradePress,
|
|
230
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.ctaText, { color: colors.surface }], children: t(
|
|
258
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.ctaText, { color: colors.surface }], children: t(LAYOUT_I18N.upgradePromptCta) })
|
|
231
259
|
}
|
|
232
260
|
),
|
|
233
261
|
onDismiss ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
234
262
|
reactNative.TouchableOpacity,
|
|
235
263
|
{
|
|
236
|
-
accessibilityHint: t(
|
|
237
|
-
accessibilityLabel: t(
|
|
264
|
+
accessibilityHint: t(LAYOUT_I18N.upgradePromptDismissHint),
|
|
265
|
+
accessibilityLabel: t(LAYOUT_I18N.upgradePromptDismiss),
|
|
238
266
|
accessibilityRole: "button",
|
|
239
267
|
style: styles5.dismiss,
|
|
240
268
|
testID: LAYOUT_TEST_IDS.upgradePromptDismiss,
|
|
241
269
|
onPress: onDismiss,
|
|
242
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.dismissText, { color: colors.textSecondary }], children: t(
|
|
270
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.dismissText, { color: colors.textSecondary }], children: t(LAYOUT_I18N.upgradePromptDismiss) })
|
|
243
271
|
}
|
|
244
272
|
) : null
|
|
245
273
|
]
|
|
@@ -337,13 +365,14 @@ function buildPortalPopoverStyle(rect, minWidth = 0) {
|
|
|
337
365
|
function buildAnchorStackStyle(isMenuOpen) {
|
|
338
366
|
return isMenuOpen ? { zIndex: ANCHOR_OPEN_Z_INDEX, elevation: MENU_ELEVATION } : null;
|
|
339
367
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
|
|
368
|
+
var MIN_VISIBLE_PX = 8;
|
|
369
|
+
function isAnchorHidden(rect, clip, minVisiblePx) {
|
|
370
|
+
const hasLayout = rect.width > 0 && rect.bottom > rect.top;
|
|
371
|
+
const hasClip = clip.bottom > clip.top && clip.right > clip.left;
|
|
372
|
+
if (!hasLayout || !hasClip) return false;
|
|
373
|
+
const visibleHeight = Math.min(rect.bottom, clip.bottom) - Math.max(rect.top, clip.top);
|
|
374
|
+
const visibleWidth = Math.min(rect.left + rect.width, clip.right) - Math.max(rect.left, clip.left);
|
|
375
|
+
return visibleHeight < minVisiblePx || visibleWidth < minVisiblePx;
|
|
347
376
|
}
|
|
348
377
|
var OPTION_BORDER_RADIUS = 4;
|
|
349
378
|
var BODY_FONT_SIZE = 14;
|
|
@@ -378,7 +407,7 @@ var OptionRow = ({
|
|
|
378
407
|
reactNative.TouchableOpacity,
|
|
379
408
|
{
|
|
380
409
|
accessible: true,
|
|
381
|
-
accessibilityHint: t(
|
|
410
|
+
accessibilityHint: t(LAYOUT_I18N.selectOptionHint),
|
|
382
411
|
accessibilityLabel: label,
|
|
383
412
|
accessibilityRole: "button",
|
|
384
413
|
"aria-selected": isSelected,
|
|
@@ -402,6 +431,33 @@ function readAnchorRect(containerRef) {
|
|
|
402
431
|
const r = node.getBoundingClientRect();
|
|
403
432
|
return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
|
|
404
433
|
}
|
|
434
|
+
function clipsAxis(overflow) {
|
|
435
|
+
return overflow !== "" && overflow !== "visible";
|
|
436
|
+
}
|
|
437
|
+
function clipToAncestor(bounds, el) {
|
|
438
|
+
const style = window.getComputedStyle(el);
|
|
439
|
+
const clipsY = clipsAxis(style.overflowY) || clipsAxis(style.overflow);
|
|
440
|
+
const clipsX = clipsAxis(style.overflowX) || clipsAxis(style.overflow);
|
|
441
|
+
if (!clipsY && !clipsX) return;
|
|
442
|
+
const r = el.getBoundingClientRect();
|
|
443
|
+
if (clipsY) {
|
|
444
|
+
bounds.top = Math.max(bounds.top, r.top);
|
|
445
|
+
bounds.bottom = Math.min(bounds.bottom, r.bottom);
|
|
446
|
+
}
|
|
447
|
+
if (clipsX) {
|
|
448
|
+
bounds.left = Math.max(bounds.left, r.left);
|
|
449
|
+
bounds.right = Math.min(bounds.right, r.right);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function readClipBounds(node) {
|
|
453
|
+
const bounds = { top: 0, left: 0, bottom: window.innerHeight, right: window.innerWidth };
|
|
454
|
+
let el = node?.parentElement ?? null;
|
|
455
|
+
while (el !== null && el !== document.body && el !== document.documentElement) {
|
|
456
|
+
clipToAncestor(bounds, el);
|
|
457
|
+
el = el.parentElement;
|
|
458
|
+
}
|
|
459
|
+
return bounds;
|
|
460
|
+
}
|
|
405
461
|
function observeLayout(node, onChange) {
|
|
406
462
|
if (typeof ResizeObserver !== "function") return null;
|
|
407
463
|
const observer = new ResizeObserver(onChange);
|
|
@@ -415,12 +471,15 @@ function useAnchorTracking(containerRef, onOutOfView) {
|
|
|
415
471
|
if (!IS_WEB) return void 0;
|
|
416
472
|
let frame = null;
|
|
417
473
|
let isDisposed = false;
|
|
474
|
+
let hasMeasured = false;
|
|
418
475
|
const apply = () => {
|
|
419
476
|
frame = null;
|
|
420
477
|
if (isDisposed) return;
|
|
421
478
|
const next = readAnchorRect(containerRef);
|
|
422
479
|
setRect(next);
|
|
423
|
-
|
|
480
|
+
const isHidden = next !== null && isAnchorHidden(next, readClipBounds(toDomNode(containerRef)), MIN_VISIBLE_PX);
|
|
481
|
+
if (hasMeasured && isHidden) onOutOfView();
|
|
482
|
+
hasMeasured = true;
|
|
424
483
|
};
|
|
425
484
|
const schedule = () => {
|
|
426
485
|
if (frame !== null) return;
|
|
@@ -678,7 +737,7 @@ var ModalDropdown = ({
|
|
|
678
737
|
useFocusTrap(dialogRef, isOpen && !isMenu);
|
|
679
738
|
const selectedLabel = React8.useMemo(() => {
|
|
680
739
|
const found = options.find((opt) => opt.value === value);
|
|
681
|
-
return found?.label ?? t(
|
|
740
|
+
return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
|
|
682
741
|
}, [options, value, t]);
|
|
683
742
|
const handleToggle = React8.useCallback(() => {
|
|
684
743
|
setIsOpen((prev) => !prev);
|
|
@@ -758,8 +817,8 @@ var ModalDropdown = ({
|
|
|
758
817
|
reactNative.TouchableOpacity,
|
|
759
818
|
{
|
|
760
819
|
accessible: true,
|
|
761
|
-
accessibilityHint: t(
|
|
762
|
-
accessibilityLabel: t(
|
|
820
|
+
accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
|
|
821
|
+
accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
|
|
763
822
|
accessibilityRole: "button",
|
|
764
823
|
activeOpacity: 1,
|
|
765
824
|
style: reactNative.StyleSheet.absoluteFill,
|
|
@@ -810,8 +869,8 @@ var ModalShell = ({
|
|
|
810
869
|
() => [styles9.container, { backgroundColor: theme.colors.background }, contentStyle],
|
|
811
870
|
[theme.colors.background, contentStyle]
|
|
812
871
|
);
|
|
813
|
-
const closeA11yLabel = t(
|
|
814
|
-
const accessibleTitle = typeof title === "string" ? title : t(
|
|
872
|
+
const closeA11yLabel = t(LAYOUT_I18N.close);
|
|
873
|
+
const accessibleTitle = typeof title === "string" ? title : t(LAYOUT_I18N.dialog);
|
|
815
874
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
816
875
|
reactNative.Modal,
|
|
817
876
|
{
|
|
@@ -828,11 +887,11 @@ var ModalShell = ({
|
|
|
828
887
|
style: containerStyle,
|
|
829
888
|
children: [
|
|
830
889
|
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles9.headerRow, children: [
|
|
831
|
-
/* @__PURE__ */ jsxRuntime.jsx(Heading, { children: title ?? t(
|
|
890
|
+
/* @__PURE__ */ jsxRuntime.jsx(Heading, { children: title ?? t(LAYOUT_I18N.closeHeading) }),
|
|
832
891
|
showClose ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
833
892
|
reactNative.TouchableOpacity,
|
|
834
893
|
{
|
|
835
|
-
accessibilityHint: t(
|
|
894
|
+
accessibilityHint: t(LAYOUT_I18N.closeDialogHint),
|
|
836
895
|
accessibilityLabel: closeA11yLabel,
|
|
837
896
|
accessibilityRole: "button",
|
|
838
897
|
style: styles9.closeButton,
|
|
@@ -1066,7 +1125,7 @@ var AccordionItem = ({
|
|
|
1066
1125
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1067
1126
|
reactNative.Pressable,
|
|
1068
1127
|
{
|
|
1069
|
-
accessibilityHint: accessibilityHint ?? t(
|
|
1128
|
+
accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.accordionToggleHint),
|
|
1070
1129
|
accessibilityLabel: resolvedLabel,
|
|
1071
1130
|
accessibilityRole: "button",
|
|
1072
1131
|
accessibilityState: { expanded, disabled },
|
|
@@ -1125,18 +1184,103 @@ var AccordionItem = ({
|
|
|
1125
1184
|
] });
|
|
1126
1185
|
};
|
|
1127
1186
|
|
|
1187
|
+
// src/TruncatedText/truncate.ts
|
|
1188
|
+
var ELLIPSIS = "\u2026";
|
|
1189
|
+
var MIN_TRUNCATABLE_CHARS = 4;
|
|
1190
|
+
var SCHEME_PREFIX = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
1191
|
+
var WWW_PREFIX = /^www\./i;
|
|
1192
|
+
var TRAILING_SLASH = /\/$/;
|
|
1193
|
+
function truncateMiddle(value, maxChars) {
|
|
1194
|
+
if (maxChars < MIN_TRUNCATABLE_CHARS) return value;
|
|
1195
|
+
if (value.length <= maxChars) return value;
|
|
1196
|
+
const budget = maxChars - 1;
|
|
1197
|
+
const head = Math.ceil(budget / 2);
|
|
1198
|
+
const tail = budget - head;
|
|
1199
|
+
return `${value.slice(0, head)}${ELLIPSIS}${value.slice(value.length - tail)}`;
|
|
1200
|
+
}
|
|
1201
|
+
function formatUrlForDisplay(value) {
|
|
1202
|
+
const withoutScheme = value.replace(SCHEME_PREFIX, "");
|
|
1203
|
+
const withoutWww = withoutScheme.replace(WWW_PREFIX, "");
|
|
1204
|
+
const trimmed = withoutWww.replace(TRAILING_SLASH, "");
|
|
1205
|
+
return trimmed.length > 0 ? trimmed : value;
|
|
1206
|
+
}
|
|
1207
|
+
var AVG_CHAR_WIDTH_RATIO = 0.58;
|
|
1208
|
+
var DEFAULT_FONT_SIZE2 = 13;
|
|
1209
|
+
var UNMEASURED = 0;
|
|
1210
|
+
var styles12 = reactNative.StyleSheet.create({
|
|
1211
|
+
base: { fontSize: DEFAULT_FONT_SIZE2 },
|
|
1212
|
+
/** `minWidth: 0` lets the text shrink inside a flex row instead of forcing the row wider. */
|
|
1213
|
+
fill: { flexShrink: 1, minWidth: 0 }
|
|
1214
|
+
});
|
|
1215
|
+
function charBudget(width, fontSize) {
|
|
1216
|
+
if (width <= UNMEASURED) return UNMEASURED;
|
|
1217
|
+
return Math.floor(width / (fontSize * AVG_CHAR_WIDTH_RATIO));
|
|
1218
|
+
}
|
|
1219
|
+
var TruncatedText = ({
|
|
1220
|
+
value,
|
|
1221
|
+
isUrl = false,
|
|
1222
|
+
href,
|
|
1223
|
+
onPress,
|
|
1224
|
+
style,
|
|
1225
|
+
testID,
|
|
1226
|
+
accessibilityLabel,
|
|
1227
|
+
accessibilityHint
|
|
1228
|
+
}) => {
|
|
1229
|
+
const [width, setWidth] = React8.useState(UNMEASURED);
|
|
1230
|
+
const hostRef = React8.useRef(null);
|
|
1231
|
+
const onLayout = React8.useCallback((e) => {
|
|
1232
|
+
setWidth(e.nativeEvent.layout.width);
|
|
1233
|
+
}, []);
|
|
1234
|
+
const attachTooltip = React8.useCallback(
|
|
1235
|
+
(node) => {
|
|
1236
|
+
hostRef.current = node;
|
|
1237
|
+
if (reactNative.Platform.OS !== "web" || node === null) return;
|
|
1238
|
+
node.setAttribute?.("title", value);
|
|
1239
|
+
},
|
|
1240
|
+
[value]
|
|
1241
|
+
);
|
|
1242
|
+
const flatStyle = React8.useMemo(() => reactNative.StyleSheet.flatten([styles12.base, style]), [style]);
|
|
1243
|
+
const fontSize = flatStyle.fontSize ?? DEFAULT_FONT_SIZE2;
|
|
1244
|
+
const display = React8.useMemo(() => {
|
|
1245
|
+
const source = isUrl ? formatUrlForDisplay(value) : value;
|
|
1246
|
+
const budget = charBudget(width, fontSize);
|
|
1247
|
+
return budget === UNMEASURED ? source : truncateMiddle(source, budget);
|
|
1248
|
+
}, [value, isUrl, width, fontSize]);
|
|
1249
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1250
|
+
reactNative.Text,
|
|
1251
|
+
{
|
|
1252
|
+
ref: attachTooltip,
|
|
1253
|
+
onLayout,
|
|
1254
|
+
numberOfLines: 1,
|
|
1255
|
+
style: [styles12.base, styles12.fill, style],
|
|
1256
|
+
testID,
|
|
1257
|
+
accessibilityRole: onPress !== void 0 || href !== void 0 ? "link" : "text",
|
|
1258
|
+
accessibilityLabel,
|
|
1259
|
+
accessibilityHint,
|
|
1260
|
+
onPress,
|
|
1261
|
+
...reactNative.Platform.OS === "web" && href !== void 0 ? { href } : {},
|
|
1262
|
+
children: display
|
|
1263
|
+
}
|
|
1264
|
+
);
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1128
1267
|
exports.Accordion = Accordion;
|
|
1129
1268
|
exports.AccordionItem = AccordionItem;
|
|
1130
1269
|
exports.DEFAULT_BILLING_ROUTE = DEFAULT_BILLING_ROUTE;
|
|
1131
1270
|
exports.DropdownVariant = DropdownVariant;
|
|
1271
|
+
exports.ELLIPSIS = ELLIPSIS;
|
|
1132
1272
|
exports.Heading = Heading;
|
|
1273
|
+
exports.LAYOUT_I18N = LAYOUT_I18N;
|
|
1133
1274
|
exports.LAYOUT_TEST_IDS = LAYOUT_TEST_IDS;
|
|
1134
1275
|
exports.ModalDropdown = ModalDropdown;
|
|
1135
1276
|
exports.ModalShell = ModalShell;
|
|
1136
1277
|
exports.Section = Section;
|
|
1137
1278
|
exports.SegmentedControl = SegmentedControl;
|
|
1138
1279
|
exports.StatusBadge = StatusBadge;
|
|
1280
|
+
exports.TruncatedText = TruncatedText;
|
|
1139
1281
|
exports.UpgradePrompt = UpgradePrompt;
|
|
1282
|
+
exports.formatUrlForDisplay = formatUrlForDisplay;
|
|
1283
|
+
exports.truncateMiddle = truncateMiddle;
|
|
1140
1284
|
exports.useFocusTrap = useFocusTrap;
|
|
1141
1285
|
//# sourceMappingURL=index.js.map
|
|
1142
1286
|
//# sourceMappingURL=index.js.map
|