@dloizides/ui-layout 1.13.0 → 1.15.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 +60 -0
- package/dist/index.d.mts +116 -1
- package/dist/index.d.ts +116 -1
- package/dist/index.js +197 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +193 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.15.1
|
|
4
|
+
|
|
5
|
+
- **Fix (`CopyableId` truncated the value with room to spare).** 1.15.0 gave the value wrapper
|
|
6
|
+
`flexShrink: 1`, which makes it SHRINK-WRAP its content — so the width the component measures to
|
|
7
|
+
decide how much to show was derived from the very string it was computing: truncate → wrapper
|
|
8
|
+
narrows → re-measure smaller → truncate harder. Verified in Chrome via `apps/ui-showcase`: a
|
|
9
|
+
506px-wide container and a 306px one rendered the SAME 196px string, i.e. a 36-character GUID was
|
|
10
|
+
cut to 26 characters with ~300px going unused.
|
|
11
|
+
|
|
12
|
+
The wrapper is now `flex: 1`, so it fills the row's leftover width and its size is independent of
|
|
13
|
+
its content. Re-verified at four widths: 520px and 320px now render the full 36-character GUID
|
|
14
|
+
untruncated; 200px and 120px middle-truncate with both ends intact, and nothing overflows.
|
|
15
|
+
|
|
16
|
+
This is the SAME failure mode `useAvailableWidth` documents for `TruncatedText` (measure the
|
|
17
|
+
parent, never the element, or the output feeds back into the input) — reintroduced one level up
|
|
18
|
+
by the new wrapper. Unit tests cannot catch it: the truncation helpers are pure and passed
|
|
19
|
+
throughout, and jsdom reports zero widths, so only a real browser shows it.
|
|
20
|
+
|
|
21
|
+
- **New: `CopyableId` accepts `style`** for its outer container. Hosts need this to give the
|
|
22
|
+
control a width that does not derive from its own content (a `flexBasis`, a `width`, or
|
|
23
|
+
`flex: 1`) — without one, a shrink-to-fit parent reintroduces the feedback loop above at the
|
|
24
|
+
host level. Documented on the prop.
|
|
25
|
+
|
|
26
|
+
## 1.15.0
|
|
27
|
+
|
|
28
|
+
- **New: `CopyableId`** — show a long machine identifier (a GUID, a reference, a correlation id)
|
|
29
|
+
so a human can both READ enough of it to tell two apart and TAKE it in one action. Composes the
|
|
30
|
+
existing `TruncatedText`, so the middle-truncation work is reused rather than re-derived.
|
|
31
|
+
|
|
32
|
+
Driven by the AML console needing to surface a screening ID an analyst can copy and re-screen
|
|
33
|
+
with, but it is deliberately domain-free: every portal has identifiers it currently either hides
|
|
34
|
+
or dumps raw into a table cell.
|
|
35
|
+
|
|
36
|
+
Three things this gets right that a naive copy button does not:
|
|
37
|
+
|
|
38
|
+
1. **It copies the FULL value, never the display string.** A truncated GUID that a user
|
|
39
|
+
hand-selects yields `3f2a9c81…d4e7`, ellipsis and all, which silently fails wherever it is
|
|
40
|
+
pasted. Showing a truncated identifier with no copy affordance is strictly WORSE than not
|
|
41
|
+
showing it. The full value is always the accessible name and the web tooltip.
|
|
42
|
+
2. **Middle truncation, not tail.** Two GUIDs from one table share a prefix far more often than
|
|
43
|
+
intuition suggests, and `numberOfLines={1}` renders them IDENTICALLY. The tail is what tells
|
|
44
|
+
them apart, so both ends survive.
|
|
45
|
+
3. **A failed copy is SHOWN, not swallowed.** `navigator.clipboard` is not merely unreliable —
|
|
46
|
+
it is `undefined` outside a secure context, which is how every staging box and LAN preview in
|
|
47
|
+
this fleet is served, i.e. exactly where people hand-test. `copyText` therefore falls back to
|
|
48
|
+
`document.execCommand` over an off-screen textarea, and returns a boolean rather than
|
|
49
|
+
assuming. On total failure the control renders a distinct `common.copyFailed` state; a silent
|
|
50
|
+
failure would leave the user believing they hold an identifier they do not.
|
|
51
|
+
|
|
52
|
+
The status is carried in the control's accessible **NAME**, not its hint, because
|
|
53
|
+
`accessibilityHint` is dropped by react-native-web and never reaches the DOM — a screen-reader
|
|
54
|
+
user would otherwise get no confirmation at all.
|
|
55
|
+
|
|
56
|
+
No native clipboard dependency is taken. Hosts on React Native inject a `writer`
|
|
57
|
+
(`Clipboard.setString`); an injected writer that throws falls through to the DOM paths.
|
|
58
|
+
|
|
59
|
+
New `LAYOUT_I18N` keys — hosts binding a missing-key guard to that map (as aml-v2 does) will
|
|
60
|
+
fail their catalog test until these are defined: `common.copy`, `common.copyHint`,
|
|
61
|
+
`common.copied`, `common.copyFailed`, `common.copyableIdHint`.
|
|
62
|
+
|
|
3
63
|
## 1.12.2
|
|
4
64
|
|
|
5
65
|
- **Fix (`TruncatedText` STILL did not middle-truncate; 1.12.1's fix was the wrong mechanism).**
|
package/dist/index.d.mts
CHANGED
|
@@ -352,6 +352,109 @@ declare function truncateMiddle(value: string, maxChars: number): string;
|
|
|
352
352
|
*/
|
|
353
353
|
declare function formatUrlForDisplay(value: string): string;
|
|
354
354
|
|
|
355
|
+
/**
|
|
356
|
+
* CopyableId — show a long machine identifier (a GUID, a reference, a correlation id) so a human
|
|
357
|
+
* can both READ enough of it to tell two apart, and TAKE it in one action.
|
|
358
|
+
*
|
|
359
|
+
* WHY MIDDLE TRUNCATION AND NOT `numberOfLines={1}`: two GUIDs from the same table share a
|
|
360
|
+
* prefix far more often than intuition suggests, and tail-truncation renders them IDENTICALLY —
|
|
361
|
+
* `3f2a9c81-…`. The tail is what distinguishes them, so both ends must survive. That is exactly
|
|
362
|
+
* what `TruncatedText` already solves for URLs, so this composes it rather than re-deriving it.
|
|
363
|
+
*
|
|
364
|
+
* WHY A COPY BUTTON IS NOT OPTIONAL POLISH: an ID exists to be pasted somewhere else — into a
|
|
365
|
+
* re-screen, a support ticket, a SQL console. Displaying a truncated GUID with no copy affordance
|
|
366
|
+
* is strictly WORSE than not showing it, because what is on screen is not the value: hand-select
|
|
367
|
+
* it and you get `3f2a9c81…d4e7`, ellipsis and all, which silently fails wherever it is pasted.
|
|
368
|
+
* The full value is therefore always the accessible name and the web tooltip, and the button
|
|
369
|
+
* copies the full value, never the display string.
|
|
370
|
+
*
|
|
371
|
+
* FAILURE IS SHOWN, NOT SWALLOWED: see `copyText` — clipboard writes really do fail on plain
|
|
372
|
+
* http, which is how staging is served. A silent failure would hand the analyst a false belief.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
interface CopyableIdProps {
|
|
376
|
+
/** The full identifier. Always what gets copied, and always the accessible name / tooltip. */
|
|
377
|
+
value: string;
|
|
378
|
+
/** Optional eyebrow above the value (e.g. "Screening ID"). Pass pre-localized. */
|
|
379
|
+
label?: string;
|
|
380
|
+
/**
|
|
381
|
+
* Style for the outer container.
|
|
382
|
+
*
|
|
383
|
+
* Hosts should give this a width that does NOT derive from its own content — a `flexBasis`, a
|
|
384
|
+
* `width`, or `flex: 1`. The component measures its container to decide how much of the value
|
|
385
|
+
* to show, so a shrink-to-fit parent makes the available width depend on the string being
|
|
386
|
+
* computed, and the id renders clipped with space to spare.
|
|
387
|
+
*/
|
|
388
|
+
style?: StyleProp<ViewStyle>;
|
|
389
|
+
/** Base testID; the copy control is `${testID}-copy` and the value `${testID}-value`. */
|
|
390
|
+
testID: string;
|
|
391
|
+
/** Accessible name for the value itself. Pass pre-localized; falls back to the raw value. */
|
|
392
|
+
accessibilityLabel?: string;
|
|
393
|
+
/**
|
|
394
|
+
* Platform clipboard writer, for hosts that have one (React Native). Omit on web — the DOM
|
|
395
|
+
* paths in `copyText` cover it.
|
|
396
|
+
*/
|
|
397
|
+
writer?: (text: string) => void | Promise<void>;
|
|
398
|
+
}
|
|
399
|
+
declare const CopyableId: ({ value, label, style, testID, accessibilityLabel, writer, }: CopyableIdProps) => React.ReactElement;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* The three states a copy affordance can be in. Its own file per the repo's
|
|
403
|
+
* "one exported enum per file" rule.
|
|
404
|
+
*
|
|
405
|
+
* `Failed` is a first-class state on purpose. Clipboard writes genuinely fail in the browser —
|
|
406
|
+
* a non-secure context (plain http, which is how every staging box and LAN preview is served)
|
|
407
|
+
* has no `navigator.clipboard` at all, and even on https the Permissions API can reject. A
|
|
408
|
+
* control that swallowed that would leave the analyst believing they hold an ID they do not,
|
|
409
|
+
* and they would only find out after pasting the WRONG thing into a re-screen.
|
|
410
|
+
*/
|
|
411
|
+
declare const enum CopyStatus {
|
|
412
|
+
Idle = "idle",
|
|
413
|
+
Copied = "copied",
|
|
414
|
+
Failed = "failed"
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** How long the "Copied!"/"Copy failed" confirmation stays up before reverting to idle. */
|
|
418
|
+
declare const COPY_FEEDBACK_MS = 2000;
|
|
419
|
+
interface CopyToClipboard {
|
|
420
|
+
status: CopyStatus;
|
|
421
|
+
/** Fire-and-forget: performs the write and drives `status`. Safe to pass straight to onPress. */
|
|
422
|
+
copy: () => void;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* @param value the text to copy
|
|
426
|
+
* @param writer optional platform clipboard writer (see `copyText`)
|
|
427
|
+
*/
|
|
428
|
+
declare function useCopyToClipboard(value: string, writer?: (text: string) => void | Promise<void>): CopyToClipboard;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Write a string to the system clipboard, reporting honestly whether it worked.
|
|
432
|
+
*
|
|
433
|
+
* THREE PATHS, IN ORDER, BECAUSE THE OBVIOUS ONE IS NOT ENOUGH:
|
|
434
|
+
*
|
|
435
|
+
* 1. `navigator.clipboard.writeText` — the modern API. It is gated on a SECURE CONTEXT, so it is
|
|
436
|
+
* simply `undefined` on plain http. Every staging box and LAN preview in this fleet is served
|
|
437
|
+
* over http, which means the happy path is missing exactly where people test. It can also
|
|
438
|
+
* reject at call time (permission denied, document not focused), so the promise is caught, not
|
|
439
|
+
* assumed.
|
|
440
|
+
* 2. `document.execCommand('copy')` over an off-screen textarea — deprecated, but it is
|
|
441
|
+
* synchronous, needs no permission, and works in non-secure contexts. It is the reason a copy
|
|
442
|
+
* button behaves the same on http staging as on https prod.
|
|
443
|
+
* 3. Neither available (React Native, or a hostile browser) — return `false`. The caller then
|
|
444
|
+
* shows a visible failure instead of a fake "Copied!". A host that wants real native clipboard
|
|
445
|
+
* support injects its own writer rather than this package taking a native dependency.
|
|
446
|
+
*
|
|
447
|
+
* Returns `true` only when a write actually succeeded.
|
|
448
|
+
*/
|
|
449
|
+
/**
|
|
450
|
+
* Copy `value`, returning whether it landed on the clipboard.
|
|
451
|
+
*
|
|
452
|
+
* `writer` lets a host inject a platform clipboard (React Native's `Clipboard.setString`, say)
|
|
453
|
+
* without this package depending on one. An injected writer that throws falls through to the DOM
|
|
454
|
+
* paths rather than failing outright.
|
|
455
|
+
*/
|
|
456
|
+
declare function copyText(value: string, writer?: (text: string) => void | Promise<void>): Promise<boolean>;
|
|
457
|
+
|
|
355
458
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
356
459
|
|
|
357
460
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
@@ -408,6 +511,18 @@ declare const LAYOUT_I18N: {
|
|
|
408
511
|
readonly upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint";
|
|
409
512
|
readonly upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss";
|
|
410
513
|
readonly upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint";
|
|
514
|
+
/** `CopyableId`: the copy control's label in each of its three states, plus its hint. */
|
|
515
|
+
readonly copy: "common.copy";
|
|
516
|
+
readonly copyHint: "common.copyHint";
|
|
517
|
+
readonly copied: "common.copied";
|
|
518
|
+
/**
|
|
519
|
+
* Shown when the clipboard write genuinely failed — non-secure context, denied permission.
|
|
520
|
+
* This string reaching a user is CORRECT behaviour, not a defect: the alternative is them
|
|
521
|
+
* believing they hold an identifier they do not.
|
|
522
|
+
*/
|
|
523
|
+
readonly copyFailed: "common.copyFailed";
|
|
524
|
+
/** `CopyableId`: hint on the value itself, explaining it is shortened for display. */
|
|
525
|
+
readonly copyableIdHint: "common.copyableIdHint";
|
|
411
526
|
};
|
|
412
527
|
|
|
413
|
-
export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, 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, formatUrlForDisplay, truncateMiddle, useFocusTrap };
|
|
528
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -352,6 +352,109 @@ declare function truncateMiddle(value: string, maxChars: number): string;
|
|
|
352
352
|
*/
|
|
353
353
|
declare function formatUrlForDisplay(value: string): string;
|
|
354
354
|
|
|
355
|
+
/**
|
|
356
|
+
* CopyableId — show a long machine identifier (a GUID, a reference, a correlation id) so a human
|
|
357
|
+
* can both READ enough of it to tell two apart, and TAKE it in one action.
|
|
358
|
+
*
|
|
359
|
+
* WHY MIDDLE TRUNCATION AND NOT `numberOfLines={1}`: two GUIDs from the same table share a
|
|
360
|
+
* prefix far more often than intuition suggests, and tail-truncation renders them IDENTICALLY —
|
|
361
|
+
* `3f2a9c81-…`. The tail is what distinguishes them, so both ends must survive. That is exactly
|
|
362
|
+
* what `TruncatedText` already solves for URLs, so this composes it rather than re-deriving it.
|
|
363
|
+
*
|
|
364
|
+
* WHY A COPY BUTTON IS NOT OPTIONAL POLISH: an ID exists to be pasted somewhere else — into a
|
|
365
|
+
* re-screen, a support ticket, a SQL console. Displaying a truncated GUID with no copy affordance
|
|
366
|
+
* is strictly WORSE than not showing it, because what is on screen is not the value: hand-select
|
|
367
|
+
* it and you get `3f2a9c81…d4e7`, ellipsis and all, which silently fails wherever it is pasted.
|
|
368
|
+
* The full value is therefore always the accessible name and the web tooltip, and the button
|
|
369
|
+
* copies the full value, never the display string.
|
|
370
|
+
*
|
|
371
|
+
* FAILURE IS SHOWN, NOT SWALLOWED: see `copyText` — clipboard writes really do fail on plain
|
|
372
|
+
* http, which is how staging is served. A silent failure would hand the analyst a false belief.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
interface CopyableIdProps {
|
|
376
|
+
/** The full identifier. Always what gets copied, and always the accessible name / tooltip. */
|
|
377
|
+
value: string;
|
|
378
|
+
/** Optional eyebrow above the value (e.g. "Screening ID"). Pass pre-localized. */
|
|
379
|
+
label?: string;
|
|
380
|
+
/**
|
|
381
|
+
* Style for the outer container.
|
|
382
|
+
*
|
|
383
|
+
* Hosts should give this a width that does NOT derive from its own content — a `flexBasis`, a
|
|
384
|
+
* `width`, or `flex: 1`. The component measures its container to decide how much of the value
|
|
385
|
+
* to show, so a shrink-to-fit parent makes the available width depend on the string being
|
|
386
|
+
* computed, and the id renders clipped with space to spare.
|
|
387
|
+
*/
|
|
388
|
+
style?: StyleProp<ViewStyle>;
|
|
389
|
+
/** Base testID; the copy control is `${testID}-copy` and the value `${testID}-value`. */
|
|
390
|
+
testID: string;
|
|
391
|
+
/** Accessible name for the value itself. Pass pre-localized; falls back to the raw value. */
|
|
392
|
+
accessibilityLabel?: string;
|
|
393
|
+
/**
|
|
394
|
+
* Platform clipboard writer, for hosts that have one (React Native). Omit on web — the DOM
|
|
395
|
+
* paths in `copyText` cover it.
|
|
396
|
+
*/
|
|
397
|
+
writer?: (text: string) => void | Promise<void>;
|
|
398
|
+
}
|
|
399
|
+
declare const CopyableId: ({ value, label, style, testID, accessibilityLabel, writer, }: CopyableIdProps) => React.ReactElement;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* The three states a copy affordance can be in. Its own file per the repo's
|
|
403
|
+
* "one exported enum per file" rule.
|
|
404
|
+
*
|
|
405
|
+
* `Failed` is a first-class state on purpose. Clipboard writes genuinely fail in the browser —
|
|
406
|
+
* a non-secure context (plain http, which is how every staging box and LAN preview is served)
|
|
407
|
+
* has no `navigator.clipboard` at all, and even on https the Permissions API can reject. A
|
|
408
|
+
* control that swallowed that would leave the analyst believing they hold an ID they do not,
|
|
409
|
+
* and they would only find out after pasting the WRONG thing into a re-screen.
|
|
410
|
+
*/
|
|
411
|
+
declare const enum CopyStatus {
|
|
412
|
+
Idle = "idle",
|
|
413
|
+
Copied = "copied",
|
|
414
|
+
Failed = "failed"
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** How long the "Copied!"/"Copy failed" confirmation stays up before reverting to idle. */
|
|
418
|
+
declare const COPY_FEEDBACK_MS = 2000;
|
|
419
|
+
interface CopyToClipboard {
|
|
420
|
+
status: CopyStatus;
|
|
421
|
+
/** Fire-and-forget: performs the write and drives `status`. Safe to pass straight to onPress. */
|
|
422
|
+
copy: () => void;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* @param value the text to copy
|
|
426
|
+
* @param writer optional platform clipboard writer (see `copyText`)
|
|
427
|
+
*/
|
|
428
|
+
declare function useCopyToClipboard(value: string, writer?: (text: string) => void | Promise<void>): CopyToClipboard;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Write a string to the system clipboard, reporting honestly whether it worked.
|
|
432
|
+
*
|
|
433
|
+
* THREE PATHS, IN ORDER, BECAUSE THE OBVIOUS ONE IS NOT ENOUGH:
|
|
434
|
+
*
|
|
435
|
+
* 1. `navigator.clipboard.writeText` — the modern API. It is gated on a SECURE CONTEXT, so it is
|
|
436
|
+
* simply `undefined` on plain http. Every staging box and LAN preview in this fleet is served
|
|
437
|
+
* over http, which means the happy path is missing exactly where people test. It can also
|
|
438
|
+
* reject at call time (permission denied, document not focused), so the promise is caught, not
|
|
439
|
+
* assumed.
|
|
440
|
+
* 2. `document.execCommand('copy')` over an off-screen textarea — deprecated, but it is
|
|
441
|
+
* synchronous, needs no permission, and works in non-secure contexts. It is the reason a copy
|
|
442
|
+
* button behaves the same on http staging as on https prod.
|
|
443
|
+
* 3. Neither available (React Native, or a hostile browser) — return `false`. The caller then
|
|
444
|
+
* shows a visible failure instead of a fake "Copied!". A host that wants real native clipboard
|
|
445
|
+
* support injects its own writer rather than this package taking a native dependency.
|
|
446
|
+
*
|
|
447
|
+
* Returns `true` only when a write actually succeeded.
|
|
448
|
+
*/
|
|
449
|
+
/**
|
|
450
|
+
* Copy `value`, returning whether it landed on the clipboard.
|
|
451
|
+
*
|
|
452
|
+
* `writer` lets a host inject a platform clipboard (React Native's `Clipboard.setString`, say)
|
|
453
|
+
* without this package depending on one. An injected writer that throws falls through to the DOM
|
|
454
|
+
* paths rather than failing outright.
|
|
455
|
+
*/
|
|
456
|
+
declare function copyText(value: string, writer?: (text: string) => void | Promise<void>): Promise<boolean>;
|
|
457
|
+
|
|
355
458
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
356
459
|
|
|
357
460
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
@@ -408,6 +511,18 @@ declare const LAYOUT_I18N: {
|
|
|
408
511
|
readonly upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint";
|
|
409
512
|
readonly upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss";
|
|
410
513
|
readonly upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint";
|
|
514
|
+
/** `CopyableId`: the copy control's label in each of its three states, plus its hint. */
|
|
515
|
+
readonly copy: "common.copy";
|
|
516
|
+
readonly copyHint: "common.copyHint";
|
|
517
|
+
readonly copied: "common.copied";
|
|
518
|
+
/**
|
|
519
|
+
* Shown when the clipboard write genuinely failed — non-secure context, denied permission.
|
|
520
|
+
* This string reaching a user is CORRECT behaviour, not a defect: the alternative is them
|
|
521
|
+
* believing they hold an identifier they do not.
|
|
522
|
+
*/
|
|
523
|
+
readonly copyFailed: "common.copyFailed";
|
|
524
|
+
/** `CopyableId`: hint on the value itself, explaining it is shortened for display. */
|
|
525
|
+
readonly copyableIdHint: "common.copyableIdHint";
|
|
411
526
|
};
|
|
412
527
|
|
|
413
|
-
export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, 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, formatUrlForDisplay, truncateMiddle, useFocusTrap };
|
|
528
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -68,7 +68,19 @@ var LAYOUT_I18N = {
|
|
|
68
68
|
upgradePromptCta: "settings.billing.upgradePrompt.cta",
|
|
69
69
|
upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint",
|
|
70
70
|
upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss",
|
|
71
|
-
upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint"
|
|
71
|
+
upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint",
|
|
72
|
+
/** `CopyableId`: the copy control's label in each of its three states, plus its hint. */
|
|
73
|
+
copy: "common.copy",
|
|
74
|
+
copyHint: "common.copyHint",
|
|
75
|
+
copied: "common.copied",
|
|
76
|
+
/**
|
|
77
|
+
* Shown when the clipboard write genuinely failed — non-secure context, denied permission.
|
|
78
|
+
* This string reaching a user is CORRECT behaviour, not a defect: the alternative is them
|
|
79
|
+
* believing they hold an identifier they do not.
|
|
80
|
+
*/
|
|
81
|
+
copyFailed: "common.copyFailed",
|
|
82
|
+
/** `CopyableId`: hint on the value itself, explaining it is shortened for display. */
|
|
83
|
+
copyableIdHint: "common.copyableIdHint"
|
|
72
84
|
};
|
|
73
85
|
var styles2 = reactNative.StyleSheet.create({
|
|
74
86
|
heading: {
|
|
@@ -1272,8 +1284,190 @@ var TruncatedText = ({
|
|
|
1272
1284
|
);
|
|
1273
1285
|
};
|
|
1274
1286
|
|
|
1287
|
+
// src/CopyableId/CopyStatus.ts
|
|
1288
|
+
var CopyStatus = /* @__PURE__ */ ((CopyStatus2) => {
|
|
1289
|
+
CopyStatus2["Idle"] = "idle";
|
|
1290
|
+
CopyStatus2["Copied"] = "copied";
|
|
1291
|
+
CopyStatus2["Failed"] = "failed";
|
|
1292
|
+
return CopyStatus2;
|
|
1293
|
+
})(CopyStatus || {});
|
|
1294
|
+
|
|
1295
|
+
// src/CopyableId/copyText.ts
|
|
1296
|
+
var OFFSCREEN_POSITION = "-9999px";
|
|
1297
|
+
function hasDom() {
|
|
1298
|
+
return typeof document !== "undefined" && document.body !== null;
|
|
1299
|
+
}
|
|
1300
|
+
function copyViaExecCommand(value) {
|
|
1301
|
+
if (!hasDom()) return false;
|
|
1302
|
+
const area = document.createElement("textarea");
|
|
1303
|
+
area.value = value;
|
|
1304
|
+
area.readOnly = true;
|
|
1305
|
+
area.setAttribute("aria-hidden", "true");
|
|
1306
|
+
area.style.position = "fixed";
|
|
1307
|
+
area.style.top = OFFSCREEN_POSITION;
|
|
1308
|
+
area.style.left = OFFSCREEN_POSITION;
|
|
1309
|
+
area.style.opacity = "0";
|
|
1310
|
+
document.body.appendChild(area);
|
|
1311
|
+
try {
|
|
1312
|
+
area.select();
|
|
1313
|
+
area.setSelectionRange(0, value.length);
|
|
1314
|
+
return document.execCommand("copy");
|
|
1315
|
+
} catch {
|
|
1316
|
+
return false;
|
|
1317
|
+
} finally {
|
|
1318
|
+
document.body.removeChild(area);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
function hasAsyncClipboard() {
|
|
1322
|
+
return typeof navigator !== "undefined" && typeof navigator.clipboard?.writeText === "function";
|
|
1323
|
+
}
|
|
1324
|
+
async function copyText(value, writer) {
|
|
1325
|
+
if (value === "") return false;
|
|
1326
|
+
if (writer !== void 0) {
|
|
1327
|
+
try {
|
|
1328
|
+
await writer(value);
|
|
1329
|
+
return true;
|
|
1330
|
+
} catch {
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (hasAsyncClipboard()) {
|
|
1334
|
+
try {
|
|
1335
|
+
await navigator.clipboard.writeText(value);
|
|
1336
|
+
return true;
|
|
1337
|
+
} catch {
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return copyViaExecCommand(value);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/CopyableId/useCopyToClipboard.ts
|
|
1344
|
+
var COPY_FEEDBACK_MS = 2e3;
|
|
1345
|
+
function useCopyToClipboard(value, writer) {
|
|
1346
|
+
const [status, setStatus] = React8.useState("idle" /* Idle */);
|
|
1347
|
+
const timerRef = React8.useRef(null);
|
|
1348
|
+
const mountedRef = React8.useRef(true);
|
|
1349
|
+
React8.useEffect(() => {
|
|
1350
|
+
mountedRef.current = true;
|
|
1351
|
+
return () => {
|
|
1352
|
+
mountedRef.current = false;
|
|
1353
|
+
if (timerRef.current !== null) clearTimeout(timerRef.current);
|
|
1354
|
+
};
|
|
1355
|
+
}, []);
|
|
1356
|
+
const copy = React8.useCallback(() => {
|
|
1357
|
+
void (async () => {
|
|
1358
|
+
const ok = await copyText(value, writer);
|
|
1359
|
+
if (!mountedRef.current) return;
|
|
1360
|
+
setStatus(ok ? "copied" /* Copied */ : "failed" /* Failed */);
|
|
1361
|
+
if (timerRef.current !== null) clearTimeout(timerRef.current);
|
|
1362
|
+
timerRef.current = setTimeout(() => {
|
|
1363
|
+
if (mountedRef.current) setStatus("idle" /* Idle */);
|
|
1364
|
+
}, COPY_FEEDBACK_MS);
|
|
1365
|
+
})();
|
|
1366
|
+
}, [value, writer]);
|
|
1367
|
+
return { status, copy };
|
|
1368
|
+
}
|
|
1369
|
+
var LABEL_FONT_SIZE = 11;
|
|
1370
|
+
var VALUE_FONT_SIZE = 12;
|
|
1371
|
+
var ACTION_FONT_SIZE = 12;
|
|
1372
|
+
var ROW_GAP = 8;
|
|
1373
|
+
var CELL_GAP = 2;
|
|
1374
|
+
var LABEL_LETTER_SPACING = 0.4;
|
|
1375
|
+
var ACTION_PADDING_H = 6;
|
|
1376
|
+
var ACTION_PADDING_V = 2;
|
|
1377
|
+
var ACTION_RADIUS = 6;
|
|
1378
|
+
var styles13 = reactNative.StyleSheet.create({
|
|
1379
|
+
cell: { gap: CELL_GAP },
|
|
1380
|
+
label: {
|
|
1381
|
+
fontSize: LABEL_FONT_SIZE,
|
|
1382
|
+
fontWeight: "700",
|
|
1383
|
+
letterSpacing: LABEL_LETTER_SPACING,
|
|
1384
|
+
textTransform: "uppercase"
|
|
1385
|
+
},
|
|
1386
|
+
row: { flexDirection: "row", alignItems: "center", gap: ROW_GAP },
|
|
1387
|
+
/**
|
|
1388
|
+
* The truncation width comes from this wrapper, not from the row: `TruncatedText` measures its
|
|
1389
|
+
* PARENT (see `useAvailableWidth`), and the row also holds the copy button.
|
|
1390
|
+
*
|
|
1391
|
+
* `flex: 1` IS LOAD-BEARING — do not weaken it to `flexShrink: 1`. A shrink-only wrapper
|
|
1392
|
+
* SHRINK-WRAPS its content, which makes the measured parent width depend on the very string we
|
|
1393
|
+
* are computing: truncate -> wrapper narrows -> re-measure smaller -> truncate harder. Verified
|
|
1394
|
+
* in Chrome: with `flexShrink: 1` a 506px-wide container and a 306px one both rendered the SAME
|
|
1395
|
+
* 196px string, i.e. the id was cut short with 300px of room going spare. `flex: 1` makes the
|
|
1396
|
+
* wrapper fill the row's leftover width instead, so its size is independent of what we put in
|
|
1397
|
+
* it — the same reason `useAvailableWidth` measures the parent and not the element.
|
|
1398
|
+
*
|
|
1399
|
+
* `minWidth: 0` is what actually permits a flex child to go below its content width.
|
|
1400
|
+
*/
|
|
1401
|
+
valueWrap: { flex: 1, minWidth: 0 },
|
|
1402
|
+
value: { fontSize: VALUE_FONT_SIZE, fontWeight: "600" },
|
|
1403
|
+
action: {
|
|
1404
|
+
fontSize: ACTION_FONT_SIZE,
|
|
1405
|
+
fontWeight: "600",
|
|
1406
|
+
paddingHorizontal: ACTION_PADDING_H,
|
|
1407
|
+
paddingVertical: ACTION_PADDING_V,
|
|
1408
|
+
borderRadius: ACTION_RADIUS
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
var TONE_STEP = "500";
|
|
1412
|
+
function useActionState(status) {
|
|
1413
|
+
const { theme } = uiFeedback.useUi();
|
|
1414
|
+
return React8.useMemo(() => {
|
|
1415
|
+
const primary = theme.palette.primary[TONE_STEP];
|
|
1416
|
+
if (status === "copied" /* Copied */) {
|
|
1417
|
+
return { key: LAYOUT_I18N.copied, color: theme.semantic.success?.[TONE_STEP] ?? primary };
|
|
1418
|
+
}
|
|
1419
|
+
if (status === "failed" /* Failed */) {
|
|
1420
|
+
return { key: LAYOUT_I18N.copyFailed, color: theme.semantic.error[TONE_STEP] };
|
|
1421
|
+
}
|
|
1422
|
+
return { key: LAYOUT_I18N.copy, color: primary };
|
|
1423
|
+
}, [status, theme]);
|
|
1424
|
+
}
|
|
1425
|
+
var CopyableId = ({
|
|
1426
|
+
value,
|
|
1427
|
+
label,
|
|
1428
|
+
style,
|
|
1429
|
+
testID,
|
|
1430
|
+
accessibilityLabel,
|
|
1431
|
+
writer
|
|
1432
|
+
}) => {
|
|
1433
|
+
const { theme, t } = uiFeedback.useUi();
|
|
1434
|
+
const { colors } = theme;
|
|
1435
|
+
const { status, copy } = useCopyToClipboard(value, writer);
|
|
1436
|
+
const action = useActionState(status);
|
|
1437
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles13.cell, style], testID, children: [
|
|
1438
|
+
label !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles13.label, { color: colors.textSecondary }], children: label }),
|
|
1439
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles13.row, children: [
|
|
1440
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles13.valueWrap, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1441
|
+
TruncatedText,
|
|
1442
|
+
{
|
|
1443
|
+
value,
|
|
1444
|
+
style: [styles13.value, { color: colors.text }],
|
|
1445
|
+
testID: `${testID}-value`,
|
|
1446
|
+
accessibilityLabel: accessibilityLabel ?? value,
|
|
1447
|
+
accessibilityHint: t(LAYOUT_I18N.copyableIdHint)
|
|
1448
|
+
}
|
|
1449
|
+
) }),
|
|
1450
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1451
|
+
reactNative.Text,
|
|
1452
|
+
{
|
|
1453
|
+
onPress: copy,
|
|
1454
|
+
accessibilityRole: "button",
|
|
1455
|
+
accessibilityLabel: t(action.key),
|
|
1456
|
+
accessibilityHint: t(LAYOUT_I18N.copyHint),
|
|
1457
|
+
testID: `${testID}-copy`,
|
|
1458
|
+
style: [styles13.action, { color: action.color }],
|
|
1459
|
+
children: t(action.key)
|
|
1460
|
+
}
|
|
1461
|
+
)
|
|
1462
|
+
] })
|
|
1463
|
+
] });
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1275
1466
|
exports.Accordion = Accordion;
|
|
1276
1467
|
exports.AccordionItem = AccordionItem;
|
|
1468
|
+
exports.COPY_FEEDBACK_MS = COPY_FEEDBACK_MS;
|
|
1469
|
+
exports.CopyStatus = CopyStatus;
|
|
1470
|
+
exports.CopyableId = CopyableId;
|
|
1277
1471
|
exports.DEFAULT_BILLING_ROUTE = DEFAULT_BILLING_ROUTE;
|
|
1278
1472
|
exports.DropdownVariant = DropdownVariant;
|
|
1279
1473
|
exports.ELLIPSIS = ELLIPSIS;
|
|
@@ -1287,8 +1481,10 @@ exports.SegmentedControl = SegmentedControl;
|
|
|
1287
1481
|
exports.StatusBadge = StatusBadge;
|
|
1288
1482
|
exports.TruncatedText = TruncatedText;
|
|
1289
1483
|
exports.UpgradePrompt = UpgradePrompt;
|
|
1484
|
+
exports.copyText = copyText;
|
|
1290
1485
|
exports.formatUrlForDisplay = formatUrlForDisplay;
|
|
1291
1486
|
exports.truncateMiddle = truncateMiddle;
|
|
1487
|
+
exports.useCopyToClipboard = useCopyToClipboard;
|
|
1292
1488
|
exports.useFocusTrap = useFocusTrap;
|
|
1293
1489
|
//# sourceMappingURL=index.js.map
|
|
1294
1490
|
//# sourceMappingURL=index.js.map
|