@dloizides/ui-layout 1.15.0 → 1.16.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/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.16.0
4
+
5
+ **`Heading` supports levels 1-6 instead of `<h1>` only.**
6
+
7
+ `Heading` rendered `<h1>` unconditionally, so any screen needing sub-structure either
8
+ shipped multiple `<h1>`s or avoided the component. The Digital Kin guide editor did the
9
+ latter — styled `<Text>` instead — and shipped **zero headings**: measured on the live
10
+ CMS, `document.querySelectorAll('h1,h2,h3,h4,h5,h6').length === 0` for the entire page.
11
+
12
+ So there was no `<h1>` naming the guide being edited and nothing marking the steps
13
+ section. Screen-reader users could not navigate by heading, and styling was standing in
14
+ for structure.
15
+
16
+ After: `h1` names the guide, `h2` marks the steps section, `h3` per step.
17
+
18
+
19
+ ## 1.15.1
20
+
21
+ - **Fix (`CopyableId` truncated the value with room to spare).** 1.15.0 gave the value wrapper
22
+ `flexShrink: 1`, which makes it SHRINK-WRAP its content — so the width the component measures to
23
+ decide how much to show was derived from the very string it was computing: truncate → wrapper
24
+ narrows → re-measure smaller → truncate harder. Verified in Chrome via `apps/ui-showcase`: a
25
+ 506px-wide container and a 306px one rendered the SAME 196px string, i.e. a 36-character GUID was
26
+ cut to 26 characters with ~300px going unused.
27
+
28
+ The wrapper is now `flex: 1`, so it fills the row's leftover width and its size is independent of
29
+ its content. Re-verified at four widths: 520px and 320px now render the full 36-character GUID
30
+ untruncated; 200px and 120px middle-truncate with both ends intact, and nothing overflows.
31
+
32
+ This is the SAME failure mode `useAvailableWidth` documents for `TruncatedText` (measure the
33
+ parent, never the element, or the output feeds back into the input) — reintroduced one level up
34
+ by the new wrapper. Unit tests cannot catch it: the truncation helpers are pure and passed
35
+ throughout, and jsdom reports zero widths, so only a real browser shows it.
36
+
37
+ - **New: `CopyableId` accepts `style`** for its outer container. Hosts need this to give the
38
+ control a width that does not derive from its own content (a `flexBasis`, a `width`, or
39
+ `flex: 1`) — without one, a shrink-to-fit parent reintroduces the feedback loop above at the
40
+ host level. Documented on the prop.
41
+
3
42
  ## 1.15.0
4
43
 
5
44
  - **New: `CopyableId`** — show a long machine identifier (a GUID, a reference, a correlation id)
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { RefObject } from 'react';
2
- import { ViewStyle, StyleProp, TextStyle, View } from 'react-native';
2
+ import { ViewStyle, Text, StyleProp, TextStyle, View } from 'react-native';
3
3
 
4
4
  /**
5
5
  * Section — a bordered card container that themes its border + surface.
@@ -12,14 +12,43 @@ interface SectionProps {
12
12
  declare const Section: ({ children, style }: SectionProps) => React.ReactElement;
13
13
 
14
14
  /**
15
- * Heading — themed section heading text.
15
+ * Heading — themed section heading text, rendered as a REAL `<h1>`–`<h6>` on web.
16
+ *
17
+ * ## Why `level` exists
18
+ *
19
+ * `accessibilityRole="header"` maps to the ARIA `heading` role, which react-native-web turns
20
+ * into a real heading element — but with no `aria-level` it always emits `<h1>`. A screen
21
+ * having several `<h1>`s and no `<h2>` is a flat document: heading navigation, the primary way
22
+ * assistive-tech users move around a long page, lists every section as a peer of the page title.
23
+ *
24
+ * `level` supplies `aria-level`, which RN-web uses to pick `h{level}`. It defaults to 2 rather
25
+ * than 1 on purpose: a page has exactly ONE `<h1>` (its title) and many section headings, so the
26
+ * common case must be the safe one. A second `<h1>` is a defect that renders identically to a
27
+ * correct heading, so nothing about the page would reveal the mistake.
28
+ *
29
+ * The visual size is deliberately NOT derived from `level`. Heading level is document structure;
30
+ * type scale is design. Tying them together is what pushes authors to pick a level for its font
31
+ * size and break the outline to get the look they want.
16
32
  */
