@nearform/quantum 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/README.md +19 -1
  2. package/dist/animations/index.d.ts +25 -0
  3. package/dist/animations/index.js +14 -37
  4. package/dist/animations/index.js.map +1 -1
  5. package/dist/assets/build/open-source.icon.d.ts +2 -0
  6. package/dist/assets/build/open-source.icon.js +7 -0
  7. package/dist/assets/build/open-source.icon.js.map +1 -0
  8. package/dist/assets/index.d.ts +13 -0
  9. package/dist/assets/index.js +29 -0
  10. package/dist/assets/index.js.map +1 -0
  11. package/dist/colors/accent.d.ts +16 -0
  12. package/dist/colors/accent.js +21 -0
  13. package/dist/colors/accent.js.map +1 -0
  14. package/dist/colors/background.d.ts +36 -0
  15. package/dist/colors/background.js +41 -0
  16. package/dist/colors/background.js.map +1 -0
  17. package/dist/colors/base.d.ts +136 -0
  18. package/dist/colors/base.js +140 -0
  19. package/dist/colors/base.js.map +1 -0
  20. package/dist/colors/border.d.ts +16 -0
  21. package/dist/colors/border.js +21 -0
  22. package/dist/colors/border.js.map +1 -0
  23. package/dist/colors/button.d.ts +106 -0
  24. package/dist/colors/button.js +115 -0
  25. package/dist/colors/button.js.map +1 -0
  26. package/dist/colors/feedback.d.ts +27 -0
  27. package/dist/colors/feedback.js +32 -0
  28. package/dist/colors/feedback.js.map +1 -0
  29. package/dist/colors/foreground.d.ts +35 -0
  30. package/dist/colors/foreground.js +40 -0
  31. package/dist/colors/foreground.js.map +1 -0
  32. package/dist/colors/index.d.ts +351 -0
  33. package/dist/colors/index.js +13 -416
  34. package/dist/colors/index.js.map +1 -1
  35. package/dist/components/Accordion/index.d.ts +13 -0
  36. package/dist/components/Accordion/index.js +97 -0
  37. package/dist/components/Accordion/index.js.map +1 -0
  38. package/dist/components/AppHeader/index.d.ts +21 -0
  39. package/dist/components/AppHeader/index.js +98 -0
  40. package/dist/components/AppHeader/index.js.map +1 -0
  41. package/dist/components/Avatar/index.d.ts +32 -0
  42. package/dist/components/Avatar/index.js +116 -0
  43. package/dist/components/Avatar/index.js.map +1 -0
  44. package/dist/components/BackLink/index.d.ts +9 -0
  45. package/dist/components/BackLink/index.js +80 -0
  46. package/dist/components/BackLink/index.js.map +1 -0
  47. package/dist/components/Badge/index.d.ts +48 -0
  48. package/dist/components/Badge/index.js +160 -0
  49. package/dist/components/Badge/index.js.map +1 -0
  50. package/dist/components/Breadcrumb/index.d.ts +13 -0
  51. package/dist/components/Breadcrumb/index.js +90 -0
  52. package/dist/components/Breadcrumb/index.js.map +1 -0
  53. package/dist/components/Button/index.d.ts +17 -0
  54. package/dist/components/Button/index.js +204 -0
  55. package/dist/components/Button/index.js.map +1 -0
  56. package/dist/components/ButtonGroup/index.d.ts +11 -0
  57. package/dist/components/ButtonGroup/index.js +102 -0
  58. package/dist/components/ButtonGroup/index.js.map +1 -0
  59. package/dist/components/Calendar/index.d.ts +8 -0
  60. package/dist/components/Calendar/index.js +146 -0
  61. package/dist/components/Calendar/index.js.map +1 -0
  62. package/dist/components/Card/index.d.ts +28 -0
  63. package/dist/components/Card/index.js +155 -0
  64. package/dist/components/Card/index.js.map +1 -0
  65. package/dist/components/Chat/index.d.ts +39 -0
  66. package/dist/components/Chat/index.js +100 -0
  67. package/dist/components/Chat/index.js.map +1 -0
  68. package/dist/components/Checkbox/index.d.ts +5 -0
  69. package/dist/components/Checkbox/index.js +128 -0
  70. package/dist/components/Checkbox/index.js.map +1 -0
  71. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +61 -0
  72. package/dist/components/CheckboxGroup/CheckboxGroup.js +107 -0
  73. package/dist/components/CheckboxGroup/CheckboxGroup.js.map +1 -0
  74. package/dist/components/CheckboxGroup/CheckboxGroupItem.d.ts +19 -0
  75. package/dist/components/CheckboxGroup/CheckboxGroupItem.js +83 -0
  76. package/dist/components/CheckboxGroup/CheckboxGroupItem.js.map +1 -0
  77. package/dist/components/CheckboxGroup/index.d.ts +2 -0
  78. package/dist/components/CheckboxGroup/index.js +9 -0
  79. package/dist/components/CheckboxGroup/index.js.map +1 -0
  80. package/dist/components/Chip/index.d.ts +11 -0
  81. package/dist/components/Chip/index.js +105 -0
  82. package/dist/components/Chip/index.js.map +1 -0
  83. package/dist/components/CodeBlock/index.d.ts +7 -0
  84. package/dist/components/CodeBlock/index.js +57 -0
  85. package/dist/components/CodeBlock/index.js.map +1 -0
  86. package/dist/components/ControlLabel/index.d.ts +13 -0
  87. package/dist/components/ControlLabel/index.js +83 -0
  88. package/dist/components/ControlLabel/index.js.map +1 -0
  89. package/dist/components/DateInput/index.d.ts +26 -0
  90. package/dist/components/DateInput/index.js +261 -0
  91. package/dist/components/DateInput/index.js.map +1 -0
  92. package/dist/components/DocsList/index.d.ts +18 -0
  93. package/dist/components/DocsList/index.js +125 -0
  94. package/dist/components/DocsList/index.js.map +1 -0
  95. package/dist/components/FormGroup/index.d.ts +121 -0
  96. package/dist/components/FormGroup/index.js +359 -0
  97. package/dist/components/FormGroup/index.js.map +1 -0
  98. package/dist/components/HeroButton/index.d.ts +17 -0
  99. package/dist/components/HeroButton/index.js +139 -0
  100. package/dist/components/HeroButton/index.js.map +1 -0
  101. package/dist/components/IconButton/index.d.ts +77 -0
  102. package/dist/components/IconButton/index.js +235 -0
  103. package/dist/components/IconButton/index.js.map +1 -0
  104. package/dist/components/Input/index.d.ts +27 -0
  105. package/dist/components/Input/index.js +179 -0
  106. package/dist/components/Input/index.js.map +1 -0
  107. package/dist/components/Label/index.d.ts +12 -0
  108. package/dist/components/Label/index.js +89 -0
  109. package/dist/components/Label/index.js.map +1 -0
  110. package/dist/components/Link/index.d.ts +8 -0
  111. package/dist/components/Link/index.js +40 -0
  112. package/dist/components/Link/index.js.map +1 -0
  113. package/dist/components/Modal/index.d.ts +26 -0
  114. package/dist/components/Modal/index.js +143 -0
  115. package/dist/components/Modal/index.js.map +1 -0
  116. package/dist/components/Navigation/index.d.ts +8 -0
  117. package/dist/components/Navigation/index.js +65 -0
  118. package/dist/components/Navigation/index.js.map +1 -0
  119. package/dist/components/Notice/index.d.ts +17 -0
  120. package/dist/components/Notice/index.js +134 -0
  121. package/dist/components/Notice/index.js.map +1 -0
  122. package/dist/components/PageHeader/index.d.ts +15 -0
  123. package/dist/components/PageHeader/index.js +90 -0
  124. package/dist/components/PageHeader/index.js.map +1 -0
  125. package/dist/components/Pagination/index.d.ts +17 -0
  126. package/dist/components/Pagination/index.js +118 -0
  127. package/dist/components/Pagination/index.js.map +1 -0
  128. package/dist/components/Password/index.d.ts +18 -0
  129. package/dist/components/Password/index.js +106 -0
  130. package/dist/components/Password/index.js.map +1 -0
  131. package/dist/components/Popover/index.d.ts +28 -0
  132. package/dist/components/Popover/index.js +97 -0
  133. package/dist/components/Popover/index.js.map +1 -0
  134. package/dist/components/Radio/RadioGroup.d.ts +42 -0
  135. package/dist/components/Radio/RadioGroup.js +82 -0
  136. package/dist/components/Radio/RadioGroup.js.map +1 -0
  137. package/dist/components/Radio/RadioGroupItem.d.ts +17 -0
  138. package/dist/components/Radio/RadioGroupItem.js +117 -0
  139. package/dist/components/Radio/RadioGroupItem.js.map +1 -0
  140. package/dist/components/Radio/index.d.ts +2 -0
  141. package/dist/components/Radio/index.js +8 -0
  142. package/dist/components/Radio/index.js.map +1 -0
  143. package/dist/components/Select/index.d.ts +19 -0
  144. package/dist/components/Select/index.js +206 -0
  145. package/dist/components/Select/index.js.map +1 -0
  146. package/dist/components/Slider/index.d.ts +18 -0
  147. package/dist/components/Slider/index.js +122 -0
  148. package/dist/components/Slider/index.js.map +1 -0
  149. package/dist/components/SortAndShow/index.d.ts +15 -0
  150. package/dist/components/SortAndShow/index.js +68 -0
  151. package/dist/components/SortAndShow/index.js.map +1 -0
  152. package/dist/components/SplitButton/index.d.ts +25 -0
  153. package/dist/components/SplitButton/index.js +224 -0
  154. package/dist/components/SplitButton/index.js.map +1 -0
  155. package/dist/components/Stats/index.d.ts +10 -0
  156. package/dist/components/Stats/index.js +63 -0
  157. package/dist/components/Stats/index.js.map +1 -0
  158. package/dist/components/Stepper/index.d.ts +23 -0
  159. package/dist/components/Stepper/index.js +142 -0
  160. package/dist/components/Stepper/index.js.map +1 -0
  161. package/dist/components/StepsIndicator/Step.d.ts +6 -0
  162. package/dist/components/StepsIndicator/Step.js +24 -0
  163. package/dist/components/StepsIndicator/Step.js.map +1 -0
  164. package/dist/components/StepsIndicator/StepsIndicator.d.ts +12 -0
  165. package/dist/components/StepsIndicator/StepsIndicator.js +67 -0
  166. package/dist/components/StepsIndicator/StepsIndicator.js.map +1 -0
  167. package/dist/components/StepsIndicator/index.d.ts +2 -0
  168. package/dist/components/StepsIndicator/index.js +19 -0
  169. package/dist/components/StepsIndicator/index.js.map +1 -0
  170. package/dist/components/Subnav/index.d.ts +14 -0
  171. package/dist/components/Subnav/index.js +94 -0
  172. package/dist/components/Subnav/index.js.map +1 -0
  173. package/dist/components/Switch/index.d.ts +4 -0
  174. package/dist/components/Switch/index.js +103 -0
  175. package/dist/components/Switch/index.js.map +1 -0
  176. package/dist/components/Table/index.d.ts +48 -0
  177. package/dist/components/Table/index.js +147 -0
  178. package/dist/components/Table/index.js.map +1 -0
  179. package/dist/components/Tabs/index.d.ts +16 -0
  180. package/dist/components/Tabs/index.js +168 -0
  181. package/dist/components/Tabs/index.js.map +1 -0
  182. package/dist/components/Textarea/index.d.ts +13 -0
  183. package/dist/components/Textarea/index.js +96 -0
  184. package/dist/components/Textarea/index.js.map +1 -0
  185. package/dist/components/Toast/index.d.ts +24 -0
  186. package/dist/components/Toast/index.js +171 -0
  187. package/dist/components/Toast/index.js.map +1 -0
  188. package/dist/components/ToggleList/index.d.ts +20 -0
  189. package/dist/components/ToggleList/index.js +68 -0
  190. package/dist/components/ToggleList/index.js.map +1 -0
  191. package/dist/components/Tooltip/index.d.ts +11 -0
  192. package/dist/components/Tooltip/index.js +66 -0
  193. package/dist/components/Tooltip/index.js.map +1 -0
  194. package/dist/components/WebsiteFooter/index.d.ts +23 -0
  195. package/dist/components/WebsiteFooter/index.js +113 -0
  196. package/dist/components/WebsiteFooter/index.js.map +1 -0
  197. package/dist/components/WebsiteHeader/index.d.ts +21 -0
  198. package/dist/components/WebsiteHeader/index.js +98 -0
  199. package/dist/components/WebsiteHeader/index.js.map +1 -0
  200. package/dist/components/choice-group.d.ts +109 -0
  201. package/dist/components/choice-group.js +200 -0
  202. package/dist/components/choice-group.js.map +1 -0
  203. package/dist/components/index.d.ts +49 -0
  204. package/dist/components/index.js +66 -0
  205. package/dist/components/index.js.map +1 -0
  206. package/dist/esm/animations/index.js +17 -0
  207. package/dist/esm/animations/index.js.map +1 -0
  208. package/dist/esm/colors/accent.js +18 -0
  209. package/dist/esm/colors/accent.js.map +1 -0
  210. package/dist/esm/colors/background.js +38 -0
  211. package/dist/esm/colors/background.js.map +1 -0
  212. package/dist/esm/colors/base.js +137 -0
  213. package/dist/esm/colors/base.js.map +1 -0
  214. package/dist/esm/colors/border.js +18 -0
  215. package/dist/esm/colors/border.js.map +1 -0
  216. package/dist/esm/colors/button.js +112 -0
  217. package/dist/esm/colors/button.js.map +1 -0
  218. package/dist/esm/colors/feedback.js +29 -0
  219. package/dist/esm/colors/feedback.js.map +1 -0
  220. package/dist/esm/colors/foreground.js +37 -0
  221. package/dist/esm/colors/foreground.js.map +1 -0
  222. package/dist/esm/colors/index.js +13 -0
  223. package/dist/esm/colors/index.js.map +1 -0
  224. package/dist/esm/package.json +1 -0
  225. package/dist/esm/tailwind-base.js +31 -0
  226. package/dist/esm/tailwind-base.js.map +1 -0
  227. package/dist/esm/tailwind-plugin.js +29 -0
  228. package/dist/esm/tailwind-plugin.js.map +1 -0
  229. package/dist/esm/theme.js +55 -0
  230. package/dist/esm/theme.js.map +1 -0
  231. package/dist/global.css +552 -485
  232. package/dist/index.d.ts +3 -1315
  233. package/dist/index.js +23 -6468
  234. package/dist/index.js.map +1 -1
  235. package/dist/lib/utils.d.ts +16 -0
  236. package/dist/lib/utils.js +23 -0
  237. package/dist/lib/utils.js.map +1 -0
  238. package/dist/tailwind-base.js +33 -0
  239. package/dist/tailwind-base.js.map +1 -0
  240. package/dist/tailwind-plugin.js +31 -497
  241. package/dist/tailwind-plugin.js.map +1 -1
  242. package/dist/theme.js +60 -0
  243. package/dist/theme.js.map +1 -0
  244. package/package.json +8 -11
  245. package/dist/animations/index.mjs +0 -8
  246. package/dist/animations/index.mjs.map +0 -1
  247. package/dist/chunk-36NLQKQR.mjs +0 -22
  248. package/dist/chunk-36NLQKQR.mjs.map +0 -1
  249. package/dist/chunk-3FFF7Q7C.mjs +0 -55
  250. package/dist/chunk-3FFF7Q7C.mjs.map +0 -1
  251. package/dist/chunk-GTI4HTES.mjs +0 -386
  252. package/dist/chunk-GTI4HTES.mjs.map +0 -1
  253. package/dist/colors/index.mjs +0 -8
  254. package/dist/colors/index.mjs.map +0 -1
  255. package/dist/global.css.map +0 -1
  256. package/dist/index.d.mts +0 -1315
  257. package/dist/index.mjs +0 -6043
  258. package/dist/index.mjs.map +0 -1
  259. package/dist/tailwind-plugin.mjs +0 -67
  260. package/dist/tailwind-plugin.mjs.map +0 -1
