@knitui/components 0.9.0 → 0.11.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.
Files changed (153) hide show
  1. package/lib/commonjs/ActionIcon/ActionIcon.js +4 -2
  2. package/lib/commonjs/ActionIcon/ActionIcon.js.map +1 -1
  3. package/lib/commonjs/Affix/Affix.js +3 -1
  4. package/lib/commonjs/Affix/Affix.js.map +1 -1
  5. package/lib/commonjs/Button/Button.js +38 -3
  6. package/lib/commonjs/Button/Button.js.map +1 -1
  7. package/lib/commonjs/CloseButton/CloseButton.js +7 -0
  8. package/lib/commonjs/CloseButton/CloseButton.js.map +1 -1
  9. package/lib/commonjs/Modal/modal-base.js +4 -2
  10. package/lib/commonjs/Modal/modal-base.js.map +1 -1
  11. package/lib/commonjs/Pill/Pill.js +1 -1
  12. package/lib/commonjs/Popover/Popover.shared.js +3 -1
  13. package/lib/commonjs/Popover/Popover.shared.js.map +1 -1
  14. package/lib/commonjs/Portal/OverlayHost.js +147 -0
  15. package/lib/commonjs/Portal/OverlayHost.js.map +1 -0
  16. package/lib/commonjs/Portal/index.js +25 -0
  17. package/lib/commonjs/Portal/index.js.map +1 -1
  18. package/lib/commonjs/ScrollArea/ScrollArea.js +5 -0
  19. package/lib/commonjs/ScrollArea/ScrollArea.js.map +1 -1
  20. package/lib/commonjs/ScrollArea/ScrollArea.native.js +32 -0
  21. package/lib/commonjs/ScrollArea/ScrollArea.native.js.map +1 -1
  22. package/lib/commonjs/ScrollArea/ScrollArea.shared.js.map +1 -1
  23. package/lib/commonjs/SegmentedControl/SegmentedControl.js +7 -1
  24. package/lib/commonjs/SegmentedControl/SegmentedControl.js.map +1 -1
  25. package/lib/commonjs/Tabs/Tabs.js +8 -1
  26. package/lib/commonjs/Tabs/Tabs.js.map +1 -1
  27. package/lib/commonjs/Tooltip/Tooltip.js +3 -1
  28. package/lib/commonjs/Tooltip/Tooltip.js.map +1 -1
  29. package/lib/commonjs/VirtualList/VirtualList.js +7 -1
  30. package/lib/commonjs/VirtualList/VirtualList.js.map +1 -1
  31. package/lib/commonjs/VirtualList/VirtualList.shared.js.map +1 -1
  32. package/lib/commonjs/floating/platform.js +4 -1
  33. package/lib/commonjs/floating/platform.js.map +1 -1
  34. package/lib/commonjs/floating/platform.native.js +15 -5
  35. package/lib/commonjs/floating/platform.native.js.map +1 -1
  36. package/lib/commonjs/floating/use-position.js +9 -3
  37. package/lib/commonjs/floating/use-position.js.map +1 -1
  38. package/lib/commonjs/index.js +24 -0
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/internal/control-icon-size.js +5 -1
  41. package/lib/commonjs/internal/control-icon-size.js.map +1 -1
  42. package/lib/commonjs/internal/control-metrics.js +13 -9
  43. package/lib/commonjs/internal/control-metrics.js.map +1 -1
  44. package/lib/commonjs/internal/style-props.js +36 -6
  45. package/lib/commonjs/internal/style-props.js.map +1 -1
  46. package/lib/module/ActionIcon/ActionIcon.js +5 -3
  47. package/lib/module/ActionIcon/ActionIcon.js.map +1 -1
  48. package/lib/module/Affix/Affix.js +4 -2
  49. package/lib/module/Affix/Affix.js.map +1 -1
  50. package/lib/module/Button/Button.js +40 -5
  51. package/lib/module/Button/Button.js.map +1 -1
  52. package/lib/module/CloseButton/CloseButton.js +8 -1
  53. package/lib/module/CloseButton/CloseButton.js.map +1 -1
  54. package/lib/module/Modal/modal-base.js +5 -3
  55. package/lib/module/Modal/modal-base.js.map +1 -1
  56. package/lib/module/Pill/Pill.js +1 -1
  57. package/lib/module/Popover/Popover.shared.js +4 -2
  58. package/lib/module/Popover/Popover.shared.js.map +1 -1
  59. package/lib/module/Portal/OverlayHost.js +138 -0
  60. package/lib/module/Portal/OverlayHost.js.map +1 -0
  61. package/lib/module/Portal/index.js +5 -0
  62. package/lib/module/Portal/index.js.map +1 -1
  63. package/lib/module/ScrollArea/ScrollArea.js +5 -0
  64. package/lib/module/ScrollArea/ScrollArea.js.map +1 -1
  65. package/lib/module/ScrollArea/ScrollArea.native.js +33 -1
  66. package/lib/module/ScrollArea/ScrollArea.native.js.map +1 -1
  67. package/lib/module/ScrollArea/ScrollArea.shared.js.map +1 -1
  68. package/lib/module/SegmentedControl/SegmentedControl.js +9 -3
  69. package/lib/module/SegmentedControl/SegmentedControl.js.map +1 -1
  70. package/lib/module/Tabs/Tabs.js +9 -2
  71. package/lib/module/Tabs/Tabs.js.map +1 -1
  72. package/lib/module/Tooltip/Tooltip.js +4 -2
  73. package/lib/module/Tooltip/Tooltip.js.map +1 -1
  74. package/lib/module/VirtualList/VirtualList.js +7 -1
  75. package/lib/module/VirtualList/VirtualList.js.map +1 -1
  76. package/lib/module/VirtualList/VirtualList.shared.js.map +1 -1
  77. package/lib/module/floating/platform.js +4 -1
  78. package/lib/module/floating/platform.js.map +1 -1
  79. package/lib/module/floating/platform.native.js +15 -5
  80. package/lib/module/floating/platform.native.js.map +1 -1
  81. package/lib/module/floating/use-position.js +9 -3
  82. package/lib/module/floating/use-position.js.map +1 -1
  83. package/lib/module/index.js +1 -1
  84. package/lib/module/index.js.map +1 -1
  85. package/lib/module/internal/control-icon-size.js +5 -1
  86. package/lib/module/internal/control-icon-size.js.map +1 -1
  87. package/lib/module/internal/control-metrics.js +13 -9
  88. package/lib/module/internal/control-metrics.js.map +1 -1
  89. package/lib/module/internal/style-props.js +33 -4
  90. package/lib/module/internal/style-props.js.map +1 -1
  91. package/lib/typescript/ActionIcon/ActionIcon.d.ts +5 -0
  92. package/lib/typescript/ActionIcon/ActionIcon.d.ts.map +1 -1
  93. package/lib/typescript/Affix/Affix.d.ts.map +1 -1
  94. package/lib/typescript/Button/Button.d.ts +6 -0
  95. package/lib/typescript/Button/Button.d.ts.map +1 -1
  96. package/lib/typescript/CloseButton/CloseButton.d.ts.map +1 -1
  97. package/lib/typescript/Input/shared.d.ts +3 -3
  98. package/lib/typescript/Modal/modal-base.d.ts.map +1 -1
  99. package/lib/typescript/Popover/Popover.shared.d.ts.map +1 -1
  100. package/lib/typescript/Portal/OverlayHost.d.ts +46 -0
  101. package/lib/typescript/Portal/OverlayHost.d.ts.map +1 -0
  102. package/lib/typescript/Portal/index.d.ts +6 -1
  103. package/lib/typescript/Portal/index.d.ts.map +1 -1
  104. package/lib/typescript/Portal/types.d.ts +10 -0
  105. package/lib/typescript/Portal/types.d.ts.map +1 -1
  106. package/lib/typescript/ScrollArea/ScrollArea.d.ts.map +1 -1
  107. package/lib/typescript/ScrollArea/ScrollArea.native.d.ts.map +1 -1
  108. package/lib/typescript/ScrollArea/ScrollArea.shared.d.ts +20 -0
  109. package/lib/typescript/ScrollArea/ScrollArea.shared.d.ts.map +1 -1
  110. package/lib/typescript/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  111. package/lib/typescript/Tabs/Tabs.d.ts.map +1 -1
  112. package/lib/typescript/Tooltip/Tooltip.d.ts.map +1 -1
  113. package/lib/typescript/VirtualList/VirtualList.d.ts.map +1 -1
  114. package/lib/typescript/VirtualList/VirtualList.shared.d.ts +9 -0
  115. package/lib/typescript/VirtualList/VirtualList.shared.d.ts.map +1 -1
  116. package/lib/typescript/floating/platform.d.ts +1 -1
  117. package/lib/typescript/floating/platform.d.ts.map +1 -1
  118. package/lib/typescript/floating/platform.native.d.ts +7 -1
  119. package/lib/typescript/floating/platform.native.d.ts.map +1 -1
  120. package/lib/typescript/floating/use-position.d.ts.map +1 -1
  121. package/lib/typescript/index.d.ts +1 -1
  122. package/lib/typescript/index.d.ts.map +1 -1
  123. package/lib/typescript/internal/control-icon-size.d.ts.map +1 -1
  124. package/lib/typescript/internal/control-metrics.d.ts +13 -9
  125. package/lib/typescript/internal/control-metrics.d.ts.map +1 -1
  126. package/lib/typescript/internal/style-props.d.ts +23 -4
  127. package/lib/typescript/internal/style-props.d.ts.map +1 -1
  128. package/package.json +4 -4
  129. package/src/ActionIcon/ActionIcon.tsx +10 -3
  130. package/src/Affix/Affix.tsx +4 -2
  131. package/src/Button/Button.tsx +69 -19
  132. package/src/CloseButton/CloseButton.tsx +7 -1
  133. package/src/Modal/modal-base.tsx +5 -3
  134. package/src/Pill/Pill.tsx +1 -1
  135. package/src/Popover/Popover.shared.tsx +4 -2
  136. package/src/Portal/OverlayHost.tsx +141 -0
  137. package/src/Portal/index.ts +11 -1
  138. package/src/Portal/types.ts +11 -0
  139. package/src/ScrollArea/ScrollArea.native.tsx +33 -2
  140. package/src/ScrollArea/ScrollArea.shared.ts +23 -0
  141. package/src/ScrollArea/ScrollArea.tsx +5 -0
  142. package/src/SegmentedControl/SegmentedControl.tsx +8 -2
  143. package/src/Tabs/Tabs.tsx +9 -1
  144. package/src/Tooltip/Tooltip.tsx +4 -2
  145. package/src/VirtualList/VirtualList.shared.ts +12 -0
  146. package/src/VirtualList/VirtualList.tsx +6 -0
  147. package/src/floating/platform.native.ts +13 -4
  148. package/src/floating/platform.ts +3 -0
  149. package/src/floating/use-position.tsx +13 -3
  150. package/src/index.ts +5 -0
  151. package/src/internal/control-icon-size.ts +5 -1
  152. package/src/internal/control-metrics.ts +13 -9
  153. package/src/internal/style-props.ts +32 -4
