@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/Button.js ADDED
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.iconButtonRecipe = exports.buttonRecipe = exports.buttonBaseRecipe = exports.IconButton = exports.Button = 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 _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * Copyright (c) 2024-present, NDLA.
13
+ *
14
+ * This source code is licensed under the GPLv3 license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ */
18
+
19
+ const buttonBaseRecipe = exports.buttonBaseRecipe = (0, _css.cva)({
20
+ base: {
21
+ display: "inline-flex",
22
+ alignItems: "center",
23
+ justifyContent: "center",
24
+ gap: "xsmall",
25
+ cursor: "pointer",
26
+ textDecoration: "none",
27
+ textStyle: "label.medium",
28
+ fontWeight: "bold",
29
+ transitionProperty: "all",
30
+ transitionDuration: "fast",
31
+ transitionTimingFunction: "default",
32
+ textAlign: "center",
33
+ borderRadius: "xsmall",
34
+ outline: "none",
35
+ boxShadowColor: "stroke.default",
36
+ _disabled: {
37
+ cursor: "not-allowed",
38
+ color: "text.onAction",
39
+ background: "surface.disabled",
40
+ _hover: {
41
+ color: "text.onAction",
42
+ background: "surface.disabled"
43
+ }
44
+ },
45
+ _focusVisible: {
46
+ boxShadow: "inset 0 0 0 3px var(--shadow-color)"
47
+ }
48
+ },
49
+ defaultVariants: {
50
+ variant: "primary"
51
+ },
52
+ variants: {
53
+ variant: {
54
+ primary: {
55
+ color: "text.onAction",
56
+ background: "surface.action",
57
+ _hover: {
58
+ color: "text.onAction",
59
+ background: "surface.action.hover"
60
+ },
61
+ _active: {
62
+ color: "text.onAction",
63
+ background: "surface.action.active"
64
+ },
65
+ _focusVisible: {
66
+ boxShadow: "inset 0 0 0 3px var(--shadow-color), inset 0px 0px 0px 6px currentcolor"
67
+ }
68
+ },
69
+ secondary: {
70
+ color: "text.strong",
71
+ background: "transparent",
72
+ boxShadow: "inset 0 0 0 1px var(--shadow-color)",
73
+ _hover: {
74
+ background: "surface.actionSubtle.hover"
75
+ },
76
+ _active: {
77
+ background: "surface.actionSubtle.active"
78
+ }
79
+ },
80
+ tertiary: {
81
+ color: "text.strong",
82
+ background: "transparent",
83
+ _hover: {
84
+ boxShadow: "inset 0 0 0 1px var(--shadow-color)",
85
+ background: "surface.actionSubtle.hover",
86
+ _focusVisible: {
87
+ boxShadow: "inset 0 0 0 3px var(--shadow-color)"
88
+ }
89
+ },
90
+ _active: {
91
+ borderColor: "stroke.default",
92
+ background: "surface.actionSubtle.active"
93
+ }
94
+ },
95
+ clear: {
96
+ background: "transparent",
97
+ color: "text.strong",
98
+ _hover: {
99
+ color: "stroke.hover"
100
+ }
101
+ },
102
+ clearSubtle: {
103
+ background: "transparent",
104
+ color: "text.onAction",
105
+ _hover: {
106
+ color: "surface.actionSubtle.hover.strong"
107
+ }
108
+ },
109
+ danger: {
110
+ background: "surface.error",
111
+ color: "text.onAction",
112
+ _hover: {
113
+ background: "surface.error.hover"
114
+ },
115
+ _active: {
116
+ background: "surface.error.active"
117
+ },
118
+ _focusVisible: {
119
+ boxShadowColor: "surface.error",
120
+ boxShadow: "inset 0 0 0 3px var(--shadow-color), inset 0px 0px 0px 6px currentcolor"
121
+ }
122
+ },
123
+ success: {
124
+ background: "surface.success",
125
+ color: "text.onAction",
126
+ _hover: {
127
+ background: "surface.success.hover"
128
+ },
129
+ _active: {
130
+ background: "surface.success.active"
131
+ },
132
+ _focusVisible: {
133
+ boxShadowColor: "surface.success",
134
+ boxShadow: "inset 0 0 0 3px var(--shadow-color), inset 0px 0px 0px 6px currentcolor"
135
+ }
136
+ },
137
+ link: {
138
+ background: "transparent",
139
+ color: "text.link",
140
+ textDecoration: "underline",
141
+ textDecorationThickness: "1px",
142
+ _hover: {
143
+ textDecoration: "none"
144
+ }
145
+ }
146
+ }
147
+ }
148
+ });
149
+ const buttonRecipe = exports.buttonRecipe = (0, _css.cva)({
150
+ defaultVariants: {
151
+ size: "default"
152
+ },
153
+ variants: {
154
+ size: {
155
+ default: {
156
+ paddingInline: "medium",
157
+ paddingBlock: "xxsmall",
158
+ minHeight: "24"
159
+ },
160
+ small: {
161
+ textStyle: "label.small",
162
+ minHeight: "19",
163
+ paddingInline: "small",
164
+ paddingBlock: "3xsmall"
165
+ }
166
+ }
167
+ }
168
+ });
169
+ const Button = exports.Button = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
170
+ let {
171
+ type,
172
+ size,
173
+ className,
174
+ variant,
175
+ ...rest
176
+ } = _ref;
177
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsx2.styled.button, {
178
+ type: type !== null && type !== void 0 ? type : "button",
179
+ className: (0, _css.cx)((0, _css.css)(buttonBaseRecipe.raw({
180
+ variant
181
+ }), buttonRecipe.raw({
182
+ size
183
+ })), className),
184
+ ...rest,
185
+ ref: ref
186
+ });
187
+ });
188
+ const IconButton = exports.IconButton = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
189
+ let {
190
+ type,
191
+ className,
192
+ variant,
193
+ ...rest
194
+ } = _ref2;
195
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsx2.styled.button, {
196
+ type: type !== null && type !== void 0 ? type : "button",
197
+ className: (0, _css.cx)((0, _css.css)(buttonBaseRecipe.raw({
198
+ variant
199
+ }), iconButtonRecipe.raw()), className),
200
+ ...rest,
201
+ ref: ref
202
+ });
203
+ });
204
+ const iconButtonRecipe = exports.iconButtonRecipe = (0, _css.cva)({
205
+ base: {
206
+ lineHeight: "1",
207
+ minHeight: "unset",
208
+ "& svg": {
209
+ marginInline: "0",
210
+ marginBlock: "0",
211
+ width: "medium",
212
+ height: "medium"
213
+ },
214
+ paddingInline: "xsmall",
215
+ paddingBlock: "xsmall"
216
+ }
217
+ });
@@ -0,0 +1,15 @@
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 { Checkbox } from "@ark-ui/react";
9
+ import { TextProps } from "./Text";
10
+ export type CheckboxRootProps = Checkbox.RootProps;
11
+ export declare const CheckboxRoot: import("react").ForwardRefExoticComponent<Checkbox.RootProps & import("react").RefAttributes<HTMLLabelElement>>;
12
+ export declare const CheckboxIndicator: import("react").ForwardRefExoticComponent<Checkbox.IndicatorProps & import("react").RefAttributes<HTMLDivElement>>;
13
+ export declare const CheckboxLabel: ({ textStyle, children, ...props }: Checkbox.LabelProps & TextProps) => import("@emotion/react/jsx-runtime").JSX.Element;
14
+ export declare const CheckboxControl: import("react").ForwardRefExoticComponent<Checkbox.ControlProps & import("react").RefAttributes<HTMLDivElement>>;
15
+ export declare const CheckboxHiddenInput: import("react").ForwardRefExoticComponent<Checkbox.HiddenInputProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CheckboxRoot = exports.CheckboxLabel = exports.CheckboxIndicator = exports.CheckboxHiddenInput = exports.CheckboxControl = void 0;
7
+ var _react = require("react");
8
+ var _anatomy = require("@ark-ui/anatomy");
9
+ var _react2 = require("@ark-ui/react");
10
+ var _css = require("@ndla/styled-system/css");
11
+ var _createStyleContext = require("./createStyleContext");
12
+ var _FormControl = require("./FormControl");
13
+ var _Text = require("./Text");
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ /**
16
+ * Copyright (c) 2024-present, NDLA.
17
+ *
18
+ * This source code is licensed under the GPLv3 license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ *
21
+ */
22
+
23
+ const checkboxRecipe = (0, _css.sva)({
24
+ slots: _anatomy.checkboxAnatomy.keys(),
25
+ base: {
26
+ root: {
27
+ userSelect: "none",
28
+ display: "flex",
29
+ alignItems: "center",
30
+ cursor: "pointer",
31
+ gap: "xxsmall",
32
+ _disabled: {
33
+ color: "text.disabled",
34
+ cursor: "not-allowed"
35
+ },
36
+ _hover: {
37
+ color: "text.action"
38
+ },
39
+ _focus: {
40
+ outline: "2px solid",
41
+ outlineOffset: "4xsmall",
42
+ outlineColor: "stroke.default",
43
+ borderRadius: "xsmall"
44
+ }
45
+ },
46
+ control: {
47
+ display: "flex",
48
+ alignItems: "center",
49
+ justifyContent: "center",
50
+ cursor: "pointer",
51
+ width: "medium",
52
+ height: "medium",
53
+ background: "surface.default",
54
+ borderRadius: "xsmall",
55
+ border: "2px solid",
56
+ borderColor: "stroke.subtle",
57
+ color: "text.strong",
58
+ transitionDuration: "normal",
59
+ transitionProperty: "border-color, background, box-shadow, color",
60
+ transitionTimingFunction: "default",
61
+ _hover: {
62
+ boxShadow: "0 0 0 4px var(--shadow-color)",
63
+ boxShadowColor: "surface.actionSubtle.hover.strong"
64
+ },
65
+ _checked: {
66
+ color: "icon.onAction",
67
+ backgroundColor: "surface.action",
68
+ borderColor: "surface.action"
69
+ },
70
+ _disabled: {
71
+ borderColor: "stroke.disabled",
72
+ _hover: {
73
+ borderColor: "stroke.disabled",
74
+ boxShadow: "none"
75
+ },
76
+ _checked: {
77
+ background: "surface.disabled"
78
+ }
79
+ },
80
+ _invalid: {
81
+ borderColor: "stroke.error",
82
+ _checked: {
83
+ color: "stroke.error",
84
+ borderColor: "stroke.error",
85
+ backgroundColor: "surface.default"
86
+ }
87
+ }
88
+ }
89
+ }
90
+ });
91
+ const {
92
+ withProvider,
93
+ withContext
94
+ } = (0, _createStyleContext.createStyleContext)(checkboxRecipe);
95
+ const InternalCheckboxRoot = withProvider(_react2.Checkbox.Root, "root");
96
+ const CheckboxRoot = exports.CheckboxRoot = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
97
+ var _field$invalid;
98
+ const field = (0, _FormControl.useFormControl)(props);
99
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(InternalCheckboxRoot, {
100
+ ...field,
101
+ invalid: (_field$invalid = field.invalid) !== null && _field$invalid !== void 0 ? _field$invalid : !!field["aria-invalid"],
102
+ ref: ref,
103
+ "aria-invalid": undefined
104
+ });
105
+ });
106
+ const CheckboxIndicator = exports.CheckboxIndicator = withContext(_react2.Checkbox.Indicator, "indicator");
107
+ const InternalCheckboxLabel = withContext(_react2.Checkbox.Label, "label");
108
+ const CheckboxLabel = _ref => {
109
+ let {
110
+ textStyle = "label.medium",
111
+ children,
112
+ ...props
113
+ } = _ref;
114
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(InternalCheckboxLabel, {
115
+ ...props,
116
+ asChild: true,
117
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Text, {
118
+ textStyle: textStyle,
119
+ children: children
120
+ })
121
+ });
122
+ };
123
+ exports.CheckboxLabel = CheckboxLabel;
124
+ const CheckboxControl = exports.CheckboxControl = withContext(_react2.Checkbox.Control, "control");
125
+ const CheckboxHiddenInput = exports.CheckboxHiddenInput = _react2.Checkbox.HiddenInput;
@@ -0,0 +1,107 @@
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 { Dialog } from "@ark-ui/react";
9
+ import { RecipeVariantProps } from "@ndla/styled-system/css";
10
+ import { SystemProperties } from "@ndla/styled-system/types";
11
+ import { TextProps } from "./Text";
12
+ declare const dialogRecipe: import("@ndla/styled-system/types").SlotRecipeRuntimeFn<"content" | "positioner" | "backdrop", {
13
+ variant: {
14
+ drawer: {
15
+ content: {
16
+ "--margin": "0px";
17
+ borderRadius: {
18
+ base: "sharp";
19
+ tablet: "sharp";
20
+ };
21
+ };
22
+ };
23
+ dialog: {
24
+ content: {
25
+ width: "var(--size)";
26
+ _open: {
27
+ animation: "dialog-in";
28
+ };
29
+ _closed: {
30
+ animation: "dialog-out";
31
+ };
32
+ };
33
+ };
34
+ };
35
+ position: {
36
+ left: {
37
+ content: {
38
+ marginInlineStart: "min(var(--margin), 5%)";
39
+ };
40
+ };
41
+ center: {};
42
+ right: {
43
+ content: {
44
+ marginInlineEnd: "var(--margin)";
45
+ };
46
+ };
47
+ bottom: {
48
+ content: {
49
+ marginBlockEnd: "var(--margin)";
50
+ };
51
+ };
52
+ top: {
53
+ content: {
54
+ marginBlockStart: "var(--margin)";
55
+ };
56
+ };
57
+ };
58
+ size: {
59
+ full: {
60
+ content: {
61
+ "--margin": "0px";
62
+ minHeight: "100%";
63
+ minWidth: "100%";
64
+ borderRadius: "sharp";
65
+ };
66
+ };
67
+ xsmall: {
68
+ content: {
69
+ "--size": "sizes.surface.xsmall";
70
+ };
71
+ };
72
+ small: {
73
+ content: {
74
+ "--size": "sizes.surface.medium";
75
+ };
76
+ };
77
+ medium: {
78
+ content: {
79
+ "--size": "sizes.surface.xlarge";
80
+ };
81
+ };
82
+ large: {
83
+ content: {
84
+ "--size": "sizes.surface.4xlarge";
85
+ };
86
+ };
87
+ };
88
+ }>;
89
+ export type DialogVariantProps = RecipeVariantProps<typeof dialogRecipe>;
90
+ export type DialogRootProps = Dialog.RootProps & DialogVariantProps;
91
+ export declare const InternalDialogRoot: (props: Dialog.RootProps & {
92
+ variant?: "dialog" | "drawer" | undefined;
93
+ position?: "center" | "bottom" | "left" | "right" | "top" | undefined;
94
+ size?: "small" | "xsmall" | "medium" | "large" | "full" | undefined;
95
+ }) => import("@emotion/react/jsx-runtime").JSX.Element;
96
+ export declare const DialogRoot: ({ lazyMount, unmountOnExit, ...props }: DialogRootProps) => import("@emotion/react/jsx-runtime").JSX.Element;
97
+ export declare const DialogBackdrop: import("react").ForwardRefExoticComponent<Omit<SystemProperties, keyof Dialog.BackdropProps> & Dialog.BackdropProps & import("react").RefAttributes<HTMLDivElement>>;
98
+ export declare const DialogStandaloneContent: import("react").ForwardRefExoticComponent<Omit<SystemProperties, keyof Dialog.ContentProps> & Dialog.ContentProps & import("react").RefAttributes<HTMLDivElement>>;
99
+ export declare const DialogPositioner: import("react").ForwardRefExoticComponent<Omit<SystemProperties, keyof Dialog.PositionerProps> & Dialog.PositionerProps & import("react").RefAttributes<HTMLDivElement>>;
100
+ export declare const DialogContent: import("react").ForwardRefExoticComponent<Omit<Omit<SystemProperties, keyof Dialog.ContentProps> & Dialog.ContentProps & import("react").RefAttributes<HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
101
+ export declare const DialogDescription: ({ textStyle, ...rest }: Dialog.DescriptionProps & TextProps) => import("@emotion/react/jsx-runtime").JSX.Element;
102
+ export declare const DialogTitle: ({ textStyle, ...rest }: Dialog.TitleProps & TextProps) => import("@emotion/react/jsx-runtime").JSX.Element;
103
+ export declare const DialogTrigger: import("react").ForwardRefExoticComponent<Dialog.TriggerProps & import("react").RefAttributes<HTMLButtonElement>>;
104
+ export declare const DialogCloseTrigger: import("react").ForwardRefExoticComponent<Dialog.CloseTriggerProps & import("react").RefAttributes<HTMLButtonElement>>;
105
+ export declare const DialogHeader: import("@ndla/styled-system/jsx").StyledComponent<"div", {}>;
106
+ export declare const DialogBody: import("@ndla/styled-system/jsx").StyledComponent<"div", {}>;
107
+ export {};