17
33
 
34
+ /** `h1`–`h6`; HTML defines no `h7`. */
35
+ type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
18
36
  interface HeadingProps {
19
37
  text?: string;
20
38
  children?: React.ReactNode;
39
+ /**
40
+ * Document outline depth → `<h1>`–`<h6>` on web, `aria-level` on native. Defaults to 2.
41
+ * Pick it from the page's STRUCTURE, never from how large you want the text to look.
42
+ */
43
+ level?: HeadingLevel;
44
+ /**
45
+ * Merged AFTER the themed base, for the genuine one-off — a page title that needs to be
46
+ * visibly larger than a section heading. Structure stays in `level`; size lives here.
47
+ */
48
+ style?: React.ComponentProps<typeof Text>['style'];
49
+ testID?: string;
21
50
  }
22
- declare const Heading: ({ text, children }: HeadingProps) => React.ReactElement;
51
+ declare const Heading: ({ text, children, level, style, testID, }: HeadingProps) => React.ReactElement;
23
52
 
24
53
  /**
25
54
  * StatusBadge — unified status pill. Colours are passed in; domain adapters map their
@@ -377,7 +406,16 @@ interface CopyableIdProps {
377
406
  value: string;
378
407
  /** Optional eyebrow above the value (e.g. "Screening ID"). Pass pre-localized. */
379
408
  label?: string;
380
- /** Base testID; the copy control is `${testID}-copy` and the status text `${testID}-status`. */
409
+ /**
410
+ * Style for the outer container.
411
+ *
412
+ * Hosts should give this a width that does NOT derive from its own content — a `flexBasis`, a
413
+ * `width`, or `flex: 1`. The component measures its container to decide how much of the value
414
+ * to show, so a shrink-to-fit parent makes the available width depend on the string being
415
+ * computed, and the id renders clipped with space to spare.
416
+ */
417
+ style?: StyleProp<ViewStyle>;
418
+ /** Base testID; the copy control is `${testID}-copy` and the value `${testID}-value`. */
381
419
  testID: string;
382
420
  /** Accessible name for the value itself. Pass pre-localized; falls back to the raw value. */
383
421
  accessibilityLabel?: string;
@@ -387,7 +425,7 @@ interface CopyableIdProps {
387
425
  */
388
426
  writer?: (text: string) => void | Promise<void>;
389
427
  }
390
- declare const CopyableId: ({ value, label, testID, accessibilityLabel, writer, }: CopyableIdProps) => React.ReactElement;
428
+ declare const CopyableId: ({ value, label, style, testID, accessibilityLabel, writer, }: CopyableIdProps) => React.ReactElement;
391
429
 
392
430
  /**
393
431
  * The three states a copy affordance can be in. Its own file per the repo's
@@ -516,4 +554,4 @@ declare const LAYOUT_I18N: {
516
554
  readonly copyableIdHint: "common.copyableIdHint";
517
555
  };
518
556
 
519
- export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, COPY_FEEDBACK_MS, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, Heading, type HeadingProps, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
557
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, COPY_FEEDBACK_MS, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, Heading, type HeadingLevel, type HeadingProps, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { RefObject } from 'react';
2
- import { ViewStyle, StyleProp, TextStyle, View } from 'react-native';
2
+ import { ViewStyle, Text, StyleProp, TextStyle, View } from 'react-native';
3
3
 
4
4
  /**
5
5
  * Section — a bordered card container that themes its border + surface.
@@ -12,14 +12,43 @@ interface SectionProps {
12
12
  declare const Section: ({ children, style }: SectionProps) => React.ReactElement;
13
13
 
14
14
  /**
15
- * Heading — themed section heading text.
15
+ * Heading — themed section heading text, rendered as a REAL `<h1>`–`<h6>` on web.
16
+ *
17
+ * ## Why `level` exists
18
+ *
19
+ * `accessibilityRole="header"` maps to the ARIA `heading` role, which react-native-web turns
20
+ * into a real heading element — but with no `aria-level` it always emits `<h1>`. A screen
21
+ * having several `<h1>`s and no `<h2>` is a flat document: heading navigation, the primary way
22
+ * assistive-tech users move around a long page, lists every section as a peer of the page title.
23
+ *
24
+ * `level` supplies `aria-level`, which RN-web uses to pick `h{level}`. It defaults to 2 rather
25
+ * than 1 on purpose: a page has exactly ONE `<h1>` (its title) and many section headings, so the
26
+ * common case must be the safe one. A second `<h1>` is a defect that renders identically to a
27
+ * correct heading, so nothing about the page would reveal the mistake.
28
+ *
29
+ * The visual size is deliberately NOT derived from `level`. Heading level is document structure;
30
+ * type scale is design. Tying them together is what pushes authors to pick a level for its font
31
+ * size and break the outline to get the look they want.
16
32
  */