package/src/index.ts CHANGED
@@ -393,13 +393,18 @@ export {
393
393
  type PopoverWidth,
394
394
  } from "./Popover";
395
395
  export {
396
+ OverlayHost,
397
+ type OverlayHostProps,
396
398
  Portal,
397
399
  PortalHost,
398
400
  type PortalHostProps,
399
401
  type PortalProps,
400
402
  PortalProvider,
401
403
  type PortalProviderProps,
404
+ ROOT_OVERLAY_HOST,
405
+ useOverlayHost,
402
406
  usePortal,
407
+ useTopmostOverlayHost,
403
408
  } from "./Portal";
404
409
  export {
405
410
  Progress,
@@ -43,5 +43,9 @@ const isSizeKey = (value: unknown): value is SizeKey =>
43
43
  */
44
44
  export const controlIconSize = (size: SizeKey | number | string | undefined): number => {
45
45
  if (typeof size === "number") return size;
46
- return isSizeKey(size) ? CONTROL_ICON_SIZE[size] : CONTROL_ICON_SIZE.md;
46
+ // A size TOKEN (`"$sm"`) names the same step as its bare key. Callers holding
47
+ // token-typed sizes (Pill's remove button passes `iconSize="$sm"`) used to fall
48
+ // through to the `md` 20px here, so every Pill's ✕ drew at 20px whatever its size.
49
+ const key = typeof size === "string" && size.startsWith("$") ? size.slice(1) : size;
50
+ return isSizeKey(key) ? CONTROL_ICON_SIZE[key] : CONTROL_ICON_SIZE.md;
47
51
  };
@@ -15,17 +15,21 @@ import { getTokenValue } from "@knitui/core";
15
15
  * design rationale (balanced text-to-height ratio, capped radius curve).
16
16
  *
17
17
  * key height font ratio padX padX(pill) gap radius
18
- * xxs 24 12 .50 6 10 6 2
19
- * xs 28 12 .43 10 12 10 2
20
- * sm 32 14 .44 12 16 12 4
21
- * md 40 18 .45 16 20 16 4
22
- * lg 48 20 .42 20 24 20 8
23
- * xl 56 24 .43 24 24 24 8
24
- * xxl 64 28 .44 32 32 32 16
18
+ * xxs 18 12 .67 2 4 2 2
19
+ * xs 24 12 .50 4 8 2 2
20
+ * sm 32 14 .44 8 12 4 4
21
+ * md 40 16 .40 12 16 4 4
22
+ * lg 48 20 .42 16 24 8 8
23
+ * xl 64 24 .38 24 24 8 8
24
+ * xxl 96 28 .29 32 32 12 16
25
+ *
26
+ * (Resolved from `core/config/scales.ts`; this table had drifted from it.)
25
27
  *
26
28
  * `fontSize` is intentionally CLAMPED at the bottom two steps (xxs/xs borrow the
27
29
  * 12px `$xxs` font instead of their same-key font) so tiny controls aren't
28
- * dominated by text; `sm → xxl` hold a flat ~0.42–0.45 ratio. `borderRadius` is
30
+ * dominated by text. `md` takes `$sm` (16), not its same-key 18: 18px put the
31
+ * default 40px control's label at heading size — larger than the body text
32
+ * around it — and left no 16 step between `sm` (14) and `lg` (20). `borderRadius` is
29
33
  * CAPPED at `$lg` (16) so large controls stay rectangles, not accidental pills.
30
34
  * `paddingHorizontalPill` is the standard padding bumped one space step — the one
31
35
  * sanctioned divergence, used by the pill family (Badge/Chip/Pill).
@@ -57,7 +61,7 @@ export const controlMetrics = {
57
61
  },
58
62
  md: {
59
63
  height: "$md",
60
- fontSize: "$md",
64
+ fontSize: "$sm",
61
65
  paddingHorizontal: "$md",
62
66
  paddingHorizontalPill: "$lg",
63
67
  gap: "$xs",
@@ -165,6 +165,16 @@ export const squareSizeVariant = {
165
165
  xxl: { minWidth: M.xxl.height, width: M.xxl.height, height: M.xxl.height },
166
166
  } as const;
167
167
 
168
+ /**
169
+ * The corner a square control (`ActionIcon`, `ThemeIcon`) takes from `sm` to `xl`
170
+ * — `$md` (8), the SAME corner `Button` uses at every size. They used to read
171
+ * `controlMetrics.borderRadius` (4 at sm/md), so an icon button beside a labelled
172
+ * one at the same height was visibly squarer than it. The tiny steps keep the
173
+ * table's 2px (an 8px corner on an 18–24px square reads as a circle); `xxl` keeps
174
+ * its 16.
175
+ */
176
+ const SQUARE_CONTROL_RADIUS = "$md";
177
+
168
178
  export const squareSizeRoundedVariant = {
169
179
  xxs: {
170
180
  minWidth: M.xxs.height,
@@ -182,25 +192,25 @@ export const squareSizeRoundedVariant = {
182
192
  minWidth: M.sm.height,
183
193
  width: M.sm.height,
184
194
  height: M.sm.height,
185
- borderRadius: M.sm.borderRadius,
195
+ borderRadius: SQUARE_CONTROL_RADIUS,
186
196
  },
187
197
  md: {
188
198
  minWidth: M.md.height,
189
199
  width: M.md.height,
190
200
  height: M.md.height,
191
- borderRadius: M.md.borderRadius,
201
+ borderRadius: SQUARE_CONTROL_RADIUS,
192
202
  },
193
203
  lg: {
194
204
  minWidth: M.lg.height,
195
205
  width: M.lg.height,
196
206
  height: M.lg.height,
197
- borderRadius: M.lg.borderRadius,
207
+ borderRadius: SQUARE_CONTROL_RADIUS,
198
208
  },
199
209
  xl: {
200
210
  minWidth: M.xl.height,
201
211
  width: M.xl.height,
202
212
  height: M.xl.height,
203
- borderRadius: M.xl.borderRadius,
213
+ borderRadius: SQUARE_CONTROL_RADIUS,
204
214
  },
205
215
  xxl: {
206
216
  minWidth: M.xxl.height,
@@ -491,6 +501,24 @@ export const WEB_BUTTON_PROPS: { render?: "button"; type?: string } = Object.fre
491
501
 
492
502
  export const webButton = (): { render?: "button"; type?: string } => WEB_BUTTON_PROPS;
493
503
 
504
+ /**
505
+ * {@link WEB_BUTTON_PROPS}, or — when the control NAVIGATES — a real `<a href>`
506
+ * with `role="link"`. A control that goes somewhere must be a link on web, or
507
+ * middle-click / ⌘-click / "copy link" / the hover URL preview all silently fail;
508
+ * wrapping a `<button>` in an `<a>` instead nests interactive content (an axe
509
+ * `nested-interactive` failure). So the button-like frames take `href` and swap
510
+ * their host element here. Native has no link host: `href` is dropped there and
511
+ * the caller's `onPress` does the navigating.
512
+ *
513
+ * The anchor keeps the browser's default click behaviour; an app that routes
514
+ * in-app cancels it itself (e.g. `preventDefault` in a capture-phase click
515
+ * handler for plain clicks, letting modified clicks through).
516
+ */
517
+ export const webButtonOrLink = (
518
+ href: string | undefined,
519
+ ): { render?: "button" | "a"; type?: string; href?: string; role?: "link" } =>
520
+ isWeb && href ? { render: "a", href, role: "link" } : WEB_BUTTON_PROPS;
521
+
494
522
  /**
495
523
  * Web-only reset for the native `<button>` user-agent `text-align: center`.
496
524
  * Returned as a raw `style` fragment to spread onto the element's `style` prop —