@dloizides/ui-layout 1.61.0 → 1.63.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/dist/index.mjs CHANGED
@@ -258,6 +258,13 @@ var ScreenColumn = ({ children, narrow = false }) => {
258
258
  return /* @__PURE__ */ jsx(View, { style: styles3.outer, children: /* @__PURE__ */ jsx(View, { style: [styles3.column, isWide ? styles3.desktop : styles3.mobile, narrow ? styles3.narrow : styles3.wide], children }) });
259
259
  };
260
260
 
261
+ // src/StatusBadge/BadgeSize.ts
262
+ var BadgeSize = /* @__PURE__ */ ((BadgeSize2) => {
263
+ BadgeSize2["Regular"] = "regular";
264
+ BadgeSize2["Compact"] = "compact";
265
+ return BadgeSize2;
266
+ })(BadgeSize || {});
267
+
261
268
  // src/StatusBadge/BadgeTone.ts
262
269
  var BadgeTone = /* @__PURE__ */ ((BadgeTone2) => {
263
270
  BadgeTone2["Neutral"] = "neutral";
@@ -341,6 +348,10 @@ var DEFAULT_PADDING_V = 4;
341
348
  var DEFAULT_BORDER_RADIUS = 12;
342
349
  var DEFAULT_FONT_SIZE = 12;
343
350
  var ICON_GAP = 4;
351
+ var COMPACT_PADDING_H = 8;
352
+ var COMPACT_PADDING_V = 1;
353
+ var COMPACT_RADIUS = 999;
354
+ var COMPACT_LINE_HEIGHT = 17;
344
355
  var styles4 = StyleSheet.create({
345
356
  badge: {
346
357
  paddingHorizontal: DEFAULT_PADDING_H,
@@ -359,6 +370,14 @@ var styles4 = StyleSheet.create({
359
370
  borderWidth: 1,
360
371
  borderStyle: "dashed"
361
372
  },
373
+ badgeCompact: {
374
+ paddingHorizontal: COMPACT_PADDING_H,
375
+ paddingVertical: COMPACT_PADDING_V,
376
+ borderRadius: COMPACT_RADIUS
377
+ },
378
+ textCompact: {
379
+ lineHeight: COMPACT_LINE_HEIGHT
380
+ },
362
381
  text: {
363
382
  fontSize: DEFAULT_FONT_SIZE,
364
383
  fontWeight: "600",
@@ -372,6 +391,7 @@ var StatusBadge = ({
372
391
  backgroundColor: rawBackground,
373
392
  icon,
374
393
  dashed = false,
394
+ size = "regular" /* Regular */,
375
395
  testID = LAYOUT_TEST_IDS.statusLabel,
376
396
  accessibilityLabel,
377
397
  accessibilityHint
@@ -387,16 +407,17 @@ var StatusBadge = ({
387
407
  const dashedColor = useMemo(() => ({ borderColor: color }), [color]);
388
408
  const dynamicText = useMemo(() => ({ color }), [color]);
389
409
  const hasIcon = icon !== void 0 && icon !== null;
410
+ const compact = size === "compact" /* Compact */;
390
411
  return /* @__PURE__ */ jsxs(
391
412
  View,
392
413
  {
393
414
  accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.statusBadgeHint),
394
415
  accessibilityLabel: accessibilityLabel ?? label,
395
- style: [styles4.badge, hasIcon && styles4.badgeWithIcon, dynamicBadge, dashed && styles4.badgeDashed, dashed && dashedColor],
416
+ style: [styles4.badge, compact && styles4.badgeCompact, hasIcon && styles4.badgeWithIcon, dynamicBadge, dashed && styles4.badgeDashed, dashed && dashedColor],
396
417
  testID,
397
418
  children: [
398
419
  hasIcon ? /* @__PURE__ */ jsx(View, { "aria-hidden": true, children: icon }) : null,
399
- /* @__PURE__ */ jsx(Text, { style: [styles4.text, dynamicText], children: label })
420
+ /* @__PURE__ */ jsx(Text, { style: [styles4.text, compact && styles4.textCompact, dynamicText], children: label })
400
421
  ]
401
422
  }
402
423
  );
@@ -3423,6 +3444,39 @@ var SectionDensity = /* @__PURE__ */ ((SectionDensity2) => {
3423
3444
  SectionDensity2["Dense"] = "dense";
3424
3445
  return SectionDensity2;
3425
3446
  })(SectionDensity || {});
3447
+ var INDICATOR_MS = 180;
3448
+ var slide = (value, toValue) => Animated.timing(value, { toValue, duration: INDICATOR_MS, easing: Easing.out(Easing.cubic), useNativeDriver: false });
3449
+ function useSlidingIndicator(activeIndex) {
3450
+ const reduced = useReducedMotion();
3451
+ const [rows, setRows] = useState([]);
3452
+ const top = useRef(new Animated.Value(0)).current;
3453
+ const height = useRef(new Animated.Value(0)).current;
3454
+ const placed = useRef(false);
3455
+ const targetY = rows[activeIndex]?.y;
3456
+ const targetHeight = rows[activeIndex]?.height;
3457
+ useEffect(() => {
3458
+ if (targetY === void 0 || targetHeight === void 0) return;
3459
+ if (reduced || !placed.current) {
3460
+ top.setValue(targetY);
3461
+ height.setValue(targetHeight);
3462
+ placed.current = true;
3463
+ return;
3464
+ }
3465
+ Animated.parallel([slide(top, targetY), slide(height, targetHeight)]).start();
3466
+ }, [targetY, targetHeight, reduced, top, height]);
3467
+ const onRowLayout = useCallback(
3468
+ (index) => (event) => {
3469
+ const { y, height: rowHeight } = event.nativeEvent.layout;
3470
+ setRows((prev) => {
3471
+ const next = [...prev];
3472
+ next[index] = { y, height: rowHeight };
3473
+ return next;
3474
+ });
3475
+ },
3476
+ []
3477
+ );
3478
+ return { measured: targetY !== void 0, top, height, onRowLayout };
3479
+ }
3426
3480
  var SECTION_INDEX_WIDTH = 200;
3427
3481
  var ACTIVE_BAR = 3;
3428
3482
  var TRANSPARENT3 = "transparent";
@@ -3438,7 +3492,8 @@ var styles30 = StyleSheet.create({
3438
3492
  denseHeading: { fontSize: 11, fontWeight: "600", letterSpacing: 0.66, lineHeight: 16, paddingBottom: 6 },
3439
3493
  denseItem: { minHeight: DENSE_TARGET_PX, paddingVertical: 6, paddingLeft: 7, paddingRight: 10, borderRadius: 7 },
3440
3494
  denseLabel: { fontSize: 13, lineHeight: DENSE_LINE },
3441
- denseLabelActive: { fontWeight: "600" }
3495
+ denseLabelActive: { fontWeight: "600" },
3496
+ indicator: { position: "absolute", left: 0, width: ACTIVE_BAR, borderRadius: ACTIVE_BAR }
3442
3497
  });
3443
3498
  function ariaCurrent(active) {
3444
3499
  return active ? { "aria-current": "location" } : {};
@@ -3447,9 +3502,12 @@ var SectionIndex = ({ sections, activeKey, heading, itemHint, onSelect, testID,
3447
3502
  const { theme } = useUi();
3448
3503
  const { colors } = theme;
3449
3504
  const bar = activeColor ?? colors.text;
3505
+ const indicator = useSlidingIndicator(sections.findIndex((entry) => entry.key === activeKey));
3506
+ const staticBar = indicator.measured ? TRANSPARENT3 : bar;
3450
3507
  return /* @__PURE__ */ jsxs(View, { role: "navigation", accessibilityLabel: heading, style: [styles30.root, dense && styles30.denseRoot, { width }], testID: `${testID}-index`, children: [
3508
+ indicator.measured ? /* @__PURE__ */ jsx(Animated.View, { pointerEvents: "none", style: [styles30.indicator, { backgroundColor: bar, top: indicator.top, height: indicator.height }], testID: `${testID}-index-indicator` }) : null,
3451
3509
  /* @__PURE__ */ jsx(Text, { style: [styles30.heading, dense && styles30.denseHeading, { color: colors.textSecondary }], children: heading }),
3452
- sections.map((entry) => {
3510
+ sections.map((entry, index) => {
3453
3511
  const active = entry.key === activeKey;
3454
3512
  return /* @__PURE__ */ jsx(
3455
3513
  Pressable,
@@ -3458,8 +3516,9 @@ var SectionIndex = ({ sections, activeKey, heading, itemHint, onSelect, testID,
3458
3516
  accessibilityRole: "link",
3459
3517
  accessibilityLabel: entry.title,
3460
3518
  accessibilityHint: itemHint,
3461
- style: [styles30.item, dense && styles30.denseItem, { borderLeftColor: active ? bar : TRANSPARENT3, backgroundColor: active ? colors.surface : TRANSPARENT3 }],
3519
+ style: [styles30.item, dense && styles30.denseItem, { borderLeftColor: active ? staticBar : TRANSPARENT3, backgroundColor: active ? colors.surface : TRANSPARENT3 }],
3462
3520
  testID: `${testID}-index-${entry.key}`,
3521
+ onLayout: indicator.onRowLayout(index),
3463
3522
  onPress: () => onSelect(entry.key),
3464
3523
  children: /* @__PURE__ */ jsx(Text, { style: [styles30.label, active && styles30.labelActive, dense && styles30.denseLabel, dense && active && styles30.denseLabelActive, { color: active ? colors.text : colors.textSecondary }], children: entry.title })
3465
3524
  },
@@ -3469,6 +3528,27 @@ var SectionIndex = ({ sections, activeKey, heading, itemHint, onSelect, testID,
3469
3528
  ] });
3470
3529
  };
3471
3530
 
3531
+ // src/SectionIndexLayout/scrollSpy.ts
3532
+ var SPY_ACTIVATION_RATIO = 0.3;
3533
+ var SPY_CLICK_LOCK_MS = 900;
3534
+ var PERCENT2 = 100;
3535
+ function resolveSticky(value) {
3536
+ if (value === void 0 || value === false) return { sticky: false, spy: false, activationRatio: SPY_ACTIVATION_RATIO, clickLockMs: SPY_CLICK_LOCK_MS };
3537
+ const config = value === true ? {} : value;
3538
+ return {
3539
+ sticky: true,
3540
+ spy: config.scrollSpy ?? true,
3541
+ activationRatio: config.activationRatio ?? SPY_ACTIVATION_RATIO,
3542
+ clickLockMs: config.clickLockMs ?? SPY_CLICK_LOCK_MS
3543
+ };
3544
+ }
3545
+ function pickActiveIndex(tops, line) {
3546
+ return tops.reduce((picked, top, index) => top <= line ? index : picked, 0);
3547
+ }
3548
+ function spyRootMargin(activationRatio) {
3549
+ return `0px 0px -${Math.round((1 - activationRatio) * PERCENT2)}% 0px`;
3550
+ }
3551
+
3472
3552
  // src/SectionIndexLayout/sectionKeys.ts
3473
3553
  var SECTION_INDEX_BREAKPOINT = 1024;
3474
3554
  function resolveActiveKey(sections, wanted) {
@@ -3484,6 +3564,70 @@ function scrollToSection(anchorId) {
3484
3564
  const target = document.getElementById(anchorId);
3485
3565
  target?.scrollIntoView?.({ behavior: "smooth", block: "start" });
3486
3566
  }
3567
+ var UNPRIMED = -2;
3568
+ var STALE = -1;
3569
+ var ID_SEPARATOR = "\n";
3570
+ function canObserve() {
3571
+ return typeof document !== "undefined" && typeof window !== "undefined" && typeof IntersectionObserver !== "undefined";
3572
+ }
3573
+ function findAnchors(ids) {
3574
+ return ids.flatMap((id, index) => {
3575
+ const element = document.getElementById(id);
3576
+ return element === null ? [] : [{ index, element }];
3577
+ });
3578
+ }
3579
+ function useScrollSpy({ anchorIds, enabled, activationRatio, onActive }) {
3580
+ const onActiveRef = useRef(onActive);
3581
+ onActiveRef.current = onActive;
3582
+ const pausedUntil = useRef(0);
3583
+ const last = useRef(UNPRIMED);
3584
+ const idsKey = anchorIds.join(ID_SEPARATOR);
3585
+ useEffect(() => {
3586
+ if (!enabled || !canObserve()) return void 0;
3587
+ const anchors = findAnchors(idsKey.split(ID_SEPARATOR));
3588
+ if (anchors.length < 2) return void 0;
3589
+ last.current = UNPRIMED;
3590
+ const evaluate = () => {
3591
+ if (Date.now() < pausedUntil.current) return;
3592
+ const picked = pickActiveIndex(anchors.map((anchor) => anchor.element.getBoundingClientRect().top), window.innerHeight * activationRatio);
3593
+ const index = anchors[picked]?.index ?? 0;
3594
+ const primed = last.current !== UNPRIMED;
3595
+ if (index === last.current) return;
3596
+ last.current = index;
3597
+ if (primed || index > 0) onActiveRef.current(index);
3598
+ };
3599
+ const observer = new IntersectionObserver(evaluate, { rootMargin: spyRootMargin(activationRatio), threshold: 0 });
3600
+ anchors.forEach((anchor) => observer.observe(anchor.element));
3601
+ return () => observer.disconnect();
3602
+ }, [enabled, activationRatio, idsKey]);
3603
+ const pause = useCallback((ms) => {
3604
+ pausedUntil.current = Date.now() + ms;
3605
+ last.current = STALE;
3606
+ }, []);
3607
+ return useMemo(() => ({ pause }), [pause]);
3608
+ }
3609
+
3610
+ // src/SectionIndexLayout/useSectionSelection.ts
3611
+ function useSectionSelection({ sections, testID, preferredKey, spyEnabled, sticky }) {
3612
+ const [current, setCurrent] = useState(void 0);
3613
+ const spy = useScrollSpy({
3614
+ anchorIds: sections.map((entry) => sectionAnchorId(testID, entry.key)),
3615
+ enabled: spyEnabled && sticky.spy,
3616
+ activationRatio: sticky.activationRatio,
3617
+ onActive: (index) => setCurrent(sections[index]?.key)
3618
+ });
3619
+ const { pause } = spy;
3620
+ const { clickLockMs } = sticky;
3621
+ const select = useCallback(
3622
+ (key) => {
3623
+ setCurrent(key);
3624
+ pause(clickLockMs);
3625
+ scrollToSection(sectionAnchorId(testID, key));
3626
+ },
3627
+ [pause, clickLockMs, testID]
3628
+ );
3629
+ return { activeKey: resolveActiveKey(sections, current ?? preferredKey), pick: setCurrent, select };
3630
+ }
3487
3631
  var COMFORTABLE_GAP = 12;
3488
3632
  var DENSE_GAP = 8;
3489
3633
  var DENSE_WIDE_GAP = 16;
@@ -3514,8 +3658,9 @@ var SectionIndexLayout = ({
3514
3658
  const fold = toFold(breakpoint);
3515
3659
  const wide = useIsWideViewport(fold.wide);
3516
3660
  const stacked = useIsWideViewport(fold.stackFrom);
3517
- const [picked, setPicked] = useState(void 0);
3518
- const activeKey = resolveActiveKey(sections, picked ?? (wide ? initialKey : collapsedKey ?? initialKey));
3661
+ const sticky = resolveSticky(stickyIndex);
3662
+ const preferredKey = wide ? initialKey : collapsedKey ?? initialKey;
3663
+ const { activeKey, pick, select } = useSectionSelection({ sections, testID, preferredKey, spyEnabled: wide && sections.length > 1, sticky });
3519
3664
  const dense = density === "dense" /* Dense */;
3520
3665
  const gap = { gap: dense ? DENSE_GAP : COMFORTABLE_GAP };
3521
3666
  if (sections.length < 2) return /* @__PURE__ */ jsx(View, { testID, children: sections[0]?.content });
@@ -3534,19 +3679,15 @@ var SectionIndexLayout = ({
3534
3679
  overflow: chipOverflow,
3535
3680
  sections,
3536
3681
  testID,
3537
- onSelect: setPicked
3682
+ onSelect: pick
3538
3683
  }
3539
3684
  ),
3540
3685
  /* @__PURE__ */ jsx(View, { nativeID: sectionAnchorId(testID, activeKey), testID: sectionAnchorId(testID, activeKey), children: active?.content })
3541
3686
  ] });
3542
3687
  }
3543
- const select = (key) => {
3544
- setPicked(key);
3545
- scrollToSection(sectionAnchorId(testID, key));
3546
- };
3547
- const sticky = stickyIndex && Platform.OS === "web" ? WEB_STICKY : null;
3688
+ const stickyStyle = sticky.sticky && Platform.OS === "web" ? WEB_STICKY : null;
3548
3689
  return /* @__PURE__ */ jsxs(View, { style: [styles31.wide, dense && { gap: DENSE_WIDE_GAP }], testID, children: [
3549
- /* @__PURE__ */ jsx(View, { style: sticky, children: /* @__PURE__ */ jsx(SectionIndex, { activeColor, activeKey, dense, heading: indexHeading, itemHint, sections, testID, width: indexWidth, onSelect: select }) }),
3690
+ /* @__PURE__ */ jsx(View, { style: stickyStyle, children: /* @__PURE__ */ jsx(SectionIndex, { activeColor, activeKey, dense, heading: indexHeading, itemHint, sections, testID, width: indexWidth, onSelect: select }) }),
3550
3691
  /* @__PURE__ */ jsx(SectionColumn, { sections, style: StyleSheet.flatten([styles31.column, gap]), testID })
3551
3692
  ] });
3552
3693
  };
@@ -4164,6 +4305,6 @@ var ListDetailLayout = ({
4164
4305
  return /* @__PURE__ */ jsx(SplitPanes, { end: null, layout: "stack" /* Stack */, start: panes.detail ? detail : list, testID });
4165
4306
  };
4166
4307
 
4167
- export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BadgeTone, BottomSheet, Breadcrumb, BuildInfoFooter, COPY_FEEDBACK_MS, ChipOverflow, ConfirmDialog, ConfirmDialogFocus, CopyControl, CopyRowEmphasis, CopyStatus, CopyValueRow, CopyableId, CountBadge, DEFAULT_BILLING_ROUTE, DayBadgeFill, DayCard, DayCardLayout, DropdownVariant, ELLIPSIS, FigureStrip, FormDialog, HEADER_STACK_BREAKPOINT, Heading, IdChip, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListDetailLayout, ListDetailPane, ListRow, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, ModalShell, PageFrame, PageHead, RecordActionButton, RecordHeader, RowSelectedStyle, SECTION_INDEX_BREAKPOINT, SECTION_INDEX_WIDTH, ScreenColumn, Section, SectionChips, SectionDensity, SectionIndex, SectionIndexLayout, SectionVariant, SegmentedControl, SegmentedVariant, SelectedMarker, SideSheet, SplitLayout, SplitPanes, StatusBadge, StickyActionBar, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TabsVariant, TextKind, Timeline, ToggleSection, TotalsStrip, TotalsTone, TransferSlip, TruncatedText, UnderlineTabs, UpgradePrompt, WidgetCard, copyActionLabel, copyText, figureCell, formatBuildInfo, formatCount, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isRecordHeaderCompact, isSplitSideBySide, isWideWebViewport, pageScale, resolveActiveKey, resolveListDetailPanes, resolveRowLook, resolveTintColors, resolveToneColors, rowSelection, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
4308
+ export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BadgeSize, BadgeTone, BottomSheet, Breadcrumb, BuildInfoFooter, COPY_FEEDBACK_MS, ChipOverflow, ConfirmDialog, ConfirmDialogFocus, CopyControl, CopyRowEmphasis, CopyStatus, CopyValueRow, CopyableId, CountBadge, DEFAULT_BILLING_ROUTE, DayBadgeFill, DayCard, DayCardLayout, DropdownVariant, ELLIPSIS, FigureStrip, FormDialog, HEADER_STACK_BREAKPOINT, Heading, IdChip, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListDetailLayout, ListDetailPane, ListRow, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, ModalShell, PageFrame, PageHead, RecordActionButton, RecordHeader, RowSelectedStyle, SECTION_INDEX_BREAKPOINT, SECTION_INDEX_WIDTH, SPY_ACTIVATION_RATIO, SPY_CLICK_LOCK_MS, ScreenColumn, Section, SectionChips, SectionDensity, SectionIndex, SectionIndexLayout, SectionVariant, SegmentedControl, SegmentedVariant, SelectedMarker, SideSheet, SplitLayout, SplitPanes, StatusBadge, StickyActionBar, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TabsVariant, TextKind, Timeline, ToggleSection, TotalsStrip, TotalsTone, TransferSlip, TruncatedText, UnderlineTabs, UpgradePrompt, WidgetCard, copyActionLabel, copyText, figureCell, formatBuildInfo, formatCount, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isRecordHeaderCompact, isSplitSideBySide, isWideWebViewport, pageScale, pickActiveIndex, resolveActiveKey, resolveListDetailPanes, resolveRowLook, resolveTintColors, resolveToneColors, rowSelection, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useScrollSpy, useVisibleViewport };
4168
4309
  //# sourceMappingURL=index.mjs.map
4169
4310
  //# sourceMappingURL=index.mjs.map