@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.12.0
|
|
4
|
+
|
|
5
|
+
- **New: `TruncatedText`** — a single-line text/link that middle-truncates to fit its container
|
|
6
|
+
and cannot overflow at any width. Promoted out of the AML console, where a full adverse-media
|
|
7
|
+
article URL rendered as raw `<Text>` and blew out its table row.
|
|
8
|
+
|
|
9
|
+
Three things that look like they would solve this and do not, all verified against
|
|
10
|
+
react-native-web 0.21 rather than assumed:
|
|
11
|
+
|
|
12
|
+
1. `numberOfLines={1}` alone truncates at the **tail** (RN-web compiles it to
|
|
13
|
+
`text-overflow: ellipsis`). Every URL from one publisher then collapses to the same
|
|
14
|
+
`timesofindia.indiatimes.com/city/de…` prefix and the reader cannot tell the articles
|
|
15
|
+
apart. There is no CSS for middle truncation, so it is computed in JS.
|
|
16
|
+
2. `title={full}` is **silently dropped** — RN-web's `<Text>` forwards only `href`, `lang`
|
|
17
|
+
and `pointerEvents` beyond the shared whitelist. The tooltip is set on the host node
|
|
18
|
+
through a ref instead.
|
|
19
|
+
3. JS truncation alone can mis-estimate an unusual glyph mix, so `numberOfLines={1}` is ALSO
|
|
20
|
+
applied as a hard backstop. Overflow is impossible by construction, not by tuning.
|
|
21
|
+
|
|
22
|
+
The full value always stays reachable — as the accessible name and, on web, the native
|
|
23
|
+
tooltip. Also exported: the pure `truncateMiddle` / `formatUrlForDisplay` helpers and
|
|
24
|
+
`ELLIPSIS`.
|
|
25
|
+
|
|
26
|
+
## 1.11.0
|
|
27
|
+
|
|
28
|
+
- **Fix (HIGH — 1.10.0's out-of-view close never fired in the real runtime).** 1.10.0 added
|
|
29
|
+
"close the menu once the trigger leaves the viewport". Repositioning worked, but the close was
|
|
30
|
+
measured **against the viewport**, and **RN-web apps never scroll the document** — every screen
|
|
31
|
+
renders inside a `ScrollView`, so scrolling happens in an inner `<div>` and `window.scrollY`
|
|
32
|
+
stays 0 forever. A trigger scrolled out of that inner scroller is invisible to the user while its
|
|
33
|
+
rect sits comfortably inside the viewport, so the check could not fire on any screen of any
|
|
34
|
+
portal. Measured in Chrome: trigger at `top: -37` (fully above the scroller), menu still rendered.
|
|
35
|
+
Visibility is now measured against the **clip window** — the viewport intersected with every
|
|
36
|
+
clipping ancestor — which is what makes it work inside an inner scroll container.
|
|
37
|
+
- **Fix: "entirely out of view" was also the wrong threshold.** When a scroll container reaches the
|
|
38
|
+
end of its range the trigger stops with a few pixels still showing (4px in the reported case), so
|
|
39
|
+
"fully out" was *unreachable* and the menu never closed however far the user scrolled. There is
|
|
40
|
+
now a minimum-visible-pixel floor (`MIN_VISIBLE_PX`).
|
|
41
|
+
- **Guard: the menu never closes on its FIRST measurement**, so opening a dropdown whose trigger is
|
|
42
|
+
already partly clipped still works; only movement after opening can close it.
|
|
43
|
+
- **The zero-area "not laid out yet" guard is unchanged in intent but now provably size-only** — it
|
|
44
|
+
asks about the element's own box, never its position, so it cannot swallow a genuine hidden case.
|
|
45
|
+
- **New: `LAYOUT_I18N`** — the manifest of every translation key this package resolves, mirroring
|
|
46
|
+
`TABLE_I18N` / `FILTERS_I18N` from `@dloizides/ui-tables` so hosts can bind an existing
|
|
47
|
+
missing-key guard to it with no new pattern. The kit is fallback-free, so a key a host forgets
|
|
48
|
+
reaches users as a raw dotted name; hand-maintained key lists rot (one portal was found missing
|
|
49
|
+
26 kit keys, another had `common.accordionToggleHint` undefined while `Accordion` was mounted).
|
|
50
|
+
Every `t(...)` call in the package now references the map, and the suite fails on a raw key
|
|
51
|
+
literal or a stale entry — so the manifest cannot drift from the code.
|
|
52
|
+
- **Fix: the 1.10.0 CHANGELOG entry was written in cp1252**, leaving the published file invalid
|
|
53
|
+
UTF-8. Re-encoded.
|
|
54
|
+
- **No breaking change.** `LAYOUT_I18N` is additive and the key strings are unchanged, so existing
|
|
55
|
+
translation files keep working untouched.
|
|
56
|
+
|
|
3
57
|
## 1.10.0
|
|
4
58
|
|
|
5
59
|
Two defects found by browser visual QA of the inline dropdown menu against a live app.
|
|
@@ -8,12 +62,12 @@ Two defects found by browser visual QA of the inline dropdown menu against a liv
|
|
|
8
62
|
menu is portalled to `document.body` with `position: fixed` at the trigger's measured rect.
|
|
9
63
|
`fixed` is viewport-relative, so that coordinate is only valid until something moves the trigger.
|
|
10
64
|
A `scroll`/`resize` listener on `window` was already in place (since 1.7.0) and does handle plain
|
|
11
|
-
scrolling
|
|
12
|
-
- **Layout changes that fire no scroll event at all**
|
|
65
|
+
scrolling — but it left three real gaps:
|
|
66
|
+
- **Layout changes that fire no scroll event at all** — an accordion above the trigger expanding,
|
|
13
67
|
a sticky header resizing, a banner appearing, an async list rendering. The trigger moved, nothing
|
|
14
68
|
scrolled, no listener fired, and the menu stayed behind. Now covered by a `ResizeObserver` on the
|
|
15
69
|
anchor and on `document.body`.
|
|
16
|
-
- **The trigger leaving the viewport.** Repositioning cannot help here
|
|
70
|
+
- **The trigger leaving the viewport.** Repositioning cannot help here — the menu just follows its
|
|
17
71
|
trigger off-screen and hangs over unrelated content with nothing on screen explaining it. The
|
|
18
72
|
menu now **closes** once the trigger is fully out of view.
|
|
19
73
|
- **Layout thrash.** The handler ran a synchronous `getBoundingClientRect()` (a forced reflow) plus
|
|
@@ -23,12 +77,12 @@ Two defects found by browser visual QA of the inline dropdown menu against a liv
|
|
|
23
77
|
any ancestor scroll container counts. Tracking moved into a dedicated `useAnchorTracking` hook.
|
|
24
78
|
Native is unaffected (the popover is in-tree and moves with its anchor).
|
|
25
79
|
- **Fix (a11y): `accessibilityHint` never reached a screen reader.** The prop is part of the public
|
|
26
|
-
API and every caller passes one, but react-native-web does not map it
|
|
80
|
+
API and every caller passes one, but react-native-web does not map it — the trigger carried
|
|
27
81
|
`aria-label` and `aria-expanded` and **no hint of any kind**, so the text was silently thrown away
|
|
28
82
|
(older react-native-web versions additionally leaked it to the DOM, logging
|
|
29
83
|
`React does not recognize the accessibilityHint prop on a DOM element`). On web the hint is now
|
|
30
|
-
rendered into a visually-hidden node referenced by `aria-describedby`
|
|
31
|
-
`@dloizides/ui-forms`' `Field` uses for its error line
|
|
84
|
+
rendered into a visually-hidden node referenced by `aria-describedby` — the same wiring
|
|
85
|
+
`@dloizides/ui-forms`' `Field` uses for its error line — and the RN-only prop is no longer passed
|
|
32
86
|
on web at all. Native still receives `accessibilityHint` unchanged.
|
|
33
87
|
- **No API change.** Both fixes are internal; every existing caller benefits without edits.
|
|
34
88
|
|
package/README.md
CHANGED
|
@@ -79,7 +79,9 @@ The apps supply the header hint string via the shared translate: key `common.acc
|
|
|
79
79
|
It is portalled to `document.body` so no ancestor stacking context or `overflow` can trap or
|
|
80
80
|
clip it, and it **stays glued to its trigger**: it re-anchors on scroll (in any ancestor scroll
|
|
81
81
|
container), on resize, and on layout changes that fire no scroll event at all, then **closes**
|
|
82
|
-
once the trigger
|
|
82
|
+
once the trigger is no longer meaningfully visible. Visibility is measured against the viewport
|
|
83
|
+
intersected with every clipping ancestor — RN-web apps scroll an inner `ScrollView`, never the
|
|
84
|
+
document, so a viewport-only test would never fire.
|
|
83
85
|
- **Narrow / mobile, or any native platform** → the original **modal** / bottom-sheet.
|
|
84
86
|
|
|
85
87
|
Pass `variant` to force either behaviour regardless of viewport — the prop overrides the auto choice:
|
|
@@ -119,3 +121,22 @@ translations, and navigation.
|
|
|
119
121
|
## License
|
|
120
122
|
|
|
121
123
|
MIT
|
|
124
|
+
|
|
125
|
+
## i18n contract (required)
|
|
126
|
+
|
|
127
|
+
The kit is **fallback-free**: the neutral default `t` returns the key itself, so a host that forgets
|
|
128
|
+
a key does not silently show English — it renders the raw dotted name to users, or announces it to
|
|
129
|
+
screen readers. `LAYOUT_I18N` is the machine-readable manifest of every key this package resolves;
|
|
130
|
+
bind your missing-key guard to it exactly as you already do for `TABLE_I18N` / `FILTERS_I18N` from
|
|
131
|
+
`@dloizides/ui-tables`, and an upgrade can never add a key your app silently fails to define.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { LAYOUT_I18N } from '@dloizides/ui-layout';
|
|
135
|
+
import { TABLE_I18N } from '@dloizides/ui-tables';
|
|
136
|
+
|
|
137
|
+
// Every value is a translation key this package will call `t(...)` with.
|
|
138
|
+
const REQUIRED_KIT_KEYS = [...Object.values(LAYOUT_I18N), ...Object.values(TABLE_I18N)];
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The manifest cannot drift: every `t(...)` call in the package references `LAYOUT_I18N`, and the test
|
|
142
|
+
suite fails on a raw key literal in a component or a stale entry in the map.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { RefObject } from 'react';
|
|
2
|
-
import { ViewStyle, StyleProp, View } from 'react-native';
|
|
2
|
+
import { ViewStyle, StyleProp, TextStyle, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Section — a bordered card container that themes its border + surface.
|
|
@@ -266,6 +266,85 @@ interface AccordionItemProps {
|
|
|
266
266
|
}
|
|
267
267
|
declare const AccordionItem: ({ id, title, right, children, defaultOpen: _defaultOpen, disabled, testID, accessibilityLabel, accessibilityHint, }: AccordionItemProps) => React.ReactElement;
|
|
268
268
|
|
|
269
|
+
/**
|
|
270
|
+
* TruncatedText — a single-line text/link that middle-truncates to fit its container and
|
|
271
|
+
* never overflows, at any width.
|
|
272
|
+
*
|
|
273
|
+
* THREE THINGS THAT LOOK LIKE THEY WOULD WORK AND DO NOT (all verified against
|
|
274
|
+
* react-native-web 0.21, not assumed):
|
|
275
|
+
*
|
|
276
|
+
* 1. `numberOfLines={1}` alone. RN-web compiles it to `text-overflow: ellipsis`, which only
|
|
277
|
+
* truncates at the TAIL. Every URL from one publisher then collapses to the same
|
|
278
|
+
* `timesofindia.indiatimes.com/city/de…` prefix — the reader cannot tell the articles
|
|
279
|
+
* apart. There is no CSS for middle truncation, so it is computed in JS here.
|
|
280
|
+
* 2. `title={full}` for the hover tooltip. RN-web's `<Text>` forwards exactly
|
|
281
|
+
* `href`, `lang` and `pointerEvents` beyond the shared whitelist — `title` is dropped
|
|
282
|
+
* silently. It is set on the host node through a ref instead (the same escape hatch
|
|
283
|
+
* `ui-buttons/useKeyboardActivation` already uses).
|
|
284
|
+
* 3. JS truncation alone. The character budget is estimated from the measured width, and an
|
|
285
|
+
* estimate can be wrong for an unusual glyph mix. So `numberOfLines={1}` is ALSO applied,
|
|
286
|
+
* as a hard backstop: if the estimate ever runs long, CSS clamps it. Overflow is then
|
|
287
|
+
* impossible by construction rather than by tuning.
|
|
288
|
+
*
|
|
289
|
+
* The full, untruncated value always stays reachable: as the accessible name (`aria-label`)
|
|
290
|
+
* and, on web, as the native tooltip.
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
interface TruncatedTextProps {
|
|
294
|
+
/** The full value. Always the accessible name and the web tooltip, however it is displayed. */
|
|
295
|
+
value: string;
|
|
296
|
+
/**
|
|
297
|
+
* Treat `value` as a URL: drop `scheme://`, a leading `www.` and a bare trailing slash so the
|
|
298
|
+
* character budget is spent on the host and the slug rather than on boilerplate.
|
|
299
|
+
*/
|
|
300
|
+
isUrl?: boolean;
|
|
301
|
+
/** Web only: render a real `<a href>`, so middle-click and "copy link address" work. */
|
|
302
|
+
href?: string;
|
|
303
|
+
onPress?: () => void;
|
|
304
|
+
style?: TextStyle | TextStyle[];
|
|
305
|
+
testID: string;
|
|
306
|
+
accessibilityLabel: string;
|
|
307
|
+
accessibilityHint: string;
|
|
308
|
+
}
|
|
309
|
+
declare const TruncatedText: ({ value, isUrl, href, onPress, style, testID, accessibilityLabel, accessibilityHint, }: TruncatedTextProps) => React.ReactElement;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Pure truncation helpers for `TruncatedText`.
|
|
313
|
+
*
|
|
314
|
+
* WHY MIDDLE AND NOT TAIL: the component exists because full URLs (adverse-media article
|
|
315
|
+
* links in the AML console) blew out their row. The obvious fix — RN's `numberOfLines={1}`,
|
|
316
|
+
* which RN-web compiles to `text-overflow: ellipsis` — truncates at the TAIL, and a
|
|
317
|
+
* tail-truncated URL is useless: every URL from one publisher collapses to the same
|
|
318
|
+
* `https://timesofindia.indiatimes.com/city/de…` prefix, so the reader learns nothing about
|
|
319
|
+
* WHICH article it is. The informative parts sit at both ends — the HOST (who published it,
|
|
320
|
+
* the trust signal) and the SLUG (what it is about). The uninformative part is the middle
|
|
321
|
+
* path. So we drop the middle:
|
|
322
|
+
*
|
|
323
|
+
* timesofindia.indiatimes.com/…/delhi-court-orders-probe
|
|
324
|
+
*
|
|
325
|
+
* CSS cannot express that, so it is computed here in JS. The component still applies
|
|
326
|
+
* `numberOfLines={1}` on top as a hard backstop, so even if the width estimate is off the
|
|
327
|
+
* text can never overflow its container.
|
|
328
|
+
*/
|
|
329
|
+
/** The single-character ellipsis (U+2026) — one glyph, so it costs one character of budget. */
|
|
330
|
+
declare const ELLIPSIS = "\u2026";
|
|
331
|
+
/**
|
|
332
|
+
* Middle-truncate `value` to at most `maxChars` characters, joining the kept head and tail
|
|
333
|
+
* with an ellipsis. Returns `value` unchanged when it already fits (or when `maxChars` is too
|
|
334
|
+
* small to leave anything readable, in which case the caller's `numberOfLines` backstop clamps
|
|
335
|
+
* it instead of us emitting a meaningless "a…z").
|
|
336
|
+
*
|
|
337
|
+
* The head keeps the extra character on an odd budget, because for both URLs and identifiers
|
|
338
|
+
* the left side is the more identifying one.
|
|
339
|
+
*/
|
|
340
|
+
declare function truncateMiddle(value: string, maxChars: number): string;
|
|
341
|
+
/**
|
|
342
|
+
* Strip the parts of a URL a human never needs to read — the scheme, a leading `www.`, and a
|
|
343
|
+
* bare trailing slash — so the truncation budget is spent on the host and the slug instead.
|
|
344
|
+
* Non-URL values (opaque list identifiers) pass through untouched.
|
|
345
|
+
*/
|
|
346
|
+
declare function formatUrlForDisplay(value: string): string;
|
|
347
|
+
|
|
269
348
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
270
349
|
|
|
271
350
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
@@ -281,5 +360,47 @@ declare const LAYOUT_TEST_IDS: {
|
|
|
281
360
|
};
|
|
282
361
|
/** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
|
|
283
362
|
declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
363
|
+
/**
|
|
364
|
+
* Every translation key this package resolves through `t(...)` — the host app's i18n contract.
|
|
365
|
+
*
|
|
366
|
+
* WHY THIS EXISTS: the kit is deliberately fallback-free. The neutral default `t` returns the key
|
|
367
|
+
* itself, so a host that forgets a key does not silently show English — it shows the raw dotted
|
|
368
|
+
* name to users, or announces it to screen readers. Without a machine-readable manifest each
|
|
369
|
+
* portal had to hand-maintain its ui-layout key list, and hand-maintained lists rot: one app was
|
|
370
|
+
* found missing 26 kit keys (rendering raw names to users), another had `accordionToggleHint`
|
|
371
|
+
* undefined while `Accordion` was mounted, announcing the raw key to assistive tech.
|
|
372
|
+
*
|
|
373
|
+
* Bind a missing-key guard to this map (the same way apps already bind `TABLE_I18N` /
|
|
374
|
+
* `FILTERS_I18N` from `@dloizides/ui-tables`) and an upgrade can never drift unnoticed. Every
|
|
375
|
+
* `t(...)` call in this package references this map, so it cannot fall out of date.
|
|
376
|
+
*/
|
|
377
|
+
declare const LAYOUT_I18N: {
|
|
378
|
+
/** Placeholder shown by `ModalDropdown` when no option matches the current value. */
|
|
379
|
+
readonly selectPlaceholder: "common.selectPlaceholder";
|
|
380
|
+
/** Accessible name + hint of the modal-variant dropdown's dismiss backdrop. */
|
|
381
|
+
readonly dismissDropdown: "common.dismissDropdown";
|
|
382
|
+
readonly dismissDropdownHint: "common.dismissDropdownHint";
|
|
383
|
+
/** Accessible hint on a single dropdown option row. */
|
|
384
|
+
readonly selectOptionHint: "common.selectOptionHint";
|
|
385
|
+
/** Default accessible hint on an `AccordionItem` header when the caller supplies none. */
|
|
386
|
+
readonly accordionToggleHint: "common.accordionToggleHint";
|
|
387
|
+
/** Default accessible hint on a `StatusBadge` when the caller supplies none. */
|
|
388
|
+
readonly statusBadgeHint: "common.statusBadgeHint";
|
|
389
|
+
/** `ModalShell`: accessible name of the dialog when its title is not a plain string. */
|
|
390
|
+
readonly dialog: "common.dialog";
|
|
391
|
+
/** `ModalShell`: accessible hint on the close button. */
|
|
392
|
+
readonly closeDialogHint: "common.closeDialogHint";
|
|
393
|
+
/** `ModalShell`: accessible name of the close button. */
|
|
394
|
+
readonly close: "quizTemplates.cancel";
|
|
395
|
+
/** `ModalShell`: heading fallback when no title is supplied. */
|
|
396
|
+
readonly closeHeading: "close";
|
|
397
|
+
readonly upgradePromptTitle: "settings.billing.upgradePrompt.title";
|
|
398
|
+
/** Body copy, parameterised: "…requires {{p1}}, you are on {{p2}}." */
|
|
399
|
+
readonly upgradePromptMessage: "settings.billing.upgradePrompt.message";
|
|
400
|
+
readonly upgradePromptCta: "settings.billing.upgradePrompt.cta";
|
|
401
|
+
readonly upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint";
|
|
402
|
+
readonly upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss";
|
|
403
|
+
readonly upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint";
|
|
404
|
+
};
|
|
284
405
|
|
|
285
|
-
export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
|
|
406
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { RefObject } from 'react';
|
|
2
|
-
import { ViewStyle, StyleProp, View } from 'react-native';
|
|
2
|
+
import { ViewStyle, StyleProp, TextStyle, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Section — a bordered card container that themes its border + surface.
|
|
@@ -266,6 +266,85 @@ interface AccordionItemProps {
|
|
|
266
266
|
}
|
|
267
267
|
declare const AccordionItem: ({ id, title, right, children, defaultOpen: _defaultOpen, disabled, testID, accessibilityLabel, accessibilityHint, }: AccordionItemProps) => React.ReactElement;
|
|
268
268
|
|
|
269
|
+
/**
|
|
270
|
+
* TruncatedText — a single-line text/link that middle-truncates to fit its container and
|
|
271
|
+
* never overflows, at any width.
|
|
272
|
+
*
|
|
273
|
+
* THREE THINGS THAT LOOK LIKE THEY WOULD WORK AND DO NOT (all verified against
|
|
274
|
+
* react-native-web 0.21, not assumed):
|
|
275
|
+
*
|
|
276
|
+
* 1. `numberOfLines={1}` alone. RN-web compiles it to `text-overflow: ellipsis`, which only
|
|
277
|
+
* truncates at the TAIL. Every URL from one publisher then collapses to the same
|
|
278
|
+
* `timesofindia.indiatimes.com/city/de…` prefix — the reader cannot tell the articles
|
|
279
|
+
* apart. There is no CSS for middle truncation, so it is computed in JS here.
|
|
280
|
+
* 2. `title={full}` for the hover tooltip. RN-web's `<Text>` forwards exactly
|
|
281
|
+
* `href`, `lang` and `pointerEvents` beyond the shared whitelist — `title` is dropped
|
|
282
|
+
* silently. It is set on the host node through a ref instead (the same escape hatch
|
|
283
|
+
* `ui-buttons/useKeyboardActivation` already uses).
|
|
284
|
+
* 3. JS truncation alone. The character budget is estimated from the measured width, and an
|
|
285
|
+
* estimate can be wrong for an unusual glyph mix. So `numberOfLines={1}` is ALSO applied,
|
|
286
|
+
* as a hard backstop: if the estimate ever runs long, CSS clamps it. Overflow is then
|
|
287
|
+
* impossible by construction rather than by tuning.
|
|
288
|
+
*
|
|
289
|
+
* The full, untruncated value always stays reachable: as the accessible name (`aria-label`)
|
|
290
|
+
* and, on web, as the native tooltip.
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
interface TruncatedTextProps {
|
|
294
|
+
/** The full value. Always the accessible name and the web tooltip, however it is displayed. */
|
|
295
|
+
value: string;
|
|
296
|
+
/**
|
|
297
|
+
* Treat `value` as a URL: drop `scheme://`, a leading `www.` and a bare trailing slash so the
|
|
298
|
+
* character budget is spent on the host and the slug rather than on boilerplate.
|
|
299
|
+
*/
|
|
300
|
+
isUrl?: boolean;
|
|
301
|
+
/** Web only: render a real `<a href>`, so middle-click and "copy link address" work. */
|
|
302
|
+
href?: string;
|
|
303
|
+
onPress?: () => void;
|
|
304
|
+
style?: TextStyle | TextStyle[];
|
|
305
|
+
testID: string;
|
|
306
|
+
accessibilityLabel: string;
|
|
307
|
+
accessibilityHint: string;
|
|
308
|
+
}
|
|
309
|
+
declare const TruncatedText: ({ value, isUrl, href, onPress, style, testID, accessibilityLabel, accessibilityHint, }: TruncatedTextProps) => React.ReactElement;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Pure truncation helpers for `TruncatedText`.
|
|
313
|
+
*
|
|
314
|
+
* WHY MIDDLE AND NOT TAIL: the component exists because full URLs (adverse-media article
|
|
315
|
+
* links in the AML console) blew out their row. The obvious fix — RN's `numberOfLines={1}`,
|
|
316
|
+
* which RN-web compiles to `text-overflow: ellipsis` — truncates at the TAIL, and a
|
|
317
|
+
* tail-truncated URL is useless: every URL from one publisher collapses to the same
|
|
318
|
+
* `https://timesofindia.indiatimes.com/city/de…` prefix, so the reader learns nothing about
|
|
319
|
+
* WHICH article it is. The informative parts sit at both ends — the HOST (who published it,
|
|
320
|
+
* the trust signal) and the SLUG (what it is about). The uninformative part is the middle
|
|
321
|
+
* path. So we drop the middle:
|
|
322
|
+
*
|
|
323
|
+
* timesofindia.indiatimes.com/…/delhi-court-orders-probe
|
|
324
|
+
*
|
|
325
|
+
* CSS cannot express that, so it is computed here in JS. The component still applies
|
|
326
|
+
* `numberOfLines={1}` on top as a hard backstop, so even if the width estimate is off the
|
|
327
|
+
* text can never overflow its container.
|
|
328
|
+
*/
|
|
329
|
+
/** The single-character ellipsis (U+2026) — one glyph, so it costs one character of budget. */
|
|
330
|
+
declare const ELLIPSIS = "\u2026";
|
|
331
|
+
/**
|
|
332
|
+
* Middle-truncate `value` to at most `maxChars` characters, joining the kept head and tail
|
|
333
|
+
* with an ellipsis. Returns `value` unchanged when it already fits (or when `maxChars` is too
|
|
334
|
+
* small to leave anything readable, in which case the caller's `numberOfLines` backstop clamps
|
|
335
|
+
* it instead of us emitting a meaningless "a…z").
|
|
336
|
+
*
|
|
337
|
+
* The head keeps the extra character on an odd budget, because for both URLs and identifiers
|
|
338
|
+
* the left side is the more identifying one.
|
|
339
|
+
*/
|
|
340
|
+
declare function truncateMiddle(value: string, maxChars: number): string;
|
|
341
|
+
/**
|
|
342
|
+
* Strip the parts of a URL a human never needs to read — the scheme, a leading `www.`, and a
|
|
343
|
+
* bare trailing slash — so the truncation budget is spent on the host and the slug instead.
|
|
344
|
+
* Non-URL values (opaque list identifiers) pass through untouched.
|
|
345
|
+
*/
|
|
346
|
+
declare function formatUrlForDisplay(value: string): string;
|
|
347
|
+
|
|
269
348
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
270
349
|
|
|
271
350
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
@@ -281,5 +360,47 @@ declare const LAYOUT_TEST_IDS: {
|
|
|
281
360
|
};
|
|
282
361
|
/** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
|
|
283
362
|
declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
363
|
+
/**
|
|
364
|
+
* Every translation key this package resolves through `t(...)` — the host app's i18n contract.
|
|
365
|
+
*
|
|
366
|
+
* WHY THIS EXISTS: the kit is deliberately fallback-free. The neutral default `t` returns the key
|
|
367
|
+
* itself, so a host that forgets a key does not silently show English — it shows the raw dotted
|
|
368
|
+
* name to users, or announces it to screen readers. Without a machine-readable manifest each
|
|
369
|
+
* portal had to hand-maintain its ui-layout key list, and hand-maintained lists rot: one app was
|
|
370
|
+
* found missing 26 kit keys (rendering raw names to users), another had `accordionToggleHint`
|
|
371
|
+
* undefined while `Accordion` was mounted, announcing the raw key to assistive tech.
|
|
372
|
+
*
|
|
373
|
+
* Bind a missing-key guard to this map (the same way apps already bind `TABLE_I18N` /
|
|
374
|
+
* `FILTERS_I18N` from `@dloizides/ui-tables`) and an upgrade can never drift unnoticed. Every
|
|
375
|
+
* `t(...)` call in this package references this map, so it cannot fall out of date.
|
|
376
|
+
*/
|
|
377
|
+
declare const LAYOUT_I18N: {
|
|
378
|
+
/** Placeholder shown by `ModalDropdown` when no option matches the current value. */
|
|
379
|
+
readonly selectPlaceholder: "common.selectPlaceholder";
|
|
380
|
+
/** Accessible name + hint of the modal-variant dropdown's dismiss backdrop. */
|
|
381
|
+
readonly dismissDropdown: "common.dismissDropdown";
|
|
382
|
+
readonly dismissDropdownHint: "common.dismissDropdownHint";
|
|
383
|
+
/** Accessible hint on a single dropdown option row. */
|
|
384
|
+
readonly selectOptionHint: "common.selectOptionHint";
|
|
385
|
+
/** Default accessible hint on an `AccordionItem` header when the caller supplies none. */
|
|
386
|
+
readonly accordionToggleHint: "common.accordionToggleHint";
|
|
387
|
+
/** Default accessible hint on a `StatusBadge` when the caller supplies none. */
|
|
388
|
+
readonly statusBadgeHint: "common.statusBadgeHint";
|
|
389
|
+
/** `ModalShell`: accessible name of the dialog when its title is not a plain string. */
|
|
390
|
+
readonly dialog: "common.dialog";
|
|
391
|
+
/** `ModalShell`: accessible hint on the close button. */
|
|
392
|
+
readonly closeDialogHint: "common.closeDialogHint";
|
|
393
|
+
/** `ModalShell`: accessible name of the close button. */
|
|
394
|
+
readonly close: "quizTemplates.cancel";
|
|
395
|
+
/** `ModalShell`: heading fallback when no title is supplied. */
|
|
396
|
+
readonly closeHeading: "close";
|
|
397
|
+
readonly upgradePromptTitle: "settings.billing.upgradePrompt.title";
|
|
398
|
+
/** Body copy, parameterised: "…requires {{p1}}, you are on {{p2}}." */
|
|
399
|
+
readonly upgradePromptMessage: "settings.billing.upgradePrompt.message";
|
|
400
|
+
readonly upgradePromptCta: "settings.billing.upgradePrompt.cta";
|
|
401
|
+
readonly upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint";
|
|
402
|
+
readonly upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss";
|
|
403
|
+
readonly upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint";
|
|
404
|
+
};
|
|
284
405
|
|
|
285
|
-
export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
|
|
406
|
+
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 };
|