@ndla/primitives 0.0.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 (97) hide show
  1. package/LICENSE +674 -0
  2. package/dist/panda.buildinfo.json +426 -0
  3. package/dist/styles.css +1738 -0
  4. package/es/Accordion.js +103 -0
  5. package/es/ArticleLists.js +106 -0
  6. package/es/Badge.js +55 -0
  7. package/es/BlockQuote.js +49 -0
  8. package/es/Button.js +211 -0
  9. package/es/Checkbox.js +118 -0
  10. package/es/Dialog.js +329 -0
  11. package/es/ExpandableBox.js +55 -0
  12. package/es/FieldErrorMessage.js +44 -0
  13. package/es/FieldHelper.js +37 -0
  14. package/es/FormControl.js +163 -0
  15. package/es/FramedContent.js +54 -0
  16. package/es/Icon.js +71 -0
  17. package/es/Input.js +159 -0
  18. package/es/Label.js +104 -0
  19. package/es/Menu.js +171 -0
  20. package/es/MessageBox.js +57 -0
  21. package/es/NdlaLogo.js +284 -0
  22. package/es/Pagination.js +37 -0
  23. package/es/Popover.js +78 -0
  24. package/es/RadioGroup.js +136 -0
  25. package/es/Skeleton.js +31 -0
  26. package/es/Slider.js +102 -0
  27. package/es/Spinner.js +54 -0
  28. package/es/Switch.js +130 -0
  29. package/es/Table.js +75 -0
  30. package/es/Text.js +54 -0
  31. package/es/Toast.js +82 -0
  32. package/es/Tooltip.js +59 -0
  33. package/es/createStyleContext.js +62 -0
  34. package/es/index.js +19 -0
  35. package/lib/Accordion.d.ts +17 -0
  36. package/lib/Accordion.js +109 -0
  37. package/lib/ArticleLists.d.ts +20 -0
  38. package/lib/ArticleLists.js +115 -0
  39. package/lib/Badge.d.ts +33 -0
  40. package/lib/Badge.js +62 -0
  41. package/lib/BlockQuote.d.ts +28 -0
  42. package/lib/BlockQuote.js +56 -0
  43. package/lib/Button.d.ts +131 -0
  44. package/lib/Button.js +217 -0
  45. package/lib/Checkbox.d.ts +15 -0
  46. package/lib/Checkbox.js +125 -0
  47. package/lib/Dialog.d.ts +107 -0
  48. package/lib/Dialog.js +338 -0
  49. package/lib/ExpandableBox.d.ts +12 -0
  50. package/lib/ExpandableBox.js +63 -0
  51. package/lib/FieldErrorMessage.d.ts +11 -0
  52. package/lib/FieldErrorMessage.js +50 -0
  53. package/lib/FieldHelper.d.ts +11 -0
  54. package/lib/FieldHelper.js +43 -0
  55. package/lib/FormControl.d.ts +65 -0
  56. package/lib/FormControl.js +173 -0
  57. package/lib/FramedContent.d.ts +32 -0
  58. package/lib/FramedContent.js +61 -0
  59. package/lib/Icon.d.ts +37 -0
  60. package/lib/Icon.js +78 -0
  61. package/lib/Input.d.ts +20 -0
  62. package/lib/Input.js +165 -0
  63. package/lib/Label.d.ts +16 -0
  64. package/lib/Label.js +110 -0
  65. package/lib/Menu.d.ts +25 -0
  66. package/lib/Menu.js +179 -0
  67. package/lib/MessageBox.d.ts +33 -0
  68. package/lib/MessageBox.js +64 -0
  69. package/lib/NdlaLogo.d.ts +15 -0
  70. package/lib/NdlaLogo.js +293 -0
  71. package/lib/Pagination.d.ts +14 -0
  72. package/lib/Pagination.js +43 -0
  73. package/lib/Popover.d.ts +22 -0
  74. package/lib/Popover.js +87 -0
  75. package/lib/RadioGroup.d.ts +19 -0
  76. package/lib/RadioGroup.js +143 -0
  77. package/lib/Skeleton.d.ts +11 -0
  78. package/lib/Skeleton.js +38 -0
  79. package/lib/Slider.d.ts +17 -0
  80. package/lib/Slider.js +109 -0
  81. package/lib/Spinner.d.ts +26 -0
  82. package/lib/Spinner.js +61 -0
  83. package/lib/Switch.d.ts +21 -0
  84. package/lib/Switch.js +137 -0
  85. package/lib/Table.d.ts +10 -0
  86. package/lib/Table.js +82 -0
  87. package/lib/Text.d.ts +24 -0
  88. package/lib/Text.js +62 -0
  89. package/lib/Toast.d.ts +18 -0
  90. package/lib/Toast.js +90 -0
  91. package/lib/Tooltip.d.ts +16 -0
  92. package/lib/Tooltip.js +65 -0
  93. package/lib/createStyleContext.d.ts +27 -0
  94. package/lib/createStyleContext.js +69 -0
  95. package/lib/index.d.ts +28 -0
  96. package/lib/index.js +130 -0
  97. package/package.json +48 -0
