@42-central/ui-react 0.27.0 → 0.29.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 (180) hide show
  1. package/dist/{chunk-5H5YOPCF.js → chunk-2RQLPN4U.js} +6 -6
  2. package/dist/{chunk-5H5YOPCF.js.map → chunk-2RQLPN4U.js.map} +1 -1
  3. package/dist/{chunk-SOUDKESO.js → chunk-37HYN7PC.js} +3 -3
  4. package/dist/{chunk-SOUDKESO.js.map → chunk-37HYN7PC.js.map} +1 -1
  5. package/dist/{chunk-OVT2KZHY.js → chunk-3KARNPW4.js} +3 -3
  6. package/dist/{chunk-OVT2KZHY.js.map → chunk-3KARNPW4.js.map} +1 -1
  7. package/dist/{chunk-Y2G47ARQ.js → chunk-5EOMSWNO.js} +5 -5
  8. package/dist/{chunk-Y2G47ARQ.js.map → chunk-5EOMSWNO.js.map} +1 -1
  9. package/dist/chunk-6B2GNPJP.js +43 -0
  10. package/dist/chunk-6B2GNPJP.js.map +1 -0
  11. package/dist/{chunk-MCRTAUSZ.js → chunk-7FPSQBWB.js} +3 -3
  12. package/dist/{chunk-MCRTAUSZ.js.map → chunk-7FPSQBWB.js.map} +1 -1
  13. package/dist/{chunk-6IRMKF5T.js → chunk-B4GNSSHU.js} +4 -4
  14. package/dist/{chunk-6IRMKF5T.js.map → chunk-B4GNSSHU.js.map} +1 -1
  15. package/dist/{chunk-BMEJBY6H.js → chunk-B5YHYI7E.js} +22 -27
  16. package/dist/chunk-B5YHYI7E.js.map +1 -0
  17. package/dist/{chunk-WERJ44ZN.js → chunk-DTFSCR3U.js} +3 -3
  18. package/dist/{chunk-WERJ44ZN.js.map → chunk-DTFSCR3U.js.map} +1 -1
  19. package/dist/{chunk-PFZMB3US.js → chunk-FQJNQW3G.js} +3 -3
  20. package/dist/{chunk-PFZMB3US.js.map → chunk-FQJNQW3G.js.map} +1 -1
  21. package/dist/{chunk-X3YIHN2U.js → chunk-FSPS7TVD.js} +5 -5
  22. package/dist/{chunk-X3YIHN2U.js.map → chunk-FSPS7TVD.js.map} +1 -1
  23. package/dist/{chunk-7OGZT7U2.js → chunk-G3AD3NJG.js} +3 -3
  24. package/dist/{chunk-7OGZT7U2.js.map → chunk-G3AD3NJG.js.map} +1 -1
  25. package/dist/{chunk-MNYY7UU2.js → chunk-GEZYGBXY.js} +6 -6
  26. package/dist/{chunk-MNYY7UU2.js.map → chunk-GEZYGBXY.js.map} +1 -1
  27. package/dist/{chunk-ULF5LOBS.js → chunk-HMNXNKDA.js} +3 -3
  28. package/dist/{chunk-ULF5LOBS.js.map → chunk-HMNXNKDA.js.map} +1 -1
  29. package/dist/{chunk-NF2PBGD3.js → chunk-IANYMDKH.js} +3 -3
  30. package/dist/{chunk-NF2PBGD3.js.map → chunk-IANYMDKH.js.map} +1 -1
  31. package/dist/{chunk-QEMXXQQO.js → chunk-JKFPRQB2.js} +3 -3
  32. package/dist/{chunk-QEMXXQQO.js.map → chunk-JKFPRQB2.js.map} +1 -1
  33. package/dist/{chunk-ZVECQBGG.js → chunk-KNGSO7A3.js} +41 -13
  34. package/dist/chunk-KNGSO7A3.js.map +1 -0
  35. package/dist/{chunk-L24N5EON.js → chunk-MQHD3EJE.js} +3 -3
  36. package/dist/{chunk-L24N5EON.js.map → chunk-MQHD3EJE.js.map} +1 -1
  37. package/dist/{chunk-IUK7OJXZ.js → chunk-OBSZ4NE2.js} +5 -4
  38. package/dist/chunk-OBSZ4NE2.js.map +1 -0
  39. package/dist/{chunk-DJ72KP32.js → chunk-OXR7BXZA.js} +3 -3
  40. package/dist/{chunk-DJ72KP32.js.map → chunk-OXR7BXZA.js.map} +1 -1
  41. package/dist/{chunk-LIZWCWED.js → chunk-PQZSTI3R.js} +3 -3
  42. package/dist/{chunk-LIZWCWED.js.map → chunk-PQZSTI3R.js.map} +1 -1
  43. package/dist/{chunk-LKFHUDEW.js → chunk-QVOBLRCM.js} +3 -3
  44. package/dist/{chunk-LKFHUDEW.js.map → chunk-QVOBLRCM.js.map} +1 -1
  45. package/dist/{chunk-E52Z2FKU.js → chunk-S5CQRCTF.js} +5 -5
  46. package/dist/{chunk-E52Z2FKU.js.map → chunk-S5CQRCTF.js.map} +1 -1
  47. package/dist/{chunk-SCXXJDKQ.js → chunk-SP6LCCTZ.js} +21 -28
  48. package/dist/chunk-SP6LCCTZ.js.map +1 -0
  49. package/dist/{chunk-BGDVUC3B.js → chunk-TUP7WXQE.js} +3 -3
  50. package/dist/{chunk-BGDVUC3B.js.map → chunk-TUP7WXQE.js.map} +1 -1
  51. package/dist/{chunk-4D2V4JE4.js → chunk-V2QZG4IT.js} +4 -4
  52. package/dist/{chunk-4D2V4JE4.js.map → chunk-V2QZG4IT.js.map} +1 -1
  53. package/dist/{chunk-D2QIPQ74.js → chunk-W3XX7BYT.js} +2 -2
  54. package/dist/chunk-W3XX7BYT.js.map +1 -0
  55. package/dist/{chunk-F374BNL4.js → chunk-YVTM2KRR.js} +12 -8
  56. package/dist/chunk-YVTM2KRR.js.map +1 -0
  57. package/dist/colors.css +328 -0
  58. package/dist/components/action-icon/action-icon.d.ts +6 -5
  59. package/dist/components/action-icon/action-icon.d.ts.map +1 -1
  60. package/dist/components/action-icon/index.js +3 -2
  61. package/dist/components/alert/index.js +3 -3
  62. package/dist/components/ambient-background/index.js +1 -1
  63. package/dist/components/app-shell/index.js +6 -5
  64. package/dist/components/app-shell/index.js.map +1 -1
  65. package/dist/components/avatar/index.js +2 -2
  66. package/dist/components/badge/badge.d.ts +1 -1
  67. package/dist/components/badge/badge.d.ts.map +1 -1
  68. package/dist/components/badge/index.js +2 -1
  69. package/dist/components/button/button.d.ts +11 -9
  70. package/dist/components/button/button.d.ts.map +1 -1
  71. package/dist/components/button/index.js +3 -2
  72. package/dist/components/button-multi-select/index.js +4 -3
  73. package/dist/components/button-multi-select/index.js.map +1 -1
  74. package/dist/components/button-select/index.js +4 -3
  75. package/dist/components/button-select/index.js.map +1 -1
  76. package/dist/components/calendar/index.js +6 -5
  77. package/dist/components/calendar-heatmap/index.js +2 -2
  78. package/dist/components/camera/index.js +8 -7
  79. package/dist/components/carousel/index.js +2 -2
  80. package/dist/components/clipboard/index.js +3 -2
  81. package/dist/components/clipboard/index.js.map +1 -1
  82. package/dist/components/code-block/index.js +1 -1
  83. package/dist/components/code-block/static.js.map +1 -1
  84. package/dist/components/compare/index.js +2 -2
  85. package/dist/components/data-table/index.js +16 -15
  86. package/dist/components/data-table/index.js.map +1 -1
  87. package/dist/components/date-picker/index.js +11 -10
  88. package/dist/components/date-picker/index.js.map +1 -1
  89. package/dist/components/download-button/index.js +4 -3
  90. package/dist/components/drawer/index.js +6 -5
  91. package/dist/components/file-item/index.js +7 -6
  92. package/dist/components/file-preview/index.js +7 -6
  93. package/dist/components/file-preview/index.js.map +1 -1
  94. package/dist/components/file-trigger/index.js +4 -3
  95. package/dist/components/file-upload/index.js +7 -6
  96. package/dist/components/file-upload/index.js.map +1 -1
  97. package/dist/components/gallery/index.js +2 -2
  98. package/dist/components/image-cropper/index.js +7 -6
  99. package/dist/components/indicator/index.js +1 -1
  100. package/dist/components/kbd/index.js +3 -3
  101. package/dist/components/lightbox/index.js +9 -8
  102. package/dist/components/lightbox/index.js.map +1 -1
  103. package/dist/components/menu/index.js +2 -2
  104. package/dist/components/modal/index.js +6 -5
  105. package/dist/components/multi-select/index.js +3 -3
  106. package/dist/components/notification/index.js +3 -3
  107. package/dist/components/overlays/index.js +8 -7
  108. package/dist/components/overlays/index.js.map +1 -1
  109. package/dist/components/password-input/index.js +1 -1
  110. package/dist/components/phone-input/flag.d.ts +9 -0
  111. package/dist/components/phone-input/flag.d.ts.map +1 -0
  112. package/dist/components/phone-input/index.d.ts +4 -0
  113. package/dist/components/phone-input/index.d.ts.map +1 -0
  114. package/dist/components/phone-input/index.js +503 -0
  115. package/dist/components/phone-input/index.js.map +1 -0
  116. package/dist/components/phone-input/phone-input.d.ts +125 -0
  117. package/dist/components/phone-input/phone-input.d.ts.map +1 -0
  118. package/dist/components/phone-input/phone.d.ts +117 -0
  119. package/dist/components/phone-input/phone.d.ts.map +1 -0
  120. package/dist/components/photo-capture/index.js +11 -10
  121. package/dist/components/photo-capture/index.js.map +1 -1
  122. package/dist/components/pills-input/index.js +3 -3
  123. package/dist/components/schedule/index.js +7 -6
  124. package/dist/components/schedule/index.js.map +1 -1
  125. package/dist/components/segment-group/index.js +3 -3
  126. package/dist/components/spinner/index.js +1 -1
  127. package/dist/components/spinner/spinner.d.ts +1 -1
  128. package/dist/components/spinner/spinner.d.ts.map +1 -1
  129. package/dist/components/spotlight/index.js +8 -7
  130. package/dist/components/spotlight/index.js.map +1 -1
  131. package/dist/components/tabs/index.js +3 -3
  132. package/dist/components/tags-input/index.js +3 -3
  133. package/dist/components/theme-icon/index.js +1 -1
  134. package/dist/components/theme-icon/theme-icon.d.ts.map +1 -1
  135. package/dist/components/time-input/index.js +4 -4
  136. package/dist/components/timeline/index.d.ts +1 -1
  137. package/dist/components/timeline/index.d.ts.map +1 -1
  138. package/dist/components/timeline/index.js +40 -11
  139. package/dist/components/timeline/index.js.map +1 -1
  140. package/dist/components/timeline/timeline.d.ts +8 -3
  141. package/dist/components/timeline/timeline.d.ts.map +1 -1
  142. package/dist/components/tree-multi-select/index.js +3 -3
  143. package/dist/index.js +4 -4
  144. package/dist/lib/button-colors.d.ts +25 -0
  145. package/dist/lib/button-colors.d.ts.map +1 -0
  146. package/dist/lib/dev-warn.d.ts +1 -0
  147. package/dist/lib/dev-warn.d.ts.map +1 -1
  148. package/dist/lib/intl.d.ts +5 -0
  149. package/dist/lib/intl.d.ts.map +1 -1
  150. package/package.json +3 -1
  151. package/src/as-child.contract.test.tsx +2 -0
  152. package/src/colors.css +328 -0
  153. package/src/components/action-icon/action-icon.test.tsx +22 -0
  154. package/src/components/action-icon/action-icon.tsx +24 -28
  155. package/src/components/badge/badge.test.tsx +53 -10
  156. package/src/components/badge/badge.tsx +64 -11
  157. package/src/components/button/button.test.tsx +41 -5
  158. package/src/components/button/button.tsx +28 -33
  159. package/src/components/phone-input/flag.tsx +86 -0
  160. package/src/components/phone-input/index.ts +14 -0
  161. package/src/components/phone-input/phone-input.test.tsx +285 -0
  162. package/src/components/phone-input/phone-input.tsx +527 -0
  163. package/src/components/phone-input/phone.test.ts +187 -0
  164. package/src/components/phone-input/phone.ts +298 -0
  165. package/src/components/spinner/spinner.tsx +3 -3
  166. package/src/components/theme-icon/theme-icon.test.tsx +7 -0
  167. package/src/components/theme-icon/theme-icon.tsx +10 -6
  168. package/src/components/timeline/index.ts +1 -0
  169. package/src/components/timeline/timeline.test.tsx +105 -4
  170. package/src/components/timeline/timeline.tsx +46 -11
  171. package/src/lib/button-colors.ts +55 -0
  172. package/src/lib/dev-warn.ts +1 -1
  173. package/src/lib/intl-direction.test.tsx +23 -0
  174. package/src/lib/intl.tsx +8 -2
  175. package/dist/chunk-BMEJBY6H.js.map +0 -1
  176. package/dist/chunk-D2QIPQ74.js.map +0 -1
  177. package/dist/chunk-F374BNL4.js.map +0 -1
  178. package/dist/chunk-IUK7OJXZ.js.map +0 -1
  179. package/dist/chunk-SCXXJDKQ.js.map +0 -1
  180. package/dist/chunk-ZVECQBGG.js.map +0 -1
