@ntbjs/react-components 3.0.0-rc.1 → 3.0.0-rc.2

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.
Files changed (139) hide show
  1. package/README.md +34 -0
  2. package/build/data/Alert/Alert.js.map +1 -1
  3. package/build/data/Alert/Alert.styled.js.map +1 -1
  4. package/build/data/Badge/Badge.js.map +1 -1
  5. package/build/data/Badge/Badge.styled.js.map +1 -1
  6. package/build/data/Popover/Popover.js.map +1 -1
  7. package/build/data/Popover/Popover.styled.js.map +1 -1
  8. package/build/data/SeverityBadge/SeverityBadge.js.map +1 -1
  9. package/build/data/Tab/Tab.js.map +1 -1
  10. package/build/data/Tab/Tab.styled.js.map +1 -1
  11. package/build/data/Tabs/Tabs.js.map +1 -1
  12. package/build/data/Tabs/Tabs.styled.js.map +1 -1
  13. package/build/data/Tooltip/Tooltip.js.map +1 -1
  14. package/build/data/Tooltip/Tooltip.styled.js.map +1 -1
  15. package/build/data/VerificationStatusIcon/VerificationStatusIcon.js.map +1 -1
  16. package/build/data/VerificationStatusIcon/VerificationStatusIcon.styled.js.map +1 -1
  17. package/build/data/_shared/FloatingArrow.styled.js.map +1 -1
  18. package/build/hooks/useEventListner.js.map +1 -1
  19. package/build/hooks/useFloatingPopover.js.map +1 -1
  20. package/build/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  21. package/build/hooks/useOnClickOutside.js.map +1 -1
  22. package/build/hooks/useTooltipAutoShow.js.map +1 -1
  23. package/build/inputs/ActionButton/ActionButton.js.map +1 -1
  24. package/build/inputs/ActionButton/ActionButton.styled.js.map +1 -1
  25. package/build/inputs/Button/Button.js.map +1 -1
  26. package/build/inputs/Button/Button.styled.js.map +1 -1
  27. package/build/inputs/Checkbox/Checkbox.js.map +1 -1
  28. package/build/inputs/Checkbox/Checkbox.styled.js.map +1 -1
  29. package/build/inputs/CompactAutocompleteSelect/CompactAutocompleteSelect.js.map +1 -1
  30. package/build/inputs/CompactAutocompleteSelect/CompactAutocompleteSelect.styled.js.map +1 -1
  31. package/build/inputs/CompactStarRating/CompactStarRating.js.map +1 -1
  32. package/build/inputs/CompactStarRating/CompactStarRating.styled.js.map +1 -1
  33. package/build/inputs/CompactTextInput/CompactTextInput.js.map +1 -1
  34. package/build/inputs/CompactTextInput/CompactTextInput.styled.js.map +1 -1
  35. package/build/inputs/MultiLevelCheckbox/MultiLevelCheckbox.js.map +1 -1
  36. package/build/inputs/MultiLevelCheckbox/MultiLevelCheckbox.styled.js.map +1 -1
  37. package/build/inputs/MultiLevelCheckbox/types.js.map +1 -1
  38. package/build/inputs/MultiLevelCheckboxSelect/MultiLevelCheckboxSelect.js.map +1 -1
  39. package/build/inputs/MultiLevelCheckboxSelect/MultiLevelCheckboxSelect.styled.js.map +1 -1
  40. package/build/inputs/MultiSelect/MultiSelect.js.map +1 -1
  41. package/build/inputs/MultiSelect/MultiSelect.styled.js.map +1 -1
  42. package/build/inputs/Radio/Radio.js.map +1 -1
  43. package/build/inputs/Radio/Radio.styled.js.map +1 -1
  44. package/build/inputs/Switch/Switch.styled.js.map +1 -1
  45. package/build/inputs/TextArea/TextArea.js.map +1 -1
  46. package/build/inputs/TextArea/TextArea.styled.js.map +1 -1
  47. package/build/inputs/TextInput/TextInput.js.map +1 -1
  48. package/build/inputs/TextInput/TextInput.styled.js.map +1 -1
  49. package/build/layout/InputGroup/InputGroup.js.map +1 -1
  50. package/build/layout/InputGroup/InputGroup.styled.js.map +1 -1
  51. package/build/layout/SectionSeparator/SectionSeparator.js.map +1 -1
  52. package/build/layout/SectionSeparator/SectionSeparator.styled.js.map +1 -1
  53. package/build/styles/utils/colors-export.d.ts +6 -25
  54. package/build/utils/dateTime.js.map +1 -1
  55. package/build/utils/defaultTheme.js.map +1 -1
  56. package/build/utils/getElementRef.js.map +1 -1
  57. package/build/utils/parseTrigger.js.map +1 -1
  58. package/build/widgets/AssetAction/AssetAction.js.map +1 -1
  59. package/build/widgets/AssetAction/AssetAction.styled.js.map +1 -1
  60. package/build/widgets/AssetActionsBase/AssetActionsBase.js.map +1 -1
  61. package/build/widgets/AssetActionsBase/AssetActionsBase.styled.js.map +1 -1
  62. package/build/widgets/AssetGallery/AssetGallery.js.map +1 -1
  63. package/build/widgets/AssetGallery/AssetGalleryBase/AssetGalleryBase.js.map +1 -1
  64. package/build/widgets/AssetGallery/AssetGalleryBase/AssetGalleryBase.styled.js.map +1 -1
  65. package/build/widgets/AssetGallery/AssetGalleryBase/AssetGalleryCompactCard/AssetGalleryCompactCard.js.map +1 -1
  66. package/build/widgets/AssetGallery/AssetGalleryBase/AssetGalleryCompactCard/AssetGalleryCompactCard.styled.js.map +1 -1
  67. package/build/widgets/AssetGallery/AssetGalleryBase/AssetGalleryGridCard/AssetGalleryGridCard.js.map +1 -1
  68. package/build/widgets/AssetGallery/AssetGalleryBase/AssetGalleryGridCard/AssetGalleryGridCard.styled.js.map +1 -1
  69. package/build/widgets/AssetPreview/AssetPreviewTopBar/AssetPreviewTopBar.js.map +1 -1
  70. package/build/widgets/AssetPreview/AssetPreviewTopBar/AssetPreviewTopBar.styled.js.map +1 -1
  71. package/build/widgets/ContextMenu/ContextMenu.js.map +1 -1
  72. package/build/widgets/ContextMenu/ContextMenu.styled.js.map +1 -1
  73. package/build/widgets/ContextMenu/ContextMenuItem/ContextMenuItem.js.map +1 -1
  74. package/build/widgets/ContextMenu/ContextMenuItem/ContextMenuItem.styled.js.map +1 -1
  75. package/build/widgets/ContextMenu/ContextMenuItemsGroup/ContextMenuItemsGroup.js.map +1 -1
  76. package/build/widgets/ContextMenu/ContextMenuItemsGroup/ContextMenuItemsGroup.styled.js.map +1 -1
  77. package/build/widgets/InfoCard/InfoCard.js.map +1 -1
  78. package/build/widgets/InfoCard/InfoCard.styled.js.map +1 -1
  79. package/build/widgets/InstructionSeverityDisplay/InstructionSeverityDisplay.js.map +1 -1
  80. package/build/widgets/InstructionSeverityDisplay/InstructionSeverityDisplay.styled.js.map +1 -1
  81. package/build/widgets/Instructions/Instructions.js.map +1 -1
  82. package/build/widgets/Instructions/Instructions.styled.js.map +1 -1
  83. package/build/widgets/ProgressBar/ProgressBar.js.map +1 -1
  84. package/build/widgets/ProgressBar/ProgressBar.styled.js.map +1 -1
  85. package/build/widgets/SummaryCard/SummaryCard.js.map +1 -1
  86. package/build/widgets/SummaryCard/SummaryCard.styled.js.map +1 -1
  87. package/package.json +8 -1
  88. package/styles/utils/colors-export.d.ts +6 -25
  89. package/types/components/data/Alert/Alert.styled.d.ts +6 -37
  90. package/types/components/data/Badge/Badge.d.ts +1 -9
  91. package/types/components/data/Badge/Badge.styled.d.ts +0 -99
  92. package/types/components/data/Popover/Popover.d.ts +11 -100
  93. package/types/components/data/Tab/Tab.d.ts +1 -14
  94. package/types/components/data/Tabs/Tabs.styled.d.ts +1 -17
  95. package/types/components/data/Tooltip/Tooltip.d.ts +4 -50
  96. package/types/components/data/VerificationStatusIcon/VerificationStatusIcon.styled.d.ts +3 -22
  97. package/types/components/data/_shared/FloatingArrow.styled.d.ts +1 -101
  98. package/types/components/inputs/ActionButton/ActionButton.styled.d.ts +2 -20
  99. package/types/components/inputs/Button/Button.styled.d.ts +0 -42
  100. package/types/components/inputs/Checkbox/Checkbox.d.ts +0 -9
  101. package/types/components/inputs/Checkbox/Checkbox.styled.d.ts +6 -10
  102. package/types/components/inputs/CompactAutocompleteSelect/CompactAutocompleteSelect.styled.d.ts +4 -57
  103. package/types/components/inputs/CompactStarRating/CompactStarRating.styled.d.ts +3 -55
  104. package/types/components/inputs/CompactTextInput/CompactTextInput.styled.d.ts +4 -32
  105. package/types/components/inputs/MultiLevelCheckbox/MultiLevelCheckbox.styled.d.ts +2 -10
  106. package/types/components/inputs/MultiLevelCheckbox/types.d.ts +3 -46
  107. package/types/components/inputs/MultiSelect/MultiSelect.d.ts +0 -57
  108. package/types/components/inputs/MultiSelect/MultiSelect.styled.d.ts +0 -65
  109. package/types/components/inputs/Radio/Radio.styled.d.ts +3 -3
  110. package/types/components/inputs/Switch/Switch.styled.d.ts +3 -7
  111. package/types/components/inputs/TextArea/TextArea.d.ts +0 -4
  112. package/types/components/inputs/TextArea/TextArea.styled.d.ts +5 -7
  113. package/types/components/inputs/TextInput/TextInput.styled.d.ts +1 -1
  114. package/types/components/layout/SectionSeparator/SectionSeparator.styled.d.ts +2 -9
  115. package/types/components/widgets/AssetAction/AssetAction.styled.d.ts +2 -7
  116. package/types/components/widgets/AssetGallery/AssetGalleryBase/AssetGalleryBase.d.ts +0 -12
  117. package/types/components/widgets/AssetGallery/AssetGalleryBase/AssetGalleryCompactCard/AssetGalleryCompactCard.styled.d.ts +7 -55
  118. package/types/components/widgets/AssetGallery/AssetGalleryBase/AssetGalleryGridCard/AssetGalleryGridCard.styled.d.ts +7 -43
  119. package/types/components/widgets/AssetGallery/asset.types.d.ts +31 -148
  120. package/types/components/widgets/AssetPreview/AssetPreviewTopBar/AssetPreviewTopBar.styled.d.ts +6 -20
  121. package/types/components/widgets/ContextMenu/ContextMenu.d.ts +1 -17
  122. package/types/components/widgets/ContextMenu/ContextMenuItem/ContextMenuItem.styled.d.ts +5 -13
  123. package/types/components/widgets/ContextMenu/ContextMenuItemsGroup/ContextMenuItemsGroup.d.ts +0 -18
  124. package/types/components/widgets/InfoCard/InfoCard.styled.d.ts +2 -19
  125. package/types/components/widgets/InstructionSeverityDisplay/InstructionSeverityDisplay.styled.d.ts +9 -19
  126. package/types/components/widgets/Instructions/Instructions.styled.d.ts +2 -14
  127. package/types/components/widgets/ProgressBar/ProgressBar.styled.d.ts +6 -43
  128. package/types/components/widgets/SummaryCard/SummaryCard.styled.d.ts +7 -46
  129. package/types/hooks/useElementSize.d.ts +3 -14
  130. package/types/hooks/useEventListner.d.ts +6 -38
  131. package/types/hooks/useFloatingPopover.d.ts +9 -90
  132. package/types/hooks/useIsomorphicLayoutEffect.d.ts +0 -23
  133. package/types/hooks/useOnClickOutside.d.ts +5 -23
  134. package/types/hooks/useTooltipAutoShow.d.ts +8 -57
  135. package/types/styles/utils/colors-export.d.ts +6 -25
  136. package/types/utils/dateTime.d.ts +2 -7
  137. package/types/utils/defaultTheme.d.ts +13 -92
  138. package/types/utils/getElementRef.d.ts +0 -19
  139. package/types/utils/parseTrigger.d.ts +8 -78