package/lib/Dialog.js ADDED
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.InternalDialogRoot = exports.DialogTrigger = exports.DialogTitle = exports.DialogStandaloneContent = exports.DialogRoot = exports.DialogPositioner = exports.DialogHeader = exports.DialogDescription = exports.DialogContent = exports.DialogCloseTrigger = exports.DialogBody = exports.DialogBackdrop = void 0;
7
+ var _react = require("react");
8
+ var _react2 = require("@ark-ui/react");
9
+ var _css = require("@ndla/styled-system/css");
10
+ var _jsx2 = require("@ndla/styled-system/jsx");
11
+ var _createStyleContext = require("./createStyleContext");
12
+ var _Text = require("./Text");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ /**
15
+ * Copyright (c) 2024-present, NDLA.
16
+ *
17
+ * This source code is licensed under the GPLv3 license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ */
21
+
22
+ const dialogRecipe = (0, _css.sva)({
23
+ // We only use a subset of the dialog components, so we roll our own slots instead of relying on @ark/anatomy.
24
+ slots: ["positioner", "backdrop", "content"],
25
+ className: "dialog",
26
+ base: {
27
+ backdrop: {
28
+ position: "fixed",
29
+ height: "100vh",
30
+ width: "100vw",
31
+ zIndex: "overlay",
32
+ left: "0",
33
+ top: "0",
34
+ // TODO: Consider if this should be a token. It's probably consistent enough between dark and light mode to be a token.
35
+ background: "rgba(1, 1, 1, 0.3)",
36
+ _open: {
37
+ animation: "backdrop-in"
38
+ },
39
+ _closed: {
40
+ animation: "backdrop-out"
41
+ }
42
+ },
43
+ positioner: {
44
+ position: "fixed",
45
+ display: "flex",
46
+ alignItems: "center",
47
+ justifyContent: "center",
48
+ overflow: "hidden",
49
+ left: "0",
50
+ top: "0",
51
+ width: "100vw",
52
+ height: "100dvh",
53
+ zIndex: "modal"
54
+ },
55
+ content: {
56
+ "--margin": "token(sizes.medium)",
57
+ position: "relative",
58
+ background: "surface.default",
59
+ boxShadow: "xlarge",
60
+ height: "min-content",
61
+ maxWidth: "95%",
62
+ maxHeight: "95%",
63
+ margin: "auto",
64
+ overflowY: "auto",
65
+ borderRadius: {
66
+ base: "sharp",
67
+ tablet: "small"
68
+ },
69
+ paddingBlockStart: "env(safe-area-inset-top)",
70
+ paddingBlockEnd: "env(safe-area-inset-bottom)",
71
+ paddingInlineStart: "env(safe-area-inset-left)",
72
+ paddingInlineEnd: "env(safe-area-inset-right)",
73
+ tabletDown: {
74
+ "--margin": "0px",
75
+ minWidth: "100%",
76
+ minHeight: "100%"
77
+ }
78
+ }
79
+ },
80
+ defaultVariants: {
81
+ size: "medium",
82
+ position: "center"
83
+ },
84
+ compoundVariants: [{
85
+ variant: "drawer",
86
+ position: "left",
87
+ css: {
88
+ content: {
89
+ minHeight: "100%",
90
+ maxHeight: "100%",
91
+ width: "var(--size)",
92
+ _open: {
93
+ animation: "drawer-in-left"
94
+ },
95
+ _closed: {
96
+ animation: "drawer-out-left"
97
+ }
98
+ }
99
+ }
100
+ }, {
101
+ variant: "drawer",
102
+ position: "right",
103
+ css: {
104
+ content: {
105
+ minHeight: "100%",
106
+ maxHeight: "100%",
107
+ width: "var(--size)",
108
+ _open: {
109
+ animation: "drawer-in-right"
110
+ },
111
+ _closed: {
112
+ animation: "drawer-out-right"
113
+ }
114
+ }
115
+ }
116
+ }, {
117
+ variant: "drawer",
118
+ position: "top",
119
+ css: {
120
+ content: {
121
+ minWidth: "100%",
122
+ maxWidth: "100%",
123
+ height: "var(--size)",
124
+ _open: {
125
+ animation: "drawer-in-top"
126
+ },
127
+ _closed: {
128
+ animation: "drawer-out-top"
129
+ }
130
+ }
131
+ }
132
+ }, {
133
+ variant: "drawer",
134
+ position: "bottom",
135
+ css: {
136
+ content: {
137
+ minWidth: "100%",
138
+ maxWidth: "100%",
139
+ height: "var(--size)",
140
+ _open: {
141
+ animation: "drawer-in-bottom"
142
+ },
143
+ _closed: {
144
+ animation: "drawer-out-bottom"
145
+ }
146
+ }
147
+ }
148
+ }, {
149
+ variant: "drawer",
150
+ size: "xsmall",
151
+ css: {
152
+ content: {
153
+ "--size": "sizes.surface.3xsmall"
154
+ }
155
+ }
156
+ }, {
157
+ variant: "drawer",
158
+ size: "small",
159
+ css: {
160
+ content: {
161
+ "--size": "sizes.surface.xsmall"
162
+ }
163
+ }
164
+ }, {
165
+ variant: "drawer",
166
+ size: "medium",
167
+ css: {
168
+ content: {
169
+ "--size": "sizes.surface.medium"
170
+ }
171
+ }
172
+ }, {
173
+ variant: "drawer",
174
+ size: "large",
175
+ css: {
176
+ content: {
177
+ "--size": "sizes.surface.xlarge"
178
+ }
179
+ }
180
+ }],
181
+ variants: {
182
+ variant: {
183
+ drawer: {
184
+ content: {
185
+ "--margin": "0px",
186
+ borderRadius: {
187
+ base: "sharp",
188
+ tablet: "sharp"
189
+ }
190
+ }
191
+ },
192
+ dialog: {
193
+ content: {
194
+ width: "var(--size)",
195
+ _open: {
196
+ animation: "dialog-in"
197
+ },
198
+ _closed: {
199
+ animation: "dialog-out"
200
+ }
201
+ }
202
+ }
203
+ },
204
+ position: {
205
+ left: {
206
+ content: {
207
+ marginInlineStart: "min(var(--margin), 5%)"
208
+ }
209
+ },
210
+ center: {},
211
+ right: {
212
+ content: {
213
+ marginInlineEnd: "var(--margin)"
214
+ }
215
+ },
216
+ bottom: {
217
+ content: {
218
+ marginBlockEnd: "var(--margin)"
219
+ }
220
+ },
221
+ top: {
222
+ content: {
223
+ marginBlockStart: "var(--margin)"
224
+ }
225
+ }
226
+ },
227
+ size: {
228
+ full: {
229
+ content: {
230
+ "--margin": "0px",
231
+ minHeight: "100%",
232
+ minWidth: "100%",
233
+ borderRadius: "sharp"
234
+ }
235
+ },
236
+ xsmall: {
237
+ content: {
238
+ "--size": "sizes.surface.xsmall"
239
+ }
240
+ },
241
+ small: {
242
+ content: {
243
+ "--size": "sizes.surface.medium"
244
+ }
245
+ },
246
+ medium: {
247
+ content: {
248
+ "--size": "sizes.surface.xlarge"
249
+ }
250
+ },
251
+ large: {
252
+ content: {
253
+ "--size": "sizes.surface.4xlarge"
254
+ }
255
+ }
256
+ }
257
+ }
258
+ });
259
+ const {
260
+ withRootProvider,
261
+ withContext
262
+ } = (0, _createStyleContext.createStyleContext)(dialogRecipe);
263
+ const InternalDialogRoot = exports.InternalDialogRoot = withRootProvider(_react2.Dialog.Root);
264
+ const DialogRoot = _ref => {
265
+ let {
266
+ lazyMount = true,
267
+ unmountOnExit = true,
268
+ ...props
269
+ } = _ref;
270
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(InternalDialogRoot, {
271
+ lazyMount: lazyMount,
272
+ unmountOnExit: unmountOnExit,
273
+ ...props
274
+ });
275
+ };
276
+ exports.DialogRoot = DialogRoot;
277
+ const DialogBackdrop = exports.DialogBackdrop = withContext(_react2.Dialog.Backdrop, "backdrop");
278
+ const DialogStandaloneContent = exports.DialogStandaloneContent = withContext(_react2.Dialog.Content, "content");
279
+ const DialogPositioner = exports.DialogPositioner = withContext(_react2.Dialog.Positioner, "positioner");
280
+ const DialogContent = exports.DialogContent = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
281
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DialogBackdrop, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DialogPositioner, {
282
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DialogStandaloneContent, {
283
+ ref: ref,
284
+ ...props
285
+ })
286
+ })]
287
+ }));
288
+ const DialogDescription = _ref2 => {
289
+ let {
290
+ textStyle = "body.large",
291
+ ...rest
292
+ } = _ref2;
293
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Dialog.Description, {
294
+ asChild: true,
295
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Text, {
296
+ as: "p",
297
+ textStyle: textStyle,
298
+ ...rest
299
+ })
300
+ });
301
+ };
302
+ exports.DialogDescription = DialogDescription;
303
+ const DialogTitle = _ref3 => {
304
+ let {
305
+ textStyle = "title.medium",
306
+ ...rest
307
+ } = _ref3;
308
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Dialog.Title, {
309
+ asChild: true,
310
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Heading, {
311
+ as: "h1",
312
+ textStyle: textStyle,
313
+ ...rest
314
+ })
315
+ });
316
+ };
317
+ exports.DialogTitle = DialogTitle;
318
+ const DialogTrigger = exports.DialogTrigger = _react2.Dialog.Trigger;
319
+ const DialogCloseTrigger = exports.DialogCloseTrigger = _react2.Dialog.CloseTrigger;
320
+ const DialogHeader = exports.DialogHeader = (0, _jsx2.styled)("div", {
321
+ base: {
322
+ display: "flex",
323
+ paddingInline: "medium",
324
+ paddingBlockStart: "medium",
325
+ justifyContent: "space-between",
326
+ gap: "xsmall"
327
+ }
328
+ });
329
+ const DialogBody = exports.DialogBody = (0, _jsx2.styled)("div", {
330
+ base: {
331
+ display: "flex",
332
+ flexDirection: "column",
333
+ gap: "xsmall",
334
+ paddingInline: "medium",
335
+ paddingBlockStart: "small",
336
+ paddingBlockEnd: "medium"
337
+ }
338
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2024-present, NDLA.
3
+ *
4
+ * This source code is licensed under the GPLv3 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { ComponentPropsWithoutRef } from "react";
9
+ export type ExpandableBoxProps = ComponentPropsWithoutRef<"details">;
10
+ export declare const ExpandableBox: (props: ExpandableBoxProps) => import("@emotion/react/jsx-runtime").JSX.Element;
11
+ export type ExpandableBoxSummaryProps = ComponentPropsWithoutRef<"summary">;
12
+ export declare const ExpandableBoxSummary: ({ children, ...rest }: ExpandableBoxSummaryProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ExpandableBoxSummary = exports.ExpandableBox = void 0;
7
+ var _jsx2 = require("@ndla/styled-system/jsx");
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ /**
10
+ * Copyright (c) 2024-present, NDLA.
11
+ *
12
+ * This source code is licensed under the GPLv3 license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
15
+ */
16
+
17
+ const StyledExpandableBox = (0, _jsx2.styled)("details", {
18
+ base: {
19
+ transitionDuration: "fast",
20
+ width: "100%",
21
+ position: "relative",
22
+ border: "1px solid",
23
+ borderRadius: "xsmall",
24
+ borderColor: "stroke.subtle",
25
+ padding: "medium",
26
+ _open: {
27
+ padding: "medium",
28
+ "& summary": {
29
+ marginBlockEnd: "-xxsmall"
30
+ }
31
+ }
32
+ }
33
+ });
34
+ const ExpandableBox = props => /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledExpandableBox, {
35
+ ...props
36
+ });
37
+ exports.ExpandableBox = ExpandableBox;
38
+ const StyledExpandableBoxSummary = (0, _jsx2.styled)("summary", {
39
+ base: {
40
+ cursor: "pointer",
41
+ margin: "-medium",
42
+ padding: "medium",
43
+ textStyle: "label.large!",
44
+ _hover: {
45
+ color: "text.action"
46
+ },
47
+ "& > *": {
48
+ display: "inline!",
49
+ textStyle: "label.large!"
50
+ }
51
+ }
52
+ });
53
+ const ExpandableBoxSummary = _ref => {
54
+ let {
55
+ children,
56
+ ...rest
57
+ } = _ref;
58
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledExpandableBoxSummary, {
59
+ ...rest,
60
+ children: children
61
+ });
62
+ };
63
+ exports.ExpandableBoxSummary = ExpandableBoxSummary;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2024-present, NDLA.
3
+ *
4
+ * This source code is licensed under the GPLv3 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { TextProps } from "./Text";
9
+ export declare const FieldErrorMessage: import("react").ForwardRefExoticComponent<Omit<TextProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
10
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
11
+ }, "ref"> & import("react").RefAttributes<HTMLSpanElement>>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FieldErrorMessage = void 0;
7
+ var _react = require("react");
8
+ var _css = require("@ndla/styled-system/css");
9
+ var _jsx2 = require("@ndla/styled-system/jsx");
10
+ var _FormControl = require("./FormControl");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ /**
13
+ * Copyright (c) 2024-present, NDLA.
14
+ *
15
+ * This source code is licensed under the GPLv3 license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+
20
+ const StyledErrorMessage = (0, _jsx2.styled)("div", {
21
+ base: {
22
+ color: "text.error",
23
+ whiteSpace: "pre-line"
24
+ }
25
+ });
26
+ const FieldErrorMessage = exports.FieldErrorMessage = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
27
+ var _field$getErrorMessag;
28
+ let {
29
+ textStyle = "label.small",
30
+ fontWeight,
31
+ color,
32
+ srOnly,
33
+ className,
34
+ ...props
35
+ } = _ref;
36
+ const field = (0, _FormControl.useFormControlContext)();
37
+ if (field && !field.isInvalid) return null;
38
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledErrorMessage, {
39
+ ...((_field$getErrorMessag = field === null || field === void 0 ? void 0 : field.getErrorMessageProps(props, ref)) !== null && _field$getErrorMessag !== void 0 ? _field$getErrorMessag : {
40
+ ref,
41
+ ...props
42
+ }),
43
+ className: (0, _css.cx)((0, _css.css)({
44
+ textStyle,
45
+ fontWeight,
46
+ color,
47
+ srOnly: srOnly
48
+ }), className)
49
+ });
50
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2024-present, NDLA.
3
+ *
4
+ * This source code is licensed under the GPLv3 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { TextProps } from "./Text";
9
+ export declare const FieldHelper: import("react").ForwardRefExoticComponent<Omit<TextProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
10
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
11
+ }, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FieldHelper = void 0;
7
+ var _react = require("react");
8
+ var _css = require("@ndla/styled-system/css");
9
+ var _jsx2 = require("@ndla/styled-system/jsx");
10
+ var _FormControl = require("./FormControl");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ /**
13
+ * Copyright (c) 2024-present, NDLA.
14
+ *
15
+ * This source code is licensed under the GPLv3 license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+
20
+ const FieldHelper = exports.FieldHelper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
21
+ var _field$getHelpTextPro;
22
+ let {
23
+ textStyle = "label.small",
24
+ fontWeight,
25
+ color,
26
+ srOnly,
27
+ className,
28
+ ...props
29
+ } = _ref;
30
+ const field = (0, _FormControl.useFormControlContext)();
31
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsx2.styled.div, {
32
+ ...((_field$getHelpTextPro = field === null || field === void 0 ? void 0 : field.getHelpTextProps(props, ref)) !== null && _field$getHelpTextPro !== void 0 ? _field$getHelpTextPro : {
33
+ ref,
34
+ ...props
35
+ }),
36
+ className: (0, _css.cx)((0, _css.css)({
37
+ textStyle,
38
+ fontWeight,
39
+ color,
40
+ srOnly
41
+ }), className)
42
+ });
43
+ });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Copyright (c) 2024-present, NDLA.
3
+ *
4
+ * This source code is licensed under the GPLv3 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { ComponentPropsWithRef, ElementType, HTMLAttributes, Ref, RefObject } from "react";
9
+ type Merge<T, P> = P & Omit<T, keyof P>;
10
+ type PropGetter<T extends ElementType = ElementType, P = {}> = (props?: Merge<ComponentPropsWithRef<T>, P>, ref?: Ref<any> | RefObject<any>) => Merge<ComponentPropsWithRef<T>, P>;
11
+ export interface FormControlOptions {
12
+ isDisabled?: boolean;
13
+ isInvalid?: boolean;
14
+ isRequired?: boolean;
15
+ }
16
+ export interface FormControlProps extends FormControlOptions {
17
+ id: string;
18
+ }
19
+ /**
20
+ * Form control component inspired by chakra-ui. Allows for easy composition of form fields.
21
+ */
22
+ export declare const FormControl: ({ children, id, isDisabled, isInvalid, isRequired, ...rest }: HTMLAttributes<HTMLDivElement> & FormControlProps) => import("@emotion/react/jsx-runtime").JSX.Element;
23
+ export declare const useFormControlContext: () => {
24
+ isRequired: boolean;
25
+ isDisabled: boolean;
26
+ isInvalid: boolean;
27
+ hasErrorText: boolean;
28
+ setHasErrorText: import("react").Dispatch<import("react").SetStateAction<boolean>>;
29
+ hasHelpText: boolean;
30
+ setHasHelpText: import("react").Dispatch<import("react").SetStateAction<boolean>>;
31
+ id: string;
32
+ labelId: string;
33
+ errorTextId: string;
34
+ helpTextId: string;
35
+ getHelpTextProps: PropGetter<ElementType, {}>;
36
+ getErrorMessageProps: PropGetter<ElementType, {}>;
37
+ getLabelProps: PropGetter<ElementType, {}>;
38
+ } | undefined;
39
+ export interface UseFormControlProps extends FormControlOptions {
40
+ id?: string;
41
+ disabled?: boolean;
42
+ readOnly?: boolean;
43
+ required?: boolean;
44
+ "aria-describedby"?: string;
45
+ }
46
+ export declare const useFormControlProps: <T extends UseFormControlProps>({ id, disabled, required, isDisabled, isInvalid, isRequired, ...rest }: T) => Omit<T, "id" | "disabled" | "required" | "isRequired" | "isDisabled" | "isInvalid"> & {
47
+ "aria-describedby": string | undefined;
48
+ id: string | undefined;
49
+ isDisabled: boolean | undefined;
50
+ isRequired: boolean | undefined;
51
+ isInvalid: boolean | undefined;
52
+ };
53
+ export declare const useFormControl: <T extends UseFormControlProps>(props: T) => Omit<Omit<T, "id" | "disabled" | "required" | "isRequired" | "isDisabled" | "isInvalid"> & {
54
+ "aria-describedby": string | undefined;
55
+ id: string | undefined;
56
+ isDisabled: boolean | undefined;
57
+ isRequired: boolean | undefined;
58
+ isInvalid: boolean | undefined;
59
+ }, "isRequired" | "isDisabled" | "isInvalid"> & {
60
+ disabled: boolean | undefined;
61
+ required: boolean | undefined;
62
+ "aria-invalid": boolean | undefined;
63
+ "aria-required": boolean | undefined;
64
+ };
65
+ export {};