@@ -4,8 +4,8 @@ import { Badge } from "./badge"
4
4
 
5
5
  describe("Badge", () => {
6
6
  it("renders a non-focusable span by default", () => {
7
- render(<Badge>12</Badge>)
8
- const badge = screen.getByText("12")
7
+ render(<Badge testId="badge">12</Badge>)
8
+ const badge = screen.getByTestId("badge")
9
9
  expect(badge.tagName).toBe("SPAN")
10
10
  expect(badge.getAttribute("tabindex")).toBeNull()
11
11
  })
@@ -14,8 +14,8 @@ describe("Badge", () => {
14
14
  // :focus-visible never matches a plain span — so that they're already in
15
15
  // place when asChild turns the badge into a real control.
16
16
  it("carries the kit's focus ring even as a plain span", () => {
17
- render(<Badge>12</Badge>)
18
- expect(screen.getByText("12").className).toContain("focus-visible:ring-brand-500")
17
+ render(<Badge testId="badge">12</Badge>)
18
+ expect(screen.getByTestId("badge").className).toContain("focus-visible:ring-brand-500")
19
19
  })
20
20
 
21
21
  it("collapses onto an asChild button that is focusable and keeps the ring", () => {
@@ -26,15 +26,21 @@ describe("Badge", () => {
26
26
  )
27
27
 
28
28
  const trigger = screen.getByRole("button", { name: "12 campuses" })
29
- // One node, not a button wrapping a span: the badge *is* the trigger.
30
- expect(trigger.querySelector("span")).toBeNull()
29
+ // One node, not a button wrapping the badge: the badge *is* the trigger,
30
+ // and its text is trimmed inside it like on a plain badge.
31
+ expect(trigger.children).toHaveLength(1)
32
+ expect(trigger.firstElementChild?.className).toBe("text-trim")
31
33
  expect(trigger.className).toContain("focus-visible:ring-brand-500")
32
34
  expect(trigger.className).toContain("focus-visible:ring-offset-2")
33
35
  })
34
36
 
35
37
  it("writes data-color so the palette resolves, but leaves the ring alone", () => {
36
- render(<Badge color="green">Validated</Badge>)
37
- const badge = screen.getByText("Validated")
38
+ render(
39
+ <Badge color="green" testId="badge">
40
+ Validated
41
+ </Badge>,
42
+ )
43
+ const badge = screen.getByTestId("badge")
38
44
  expect(badge.getAttribute("data-color")).toBe("green")
39
45
  // Focus stays brand-500 regardless of palette — see focusStyles.
40
46
  expect(badge.className).toContain("focus-visible:ring-brand-500")
@@ -42,10 +48,47 @@ describe("Badge", () => {
42
48
 
43
49
  it("omits data-color on the gradient variant", () => {
44
50
  render(
45
- <Badge variant="gradient" color="green">
51
+ <Badge variant="gradient" color="green" testId="badge">
46
52
  Pro
47
53
  </Badge>,
48
54
  )
49
- expect(screen.getByText("Pro").getAttribute("data-color")).toBeNull()
55
+ expect(screen.getByTestId("badge").getAttribute("data-color")).toBeNull()
56
+ })
57
+
58
+ // The trimmed span hugs cap height → baseline, so `items-center` centres
59
+ // the caps rather than Lato's lopsided ascent/descent box.
60
+ describe("text trimming", () => {
61
+ it("wraps a run of text in one text-trim span, keeping its spaces", () => {
62
+ const count = 3
63
+ render(<Badge testId="badge">{count} items</Badge>)
64
+ const badge = screen.getByTestId("badge")
65
+ expect(badge.children).toHaveLength(1)
66
+ expect(badge.firstElementChild?.className).toBe("text-trim")
67
+ expect(badge.firstElementChild?.textContent).toBe("3 items")
68
+ })
69
+
70
+ it("leaves icons and other elements as flex siblings of the text", () => {
71
+ render(
72
+ <Badge testId="badge">
73
+ <svg data-testid="icon" />
74
+ Live
75
+ <strong>!</strong>
76
+ </Badge>,
77
+ )
78
+ const kids = [...screen.getByTestId("badge").children]
79
+ expect(kids.map((kid) => kid.tagName)).toEqual(["svg", "SPAN", "STRONG"])
80
+ expect(kids[1]?.className).toBe("text-trim")
81
+ })
82
+
83
+ it("renders no empty span for empty or missing children", () => {
84
+ render(
85
+ <Badge testId="badge">
86
+ {""}
87
+ {null}
88
+ {false}
89
+ </Badge>,
90
+ )
91
+ expect(screen.getByTestId("badge").children).toHaveLength(0)
92
+ })
50
93
  })
51
94
  })
@@ -1,5 +1,7 @@
1
1
  import { ark, type HTMLArkProps } from "@ark-ui/react"
2
2
  import { cva, type VariantProps } from "class-variance-authority"
3
+ import { Children, type ReactNode } from "react"
4
+ import { composeChildren } from "../../lib/as-child"
3
5
  import { cn } from "../../lib/cn"
4
6
  import type { Color } from "../../lib/colors"
5
7
  import { focusStyles } from "../../lib/focus-styles"
@@ -41,6 +43,14 @@ const badgeVariants = cva(
41
43
  "inline-flex items-center",
42
44
  "whitespace-nowrap select-none",
43
45
  "font-sans font-medium",
46
+ // Optically equal padding on all four sides. Each size sets only its
47
+ // height (`--badge-h`); the inline padding is derived from it so the gap
48
+ // beside the text matches the gap above and below the caps:
49
+ // (height − cap height) / 2 − side bearing
50
+ // `1cap` is the cap height of the badge's own font, so this holds for
51
+ // every size and survives a font swap. The 0.08em is Lato's average
52
+ // glyph side bearing, already part of the visible gap at either end.
53
+ "min-h-(--badge-h) px-[calc((var(--badge-h)_-_1cap)/2_-_0.08em)]",
44
54
  // Figma strokes every badge at 0.5px, inside the box. A CSS border cannot
45
55
  // draw that: Chrome rounds any border-width under 1px up to 1px. An inset
46
56
  // ring (box-shadow) is not rounded — one device pixel on a 2x screen, a
@@ -86,19 +96,20 @@ const badgeVariants = cva(
86
96
  },
87
97
  // Figma (node 14950-143827) defines sm/md/lg; xs/xl extrapolate one
88
98
  // step past either end. Radius follows Figma on every step
89
- // (`rounded-badge`, 4px), as do md's height and padding. The rest of
99
+ // (`rounded-badge`, 4px), as does md's height. The rest of
90
100
  // the scale departs from Figma on purpose (3b408c4c), so there the
91
101
  // design catches up to the kit, not the reverse: sm is 12px text, 3px gap, 22px tall
92
- // (Figma 10/4/20); md has a 6px gap (4); lg is 16px text, 8px gap,
93
- // 8px padding (14/4/10). Icon size ([&_svg]:size-*) isn't in the
94
- // Figma spec — scaled by eye to each step, same convention as
95
- // Button's own size variant.
102
+ // (Figma 10/4/20); md has a 6px gap (4); lg is 16px text and an 8px
103
+ // gap (14/4). Padding is not a per-size value: the base classes derive
104
+ // it from `--badge-h`, which lands md on Figma's ~6px. Icon size
105
+ // ([&_svg]:size-*) isn't in the Figma spec — scaled by eye to each
106
+ // step, same convention as Button's own size variant.
96
107
  size: {
97
- xs: "min-h-5 px-0.5 text-[10px] leading-2.5 gap-0.5 rounded-badge [&_svg]:size-2.5",
98
- sm: "min-h-5.5 px-1 text-xs gap-0.75 rounded-badge [&_svg]:size-3",
99
- md: "min-h-6 px-1.5 text-sm gap-1.5 rounded-badge [&_svg]:size-3",
100
- lg: "min-h-7 px-2 text-md gap-2 rounded-badge [&_svg]:size-3.5",
101
- xl: "min-h-8 px-2.5 text-lg gap-3.5 rounded-badge [&_svg]:size-4",
108
+ xs: "[--badge-h:--spacing(5)] text-[10px] leading-2.5 gap-0.5 rounded-badge [&_svg]:size-2.5",
109
+ sm: "[--badge-h:--spacing(5.5)] text-xs gap-0.75 rounded-badge [&_svg]:size-3",
110
+ md: "[--badge-h:--spacing(6)] text-sm gap-1.5 rounded-badge [&_svg]:size-3",
111
+ lg: "[--badge-h:--spacing(7)] text-md gap-2 rounded-badge [&_svg]:size-3.5",
112
+ xl: "[--badge-h:--spacing(8)] text-lg gap-3.5 rounded-badge [&_svg]:size-4",
102
113
  },
103
114
  },
104
115
  defaultVariants: {
@@ -127,6 +138,43 @@ export type BadgeProps = Omit<HTMLArkProps<"span">, "color"> &
127
138
  gradient?: GradientProps
128
139
  }
129
140
 
141
+ type TextNode = string | number
142
+ const isText = (node: ReactNode): node is TextNode =>
143
+ typeof node === "string" || typeof node === "number"
144
+
145
+ /**
146
+ * Wraps each run of bare text in a `text-trim` span, leaving icons and other
147
+ * elements as they are.
148
+ *
149
+ * Untrimmed, the text's line box carries the font's ascent and descent, which
150
+ * Lato does not split evenly around its caps — so `items-center` centred the
151
+ * line box and left the caps ~1px high at sm/md. Trimmed to cap height →
152
+ * baseline, the span *is* the caps, so `items-center` centres them, and an icon
153
+ * beside them centres on the caps too. It has to be a wrapper: `text-box-trim`
154
+ * applies to block containers and inline boxes, and bare text in a flex
155
+ * container lives in an anonymous flex item that no class can reach.
156
+ *
157
+ * A run is grouped, not each node wrapped: `{count} items` arrives as two
158
+ * children, and splitting them would put the flex `gap` where the space was.
159
+ * The trimmed box ends at the baseline but nothing clips it, so descenders
160
+ * still paint below it.
161
+ */
162
+ const trimTextRuns = (own: ReactNode): ReactNode => {
163
+ const nodes = Children.toArray(own).filter((node) => node !== "")
164
+ return nodes.flatMap<ReactNode>((node, i) => {
165
+ if (!isText(node)) return [node]
166
+ // Only the first node of a run renders it; the rest are already inside.
167
+ if (i > 0 && isText(nodes[i - 1])) return []
168
+ const end = nodes.findIndex((next, j) => j > i && !isText(next))
169
+ return [
170
+ // biome-ignore lint/suspicious/noArrayIndexKey: a text run has no identity but its position
171
+ <span key={`text-${i}`} className="text-trim">
172
+ {nodes.slice(i, end === -1 ? undefined : end)}
173
+ </span>,
174
+ ]
175
+ })
176
+ }
177
+
130
178
  export const Badge = ({
131
179
  className,
132
180
  variant,
@@ -135,6 +183,8 @@ export const Badge = ({
135
183
  gradient,
136
184
  style,
137
185
  testId,
186
+ asChild,
187
+ children,
138
188
  ...rest
139
189
  }: BadgeProps) => {
140
190
  const isGradient = variant === "gradient"
@@ -149,7 +199,10 @@ export const Badge = ({
149
199
  className,
150
200
  )}
151
201
  {...props({ "data-testid": testId })}
202
+ asChild={asChild}
152
203
  {...rest}
153
- />
204
+ >
205
+ {composeChildren(asChild, children, trimTextRuns)}
206
+ </ark.span>
154
207
  )
155
208
  }
@@ -135,12 +135,48 @@ describe("Button", () => {
135
135
  expect(onLinkClick).not.toHaveBeenCalled()
136
136
  })
137
137
 
138
- it("keeps full contrast while loading, scoping the :disabled dim to a plain disabled", () => {
138
+ it("keeps full contrast while loading, scoping the :disabled tints to a plain disabled", () => {
139
139
  render(<Button loading>Saving</Button>)
140
140
  const loading = screen.getByRole("button", { name: "Saving" })
141
- // Class tokens, not substrings: `disabled:not-data-loading:opacity-50`
142
- // contains `data-loading:opacity-50`.
143
- expect([...loading.classList]).not.toContain("data-loading:opacity-50")
144
- expect([...loading.classList]).toContain("disabled:not-data-loading:opacity-50")
141
+ const classes = [...loading.classList]
142
+ expect(classes.some((c) => c.includes("opacity-50"))).toBe(false)
143
+ // Every :disabled colour is gated off while loading, which also sets native disabled.
144
+ const disabledColours = classes.filter(
145
+ (c) => c.startsWith("disabled:") && c.includes("(--btn-"),
146
+ )
147
+ expect(disabledColours.length).toBeGreaterThan(0)
148
+ expect(disabledColours.every((c) => c.startsWith("disabled:not-data-loading:"))).toBe(true)
149
+ })
150
+
151
+ it("keys the disabled tints off data-disabled too, for an asChild element", () => {
152
+ render(<Button disabled>Off</Button>)
153
+ expect([...screen.getByRole("button", { name: "Off" }).classList]).toContain(
154
+ "data-disabled:bg-(--btn-disabled-bg)",
155
+ )
156
+ })
157
+
158
+ it("renders the link variant as bare underlined text, without the size box", () => {
159
+ render(
160
+ <Button variant="link" size="lg" startSlot={<span data-testid="icon" />}>
161
+ Read more
162
+ </Button>,
163
+ )
164
+ const link = screen.getByRole("button", { name: "Read more" })
165
+ const classes = [...link.classList]
166
+ expect(link.getAttribute("data-variant")).toBe("link")
167
+ expect(classes).toEqual(
168
+ expect.arrayContaining(["h-auto", "px-0", "underline", "text-(--btn-link-text)"]),
169
+ )
170
+ expect(classes).not.toContain("h-10")
171
+ expect(classes).not.toContain("no-underline")
172
+ // The slot's negative margin would pull the icon outside the unpadded box.
173
+ expect(screen.getByTestId("icon").parentElement?.className).toContain("ms-0")
174
+ })
175
+
176
+ it("sizes its icons through a zero-specificity rule, so a class on the icon wins", () => {
177
+ render(<Button size="lg">Go</Button>)
178
+ const classes = [...screen.getByRole("button", { name: "Go" }).classList]
179
+ expect(classes).toContain("[:where(&)_svg]:size-5")
180
+ expect(classes.some((c) => c.startsWith("[&_svg]"))).toBe(false)
145
181
  })
146
182
  })
@@ -4,6 +4,7 @@ import { ark, type HTMLArkProps } from "@ark-ui/react"
4
4
  import { cva, type VariantProps } from "class-variance-authority"
5
5
  import type { MouseEvent, ReactNode } from "react"
6
6
  import { withAsChildContent } from "../../lib/as-child"
7
+ import { buttonColorVariants } from "../../lib/button-colors"
7
8
  import { cn } from "../../lib/cn"
8
9
  import type { Color } from "../../lib/colors"
9
10
  import { focusStyles } from "../../lib/focus-styles"
@@ -15,13 +16,15 @@ import { Spinner } from "../spinner/spinner"
15
16
  * Button — interactive but stateless primitive.
16
17
  *
17
18
  * The new (variant × color) model splits visual treatment from accent palette:
18
- * - `variant` picks the shape (filled / light / outline / subtle)
19
- * - `color` picks the palette (brand / gray / neutral / red / orange / …)
19
+ * - `variant` picks the shape (filled / light / outline / subtle / link)
20
+ * - `color` picks the palette (brand / neutral / red / orange / …)
20
21
  *
21
22
  * Color is delivered through CSS variables: the component writes a
22
23
  * `data-color="…"` attribute and the global rules in `colors.css` resolve
23
- * `--c-solid`, `--c-soft`, `--c-text` etc. for both light and dark mode. So
24
- * the cva matrix only enumerates variants, not (variant × color) pairs.
24
+ * the button-only `--btn-*` slots (copied from the Figma Button set) for
25
+ * both light and dark mode. So the cva matrix only enumerates variants, not
26
+ * (variant × color) pairs; the per-variant classes live in
27
+ * `lib/button-colors.ts`, shared with ActionIcon.
25
28
  * When `color` is omitted, no `data-color` attribute is rendered and the
26
29
  * slot vars cascade from `:root` — which mirrors `neutral` — so the
27
30
  * zero-config `<Button>` renders `filled` · `neutral`. Consumers retheme the
@@ -53,10 +56,10 @@ import { Spinner } from "../spinner/spinner"
53
56
  * spinner at all. Under `motion-reduce` the swap is instant; the spinner
54
57
  * itself still turns.
55
58
  *
56
- * A loading button keeps full contrast — dimming it would read as
57
- * `disabled`. `disabled` alone still dims (`not-data-loading:` scopes the
58
- * `:disabled` dim off, since `resolvedDisabled` sets native `disabled` for
59
- * `loading` too).
59
+ * A loading button keeps full contrast — muting it would read as
60
+ * `disabled`. `disabled` alone switches to the palette's disabled tints
61
+ * (`not-data-loading:` scopes the `:disabled` colours off, since
62
+ * `resolvedDisabled` sets native `disabled` for `loading` too).
60
63
  *
61
64
  * `loading` doesn't use `pointer-events-none` to block interaction — that
62
65
  * also blocks `:hover`, which would make `cursor-progress` unreachable by a
@@ -77,37 +80,29 @@ const buttonVariants = cva(
77
80
  "rounded-button border border-transparent",
78
81
  "transition-colors-radius",
79
82
  focusStyles(),
80
- "disabled:not-data-loading:pointer-events-none disabled:not-data-loading:opacity-50",
81
- "data-disabled:pointer-events-none data-disabled:opacity-50",
83
+ "disabled:not-data-loading:pointer-events-none data-disabled:pointer-events-none",
82
84
  "not-data-loading:hover:cursor-pointer",
83
85
  "data-loading:cursor-progress",
84
- "[&_svg]:shrink-0 [&_svg]:pointer-events-none",
86
+ // Every svg rule is `[:where(&)_svg]`: zero class specificity, so a size
87
+ // class on the icon itself (`<Star className="size-5" />`) or a nested
88
+ // component's own svg rule wins whatever the CSS order. Lucide's `size`
89
+ // prop is only an HTML attribute and still loses. Same fix as Input (#427).
90
+ "[:where(&)_svg]:shrink-0 [:where(&)_svg]:pointer-events-none",
85
91
  ],
86
92
  {
87
93
  variants: {
88
- variant: {
89
- filled: [
90
- "bg-(--c-solid) text-(--c-on-solid)",
91
- "not-data-loading:hover:bg-(--c-solid-hover)",
92
- ],
93
- light: [
94
- "bg-(--c-soft) text-(--c-text) border-(--c-soft-hover)",
95
- "not-data-loading:hover:bg-(--c-soft-hover) not-data-loading:hover:border-(--c-solid)",
96
- ],
97
- outline: [
98
- "bg-transparent text-(--c-text) border-(--c-solid)/35",
99
- "not-data-loading:hover:bg-(--c-soft)",
100
- ],
101
- subtle: ["bg-transparent text-(--c-text)", "not-data-loading:hover:bg-(--c-soft)"],
102
- },
94
+ variant: buttonColorVariants,
103
95
  size: {
104
- xs: "h-7 px-2 text-xs [&_svg]:size-3 gap-1",
105
- sm: "h-8 px-3 text-sm [&_svg]:size-3.5 gap-1.5",
106
- md: "h-9 px-4 text-md [&_svg]:size-4 gap-2",
107
- lg: "h-10 px-4 text-lg [&_svg]:size-5 gap-3",
108
- xl: "h-12 px-5 text-xl [&_svg]:size-6 gap-3",
96
+ xs: "h-7 px-2 text-xs [:where(&)_svg]:size-3 gap-1",
97
+ sm: "h-8 px-3 text-sm [:where(&)_svg]:size-3.5 gap-1.5",
98
+ md: "h-9 px-4 text-md [:where(&)_svg]:size-4 gap-2",
99
+ lg: "h-10 px-4 text-lg [:where(&)_svg]:size-5 gap-3",
100
+ xl: "h-12 px-5 text-xl [:where(&)_svg]:size-6 gap-3",
109
101
  },
110
102
  },
103
+ // Figma's link is bare text: no box, no padding, no fixed height. A
104
+ // compound variant so it lands after (and wins over) the size classes.
105
+ compoundVariants: [{ variant: "link", class: "h-auto px-0 rounded-none border-0" }],
111
106
  defaultVariants: {
112
107
  variant: "filled",
113
108
  size: "md",
@@ -271,13 +266,13 @@ export const Button = ({
271
266
  const content = (own: ReactNode) => (
272
267
  <>
273
268
  {startSlot && (
274
- <HiddenSlot className={startSlotVariants({ size })}>
269
+ <HiddenSlot className={cn(startSlotVariants({ size }), variant === "link" && "ms-0")}>
275
270
  {morph === "start" ? <LoadingSlot loading={loading}>{startSlot}</LoadingSlot> : startSlot}
276
271
  </HiddenSlot>
277
272
  )}
278
273
  {morph === "label" ? <LoadingLabel loading={loading}>{own}</LoadingLabel> : own}
279
274
  {endSlot && (
280
- <HiddenSlot className={endSlotVariants({ size })}>
275
+ <HiddenSlot className={cn(endSlotVariants({ size }), variant === "link" && "me-0")}>
281
276
  {morph === "end" ? <LoadingSlot loading={loading}>{endSlot}</LoadingSlot> : endSlot}
282
277
  </HiddenSlot>
283
278
  )}
@@ -0,0 +1,86 @@
1
+ "use client"
2
+
3
+ import type { ComponentType, SVGProps } from "react"
4
+ import { useSyncExternalStore } from "react"
5
+ import { cn } from "../../lib/cn"
6
+
7
+ /**
8
+ * Country flags, from `country-flag-icons` (3×2 SVGs).
9
+ *
10
+ * All ~260 flags weigh about 47 KB gzipped, which is too much to put in the
11
+ * bundle of every page that renders a phone field. They load as one lazy
12
+ * chunk the first time a `Flag` mounts and stay cached for the rest of the
13
+ * session. Until the chunk arrives (and always during SSR and hydration),
14
+ * each flag draws a neutral box of the same size, so nothing shifts when the
15
+ * real flags paint.
16
+ */
17
+
18
+ type FlagComponent = ComponentType<SVGProps<SVGSVGElement>>
19
+ type FlagSet = Readonly<Record<string, FlagComponent | undefined>>
20
+
21
+ let flags: FlagSet | null = null
22
+ let requested = false
23
+ const listeners = new Set<() => void>()
24
+
25
+ const load = () => {
26
+ if (requested) return
27
+ requested = true
28
+ import("country-flag-icons/react/3x2").then(
29
+ (module) => {
30
+ flags = module as unknown as FlagSet
31
+ listeners.forEach((listener) => {
32
+ listener()
33
+ })
34
+ },
35
+ () => {
36
+ // Let the next mount try again; until then the placeholders stay.
37
+ requested = false
38
+ },
39
+ )
40
+ }
41
+
42
+ const subscribe = (listener: () => void) => {
43
+ listeners.add(listener)
44
+ load()
45
+ return () => {
46
+ listeners.delete(listener)
47
+ }
48
+ }
49
+
50
+ const useFlags = () =>
51
+ useSyncExternalStore(
52
+ subscribe,
53
+ () => flags,
54
+ () => null,
55
+ )
56
+
57
+ /** The flag box: 3×2, sized in `em` so it follows the shell's text scale, with an inset
58
+ * hairline so a white flag (Japan, Finland) still has an edge on a white surface. The
59
+ * hairline is a pseudo-element over the flag, since an inset shadow on the box itself
60
+ * would be painted under the SVG. */
61
+ const flagBox = cn(
62
+ "relative inline-flex h-[0.75em] w-[1.125em] shrink-0 overflow-hidden rounded-[2px]",
63
+ "after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit]",
64
+ "after:shadow-[inset_0_0_0_1px_rgb(0_0_0/0.12)] dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.15)]",
65
+ )
66
+
67
+ export type FlagProps = {
68
+ /** ISO 3166-1 alpha-2 code (`"FR"`). */
69
+ country: string
70
+ className?: string
71
+ }
72
+
73
+ /** A country's flag, decorative (`aria-hidden`): the country's name is always spelled out
74
+ * next to it, or carried by the trigger's accessible name. */
75
+ export const Flag = ({ country, className }: FlagProps) => {
76
+ const Svg = useFlags()?.[country]
77
+ return (
78
+ <span
79
+ aria-hidden
80
+ data-flag={country}
81
+ className={cn(flagBox, !Svg && "bg-brand-900/10 dark:bg-white/12", className)}
82
+ >
83
+ {Svg && <Svg className="size-full" />}
84
+ </span>
85
+ )
86
+ }
@@ -0,0 +1,14 @@
1
+ "use client"
2
+
3
+ export { isValidPhoneNumber } from "libphonenumber-js/min"
4
+ export { Flag, type FlagProps } from "./flag"
5
+ export {
6
+ type CountryCode,
7
+ PHONE_INPUT_DEFAULT_TRANSLATIONS,
8
+ PhoneInput,
9
+ type PhoneInputChangeDetails,
10
+ type PhoneInputIconSlot,
11
+ type PhoneInputIcons,
12
+ type PhoneInputProps,
13
+ type PhoneInputTranslations,
14
+ } from "./phone-input"