@@ -1,46 +1,14 @@
1
1
  import type { RefObject } from 'react';
2
- /**
3
- * Every event name this hook accepts, mapped to the event object the handler
4
- * actually receives.
5
- *
6
- * AN INTERSECTION, NOT `interface DomEventMap extends WindowEventMap,
7
- * HTMLElementEventMap, DocumentEventMap {}`. The three lib.dom maps share keys
8
- * through `GlobalEventHandlersEventMap`, and an interface extending all three is
9
- * a TS2320 candidate ("named property 'X' of types … are not identical") as soon
10
- * as two of them declare a shared key with types that are equivalent rather than
11
- * identical — a lib.dom detail that changes between TypeScript releases. An
12
- * intersection has no such rule: overlapping keys become `MouseEvent &
13
- * MouseEvent`, `keyof` is still the union of all three key sets, and lib.dom
14
- * stays the single source of truth for which event class each name carries. Do
15
- * not "tidy" this into an interface.
16
- *
17
- * All three maps are needed because the target is chosen at runtime:
18
- * `element?.current ?? window`.
19
- */
20
2
  export type DomEventMap = WindowEventMap & HTMLElementEventMap & DocumentEventMap;
21
- /** Any DOM event name this hook accepts — `keyof DomEventMap`. */
22
3
  export type DomEventName = keyof DomEventMap;