17
33
 
34
+ /** `h1`–`h6`; HTML defines no `h7`. */
35
+ type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
18
36
  interface HeadingProps {
19
37
  text?: string;
20
38
  children?: React.ReactNode;
39
+ /**
40
+ * Document outline depth → `<h1>`–`<h6>` on web, `aria-level` on native. Defaults to 2.
41
+ * Pick it from the page's STRUCTURE, never from how large you want the text to look.
42
+ */
43
+ level?: HeadingLevel;
44
+ /**
45
+ * Merged AFTER the themed base, for the genuine one-off — a page title that needs to be
46
+ * visibly larger than a section heading. Structure stays in `level`; size lives here.
47
+ */
48
+ style?: React.ComponentProps<typeof Text>['style'];
49
+ testID?: string;
21
50
  }
22
- declare const Heading: ({ text, children }: HeadingProps) => React.ReactElement;
51
+ declare const Heading: ({ text, children, level, style, testID, }: HeadingProps) => React.ReactElement;
23
52
 
24
53
  /**
25
54
  * StatusBadge — unified status pill. Colours are passed in; domain adapters map their
@@ -377,7 +406,16 @@ interface CopyableIdProps {
377
406
  value: string;
378
407
  /** Optional eyebrow above the value (e.g. "Screening ID"). Pass pre-localized. */
379
408
  label?: string;
380
- /** Base testID; the copy control is `${testID}-copy` and the status text `${testID}-status`. */
409
+ /**
410
+ * Style for the outer container.
411
+ *
412
+ * Hosts should give this a width that does NOT derive from its own content — a `flexBasis`, a
413
+ * `width`, or `flex: 1`. The component measures its container to decide how much of the value
414
+ * to show, so a shrink-to-fit parent makes the available width depend on the string being
415
+ * computed, and the id renders clipped with space to spare.
416
+ */
417
+ style?: StyleProp<ViewStyle>;
418
+ /** Base testID; the copy control is `${testID}-copy` and the value `${testID}-value`. */
381
419
  testID: string;
382
420
  /** Accessible name for the value itself. Pass pre-localized; falls back to the raw value. */
383
421
  accessibilityLabel?: string;
@@ -387,7 +425,7 @@ interface CopyableIdProps {
387
425
  */
388
426
  writer?: (text: string) => void | Promise<void>;
389
427
  }
390
- declare const CopyableId: ({ value, label, testID, accessibilityLabel, writer, }: CopyableIdProps) => React.ReactElement;
428
+ declare const CopyableId: ({ value, label, style, testID, accessibilityLabel, writer, }: CopyableIdProps) => React.ReactElement;
391
429
 
