@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/es/Slider.js ADDED
@@ -0,0 +1,102 @@
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
+
9
+ import { sliderAnatomy } from "@ark-ui/anatomy";
10
+ import { Slider } from "@ark-ui/react";
11
+ import { sva } from "@ndla/styled-system/css";
12
+ import { createStyleContext } from "./createStyleContext";
13
+ import { Label } from "./Label";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ const sliderRecipe = sva({
16
+ slots: sliderAnatomy.keys(),
17
+ base: {
18
+ root: {
19
+ display: "flex",
20
+ flexDirection: "column",
21
+ gap: "4xsmall",
22
+ width: "100%"
23
+ },
24
+ control: {
25
+ position: "relative",
26
+ display: "flex",
27
+ _vertical: {
28
+ flexDirection: "column"
29
+ },
30
+ alignItems: "center",
31
+ height: "medium"
32
+ },
33
+ track: {
34
+ background: "surface.disabled",
35
+ overflow: "hidden",
36
+ flex: "1",
37
+ _vertical: {
38
+ width: "4xsmall"
39
+ },
40
+ _horizontal: {
41
+ height: "4xsmall"
42
+ }
43
+ },
44
+ range: {
45
+ background: "surface.action",
46
+ _vertical: {
47
+ width: "4xsmall"
48
+ },
49
+ _horizontal: {
50
+ height: "4xsmall"
51
+ }
52
+ },
53
+ thumb: {
54
+ background: "surface.action",
55
+ borderRadius: "full",
56
+ outline: "none",
57
+ zIndex: "1",
58
+ height: "medium",
59
+ width: "medium",
60
+ transitionDuration: "fast",
61
+ transitionTimingFunction: "default",
62
+ transitionProperty: "background",
63
+ _hover: {
64
+ background: "surface.action.hover"
65
+ },
66
+ _active: {
67
+ background: "surface.action.active"
68
+ },
69
+ _focusVisible: {
70
+ border: "2px solid",
71
+ borderColor: "background.default",
72
+ outline: "3px solid",
73
+ outlineColor: "surface.action",
74
+ outlineOffset: "0px"
75
+ }
76
+ }
77
+ }
78
+ });
79
+ const {
80
+ withProvider,
81
+ withContext
82
+ } = createStyleContext(sliderRecipe);
83
+ export const SliderRoot = withProvider(Slider.Root, "root");
84
+ export const SliderControl = withContext(Slider.Control, "control");
85
+ export const SliderTrack = withContext(Slider.Track, "track");
86
+ export const SliderRange = withContext(Slider.Range, "range");
87
+ export const SliderThumb = withContext(Slider.Thumb, "thumb");
88
+ const InternalSliderLabel = withContext(Slider.Label, "label");
89
+ export const SliderLabel = _ref => {
90
+ let {
91
+ textStyle = "label.medium",
92
+ ...props
93
+ } = _ref;
94
+ return /*#__PURE__*/_jsx(InternalSliderLabel, {
95
+ asChild: true,
96
+ children: /*#__PURE__*/_jsx(Label, {
97
+ textStyle: textStyle,
98
+ ...props
99
+ })
100
+ });
101
+ };
102
+ export const SliderHiddenInput = Slider.HiddenInput;
package/es/Spinner.js ADDED
@@ -0,0 +1,54 @@
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
+
9
+ import { cva, cx } from "@ndla/styled-system/css";
10
+ import { styled } from "@ndla/styled-system/jsx";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ export const spinnerRecipe = cva({
13
+ base: {
14
+ borderRadius: "full",
15
+ animation: "spin",
16
+ display: "block",
17
+ borderStyle: "solid",
18
+ borderBlockColor: "background.subtle",
19
+ borderInlineStartColor: "background.subtle",
20
+ borderInlineEndColor: "stroke.default",
21
+ marginBlock: "medium",
22
+ marginInline: "auto"
23
+ },
24
+ defaultVariants: {
25
+ size: "large"
26
+ },
27
+ variants: {
28
+ size: {
29
+ medium: {
30
+ borderWidth: "4px",
31
+ height: "large",
32
+ width: "large"
33
+ },
34
+ large: {
35
+ borderWidth: "8px",
36
+ height: "xxlarge",
37
+ width: "xxlarge"
38
+ }
39
+ }
40
+ }
41
+ });
42
+ export const Spinner = _ref => {
43
+ let {
44
+ size,
45
+ className,
46
+ ...props
47
+ } = _ref;
48
+ return /*#__PURE__*/_jsx(styled.div, {
49
+ className: cx(spinnerRecipe({
50
+ size
51
+ }), className),
52
+ ...props
53
+ });
54
+ };
package/es/Switch.js ADDED
@@ -0,0 +1,130 @@
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
+
9
+ import { forwardRef } from "react";
10
+ import { switchAnatomy } from "@ark-ui/anatomy";
11
+ import { Switch } from "@ark-ui/react";
12
+ import { sva } from "@ndla/styled-system/css";
13
+ import { createStyleContext } from "./createStyleContext";
14
+ import { useFormControl } from "./FormControl";
15
+ import { Text } from "./Text";
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ const switchRecipe = sva({
18
+ slots: switchAnatomy.keys(),
19
+ base: {
20
+ root: {
21
+ display: "inline-flex",
22
+ alignItems: "center",
23
+ position: "relative",
24
+ gap: "xxsmall",
25
+ _focus: {
26
+ outline: "2px solid",
27
+ outlineOffset: "4xsmall",
28
+ outlineColor: "stroke.default",
29
+ borderRadius: "xsmall"
30
+ }
31
+ },
32
+ control: {
33
+ display: "inline-flex",
34
+ alignItems: "center",
35
+ background: "surface.disabled.strong",
36
+ width: "xxlarge",
37
+ padding: "1",
38
+ borderRadius: "medium",
39
+ cursor: "pointer",
40
+ flexShrink: "0",
41
+ transitionDuration: "fast",
42
+ transitionProperty: "background",
43
+ transitionTimingFunction: "default",
44
+ _checked: {
45
+ background: "surface.action.active"
46
+ },
47
+ _disabled: {
48
+ background: "surface.disabled",
49
+ cursor: "not-allowed"
50
+ }
51
+ },
52
+ thumb: {
53
+ display: "inline-flex",
54
+ alignItems: "center",
55
+ justifyContent: "center",
56
+ background: "icon.onAction",
57
+ borderRadius: "full",
58
+ boxShadow: "xsmall",
59
+ transitionDuration: "fast",
60
+ transitionProperty: "transform",
61
+ transitionTimingFunction: "default",
62
+ width: "10",
63
+ height: "10",
64
+ textStyle: "label.xsmall",
65
+ fontWeight: "bold",
66
+ _hover: {
67
+ transform: "translateX(20%)",
68
+ _disabled: {
69
+ transform: "translateX(0)"
70
+ }
71
+ },
72
+ _checked: {
73
+ transform: "translateX(120%)",
74
+ _hover: {
75
+ transform: "translateX(100%)",
76
+ _disabled: {
77
+ transform: "translateX(120%)"
78
+ }
79
+ }
80
+ }
81
+ },
82
+ label: {
83
+ color: "text.strong",
84
+ transitionDuration: "fast",
85
+ transitionProperty: "color",
86
+ transitionTimingFunction: "default",
87
+ _hover: {
88
+ color: "text.action"
89
+ },
90
+ _disabled: {
91
+ color: "text.disabled",
92
+ _hover: {
93
+ color: "text.disabled"
94
+ }
95
+ }
96
+ }
97
+ }
98
+ });
99
+ const {
100
+ withProvider,
101
+ withContext
102
+ } = createStyleContext(switchRecipe);
103
+ export const InternalSwitchRoot = withProvider(Switch.Root, "root");
104
+ export const SwitchRoot = /*#__PURE__*/forwardRef((props, ref) => {
105
+ var _field$invalid;
106
+ const field = useFormControl(props);
107
+ return /*#__PURE__*/_jsx(InternalSwitchRoot, {
108
+ invalid: (_field$invalid = field.invalid) !== null && _field$invalid !== void 0 ? _field$invalid : !!field["aria-invalid"],
109
+ ...field,
110
+ ref: ref
111
+ });
112
+ });
113
+ export const SwitchControl = withContext(Switch.Control, "control");
114
+ export const SwitchThumb = withContext(Switch.Thumb, "thumb");
115
+ export const InternalSwitchLabel = withContext(Switch.Label, "label");
116
+ export const SwitchLabel = _ref => {
117
+ let {
118
+ textStyle = "label.medium",
119
+ ...props
120
+ } = _ref;
121
+ return /*#__PURE__*/_jsx(InternalSwitchLabel, {
122
+ asChild: true,
123
+ children: /*#__PURE__*/_jsx(Text, {
124
+ as: "span",
125
+ textStyle: textStyle,
126
+ ...props
127
+ })
128
+ });
129
+ };
130
+ export const SwitchHiddenInput = Switch.HiddenInput;
package/es/Table.js ADDED
@@ -0,0 +1,75 @@
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
+
9
+ import { styled } from "@ndla/styled-system/jsx";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ const StyledTable = styled("table", {
12
+ base: {
13
+ display: "block",
14
+ overflowX: "auto",
15
+ maxWidth: "100%",
16
+ padding: "4xsmall",
17
+ tableLayout: "fixed",
18
+ "& > caption": {
19
+ fontWeight: "bold",
20
+ textAlign: "left",
21
+ textTransform: "uppercase",
22
+ marginBlockEnd: "xsmall"
23
+ },
24
+ "& thead": {
25
+ overflow: "hidden"
26
+ },
27
+ "& thead tr th": {
28
+ fontWeight: "bold",
29
+ borderBottom: "3px solid",
30
+ borderColor: "surface.brand.1.strong",
31
+ verticalAlign: "text-top"
32
+ },
33
+ "& tbody th": {
34
+ borderRight: "3px solid",
35
+ borderColor: "surface.brand.1.strong",
36
+ padding: "3xsmall"
37
+ },
38
+ "& thead tr:nth-child(2) th": {
39
+ border: "1px solid",
40
+ borderColor: "surface.brand.1.subtle",
41
+ textTransform: "none",
42
+ fontWeight: "semibold",
43
+ height: "large",
44
+ backgroundColor: "surface.brand.1.subtle",
45
+ paddingBlock: "4xsmall",
46
+ paddingInlineEnd: "medium",
47
+ paddingInlineStart: "3xsmall",
48
+ _empty: {
49
+ backgroundColor: "transparent"
50
+ }
51
+ },
52
+ "& td": {
53
+ border: "1px solid",
54
+ borderColor: "surface.brand.1.subtle",
55
+ verticalAlign: "top"
56
+ },
57
+ "& td, & th": {
58
+ display: "table-cell",
59
+ paddingInline: "xsmall",
60
+ paddingBlock: "3xsmall",
61
+ "&[data-align='center']": {
62
+ textAlign: "center"
63
+ },
64
+ "&[data-align='left']": {
65
+ textAlign: "left"
66
+ },
67
+ "&[data-align='right']": {
68
+ textAlign: "right"
69
+ }
70
+ }
71
+ }
72
+ });
73
+ export const Table = props => /*#__PURE__*/_jsx(StyledTable, {
74
+ ...props
75
+ });
package/es/Text.js ADDED
@@ -0,0 +1,54 @@
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
+
9
+ import { css, cx } from "@ndla/styled-system/css";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ const BaseText = props => {
12
+ const {
13
+ as: As = "p",
14
+ className,
15
+ fontWeight,
16
+ color,
17
+ textStyle = "body.medium",
18
+ srOnly,
19
+ ...rest
20
+ } = props;
21
+ return /*#__PURE__*/_jsx(As, {
22
+ className: cx(css({
23
+ textStyle,
24
+ fontWeight,
25
+ color,
26
+ srOnly: srOnly
27
+ }), className),
28
+ ...rest
29
+ });
30
+ };
31
+ export const Heading = props => {
32
+ const {
33
+ as = "h1",
34
+ textStyle = "heading.medium",
35
+ ...rest
36
+ } = props;
37
+ return /*#__PURE__*/_jsx(BaseText, {
38
+ as: as,
39
+ textStyle: textStyle,
40
+ ...rest
41
+ });
42
+ };
43
+ export const Text = props => {
44
+ const {
45
+ as = "p",
46
+ textStyle = "body.medium",
47
+ ...rest
48
+ } = props;
49
+ return /*#__PURE__*/_jsx(BaseText, {
50
+ as: as,
51
+ textStyle: textStyle,
52
+ ...rest
53
+ });
54
+ };
package/es/Toast.js ADDED
@@ -0,0 +1,82 @@
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
+
9
+ import { toastAnatomy } from "@ark-ui/anatomy";
10
+ import { Toast } from "@ark-ui/react";
11
+ import { sva } from "@ndla/styled-system/css";
12
+ import { createStyleContext } from "./createStyleContext";
13
+ import { Text } from "./Text";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ const toastRecipe = sva({
16
+ slots: toastAnatomy.keys(),
17
+ base: {
18
+ root: {
19
+ position: "relative",
20
+ background: "surface.action",
21
+ color: "text.onAction",
22
+ borderRadius: "xsmall",
23
+ boxShadow: "medium",
24
+ minWidth: "20rem",
25
+ height: "var(--height)",
26
+ opacity: "var(--opacity)",
27
+ overflowWrap: "anywhere",
28
+ padding: "small",
29
+ scale: "var(--scale)",
30
+ translate: "var(--x) var(--y) 0",
31
+ willChange: "translate, scale, opacity, height",
32
+ zIndex: "var(--z-index)",
33
+ transitionDuration: "slow",
34
+ transitionProperty: "translate, scale, opacity, height",
35
+ transitionTimingFunction: "default"
36
+ },
37
+ closeTrigger: {
38
+ position: "absolute",
39
+ top: "xxsmall",
40
+ right: "xxsmall"
41
+ }
42
+ }
43
+ });
44
+ const {
45
+ withProvider,
46
+ withContext
47
+ } = createStyleContext(toastRecipe);
48
+ export const ToastRoot = withProvider(Toast.Root, "root");
49
+ export const ToastActionTrigger = withContext(Toast.ActionTrigger, "actionTrigger");
50
+ export const ToastCloseTrigger = withContext(Toast.CloseTrigger, "closeTrigger");
51
+ export const InternalToastDescription = withContext(Toast.Description, "description");
52
+ export const ToastDescription = _ref => {
53
+ let {
54
+ textStyle = "label.medium",
55
+ ...props
56
+ } = _ref;
57
+ return /*#__PURE__*/_jsx(InternalToastDescription, {
58
+ asChild: true,
59
+ children: /*#__PURE__*/_jsx(Text, {
60
+ as: "div",
61
+ textStyle: textStyle,
62
+ ...props
63
+ })
64
+ });
65
+ };
66
+ export const InternalToastTitle = withContext(Toast.Title, "title");
67
+ export const ToastTitle = _ref2 => {
68
+ let {
69
+ textStyle = "label.medium",
70
+ fontWeight = "semibold",
71
+ ...props
72
+ } = _ref2;
73
+ return /*#__PURE__*/_jsx(InternalToastTitle, {
74
+ asChild: true,
75
+ children: /*#__PURE__*/_jsx(Text, {
76
+ as: "div",
77
+ fontWeight: fontWeight,
78
+ textStyle: textStyle,
79
+ ...props
80
+ })
81
+ });
82
+ };
package/es/Tooltip.js ADDED
@@ -0,0 +1,59 @@
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
+
9
+ import { forwardRef } from "react";
10
+ import { tooltipAnatomy } from "@ark-ui/anatomy";
11
+ import { Tooltip } from "@ark-ui/react";
12
+ import { sva } from "@ndla/styled-system/css";
13
+ import { createStyleContext } from "./createStyleContext";
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
+ const tooltipRecipe = sva({
16
+ slots: tooltipAnatomy.keys(),
17
+ base: {
18
+ content: {
19
+ background: "surface.action",
20
+ textStyle: "label.small",
21
+ color: "text.onAction",
22
+ paddingInline: "xxsmall",
23
+ paddingBlock: "4xsmall",
24
+ "--arrow-size": "spacing.xxsmall",
25
+ "--arrow-background": "colors.surface.action",
26
+ _open: {
27
+ animation: "fade-shift-in 0.2s ease-out"
28
+ },
29
+ _closed: {
30
+ animation: "fade-shift-out 0.2s ease-out"
31
+ }
32
+ }
33
+ }
34
+ });
35
+ const {
36
+ withRootProvider,
37
+ withContext
38
+ } = createStyleContext(tooltipRecipe);
39
+ export const TooltipRoot = withRootProvider(Tooltip.Root);
40
+ export const TooltipArrow = withContext(Tooltip.Arrow, "arrow");
41
+ export const TooltipArrowTip = withContext(Tooltip.ArrowTip, "arrowTip");
42
+ export const TooltipContentStandalone = withContext(Tooltip.Content, "content");
43
+ export const TooltipContent = /*#__PURE__*/forwardRef((_ref, ref) => {
44
+ let {
45
+ children,
46
+ ...props
47
+ } = _ref;
48
+ return /*#__PURE__*/_jsx(TooltipPositioner, {
49
+ children: /*#__PURE__*/_jsxs(TooltipContentStandalone, {
50
+ ...props,
51
+ ref: ref,
52
+ children: [/*#__PURE__*/_jsx(TooltipArrow, {
53
+ children: /*#__PURE__*/_jsx(TooltipArrowTip, {})
54
+ }), children]
55
+ })
56
+ });
57
+ });
58
+ export const TooltipPositioner = withContext(Tooltip.Positioner, "positioner");
59
+ export const TooltipTrigger = withContext(Tooltip.Trigger, "trigger");
@@ -0,0 +1,62 @@
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
+
9
+ import { createContext, forwardRef, useContext } from "react";
10
+ import { cx } from "@ndla/styled-system/css";
11
+ import { styled } from "@ndla/styled-system/jsx";
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ /**
14
+ * A utility for creating a style context for a recipe, allowing one to change the styles of all parts of a component from the root component. Credit: https://github.com/cschroeter/park-ui/blob/main/website/src/lib/create-style-context.tsx.
15
+ */
16
+ export const createStyleContext = recipe => {
17
+ const StyleContext = /*#__PURE__*/createContext(null);
18
+ const withRootProvider = Component => {
19
+ const StyledComponent = props => {
20
+ const [variantProps, otherProps] = recipe.splitVariantProps(props);
21
+ const slotStyles = recipe(variantProps);
22
+ return /*#__PURE__*/_jsx(StyleContext.Provider, {
23
+ value: slotStyles,
24
+ children: /*#__PURE__*/_jsx(Component, {
25
+ ...otherProps
26
+ })
27
+ });
28
+ };
29
+ return StyledComponent;
30
+ };
31
+ const withProvider = (Component, slot) => {
32
+ const StyledComponent = styled(Component);
33
+ return /*#__PURE__*/forwardRef((props, ref) => {
34
+ const [variantProps, otherProps] = recipe.splitVariantProps(props);
35
+ const slotStyles = recipe(variantProps);
36
+ return /*#__PURE__*/_jsx(StyleContext.Provider, {
37
+ value: slotStyles,
38
+ children: /*#__PURE__*/_jsx(StyledComponent, {
39
+ ...otherProps,
40
+ ref: ref,
41
+ className: cx(slotStyles === null || slotStyles === void 0 ? void 0 : slotStyles[slot], props.className)
42
+ })
43
+ });
44
+ });
45
+ };
46
+ const withContext = (Component, slot) => {
47
+ const StyledComponent = styled(Component);
48
+ return /*#__PURE__*/forwardRef((props, ref) => {
49
+ const slotStyles = useContext(StyleContext);
50
+ return /*#__PURE__*/_jsx(StyledComponent, {
51
+ ...props,
52
+ ref: ref,
53
+ className: cx(slotStyles === null || slotStyles === void 0 ? void 0 : slotStyles[slot], props.className)
54
+ });
55
+ });
56
+ };
57
+ return {
58
+ withRootProvider,
59
+ withProvider,
60
+ withContext
61
+ };
62
+ };
package/es/index.js ADDED
@@ -0,0 +1,19 @@
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
+
9
+ export { BlockQuote } from "./BlockQuote";
10
+ export { Button, IconButton } from "./Button";
11
+ export { ExpandableBox, ExpandableBoxSummary } from "./ExpandableBox";
12
+ export { Input, InputContainer, TextArea } from "./Input";
13
+ export { OrderedList, UnOrderedList } from "./ArticleLists";
14
+ export { Icon } from "./Icon";
15
+ export { NdlaLogoEn, NdlaLogoNb, NdlaLogoText } from "./NdlaLogo";
16
+ export { Spinner } from "./Spinner";
17
+ export { Table } from "./Table";
18
+ export { Text, Heading } from "./Text";
19
+ export { MessageBox } from "./MessageBox";
@@ -0,0 +1,17 @@
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 type { Assign } from "@ark-ui/react";
9
+ import { Accordion } from "@ark-ui/react";
10
+ import { SystemProperties } from "@ndla/styled-system/types";
11
+ export interface AccordionRootProps extends Assign<SystemProperties, Accordion.RootProps> {
12
+ }
13
+ export declare const AccordionRoot: import("react").ForwardRefExoticComponent<AccordionRootProps & import("react").RefAttributes<HTMLDivElement>>;
14
+ export declare const AccordionItemContent: import("react").ForwardRefExoticComponent<Omit<SystemProperties, keyof Accordion.ItemContentProps> & Accordion.ItemContentProps & import("react").RefAttributes<HTMLDivElement>>;
15
+ export declare const AccordionItemIndicator: import("react").ForwardRefExoticComponent<Omit<SystemProperties, keyof Accordion.ItemIndicatorProps> & Accordion.ItemIndicatorProps & import("react").RefAttributes<HTMLDivElement>>;
16
+ export declare const AccordionItem: import("react").ForwardRefExoticComponent<Omit<SystemProperties, keyof Accordion.ItemProps> & Accordion.ItemProps & import("react").RefAttributes<HTMLDivElement>>;
17
+ export declare const AccordionItemTrigger: import("react").ForwardRefExoticComponent<Omit<SystemProperties, keyof Accordion.ItemTriggerProps> & Accordion.ItemTriggerProps & import("react").RefAttributes<HTMLButtonElement>>;