23
4
  /**
24
- * Subscribes to a DOM event for the lifetime of the component, always calling
25
- * the latest `handler` without re-subscribing when it changes identity.
26
- *
27
- * `element` AND `options` ARE OPTIONAL, AND THAT IS THE ENTIRE FIX FOR THE
28
- * TS2554 ARITY ERRORS IN THIS DIRECTORY. In JavaScript a missing argument is
29
- * `undefined`; in TypeScript a parameter with neither `?` nor a default is
30
- * REQUIRED. Annotating the original four parameters without marking the last two
31
- * optional is what made every existing 2- and 3-argument call site a hard error
32
- * (`useOnClickOutside.ts:4`, `useElementSize.ts:22`,
33
- * `MultiLevelCheckboxSelect.tsx:65-67`). `element` really is optional — the hook
34
- * falls back to `window` — and `options` really is optional, so the declaration
35
- * below records what this function has always done. The body is unchanged.
5
+ * Subscribes to a DOM event for the component lifetime, always calling the latest handler.
6
+ * Element and options are optional (fall back to window and no options).
36
7
  *
37
- * @param eventName any DOM event name; it selects the handler's event type
38
- * @param handler receives the event. Stored in a ref, so it may be a fresh
39
- * closure on every render without rebinding the listener
40
- * @param element ref to the target. Omit it — or pass a ref whose `current` is
41
- * still `null` — to listen on `window`
42
- * @param options forwarded verbatim to `addEventListener` and
43
- * `removeEventListener`
8
+ * @param eventName any DOM event name; selects the handler's event type
9
+ * @param handler received event; stored in a ref so closures don't rebind the listener
10
+ * @param element target ref; omit to listen on `window`
11
+ * @param options forwarded to addEventListener and removeEventListener
44
12
  */
45
13
  declare function useEventListener<K extends DomEventName, T extends EventTarget = HTMLElement>(eventName: K, handler: (event: DomEventMap[K]) => void, element?: RefObject<T | null> | null, options?: boolean | AddEventListenerOptions): void;
46
14
  export { useEventListener };
@@ -1,61 +1,8 @@
1
1
  import { useInteractions, useTransitionStyles } from '@floating-ui/react';
2
2
  import type { Middleware, OpenChangeReason, Placement, UseClickProps, UseDismissProps, UseFloatingReturn, UseFocusProps, UseHoverProps, UseTransitionStylesProps } from '@floating-ui/react';