392
430
  /**
393
431
  * The three states a copy affordance can be in. Its own file per the repo's
@@ -516,4 +554,4 @@ declare const LAYOUT_I18N: {
516
554
  readonly copyableIdHint: "common.copyableIdHint";
517
555
  };
518
556
 
519
- export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, COPY_FEEDBACK_MS, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, Heading, type HeadingProps, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
557
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, COPY_FEEDBACK_MS, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, Heading, type HeadingLevel, type HeadingProps, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
package/dist/index.js CHANGED
@@ -88,13 +88,29 @@ var styles2 = reactNative.StyleSheet.create({
88
88
  fontSize: 16
89
89
  }
90
90
  });
91
- var Heading = ({ text, children }) => {
91
+ var DEFAULT_HEADING_LEVEL = 2;
92
+ var Heading = ({
93
+ text,
94
+ children,
95
+ level = DEFAULT_HEADING_LEVEL,
96
+ style,
97
+ testID
98
+ }) => {
92
99
  const { theme } = uiFeedback.useUi();
93
100
  const headingStyle = React8__default.default.useMemo(
94
- () => [styles2.heading, { color: theme.colors.text }],
95
- [theme.colors.text]
101
+ () => [styles2.heading, { color: theme.colors.text }, style],
102
+ [theme.colors.text, style]
103
+ );
104
+ return /* @__PURE__ */ jsxRuntime.jsx(
105
+ reactNative.Text,
106
+ {
107
+ accessibilityRole: "header",
108
+ "aria-level": level,
109
+ style: headingStyle,
110
+ testID: testID ?? LAYOUT_TEST_IDS.headingText,
111
+ children: text ?? children
112
+ }
96
113
  );
97
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { accessibilityRole: "header", style: headingStyle, testID: LAYOUT_TEST_IDS.headingText, children: text ?? children });
98
114
  };
99
115
  var DEFAULT_PADDING_H = 10;
100
116
  var DEFAULT_PADDING_V = 4;
@@ -1386,11 +1402,19 @@ var styles13 = reactNative.StyleSheet.create({
1386
1402
  row: { flexDirection: "row", alignItems: "center", gap: ROW_GAP },
1387
1403
  /**
1388
1404
  * The truncation width comes from this wrapper, not from the row: `TruncatedText` measures its
1389
- * PARENT (see `useAvailableWidth`), and the row also holds the button. `minWidth: 0` is what
1390
- * actually lets a flex child shrink below its content width — without it the row just grows and
1391
- * nothing ever truncates.
1405
+ * PARENT (see `useAvailableWidth`), and the row also holds the copy button.
1406
+ *
1407
+ * `flex: 1` IS LOAD-BEARING — do not weaken it to `flexShrink: 1`. A shrink-only wrapper
1408
+ * SHRINK-WRAPS its content, which makes the measured parent width depend on the very string we
1409
+ * are computing: truncate -> wrapper narrows -> re-measure smaller -> truncate harder. Verified
1410
+ * in Chrome: with `flexShrink: 1` a 506px-wide container and a 306px one both rendered the SAME
1411
+ * 196px string, i.e. the id was cut short with 300px of room going spare. `flex: 1` makes the
1412
+ * wrapper fill the row's leftover width instead, so its size is independent of what we put in
1413
+ * it — the same reason `useAvailableWidth` measures the parent and not the element.
1414
+ *
1415
+ * `minWidth: 0` is what actually permits a flex child to go below its content width.
1392
1416
  */
1393
- valueWrap: { flexShrink: 1, minWidth: 0 },
1417
+ valueWrap: { flex: 1, minWidth: 0 },
1394
1418
  value: { fontSize: VALUE_FONT_SIZE, fontWeight: "600" },
1395
1419
  action: {
1396
1420
  fontSize: ACTION_FONT_SIZE,
@@ -1417,6 +1441,7 @@ function useActionState(status) {
1417
1441
  var CopyableId = ({
1418
1442
  value,
1419
1443
  label,
1444
+ style,
1420
1445
  testID,
1421
1446
  accessibilityLabel,
1422
1447
  writer
@@ -1425,7 +1450,7 @@ var CopyableId = ({
1425
1450
  const { colors } = theme;
1426
1451
  const { status, copy } = useCopyToClipboard(value, writer);
1427
1452
  const action = useActionState(status);
1428
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles13.cell, testID, children: [
1453
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles13.cell, style], testID, children: [
1429
1454
  label !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles13.label, { color: colors.textSecondary }], children: label }),
1430
1455
  /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles13.row, children: [
1431
1456
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles13.valueWrap, children: /* @__PURE__ */ jsxRuntime.jsx(