@@ -0,0 +1,359 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __rest = (this && this.__rest) || function (s, e) {
36
+ var t = {};
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
+ t[p] = s[p];
39
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
+ t[p[i]] = s[p[i]];
43
+ }
44
+ return t;
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.useFormGroup = exports.FieldError = exports.FieldDescription = exports.FormGroup = void 0;
48
+ const jsx_runtime_1 = require("react/jsx-runtime");
49
+ const React = __importStar(require("react"));
50
+ const class_variance_authority_1 = require("class-variance-authority");
51
+ const utils_1 = require("../../lib/utils");
52
+ const Label_1 = require("../Label");
53
+ /**
54
+ * A field is three things that have to agree with each other: a label, a
55
+ * control, and a message below it. Getting them to agree is entirely id
56
+ * plumbing -- the label's `htmlFor` has to match the control's `id`, the
57
+ * message's `id` has to appear in the control's `aria-describedby`, and the
58
+ * control has to be marked `aria-invalid` when the message is an error. That
59
+ * is what `FormGroup` does; the layout is the smaller half of the job.
60
+ *
61
+ * The plumbing is done by cloning the children rather than by having the
62
+ * children read a context, so the group works with anything that takes the
63
+ * props every form control already takes -- our `Input` and `Select`, a bare
64
+ * `<input>`, a control from somewhere else. The only requirement is that they
65
+ * are direct children, which is the arrangement the design file draws.
66
+ */
67
+ const formGroupVariants = (0, class_variance_authority_1.cva)('grid', {
68
+ variants: {
69
+ orientation: {
70
+ // One column, so the children simply stack in source order.
71
+ vertical: ['grid-cols-1', 'gap-y-2'],
72
+ // The label takes as much width as its text and the control takes the
73
+ // rest; the message sits under the control rather than under the label,
74
+ // which is the indent the design shows. There is no `gap-x` because an
75
+ // empty first column would still occupy it -- the label carries its own
76
+ // trailing space instead, so a group with no label has none.
77
+ horizontal: ['grid-cols-[auto_minmax(0,1fr)]', 'items-center', 'gap-y-1']
78
+ }
79
+ },
80
+ defaultVariants: {
81
+ orientation: 'vertical'
82
+ }
83
+ });
84
+ const FormGroupContext = React.createContext(null);
85
+ /**
86
+ * The group's messages and the ids they are published under. `null` outside a
87
+ * `FormGroup`, which is what lets `FieldError` and `FieldDescription` be
88
+ * rendered on their own.
89
+ *
90
+ * Useful for a control the group cannot reach -- one nested inside a wrapper
91
+ * of your own, say -- which can take `errorId` from here and put it in its own
92
+ * `aria-describedby`.
93
+ */
94
+ const useFormGroup = () => React.useContext(FormGroupContext);
95
+ exports.useFormGroup = useFormGroup;
96
+ const messageVariants = (0, class_variance_authority_1.cva)(['text-xs'], {
97
+ variants: {
98
+ tone: {
99
+ description: ['text-foreground-muted', 'dark:text-foreground-muted-dark'],
100
+ error: [
101
+ 'font-medium',
102
+ 'text-feedback-error',
103
+ 'dark:text-feedback-error-dark'
104
+ ]
105
+ }
106
+ },
107
+ defaultVariants: {
108
+ tone: 'description'
109
+ }
110
+ });
111
+ /**
112
+ * The hint under the control. Takes its text from the group's `description`,
113
+ * or from its own children when you would rather write it inline.
114
+ *
115
+ * Stands down while the group's `FieldError` has something to say, so the two
116
+ * can be written side by side once and the field shows one message at a time
117
+ * rather than growing a second line as it is validated. The error is the more
118
+ * urgent of the two and it takes the place, not the space below it. A field
119
+ * that genuinely needs both messages at once wants a second element of its
120
+ * own rather than this one.
121
+ */
122
+ const FieldDescription = React.forwardRef((_a, ref) => {
123
+ var { className, children } = _a, props = __rest(_a, ["className", "children"]);
124
+ const group = useFormGroup();
125
+ const content = (group === null || group === void 0 ? void 0 : group.errorShown)
126
+ ? undefined
127
+ : (children !== null && children !== void 0 ? children : group === null || group === void 0 ? void 0 : group.description);
128
+ if (!content)
129
+ return null;
130
+ return ((0, jsx_runtime_1.jsx)("p", Object.assign({ ref: ref, id: group === null || group === void 0 ? void 0 : group.descriptionId, className: (0, utils_1.cn)(messageVariants({ tone: 'description' }), className) }, props, { children: content })));
131
+ });
132
+ exports.FieldDescription = FieldDescription;
133
+ FieldDescription.displayName = 'FieldDescription';
134
+ /**
135
+ * The validation message under the control, and the thing that puts the group
136
+ * in its error state: a `FormGroup` whose `error` is set marks its control
137
+ * `aria-invalid` whether or not a `FieldError` is there to render it.
138
+ *
139
+ * `role="alert"` is what announces a message that appears after the page has
140
+ * loaded -- an element carrying it is read out when it enters the DOM, and
141
+ * this one is not rendered at all until there is something to say. The
142
+ * `aria-describedby` link the group sets up covers the other direction: a
143
+ * message that was already on screen is read when focus reaches the control.
144
+ */
145
+ const FieldError = React.forwardRef((_a, ref) => {
146
+ var { className, children } = _a, props = __rest(_a, ["className", "children"]);
147
+ const group = useFormGroup();
148
+ const content = children !== null && children !== void 0 ? children : group === null || group === void 0 ? void 0 : group.error;
149
+ if (!content)
150
+ return null;
151
+ return ((0, jsx_runtime_1.jsx)("p", Object.assign({ ref: ref, id: group === null || group === void 0 ? void 0 : group.errorId, role: "alert", className: (0, utils_1.cn)(messageVariants({ tone: 'error' }), className) }, props, { children: content })));
152
+ });
153
+ exports.FieldError = FieldError;
154
+ FieldError.displayName = 'FieldError';
155
+ /**
156
+ * `disabled` and `required` are real attributes rather than styling, so they
157
+ * are only forwarded to something that can hold them. React renders an unknown
158
+ * attribute on a host element verbatim and warns about it, so
159
+ * `<div disabled="true">` is both a console warning and markup a browser
160
+ * ignores. A component is trusted with them -- what it does with them is its
161
+ * own business.
162
+ */
163
+ const ATTRIBUTE_HOLDERS = new Set([
164
+ 'button',
165
+ 'fieldset',
166
+ 'input',
167
+ 'select',
168
+ 'textarea'
169
+ ]);
170
+ const takesFormAttributes = (element) => typeof element.type !== 'string' || ATTRIBUTE_HOLDERS.has(element.type);
171
+ const slotOf = (node) => {
172
+ if (!React.isValidElement(node))
173
+ return null;
174
+ if (node.type === Label_1.Label || node.type === 'label')
175
+ return 'label';
176
+ if (node.type === FieldDescription)
177
+ return 'description';
178
+ if (node.type === FieldError)
179
+ return 'error';
180
+ return 'control';
181
+ };
182
+ /**
183
+ * Wraps a label, a control and its messages into one field, wiring them
184
+ * together and laying them out in either orientation.
185
+ *
186
+ * ```tsx
187
+ * <FormGroup orientation="vertical" error="Pick a date in the future">
188
+ * <Label>Start date</Label>
189
+ * <Input type="date" variant="error" onClear={clear} />
190
+ * <FieldError />
191
+ * </FormGroup>
192
+ * ```
193
+ *
194
+ * The label, the messages and the control are recognised by what they are, so
195
+ * they can be written in any order -- though writing them in the order they
196
+ * appear is what makes the vertical layout need no placement rules at all.
197
+ * Anything that is not a `Label`, a `FieldDescription` or a `FieldError` is
198
+ * taken to be the control; only the first one is wired, since an id can only
199
+ * belong to one element.
200
+ *
201
+ * Nothing is overwritten. A child that already has an `htmlFor`, an
202
+ * `aria-describedby`, a `disabled` or a `required` keeps it, and its own
203
+ * `className` is applied after the group's. A control that already has an `id`
204
+ * keeps that too, and the label and the messages are built around it --
205
+ * `controlId` is the one way to override it, since a group asked for a
206
+ * specific id has been asked by the only party above both of them.
207
+ *
208
+ * `aria-invalid="false"` is the single exception, because it is the only one
209
+ * of these that says nothing by being there: it is the attribute's default
210
+ * and reads identically to its absence. See the guard below.
211
+ */
212
+ const FormGroup = React.forwardRef((_a, ref) => {
213
+ var _b;
214
+ var { className, orientation = 'vertical', controlId, description, error, invalid, disabled, required, children } = _a, props = __rest(_a, ["className", "orientation", "controlId", "description", "error", "invalid", "disabled", "required", "children"]);
215
+ const generatedId = React.useId();
216
+ const horizontal = orientation === 'horizontal';
217
+ const items = React.Children.toArray(children);
218
+ const slots = items.map(slotOf);
219
+ const controlIndex = slots.indexOf('control');
220
+ /**
221
+ * A control that arrived with an `id` keeps it, and the rest of the field
222
+ * is built around that instead: the label points at the id the control
223
+ * actually has, and the messages are published under ids derived from it.
224
+ * Overwriting it would break whatever put it there -- a form library's
225
+ * `register`, or an `aria-controls` elsewhere on the page.
226
+ */
227
+ const ownControlId = controlIndex === -1
228
+ ? undefined
229
+ : items[controlIndex].props.id;
230
+ const fieldId = (_b = controlId !== null && controlId !== void 0 ? controlId : ownControlId) !== null && _b !== void 0 ? _b : generatedId;
231
+ const descriptionId = `${fieldId}-description`;
232
+ const errorId = `${fieldId}-error`;
233
+ /**
234
+ * A message element with children of its own renders them instead of the
235
+ * group's, so "is there a message" is a question about both. Reading the
236
+ * child's props during render rather than having it register itself keeps
237
+ * `aria-invalid` correct on the very first render, including on the
238
+ * server, where an effect would not have run.
239
+ */
240
+ const contentOf = (slot, fallback) => {
241
+ const index = slots.indexOf(slot);
242
+ if (index === -1)
243
+ return undefined;
244
+ const own = items[index]
245
+ .props.children;
246
+ return own !== null && own !== void 0 ? own : fallback;
247
+ };
248
+ const shownError = contentOf('error', error);
249
+ const errorShown = Boolean(shownError);
250
+ // The error replaces the hint rather than joining it, so on an invalid
251
+ // field there is no hint left to describe the control with.
252
+ const descriptionShown = !errorShown && Boolean(contentOf('description', description));
253
+ const isInvalid = invalid !== null && invalid !== void 0 ? invalid : Boolean(error || shownError);
254
+ /**
255
+ * The group owns its two message ids outright: it strips them from
256
+ * whatever the control arrived with and puts them back only while the
257
+ * message they name is on the page. Everything else the control points at
258
+ * is left exactly as it was.
259
+ *
260
+ * Owning them in both directions is what matters. Only adding them would
261
+ * leave a caller who pre-wired `aria-describedby="<id>-error"` -- which
262
+ * `useFormGroup()` invites, since it hands out these very ids -- pointing
263
+ * at a removed element the moment the error cleared, because the group
264
+ * would have stopped appending the id while the caller's copy stayed put.
265
+ * A dangling idref announces nothing at all, which is the failure this
266
+ * component exists to prevent.
267
+ */
268
+ const managedIds = new Set([descriptionId, errorId]);
269
+ const describedBy = (existing) => {
270
+ var _a;
271
+ return [
272
+ ...new Set([
273
+ ...((_a = existing === null || existing === void 0 ? void 0 : existing.split(/\s+/)) !== null && _a !== void 0 ? _a : []).filter(token => token && !managedIds.has(token)),
274
+ descriptionShown ? descriptionId : undefined,
275
+ errorShown ? errorId : undefined
276
+ ].filter(Boolean))
277
+ ].join(' ') || undefined;
278
+ };
279
+ let controlWired = false;
280
+ const wire = (element, slot) => {
281
+ var _a;
282
+ const own = element.props;
283
+ if (slot === 'label') {
284
+ return React.cloneElement(element, {
285
+ htmlFor: (_a = own.htmlFor) !== null && _a !== void 0 ? _a : fieldId,
286
+ className: (0, utils_1.cn)(horizontal && 'col-start-1 row-start-1 pe-3', disabled && 'opacity-70', own.className)
287
+ });
288
+ }
289
+ if (slot !== 'control') {
290
+ return React.cloneElement(element, {
291
+ className: (0, utils_1.cn)(horizontal && 'col-start-2', own.className)
292
+ });
293
+ }
294
+ // Read before the flag is set, not inside `place` -- `place` runs after
295
+ // the assignment below, so a closure over `controlWired` would see
296
+ // `true` for the first control as well and never anchor it to the
297
+ // label's row.
298
+ const isFirstControl = !controlWired;
299
+ controlWired = true;
300
+ // Every control is wrapped in horizontal mode rather than given the
301
+ // placement classes directly: a control's `className` does not
302
+ // necessarily land on its outermost element -- `Input` puts it on the
303
+ // `<input>` inside its border -- so it is not a reliable way to position
304
+ // one in a grid.
305
+ //
306
+ // The first control is pinned to row 1 rather than left to
307
+ // auto-placement, which would happen to put it there only while the
308
+ // children are written in the order they are drawn in. A group whose
309
+ // `FieldError` comes first would otherwise give row 1 to the message and
310
+ // push the control below its own label.
311
+ const place = (node) => horizontal ? ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)('min-w-0', 'col-start-2', isFirstControl && 'row-start-1'), children: node }, element.key)) : (node);
312
+ if (!isFirstControl)
313
+ return place(element);
314
+ const wiring = {
315
+ // Already the control's own id unless `controlId` overrode it.
316
+ id: fieldId,
317
+ 'aria-describedby': describedBy(own['aria-describedby'])
318
+ };
319
+ /**
320
+ * The one place the group overrules the control, and only because
321
+ * `aria-invalid="false"` is indistinguishable from no attribute at all
322
+ * in the accessibility tree. It is the attribute's default, so a control
323
+ * carrying it has asserted nothing, and treating it as a considered
324
+ * "this field is valid" would let a template that ships
325
+ * `aria-invalid={false}` -- a common enough default -- sit inside a
326
+ * group with an error and render a field that is visibly invalid,
327
+ * announces an error message, and tells a screen reader it is fine.
328
+ *
329
+ * Every other value is an assertion and is kept, including `grammar`
330
+ * and `spelling`, which say more than the group's `true` would.
331
+ */
332
+ const ownInvalid = own['aria-invalid'];
333
+ const assertsValidity = ownInvalid !== undefined &&
334
+ ownInvalid !== false &&
335
+ ownInvalid !== 'false';
336
+ if (isInvalid && !assertsValidity) {
337
+ wiring['aria-invalid'] = true;
338
+ }
339
+ if (takesFormAttributes(element)) {
340
+ if (disabled !== undefined && own.disabled === undefined) {
341
+ wiring.disabled = disabled;
342
+ }
343
+ if (required !== undefined && own.required === undefined) {
344
+ wiring.required = required;
345
+ }
346
+ }
347
+ return place(React.cloneElement(element, wiring));
348
+ };
349
+ const context = React.useMemo(() => ({ description, error, descriptionId, errorId, errorShown }), [description, error, descriptionId, errorId, errorShown]);
350
+ return ((0, jsx_runtime_1.jsx)(FormGroupContext.Provider, { value: context, children: (0, jsx_runtime_1.jsx)("div", Object.assign({ ref: ref, className: (0, utils_1.cn)(formGroupVariants({ orientation }), className) }, props, { children: items.map((child, index) => {
351
+ const slot = slots[index];
352
+ return slot === null
353
+ ? child
354
+ : wire(child, slot);
355
+ }) })) }));
356
+ });
357
+ exports.FormGroup = FormGroup;
358
+ FormGroup.displayName = 'FormGroup';
359
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/FormGroup/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC5B,CAAC;YACD,IAAI,QAAQ,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBACzD,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAA;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,MAA6B,CAAC,CAAC,CAAA;IAC1E,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAC3B,GAAG,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,EAClE,CAAC,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,CAAC,CACzD,CAAA;IAED,OAAO,CACL,uBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YACvC,8CACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,IAAA,UAAE,EAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,SAAS,CAAC,IACxD,KAAK,cAER,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;gBACzB,OAAO,IAAI,KAAK,IAAI;oBAClB,CAAC,CAAC,KAAK;oBACP,CAAC,CAAC,IAAI,CAAC,KAA2B,EAAE,IAAI,CAAC,CAAA;YAC7C,CAAC,CAAC,IACE,GACoB,CAC7B,CAAA;AACH,CAAC,CACF,CAAA;AAIC,8BAAS;AAHX,SAAS,CAAC,WAAW,GAAG,WAAW,CAAA"}
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { type VariantProps } from 'class-variance-authority';
3
+ declare const heroButtonVariants: (props?: ({
4
+ variant?: "primary" | "secondary" | null | undefined;
5
+ size?: "md" | "lg" | "xl" | null | undefined;
6
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
7
+ export interface HeroButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof heroButtonVariants> {
8
+ leftSideChild?: React.ReactNode;
9
+ rightSideChild?: React.ReactNode;
10
+ leftSideClassName?: string;
11
+ rightSideClassName?: string;
12
+ children: any;
13
+ asChild?: boolean;
14
+ onClick?: React.MouseEventHandler<HTMLButtonElement> | undefined;
15
+ }
16
+ declare const HeroButton: React.ForwardRefExoticComponent<HeroButtonProps & React.RefAttributes<HTMLButtonElement>>;
17
+ export { HeroButton, heroButtonVariants };
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __rest = (this && this.__rest) || function (s, e) {
36
+ var t = {};
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
+ t[p] = s[p];
39
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
+ t[p[i]] = s[p[i]];
43
+ }
44
+ return t;
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.heroButtonVariants = exports.HeroButton = void 0;
48
+ const jsx_runtime_1 = require("react/jsx-runtime");
49
+ const React = __importStar(require("react"));
50
+ const react_slot_1 = require("@radix-ui/react-slot");
51
+ const class_variance_authority_1 = require("class-variance-authority");
52
+ const utils_1 = require("../../lib/utils");
53
+ const heroButtonVariants = (0, class_variance_authority_1.cva)([
54
+ 'inline-flex items-center justify-center',
55
+ 'rounded-full',
56
+ 'transition-colors',
57
+ 'focus-visible:outline-hidden',
58
+ 'disabled:pointer-events-none',
59
+ 'cursor-pointer',
60
+ 'disabled:cursor-default',
61
+ 'font-bold'
62
+ ], {
63
+ variants: {
64
+ variant: {
65
+ primary: [
66
+ 'border-0',
67
+ 'bg-button-primary',
68
+ 'text-white',
69
+ 'hover:bg-button-primary-hover',
70
+ 'focus:bg-button-primary-focus',
71
+ 'focus:shadow-brandGreen',
72
+ 'active:shadow-none',
73
+ 'disabled:bg-button-primary-disabled',
74
+ 'disabled:text-foreground-subtle',
75
+ 'dark:bg-button-primary-dark',
76
+ 'dark:text-foreground-inverse-dark',
77
+ 'dark:hover:bg-button-primary-hover-dark',
78
+ 'dark:focus:bg-button-primary-dark',
79
+ 'dark:focus:border-brandGreen-30',
80
+ 'dark:active:border-transparent',
81
+ 'dark:disabled:bg-button-primary-disabled-dark',
82
+ 'dark:disabled:text-foreground-subtle'
83
+ ],
84
+ secondary: [
85
+ 'border-2',
86
+ 'bg-white',
87
+ 'text-grey-900',
88
+ 'border-border',
89
+ 'hover:bg-button-secondary-hover',
90
+ 'hover:border-button-secondary-border-hover',
91
+ 'focus:shadow-brandGreen',
92
+ 'active:border-border',
93
+ 'active:shadow-none',
94
+ 'disabled:bg-button-secondary-disabled',
95
+ 'disabled:border-button-secondary-border-disabled',
96
+ 'disabled:text-foreground-subtle',
97
+ 'dark:bg-button-secondary-dark',
98
+ 'dark:border-button-secondary-border-dark',
99
+ 'dark:text-white',
100
+ 'dark:hover:bg-button-secondary-hover-dark',
101
+ 'dark:hover:border-button-secondary-border-hover-dark',
102
+ 'dark:focus:bg-button-secondary-dark',
103
+ 'dark:focus:shadow-brandGreen10',
104
+ 'dark:active:border-button-secondary-border-dark',
105
+ 'dark:active:shadow-none',
106
+ 'dark:disabled:bg-button-secondary-disabled-dark',
107
+ 'dark:disabled:text-foreground-subtle-dark',
108
+ 'dark:disabled:border-button-secondary-disabled-dark'
109
+ ]
110
+ },
111
+ size: {
112
+ xl: ['px-4', 'py-3', 'text-xl', 'gap-2'],
113
+ lg: ['px-4', 'py-3', 'text-lg', 'gap-2'],
114
+ md: ['px-4', 'py-2.5', 'text-base', 'gap-1.5']
115
+ }
116
+ },
117
+ compoundVariants: [
118
+ { variant: 'secondary', size: 'xl', class: 'py-2.5' },
119
+ { variant: 'secondary', size: 'lg', class: 'py-2.5' },
120
+ { variant: 'secondary', size: 'md', class: 'py-2' }
121
+ ],
122
+ defaultVariants: {
123
+ variant: 'primary',
124
+ size: 'lg'
125
+ }
126
+ });
127
+ exports.heroButtonVariants = heroButtonVariants;
128
+ const HeroButton = React.forwardRef((_a, ref) => {
129
+ var { className, variant, children, size, leftSideChild, rightSideChild, leftSideClassName, rightSideClassName, disabled = false, asChild = false, onClick } = _a, props = __rest(_a, ["className", "variant", "children", "size", "leftSideChild", "rightSideChild", "leftSideClassName", "rightSideClassName", "disabled", "asChild", "onClick"]);
130
+ const sideChildClassed = 'inline-flex items-center justify-center text-inherit text-justify';
131
+ const Comp = asChild ? react_slot_1.Slot : 'button';
132
+ return ((0, jsx_runtime_1.jsxs)(Comp, Object.assign({ className: (0, utils_1.cn)(heroButtonVariants({ variant, size }), className), ref: ref, disabled: disabled, onClick: e => {
133
+ if (onClick)
134
+ onClick(e);
135
+ } }, props, { children: [leftSideChild ? ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)(sideChildClassed, 'mr-3', leftSideClassName), children: leftSideChild })) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {})), (0, jsx_runtime_1.jsx)(react_slot_1.Slottable, { children: asChild ? children : (0, jsx_runtime_1.jsx)("div", { children: children }) }), rightSideChild ? ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)(sideChildClassed, 'ml-3', rightSideClassName), children: rightSideChild })) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}))] })));
136
+ });
137
+ exports.HeroButton = HeroButton;
138
+ HeroButton.displayName = 'HeroButton';
139
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/HeroButton/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8B;AAC9B,qDAAsD;AACtD,uEAAiE;AAEjE,2CAAoC;AAEpC,MAAM,kBAAkB,GAAG,IAAA,8BAAG,EAC5B;IACE,yCAAyC;IACzC,cAAc;IACd,mBAAmB;IACnB,8BAA8B;IAC9B,8BAA8B;IAC9B,gBAAgB;IAChB,yBAAyB;IACzB,WAAW;CACZ,EACD;IACE,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,UAAU;gBACV,mBAAmB;gBACnB,YAAY;gBACZ,+BAA+B;gBAC/B,+BAA+B;gBAC/B,yBAAyB;gBACzB,oBAAoB;gBACpB,qCAAqC;gBACrC,iCAAiC;gBACjC,6BAA6B;gBAC7B,mCAAmC;gBAC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P,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,GAAG,KAAK,EAChB,OAAO,GAAG,KAAK,EACf,OAAO,OAER,EADI,KAAK,cAZV,4JAaC,CADS;IAIV,MAAM,gBAAgB,GACpB,mEAAmE,CAAA;IAErE,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,iBAAI,CAAC,CAAC,CAAC,QAAQ,CAAA;IAEtC,OAAO,CACL,wBAAC,IAAI,kBACH,SAAS,EAAE,IAAA,UAAE,EAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,EAC/D,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,CAAC,CAAC,EAAE;YACX,IAAI,OAAO;gBAAE,OAAO,CAAC,CAAC,CAAC,CAAA;QACzB,CAAC,IACG,KAAK,eAER,aAAa,CAAC,CAAC,CAAC,CACf,gCAAK,SAAS,EAAE,IAAA,UAAE,EAAC,gBAAgB,EAAE,MAAM,EAAE,iBAAiB,CAAC,YAC5D,aAAa,GACV,CACP,CAAC,CAAC,CAAC,CACF,kDAAK,CACN,EACD,uBAAC,sBAAS,cAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAM,QAAQ,GAAO,GAAa,EAClE,cAAc,CAAC,CAAC,CAAC,CAChB,gCAAK,SAAS,EAAE,IAAA,UAAE,EAAC,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,CAAC,YAC7D,cAAc,GACX,CACP,CAAC,CAAC,CAAC,CACF,kDAAK,CACN,KACI,CACR,CAAA;AACH,CAAC,CACF,CAAA;AAIQ,gCAAU;AAFnB,UAAU,CAAC,WAAW,GAAG,YAAY,CAAA"}
@@ -0,0 +1,77 @@
1
+ import * as React from 'react';
2
+ import { type VariantProps } from 'class-variance-authority';
3
+ import { buttonVariants } from '../Button';
4
+ /**
5
+ * An icon button is a `Button` with the label taken out, so it takes its
6
+ * colours from `buttonVariants` rather than restating them. That import is
7
+ * the point rather than an economy: the two sit beside each other in a
8
+ * toolbar, so a variant that gained a hover state or a focus ring in one and
9
+ * not the other would be visible in the gap between them.
10
+ *
11
+ * `size: null` is how cva is told to skip a variant *and* its default, so
12
+ * `Button`'s padding and text sizes are left off entirely and the square
13
+ * below is the only thing setting the box.
14
+ *
15
+ * Which is the other half of the borrowing: a `Button`'s height is arithmetic
16
+ * -- padding plus line box plus border, with compound variants putting
17
+ * `secondary`'s 2px back -- and there is no line box here to add up, because
18
+ * there is no text. So the height is set outright, as `Input` sets its own,
19
+ * and `border-box` absorbs `secondary`'s border rather than a compound
20
+ * variant having to. The numbers are `Button`'s, measured: an icon button
21
+ * belongs in a row with one.
22
+ */
23
+ declare const iconButtonVariants: (props?: ({
24
+ size?: "sm" | "md" | "lg" | "xs" | null | undefined;
25
+ shape?: "circle" | "rounded" | null | undefined;
26
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
27
+ interface IconButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'title'>, VariantProps<typeof iconButtonVariants> {
28
+ /** The icon. It is the whole of the button's content. */
29
+ icon: React.ReactNode;
30
+ /**
31
+ * What the button does, in words -- "Close", "Add to basket", not "cross"
32
+ * or "plus". Required, because there is no text for a screen reader to fall
33
+ * back on.
34
+ */
35
+ label: string;
36
+ variant?: VariantProps<typeof buttonVariants>['variant'];
37
+ }
38
+ /**
39
+ * A button whose content is an icon and nothing else: the close on a dialog,
40
+ * the actions at the end of a table row, a toolbar.
41
+ *
42
+ * `label` is required and has no default, which is the one way this differs
43
+ * from every other prop here. An icon button with no accessible name is a
44
+ * control a screen reader announces as "button" and nothing more, and unlike
45
+ * a missing colour it is invisible to everyone who is not affected by it.
46
+ * There is no name that could be guessed from an icon, so the type asks for
47
+ * one rather than inventing it (WCAG 4.1.2).
48
+ *
49
+ * The icon is left out of the accessibility tree by `aria-label` itself,
50
+ * which replaces an element's contents when the name is computed, so the icon
51
+ * needs no `aria-hidden` of its own. What the icon must not carry is a
52
+ * `title`, which would put a browser tooltip on it that the button's own
53
+ * `Tooltip` did not put there. That one is unreachable from here: `icon` is a
54
+ * `ReactNode`, so there is nothing to type-check.
55
+ *
56
+ * `title` is off the button as well, which is the one prop of a `<button>`
57
+ * this component takes away. It is not that it competes for the name --
58
+ * `title` is the last resort in the naming order, behind both `aria-label`
59
+ * and the contents, so while there is a label it never wins. It is that every
60
+ * reason to reach for it here is already served by something better, and
61
+ * served properly: a tooltip is `Tooltip`, which is reachable by keyboard and
62
+ * by touch as a native one is not, and a name is `label`. What is left is a
63
+ * second tooltip doubling up with the first, and a name that appears out of
64
+ * nowhere in the one case where `label` resolved empty. Neither is worth a
65
+ * prop, so the type stops it at the point where it can still be changed
66
+ * cheaply.
67
+ *
68
+ * Only the type stops it. A `title` arriving through an untyped spread is
69
+ * passed to the element like any other attribute, because deleting an
70
+ * attribute a caller explicitly set is a worse surprise than rendering it.
71
+ *
72
+ * `type` defaults to `"button"`. A bare `<button>` inside a form is a submit
73
+ * button, and an icon button is most often a close or a remove -- the one
74
+ * place that default does the most damage.
75
+ */
76
+ declare const IconButton: React.ForwardRefExoticComponent<IconButtonProps & React.RefAttributes<HTMLButtonElement>>;
77
+ export { IconButton, iconButtonVariants, type IconButtonProps };