3
- /**
4
- * THE ARROW HEIGHT, RE-DERIVED — AND THE `+15` IN `Popover.tsx` WAS NEVER A FUDGE.
5
- *
6
- * `Popover.tsx` computes `const errorOffset = useMemo(() => (arrow ? 15 : 0), [arrow])`
7
- * and passes `offset={[offset[0], offset[1] + errorOffset]}`. The name says the
8
- * 15 is a correction for a mistake. It is not: it is the arrow's height, and here
9
- * is the measurement chain.
10
- *
11
- * 1. `Popover.styled.ts` OVERRIDES tippy's default arrow geometry. For a top
12
- * placement it writes `border-width: 15px 13px 0` on both `.tippy-arrow::before`
13
- * and `::after` — a CSS border triangle **15px tall on a 26px base**
14
- * (13px + 13px). The same 15/13 pair appears on all four sides.
15
- * 2. The FILL layer, `& > .tippy-arrow:after`, is positioned `bottom: -15px`. The
16
- * `.tippy-arrow` box's bottom edge is the `.tippy-box` edge, so all 15px of
17
- * that triangle sit OUTSIDE the box: **the arrow protrudes exactly 15px.**
18
- * (The outline layer, `::before`, is at `-16px` — 1px further out. That 1px is
19
- * the popover's border continued around the arrow, not extra arrow.)
20
- * 3. So with `offset={[0, 8]}` (the `Popover` default) plus 15, tippy puts the BOX
21
- * 23px from the reference and the arrow TIP 23 − 15 = **8px** from it. The
22
- * public `offset` prop has therefore always meant "gap between the arrow tip
23
- * and the reference", and `15` is the term that makes it mean that.
24
- * 4. Floating UI's `FloatingArrow` positions its `<svg>` at `[side]: '100%'` —
25
- * flush against the outside edge of the floating element — so the full
26
- * `height` prop protrudes, exactly like tippy's fill layer. Therefore
27
- * `mainAxis = distance + height` reproduces today's geometry when, and only
28
- * when, `height === 15`.
29
- *
30
- * Get this wrong and it is immediately visible: leaving Floating UI's own default
31
- * `height = 7` would put a 7px arrow in a 23px gap (16px of daylight between tip
32
- * and reference), and dropping the term would put the box 8px out with a 15px
33
- * arrow, i.e. the tip 7px INSIDE the reference.
34
- *
35
- * One sub-pixel inconsistency does not survive: tippy's bottom-placement fill
36
- * layer is at `top: -14.5px`, half a pixel less than the other three sides. 15 is
37
- * used uniformly here.
38
- *
39
- * The `Tooltip` arrow is a different size — it never overrode tippy's default
40
- * geometry — and its number is derived at `TOOLTIP_ARROW` in
41
- * `src/components/data/_shared/FloatingArrow.styled.ts`, which also re-exports
42
- * this constant as the popover arrow's height so the offset maths and the rendered
43
- * `<svg>` cannot disagree.
44
- */
45
3
  export declare const DEFAULT_ARROW_HEIGHT = 15;
46
- /**
47
- * The placement vocabulary of our public props: Floating UI's `Placement` plus
48
- * Popper's three `auto` values.
49
- *
50
- * The 12 concrete names are identical in both libraries (`bottom-end`,
51
- * `right-start`, …) so they need no translation. `auto*` has no Floating UI
52
- * equivalent — it is a different middleware — which is handled in
53
- * `buildMiddleware` below.
54
- */
55
4
  export type PopoverPlacement = Placement | AutoPlacement;
56
- /** Popper's three `auto` values, which Floating UI has no string for. */
57
5
  export type AutoPlacement = 'auto' | 'auto-start' | 'auto-end';
58
- /** Popper's `offset` modifier shape: `[skidding, distance]`. */
59
6
  export type PopperOffset = readonly [skidding: number, distance: number];
60
7
  /** What `useFloatingPopover` accepts. Every member is optional. */
61
8
  export interface UseFloatingPopoverOptions {
@@ -87,15 +34,8 @@ export interface UseFloatingPopoverOptions {
87
34
  */
88
35
  trigger?: string | null;
89
36
  /**
90
- * Popper's `[skidding, distance]`, where `distance` is the gap between the
91
- * ARROW TIP and the reference (rule 3 in the file header). `skidding` maps to
92
- * Floating UI's `crossAxis` and NOT `alignmentAxis`: Popper applies skidding as
93
- * a plain shift along the cross axis with no sign flip for `-end` placements
94
- * (`distanceAndSkiddingToXY` in `@popperjs/core`), which is `crossAxis`'s
95
- * behaviour, whereas `alignmentAxis` inverts on `end`. Every consumer offset
96
- * measured so far is `[0, n]`, so the distinction is currently unobservable —
97
- * which is exactly why it is written down rather than discovered later.
98
- *
37
+ * `[skidding, distance]` where distance is the arrow-tip gap (see `DEFAULT_ARROW_HEIGHT`).
38
+ * Skidding maps to Floating UI's `crossAxis` (no sign flip for `-end` placements).
99
39
  * @default [0, 0]
100
40
  */
101
41
  offset?: PopperOffset;
@@ -115,15 +55,8 @@ export interface UseFloatingPopoverOptions {
115
55
  */
116
56
  arrowHeight?: number;
117
57
  /**
118
- * tippy's `interactive`: the pointer may travel from the reference into the
119
- * floating element without closing it. Implemented as
120
- * `useHover(context, { handleClose: safePolygon() })`, which is only
121
- * meaningful for a hover trigger — a click-triggered popover is "interactive"
122
- * by construction.
123
- *
124
- * Also decides `pointerEvents` in the return value, because tippy sets
125
- * `pointer-events: none` on its popper root for a non-interactive instance.
126
- *
58
+ * Pointer can travel from reference to floating element without closing.
59
+ * Also determines `pointerEvents` in the return value.
127
60
  * @default false
128
61
  */
129
62
  interactive?: boolean;
@@ -148,13 +81,8 @@ export interface UseFloatingPopoverOptions {
148
81
  */
149
82
  transition?: Omit<UseTransitionStylesProps, 'duration'>;
150
83
  /**
151
- * `useDismiss` overrides. The hook's own defaults are tippy's behaviour:
152
- * `outsidePress: true` (tippy's `hideOnClick` default), `referencePress: false`
153
- * (tippy explicitly does NOT hide when a hover-triggered reference is pressed)
154
- * and `escapeKey: false` (rule 4 in the file header).
155
- *
156
- * `enabled` is NOT overridable — it is `!disabled`, because a disabled instance
157
- * has nothing to dismiss.
84
+ * `useDismiss` overrides. Defaults match tippy: `outsidePress: true`,
85
+ * `referencePress: false`, `escapeKey: false`. `enabled` is `!disabled`.
158
86
  */
159
87
  dismiss?: Omit<UseDismissProps, 'enabled'>;
160
88
  /** `useHover` overrides, e.g. `restMs`. `enabled` and `handleClose` are owned here. */
@@ -162,21 +90,12 @@ export interface UseFloatingPopoverOptions {
162
90
  /** `useClick` overrides. `enabled` is owned here. */
163
91
  click?: Omit<UseClickProps, 'enabled'>;
164
92
  /**
165
- * `useFocus` overrides. `enabled` is owned here, and `visibleOnly` DEFAULTS TO
166
- * `false` rather than Floating UI's `true`: tippy's `focus`/`focusin` triggers
167
- * attach a plain `focusin` listener with no `:focus-visible` test, so leaving
168
- * `visibleOnly` at `true` would stop every `trigger="mouseenter focus"` tooltip
169
- * from opening on a mouse-driven focus. 6 consumer call sites pass
170
- * `"mouseenter focus"`.
93
+ * `useFocus` overrides. `visibleOnly` defaults to `false` (not Floating UI's `true`)
94
+ * to match tippy's plain focusin listener without :focus-visible test.
171
95
  */
172
96
  focus?: Omit<UseFocusProps, 'enabled'>;
173
97
  /**
174
- * Cap the floating element's height to the space available, replacing the
175
- * `popper-max-size-modifier` + `applyMaxSize` pair in `Popover.tsx`.
176
- *
177
- * OPT-IN, because only `Popover` has it today. Turning it on for `Tooltip`
178
- * would add a `max-height` to every tooltip in both consumers.
179
- *
98
+ * Cap floating element height to available space. Opt-in; only Popover uses it.
180
99
  * @default false
181
100
  */
182
101
  constrainHeight?: boolean;
@@ -1,26 +1,3 @@
1
1
  import type { DependencyList, EffectCallback } from 'react';
2
- /**
3
- * `useLayoutEffect` in the browser, `useEffect` on the server.
4
- *
5
- * WHY THE ANNOTATION IS EXPLICIT RATHER THAN INFERRED. The two hooks have
6
- * identical signatures, so the inferred type of the ternary is a UNION of two
7
- * call signatures — and a union of signatures is only callable through their
8
- * intersection, which is a worse thing to hand 1 call site and every future one
9
- * than the single signature they agree on. Naming that signature is also what
10
- * the deleted `@type` JSDoc was clumsily trying to say by listing the same
11
- * signature twice.
12
- *
13
- * WHY THE RUNTIME TERNARY MUST STAY A RUNTIME TERNARY. The two hooks are
14
- * interchangeable to the type system and NOT interchangeable to React:
15
- * `useLayoutEffect` logs "useLayoutEffect does nothing on the server" under
16
- * `renderToStaticMarkup` — which the render gate captures as a warning with its
17
- * own exit code — and it runs before paint rather than after it. So this file
18
- * cannot be simplified into a plain re-export, and no type here can protect
19
- * that. Hence this comment.
20
- *
21
- * `typeof window !== 'undefined'` is evaluated ONCE, at module scope, on
22
- * purpose: the choice must not vary between renders or React sees a different
23
- * hook in the same slot.
24
- */
25
2
  declare const useIsomorphicLayoutEffect: (effect: EffectCallback, deps?: DependencyList) => void;
26
3
  export default useIsomorphicLayoutEffect;
@@ -1,31 +1,13 @@
1
1
  import type { DomEventMap } from './useEventListner';
2
2
  import type { RefObject } from 'react';
3
- /**
4
- * The event names this hook can watch for. Narrower than `DomEventName` on
5
- * purpose — the parameter is called `mouseEvent`, and a non-pointer event name
6
- * here would silently never fire the outside-click check.
7
- */
8
3
  export type OutsideClickEventName = 'mousedown' | 'mouseup' | 'click';
9
- /**
10
- * What the handler receives. DERIVED from `DomEventMap` rather than written as
11
- * `MouseEvent`, so it follows lib.dom if a future TypeScript retypes any of
12
- * these three names (`click` has already moved between `MouseEvent` and
13
- * `PointerEvent` upstream).
14
- */
15
4
  export type OutsideClickEvent = DomEventMap[OutsideClickEventName];
16
5
  /**
17
- * Calls `handler` when the chosen pointer event happens anywhere outside `ref`'s
18
- * element and its descendants.
19
- *
20
- * `ref` IS TYPED AS NULLABLE BECAUSE THE BODY READS `ref?.current`. That is not
21
- * defensiveness copied from elsewhere — it is the existing runtime contract, so
22
- * the type records it. Contrast `useElementSize`, whose body reads `ref.current`
23
- * and whose `ref` is therefore required.
6
+ * Fires handler on pointer events outside ref (and its descendants).
7
+ * Ref is nullable — the runtime contract checks ref?.current.
24
8
  *
25
- * @param ref the "inside" element. A click on it or on any descendant is
26
- * ignored
27
- * @param handler called with the originating event for outside clicks only
28
- * @param mouseEvent which event to listen for; defaults to `'mousedown'` so the
29
- * callback fires before a click can move focus
9
+ * @param ref the "inside" element; clicks on it or descendants are ignored
10
+ * @param handler called only for outside clicks
11
+ * @param mouseEvent event to listen for; defaults to `'mousedown'` (before focus moves)
30
12
  */
31
13
  export declare function useOnClickOutside<T extends Node = HTMLElement>(ref: RefObject<T | null> | null | undefined, handler: (event: OutsideClickEvent) => void, mouseEvent?: OutsideClickEventName): void;
@@ -13,68 +13,19 @@ export interface TooltipAutoShow {
13
13
  /** `true` while there is no content, which suppresses the tooltip entirely. */
14
14
  toolTipDisabled: boolean;
15
15
  /**
16
- * `true` | `undefined` — NEVER `false`, AND THE `undefined` IS LOAD-BEARING.
17
- * `Tooltip` treats `visible` as the switch between UNCONTROLLED and CONTROLLED
18
- * mode: `undefined` leaves the tooltip under its own `trigger` prop
19
- * (hover/focus), while any boolean — including `false` — hands control to us
20
- * permanently and the tooltip stops responding to hover for the rest of its
21
- * life. So this type is `true | undefined` rather than the `boolean` it looks
22
- * like it wants to be. DO NOT "SIMPLIFY" IT: widening to `boolean` compiles
23
- * fine and silently breaks every hover tooltip in `TextArea` and
24
- * `CompactTextInput`.
25
- *
26
- * That rule was tippy's and is now the library's own: `useFloatingPopover`
27
- * decides controlled-ness with `typeof open === 'boolean'`, so this contract
28
- * survived the Floating UI migration unchanged and deliberately.
29
- *
30
- * ONE SEMANTIC DIFFERENCE, RECORDED BECAUSE IT IS REAL EVEN THOUGH THE
31
- * OBSERVABLE OUTCOME IS THE SAME. Going from `true` back to `undefined` used
32
- * to leave the tippy instance SHOWN — `@tippyjs/react` only issues an
33
- * imperative `show()`/`hide()` while `visible !== undefined`, so dropping out
34
- * of controlled mode issued nothing and the tooltip stayed up until the
35
- * reference's own `mouseleave` hid it. `useFloatingPopover` instead resolves
36
- * to its uncontrolled state, which is closed. Both end with the tooltip
37
- * hidden, because the caller drives this from `onMouseLeave` and that same
38
- * pointer exit is what used to hide it; the new path just does not depend on a
39
- * second event arriving.
16
+ * `true | undefined`, never `false`. Any boolean (including `false`) switches
17
+ * to controlled mode and disables hover triggering. `undefined` means uncontrolled;
18
+ * `true` means force-visible. This contract is checked by `useFloatingPopover`
19
+ * with `typeof open === 'boolean'`.
40
20
  */
41
21
  toolTipVisible: true | undefined;
42
22
  }
43
23
  /**
44
- * Tracks a tooltip's content and automatically forces it to be visible when the
45
- * content transitions from empty → non-empty, then defaults to trigger prop.
24
+ * Tracks tooltip content and forces visibility when content transitions from
25
+ * empty → non-empty, then defaults to trigger prop.
46
26
  *
47
- * ================== PLAN C8, DECIDED: THIS STAYS A SEPARATE HOOK ==================
48
- *
49
- * The plan asks whether `useFloatingPopover` should absorb this. It should not,
50
- * and the premise of the question turned out to be wrong.
51
- *
52
- * 1. **It does not read tippy's imperative instance API.** The plan describes it
53
- * as doing so, but measured — `grep -i tippy` over this file — the only match
54
- * is prose. There is no `_tippy`, no instance handle, no `show()`/`hide()`,
55
- * and no tippy import. Whatever was true when the plan was written, the
56
- * TypeScript migration left a hook that is pure React: two refs, one
57
- * `useState`, one `useEffect`.
58
- * 2. **What it depends on is a CONTRACT, not an implementation**, namely the
59
- * `undefined`-means-uncontrolled rule documented on `toolTipVisible`.
60
- * `useFloatingPopover` preserves that rule exactly, so this file needed no
61
- * behavioural change to survive the migration — and did not get one.
62
- * 3. **Merging it would put the wrong responsibility in the wrong place.** This
63
- * is a content-change detector: it compares the previous `content` string with
64
- * the current one and force-shows on the empty → non-empty edge.
65
- * `useFloatingPopover` owns position and interaction and never reads `content`
66
- * at all. Absorbing this would mean giving the positioning hook a `content`
67
- * parameter and a sticky-previous-value state machine for the benefit of the
68
- * two call sites that want it, out of the five it is meant to serve — three of
69
- * which (`SummaryCard`, `AssetAction`, `AssetGalleryCompactCard`) have no
70
- * content prop to diff.
71
- *
72
- * So the change here is documentation only: the JSDoc used to attribute the
73
- * controlled-mode rule to tippy, and tippy is going away.
74
- *
75
- * @param content the tooltip text. `string`, because both call sites declare
76
- * `descriptionToolTip: PropTypes.string` with a `''` default —
77
- * the sticky `displayContent` ref would not survive a `ReactNode`
27
+ * @param content the tooltip text. `string`, not `ReactNode`, because both call sites
28
+ * use it with an empty-string default.
78
29
  */
79
30
  declare function useTooltipAutoShow(content?: string): TooltipAutoShow;
80
31
  export default useTooltipAutoShow;
@@ -1,31 +1,12 @@
1
1
  /**
2
2
  * Hand-written types for colors-export.js.
3
3
  *
4
- * ============================ WHY BY HAND ================================
5
- * NEVER DERIVE THIS FROM THE .js WITH `keyof typeof`.
6
- *
7
- * It works locally, because the library compiles with `allowJs`. It collapses
8
- * silently in the consumer, which does not: with no `allowJs`, TypeScript cannot
9
- * read colors-export.js at all, `keyof typeof colors` degrades to
10
- * `string | number | symbol` WITH NO DIAGNOSTIC, and `colors[name]` inside a
11
- * template string then emits TS2731 — an error in OUR file, appearing only in
12
- * THEIR build. A hand-written .d.ts resolves under every `moduleResolution` mode
13
- * with or without `allowJs`.
14
- *
15
- * The cost is that this is a THIRD hand-maintained copy of the palette, beside
16
- * src/styles/.config.scss and colors-export.js. That is what
17
- * `npm run verify:palette` (scripts/ts-migration/verify-palette.cjs) is for: it
18
- * makes drift a build failure rather than a silent `undefined` at runtime. Add a
19
- * colour to the .js and this union without the other and the gate names it.
20
- * =========================================================================
21
- *
22
- * src/styles stays .js permanently (playbook §A.1) and rollup copies the whole
23
- * directory verbatim into the published `styles/` and `build/styles/` trees, so
24
- * this file ships NEXT TO its .js and
25
- * `@ntbjs/react-components/styles/utils/colors-export` gains types where it
26
- * previously resolved none. A `.d.ts` is explicitly allowed by
27
- * scripts/assert-no-published-typescript.cjs for exactly this reason; a `.ts`
28
- * there would be raw TypeScript in a published package.
4
+ * Do not derive this from the .js with `keyof typeof`: it works here because the library
5
+ * compiles with `allowJs`, but a consumer without it degrades the key to
6
+ * `string | number | symbol` silently and then emits TS2731 in their build, not ours.
7
+ * The cost is a third hand-maintained copy of the palette beside .config.scss and
8
+ * colors-export.js, so drift is caught by a build gate rather than at runtime.
9
+ * It must stay a `.d.ts` — a `.ts` would ship raw TypeScript in the published package.
29
10
  */
30
11
 
31
12
  /**
@@ -2,12 +2,7 @@
2
2
  * Convert time given in miliseconds to a string representation of hours, minutes and seconds
3
3
  * in the format HH:MM:SS
4
4
  *
5
- * The hours segment is omitted entirely for durations under an hour, so the
6
- * result is `MM:SS` there — the `HH:` above is the maximal form, not a promise
7
- * about width. Both call sites (`AssetGalleryGridCard`,
8
- * `AssetGalleryCompactCard`) feed it straight into a `Badge`.
9
- *
10
- * @param ms duration in milliseconds. `number`, not `number | string`: the body
11
- * divides it, and a string would produce `NaN:NaN` rather than fail
5
+ * Hours are omitted for durations under an hour (result is MM:SS).
6
+ * @param ms duration in milliseconds as number (not string, to avoid NaN)
12
7
  */
13
8
  export declare const convertMsToHMS: (ms: number) => string;
@@ -1,67 +1,31 @@
1
1
  import type { ColorName } from '../styles/utils/colors-export';
2
2
  import type { Interpolation, RuleSet } from 'styled-components';
3
3
  export type { ColorName };
4
- /**
5
- * Looks up a design-token colour.
6
- *
7
- * Throws at runtime for an unregistered name, which is why the parameter is the
8
- * closed `ColorName` union rather than `string`: the error moves from a runtime
9
- * throw inside a styled template to a compile error at the call site.
10
- */
11
4
  export type GetColor = (name: ColorName) => string;
12
- /**
13
- * A value `themeProp` interpolates into the generated rule. Widened to
14
- * styled-components' own `Interpolation` because that is literally what happens
15
- * to it — six call sites in `Badge.styled.ts` and `Tabs.styled.ts` pass a
16
- * `() => string` callback rather than a string, and two in `TextInput.styled.ts`
17
- * pass numbers. The guarantee this type buys is ARITY, not value narrowness.
18
- */
19
5
  export type ThemePropValue = Interpolation<object>;
20
6
  /**
21
- * Emits one declaration three times — for `body.dark-theme`, for
22
- * `body.light-theme`, and for neither-class-set with a
23
- * `prefers-color-scheme: dark` fallback — so a single property can differ
24
- * between themes.
25
- *
26
- * TWO REPO CONVENTIONS THE TYPE SYSTEM CANNOT ENFORCE, and both cause real
27
- * visual bugs when broken:
7
+ * Emits three declarations: body.dark-theme, body.light-theme, and
8
+ * neither-class with prefers-color-scheme fallback, so one property can
9
+ * differ between themes.
28
10
  *
29
- * - **Never call `themeProp()` inside an `&::after` / `&::before` block.** The
30
- * generated `body.dark-theme &&` selector cannot address a pseudo-element from
31
- * inside one. Write the two rules out explicitly instead:
32
- * `body.light-theme &::after { … }` and `body.dark-theme &::after { … }`.
11
+ * Two unenforceable conventions that cause visual bugs: (1) Don't call inside
12
+ * `&::after` / `&::before` — generated selector can't address pseudo-elements;
13
+ * write rules explicitly instead. (2) Use static `&[data-x='state']` selectors,
14
+ * not dynamic `${props => css\`\`}` — dynamic rules share componentId, so
15
+ * instances collide.
33
16
  *
34
- * - **Prefer static `&[data-x='state']` selectors over dynamic
35
- * `${props => css\`…\`}` rules for per-instance state.** Interpolated rules
36
- * share the component's `componentId`, so two instances in different states
37
- * collide and one wins for both.
38
- *
39
- * @param property the CSS property, e.g. `color`, `background`, or a custom
40
- * property like `--checkbox-black-box`
41
- * @param darkMode the value applied under `body.dark-theme`
42
- * @param lightMode the value applied under `body.light-theme`, and the fallback
43
- * when neither class is present
44
- * @param specificity how many `&` to repeat in the generated selector. A NUMBER —
45
- * the implementation does `Array(specificity).fill('&')`, so a
46
- * string silently produces a one-element array and specificity
47
- * 1. Typing it `number` is deliberate: it turns the one site
48
- * that passes `'!important'` here into a compile error rather
49
- * than blessing it.
17
+ * @param property CSS property (e.g. color, background, --custom-prop)
18
+ * @param darkMode value for body.dark-theme
19
+ * @param lightMode value for body.light-theme (also fallback when no class)
20
+ * @param specificity how many `&` to repeat in selector; a number (prevents
21
+ * passing '!important' by mistake)
50
22
  */
51
23
  export type ThemeProp = (property: string, darkMode: ThemePropValue, lightMode: ThemePropValue, specificity?: number) => RuleSet<object>;
52
- /**
53
- * Spacing scale. Consumed by react-select through its own `theme` prop as well
54
- * as by our styled templates, which is why the member names are react-select's.
55
- */
56
24
  export interface ThemeSpacing {
57
25
  baseUnit: number;
58
26
  controlHeight: number;
59
27
  menuGutter: number;
60
28
  }
61
- /**
62
- * react-select's colour contract, filled from our palette. These names are
63
- * react-select's, not ours — do not rename them to design-token names.
64
- */
65
29
  export interface ThemeColors {
66
30
  primary: string;
67
31
  primary75: string;
@@ -80,17 +44,6 @@ export interface ThemeColors {
80
44
  neutral80: string;
81
45
  neutral90: string;
82
46
  }
83
- /**
84
- * The whole theme, as a styled template sees it.
85
- *
86
- * Every member is REQUIRED, which is the truth inside an interpolation
87
- * (`props.theme.getColor` is always there) and a constraint at the
88
- * `<ThemeProvider>` boundary. Nothing in this repo hands over a partial theme —
89
- * the only `ThemeProvider` is `.storybook/preview.js`, with the full
90
- * `defaultTheme`. A consumer that wants to override part of it uses
91
- * `PartialNtbTheme` + `applyDefaultTheme`, which is what every `.styled` file
92
- * here does.
93
- */
94
47
  export interface NtbTheme {
95
48
  getColor: GetColor;
96
49
  primaryFontFamily: string;
@@ -99,20 +52,7 @@ export interface NtbTheme {
99
52
  spacing: ThemeSpacing;
100
53
  colors: ThemeColors;
101
54
  }
102
- /** A theme override: any subset of `NtbTheme`. */
103
55
  export type PartialNtbTheme = Partial<NtbTheme>;
104
- /**
105
- * What `applyDefaultTheme` accepts.
106
- *
107
- * DELIBERATELY NOT `ExecutionProps & { theme?: PartialNtbTheme }`.
108
- * `ExecutionProps['theme']` is `DefaultTheme | undefined`, and after the
109
- * augmentation below `DefaultTheme` is `NtbTheme` with every member required —
110
- * so intersecting makes the override required again and the function's own
111
- * `theme = {}` default stops compiling (TS2322). Extra props still flow in
112
- * fine: this is a parameter position, so a caller passing the full styled
113
- * execution context is accepted and the runtime spreads the rest through
114
- * unchanged.
115
- */
116
56
  export interface ThemedProps {
117
57
  theme?: PartialNtbTheme;
118
58
  }
@@ -145,26 +85,7 @@ export declare const defaultTheme: {
145
85
  neutral90: string;
146
86
  };
147
87
  };
148
- /**
149
- * Applies a different css property value for dark and light mode.
150
- *
151
- * Read `ThemeProp` above before changing the signature — its JSDoc carries the
152
- * two conventions that the type system cannot enforce and that cause real
153
- * visual bugs when broken.
154
- */
155
88
  declare function themeProp(property: string, darkMode: ThemePropValue, lightMode: ThemePropValue, specificity?: number): RuleSet<object>;
156
- /**
157
- * `.attrs()` helper: merges a caller's partial theme over `defaultTheme` so
158
- * every interpolation can rely on the full contract.
159
- *
160
- * THE RETURN TYPE IS `{ theme: NtbTheme }` AND NOT `P & { theme: NtbTheme }`,
161
- * ON PURPOSE. `attrs` merges its result OVER the incoming props, so a declared
162
- * type only has to describe what this function CONTRIBUTES. Saying it also
163
- * returns the caller's props re-declares them from a position that knows nothing
164
- * about them, which is what produced the measured 25–31 TS2345 `.attrs()`
165
- * assignability errors. The runtime still spreads the rest through — that part
166
- * is unchanged, and 36 `.styled` files depend on it.
167
- */
168
89
  export declare function applyDefaultTheme({ theme, ...props }: ThemedProps): {
169
90
  theme: NtbTheme;
170
91
  };
@@ -1,21 +1,2 @@
1
1
  import * as React from 'react';
2
- /**
3
- * Reads a child element's `ref` across the peer range (`react >= 16.14`).
4
- *
5
- * `ref` is a regular prop only from React 19. Before that `createElement` moves it to
6
- * `element.ref`, so reading `element.props.ref` silently returns `undefined` and the
7
- * `cloneElement(children, { ref })` that follows destroys the child's ref.
8
- *
9
- * Neither location can be read unconditionally: React 19 warns on `element.ref`, React
10
- * 18.3 warns on `props.ref`. Both warnings are `console.error`, which the stories gate
11
- * fails on. The property SHAPE says which is live, measured on 19.2.4:
12
- *
13
- * React 19, ref passed props.ref data prop element.ref warning getter
14
- * React 19, no ref props.ref absent element.ref data prop (null)
15
- * React <19 props.ref absent element.ref data prop
16
- * React 18.3, ref passed props.ref warning get element.ref data prop
17
- *
18
- * Returning early on React 19's data-property `props.ref` is what keeps every branch off
19
- * a warning getter.
20
- */
21
2
  export declare function getElementRef(element: React.ReactElement): React.Ref<unknown> | null;