@postenbring/hedwig-react 0.0.64 → 0.0.66

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 (208) hide show
  1. package/dist/_tsup-dts-rollup.d.mts +301 -68
  2. package/dist/_tsup-dts-rollup.d.ts +301 -68
  3. package/dist/accordion/accordion-content.js +5 -9
  4. package/dist/accordion/accordion-content.js.map +1 -1
  5. package/dist/accordion/accordion-content.mjs +1 -1
  6. package/dist/accordion/accordion-header.js +6 -9
  7. package/dist/accordion/accordion-header.js.map +1 -1
  8. package/dist/accordion/accordion-header.mjs +1 -1
  9. package/dist/accordion/accordion-item.js +2 -7
  10. package/dist/accordion/accordion-item.js.map +1 -1
  11. package/dist/accordion/accordion-item.mjs +1 -1
  12. package/dist/accordion/index.js +13 -25
  13. package/dist/accordion/index.js.map +1 -1
  14. package/dist/accordion/index.mjs +4 -4
  15. package/dist/chunk-27XJO7E4.mjs +51 -0
  16. package/dist/chunk-27XJO7E4.mjs.map +1 -0
  17. package/dist/{chunk-POJTVNEO.mjs → chunk-2ICZ3Q7N.mjs} +1 -1
  18. package/dist/chunk-2ICZ3Q7N.mjs.map +1 -0
  19. package/dist/{chunk-H3VGHTDC.mjs → chunk-2JH4FG63.mjs} +2 -2
  20. package/dist/chunk-2JH4FG63.mjs.map +1 -0
  21. package/dist/{chunk-SAGJ5W7M.mjs → chunk-62F4I3MQ.mjs} +3 -8
  22. package/dist/{chunk-SAGJ5W7M.mjs.map → chunk-62F4I3MQ.mjs.map} +1 -1
  23. package/dist/{chunk-V4NGUB4I.mjs → chunk-6NGF7FFY.mjs} +2 -2
  24. package/dist/chunk-6NGF7FFY.mjs.map +1 -0
  25. package/dist/{chunk-BYDSISQZ.mjs → chunk-A47QULAK.mjs} +2 -2
  26. package/dist/{chunk-BYDSISQZ.mjs.map → chunk-A47QULAK.mjs.map} +1 -1
  27. package/dist/chunk-BZRCDLEW.mjs +118 -0
  28. package/dist/chunk-BZRCDLEW.mjs.map +1 -0
  29. package/dist/chunk-CLXHNRAI.mjs +104 -0
  30. package/dist/chunk-CLXHNRAI.mjs.map +1 -0
  31. package/dist/{chunk-37WVYY6X.mjs → chunk-DM4PJFLG.mjs} +6 -3
  32. package/dist/chunk-DM4PJFLG.mjs.map +1 -0
  33. package/dist/{chunk-KRGKVH5J.mjs → chunk-GUB3UCXO.mjs} +6 -10
  34. package/dist/chunk-GUB3UCXO.mjs.map +1 -0
  35. package/dist/{chunk-WGVZWX5L.mjs → chunk-HMB4TY2F.mjs} +14 -4
  36. package/dist/chunk-HMB4TY2F.mjs.map +1 -0
  37. package/dist/{chunk-5MDJP43L.mjs → chunk-IFGQR4J6.mjs} +10 -10
  38. package/dist/chunk-IFGQR4J6.mjs.map +1 -0
  39. package/dist/chunk-KQITCS3U.mjs +18 -0
  40. package/dist/chunk-KQITCS3U.mjs.map +1 -0
  41. package/dist/chunk-L4GQJETB.mjs +1 -0
  42. package/dist/{chunk-QSYU64U4.mjs → chunk-MRCE2Q7A.mjs} +2 -2
  43. package/dist/chunk-NE6W2PCD.mjs +9 -0
  44. package/dist/chunk-NE6W2PCD.mjs.map +1 -0
  45. package/dist/chunk-RHCMBJOT.mjs +76 -0
  46. package/dist/chunk-RHCMBJOT.mjs.map +1 -0
  47. package/dist/chunk-RXIP2JTE.mjs +19 -0
  48. package/dist/chunk-RXIP2JTE.mjs.map +1 -0
  49. package/dist/{chunk-EJADADIY.mjs → chunk-UWTGHSWT.mjs} +6 -9
  50. package/dist/chunk-UWTGHSWT.mjs.map +1 -0
  51. package/dist/{chunk-2E6XPNPX.mjs → chunk-X46LM2QH.mjs} +9 -6
  52. package/dist/chunk-X46LM2QH.mjs.map +1 -0
  53. package/dist/{chunk-DJRMXOCP.mjs → chunk-XIHKASNB.mjs} +4 -4
  54. package/dist/{chunk-MBBFU4IR.mjs → chunk-XVFQWVHO.mjs} +3 -9
  55. package/dist/{chunk-MBBFU4IR.mjs.map → chunk-XVFQWVHO.mjs.map} +1 -1
  56. package/dist/chunk-YWNVB7TY.mjs +1 -0
  57. package/dist/{chunk-FT5CX2W5.mjs → chunk-YXHXRUFX.mjs} +7 -10
  58. package/dist/chunk-YXHXRUFX.mjs.map +1 -0
  59. package/dist/chunk-ZTYEOZLK.mjs +18 -0
  60. package/dist/chunk-ZTYEOZLK.mjs.map +1 -0
  61. package/dist/footer/footer.d.mts +7 -0
  62. package/dist/footer/footer.d.ts +7 -0
  63. package/dist/footer/footer.js +401 -0
  64. package/dist/footer/footer.js.map +1 -0
  65. package/dist/footer/footer.mjs +26 -0
  66. package/dist/footer/footer.mjs.map +1 -0
  67. package/dist/footer/index.d.mts +7 -0
  68. package/dist/footer/index.d.ts +7 -0
  69. package/dist/footer/index.js +402 -0
  70. package/dist/footer/index.js.map +1 -0
  71. package/dist/footer/index.mjs +19 -0
  72. package/dist/footer/index.mjs.map +1 -0
  73. package/dist/form/checkbox/checkbox.js +122 -24
  74. package/dist/form/checkbox/checkbox.js.map +1 -1
  75. package/dist/form/checkbox/checkbox.mjs +5 -1
  76. package/dist/form/checkbox/index.js +122 -24
  77. package/dist/form/checkbox/index.js.map +1 -1
  78. package/dist/form/checkbox/index.mjs +5 -1
  79. package/dist/form/fieldset/fieldset.d.mts +1 -0
  80. package/dist/form/fieldset/fieldset.d.ts +1 -0
  81. package/dist/form/fieldset/fieldset.js +7 -3
  82. package/dist/form/fieldset/fieldset.js.map +1 -1
  83. package/dist/form/fieldset/fieldset.mjs +5 -3
  84. package/dist/form/fieldset/index.d.mts +1 -0
  85. package/dist/form/fieldset/index.d.ts +1 -0
  86. package/dist/form/fieldset/index.js +7 -3
  87. package/dist/form/fieldset/index.js.map +1 -1
  88. package/dist/form/fieldset/index.mjs +5 -3
  89. package/dist/form/index.d.mts +2 -1
  90. package/dist/form/index.d.ts +2 -1
  91. package/dist/form/index.js +68 -27
  92. package/dist/form/index.js.map +1 -1
  93. package/dist/form/index.mjs +20 -16
  94. package/dist/form/radiobutton/index.d.mts +1 -1
  95. package/dist/form/radiobutton/index.d.ts +1 -1
  96. package/dist/form/radiobutton/index.js +17 -8
  97. package/dist/form/radiobutton/index.js.map +1 -1
  98. package/dist/form/radiobutton/index.mjs +7 -5
  99. package/dist/form/radiobutton/radiobutton.js +13 -6
  100. package/dist/form/radiobutton/radiobutton.js.map +1 -1
  101. package/dist/form/radiobutton/radiobutton.mjs +3 -3
  102. package/dist/form/radiobutton/radiogroup.js +2 -1
  103. package/dist/form/radiobutton/radiogroup.js.map +1 -1
  104. package/dist/form/radiobutton/radiogroup.mjs +2 -2
  105. package/dist/index-no-css.d.mts +20 -7
  106. package/dist/index-no-css.d.ts +20 -7
  107. package/dist/index-no-css.js +537 -310
  108. package/dist/index-no-css.js.map +1 -1
  109. package/dist/index-no-css.mjs +100 -68
  110. package/dist/index.d.mts +20 -7
  111. package/dist/index.d.ts +20 -7
  112. package/dist/index.js +537 -310
  113. package/dist/index.js.map +1 -1
  114. package/dist/index.mjs +100 -68
  115. package/dist/index.mjs.map +1 -1
  116. package/dist/layout/index.d.mts +5 -1
  117. package/dist/layout/index.d.ts +5 -1
  118. package/dist/layout/index.js +62 -2
  119. package/dist/layout/index.js.map +1 -1
  120. package/dist/layout/index.mjs +12 -2
  121. package/dist/layout/responsive.d.mts +2 -0
  122. package/dist/layout/responsive.d.ts +2 -0
  123. package/dist/layout/responsive.js +42 -0
  124. package/dist/layout/responsive.js.map +1 -0
  125. package/dist/layout/responsive.mjs +8 -0
  126. package/dist/layout/responsive.mjs.map +1 -0
  127. package/dist/layout/spacing.d.mts +3 -0
  128. package/dist/layout/spacing.d.ts +3 -0
  129. package/dist/layout/spacing.js +33 -0
  130. package/dist/layout/spacing.js.map +1 -0
  131. package/dist/layout/spacing.mjs +8 -0
  132. package/dist/layout/spacing.mjs.map +1 -0
  133. package/dist/layout/stack/index.d.mts +4 -0
  134. package/dist/layout/stack/index.d.ts +4 -0
  135. package/dist/layout/stack/index.js +117 -0
  136. package/dist/layout/stack/index.js.map +1 -0
  137. package/dist/layout/stack/index.mjs +14 -0
  138. package/dist/layout/stack/index.mjs.map +1 -0
  139. package/dist/layout/stack/stack.d.mts +4 -0
  140. package/dist/layout/stack/stack.d.ts +4 -0
  141. package/dist/layout/stack/stack.js +115 -0
  142. package/dist/layout/stack/stack.js.map +1 -0
  143. package/dist/layout/stack/stack.mjs +14 -0
  144. package/dist/layout/stack/stack.mjs.map +1 -0
  145. package/dist/modal/index.js.map +1 -1
  146. package/dist/modal/index.mjs +2 -2
  147. package/dist/modal/modal.js.map +1 -1
  148. package/dist/modal/modal.mjs +1 -1
  149. package/dist/navbar/index.d.mts +1 -0
  150. package/dist/navbar/index.d.ts +1 -0
  151. package/dist/navbar/index.js +11 -7
  152. package/dist/navbar/index.js.map +1 -1
  153. package/dist/navbar/index.mjs +7 -4
  154. package/dist/navbar/navbar-expandable-menu.d.mts +1 -0
  155. package/dist/navbar/navbar-expandable-menu.d.ts +1 -0
  156. package/dist/navbar/navbar-expandable-menu.js +11 -7
  157. package/dist/navbar/navbar-expandable-menu.js.map +1 -1
  158. package/dist/navbar/navbar-expandable-menu.mjs +5 -3
  159. package/dist/skeleton/index.js +1 -1
  160. package/dist/skeleton/index.js.map +1 -1
  161. package/dist/skeleton/index.mjs +1 -1
  162. package/dist/skeleton/skeleton.js +1 -1
  163. package/dist/skeleton/skeleton.js.map +1 -1
  164. package/dist/skeleton/skeleton.mjs +1 -1
  165. package/dist/tabs/context.d.mts +1 -0
  166. package/dist/tabs/context.d.ts +1 -0
  167. package/dist/tabs/context.js +13 -8
  168. package/dist/tabs/context.js.map +1 -1
  169. package/dist/tabs/context.mjs +5 -3
  170. package/dist/tabs/index.d.mts +5 -5
  171. package/dist/tabs/index.d.ts +5 -5
  172. package/dist/tabs/index.js +59 -33
  173. package/dist/tabs/index.js.map +1 -1
  174. package/dist/tabs/index.mjs +16 -6
  175. package/dist/tabs/tabs-content.js +11 -11
  176. package/dist/tabs/tabs-content.js.map +1 -1
  177. package/dist/tabs/tabs-content.mjs +2 -2
  178. package/dist/tabs/tabs-list.d.mts +2 -2
  179. package/dist/tabs/tabs-list.d.ts +2 -2
  180. package/dist/tabs/tabs-list.js +49 -22
  181. package/dist/tabs/tabs-list.js.map +1 -1
  182. package/dist/tabs/tabs-list.mjs +6 -6
  183. package/dist/tabs/tabs.js +2 -14
  184. package/dist/tabs/tabs.js.map +1 -1
  185. package/dist/tabs/tabs.mjs +2 -2
  186. package/package.json +5 -5
  187. package/dist/chunk-2E6XPNPX.mjs.map +0 -1
  188. package/dist/chunk-33JD5XDW.mjs +0 -14
  189. package/dist/chunk-33JD5XDW.mjs.map +0 -1
  190. package/dist/chunk-37WVYY6X.mjs.map +0 -1
  191. package/dist/chunk-5MDJP43L.mjs.map +0 -1
  192. package/dist/chunk-EJADADIY.mjs.map +0 -1
  193. package/dist/chunk-FT5CX2W5.mjs.map +0 -1
  194. package/dist/chunk-H3VGHTDC.mjs.map +0 -1
  195. package/dist/chunk-H4GIHEB2.mjs +0 -1
  196. package/dist/chunk-KRGKVH5J.mjs.map +0 -1
  197. package/dist/chunk-OIQUYB26.mjs +0 -1
  198. package/dist/chunk-POJTVNEO.mjs.map +0 -1
  199. package/dist/chunk-PXHYOQPB.mjs +0 -42
  200. package/dist/chunk-PXHYOQPB.mjs.map +0 -1
  201. package/dist/chunk-V4NGUB4I.mjs.map +0 -1
  202. package/dist/chunk-WGVZWX5L.mjs.map +0 -1
  203. package/dist/chunk-XVZ44NGD.mjs +0 -80
  204. package/dist/chunk-XVZ44NGD.mjs.map +0 -1
  205. /package/dist/{chunk-H4GIHEB2.mjs.map → chunk-L4GQJETB.mjs.map} +0 -0
  206. /package/dist/{chunk-QSYU64U4.mjs.map → chunk-MRCE2Q7A.mjs.map} +0 -0
  207. /package/dist/{chunk-DJRMXOCP.mjs.map → chunk-XIHKASNB.mjs.map} +0 -0
  208. /package/dist/{chunk-OIQUYB26.mjs.map → chunk-YWNVB7TY.mjs.map} +0 -0
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __objRest = (source, exclude) => {
24
+ var target = {};
25
+ for (var prop in source)
26
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
27
+ target[prop] = source[prop];
28
+ if (source != null && __getOwnPropSymbols)
29
+ for (var prop of __getOwnPropSymbols(source)) {
30
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
31
+ target[prop] = source[prop];
32
+ }
33
+ return target;
34
+ };
35
+ var __export = (target, all) => {
36
+ for (var name in all)
37
+ __defProp(target, name, { get: all[name], enumerable: true });
38
+ };
39
+ var __copyProps = (to, from, except, desc) => {
40
+ if (from && typeof from === "object" || typeof from === "function") {
41
+ for (let key of __getOwnPropNames(from))
42
+ if (!__hasOwnProp.call(to, key) && key !== except)
43
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
44
+ }
45
+ return to;
46
+ };
47
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
48
+
49
+ // src/layout/stack/index.tsx
50
+ var stack_exports = {};
51
+ __export(stack_exports, {
52
+ HStack: () => HStack,
53
+ Stack: () => Stack,
54
+ VStack: () => VStack
55
+ });
56
+ module.exports = __toCommonJS(stack_exports);
57
+
58
+ // src/layout/stack/stack.tsx
59
+ var React = require("react");
60
+ var import_typed_classname = require("@postenbring/hedwig-css/typed-classname");
61
+ var import_react = require("react");
62
+ var import_react_slot = require("@radix-ui/react-slot");
63
+
64
+ // src/layout/spacing.ts
65
+ function getSpacingVariable(size) {
66
+ return `var(--hds-spacing-${size})`;
67
+ }
68
+
69
+ // src/layout/responsive.ts
70
+ function getResponsiveProps(variable, inputValues, valueTransformer = (value) => String(value)) {
71
+ if (!inputValues)
72
+ return {};
73
+ if (typeof inputValues !== "object") {
74
+ return { [`${variable}-xsmall`]: valueTransformer(inputValues) };
75
+ }
76
+ const result = {};
77
+ for (const [key, value] of Object.entries(inputValues)) {
78
+ result[`${variable}-${key}`] = valueTransformer(value);
79
+ }
80
+ return result;
81
+ }
82
+
83
+ // src/layout/stack/stack.tsx
84
+ var import_jsx_runtime = require("react/jsx-runtime");
85
+ var Stack = (0, import_react.forwardRef)(
86
+ (_a, ref) => {
87
+ var _b = _a, { children, asChild, className, style: _style, gap, direction, wrap, align, justify } = _b, rest = __objRest(_b, ["children", "asChild", "className", "style", "gap", "direction", "wrap", "align", "justify"]);
88
+ const Component = asChild ? import_react_slot.Slot : "div";
89
+ const style = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, _style), getResponsiveProps("--hds-stack-gap", gap, getSpacingVariable)), getResponsiveProps("--hds-stack-direction", direction)), getResponsiveProps("--hds-stack-wrap", wrap, (value) => value ? "wrap" : "nowrap")), getResponsiveProps("--hds-stack-align", align)), getResponsiveProps("--hds-stack-justify", justify));
90
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
91
+ Component,
92
+ __spreadProps(__spreadValues({
93
+ style,
94
+ className: (0, import_typed_classname.clsx)("hds-stack", className),
95
+ ref
96
+ }, rest), {
97
+ children
98
+ })
99
+ );
100
+ }
101
+ );
102
+ Stack.displayName = "Stack";
103
+ var HStack = (0, import_react.forwardRef)((props, ref) => {
104
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stack, __spreadProps(__spreadValues({ ref }, props), { direction: "row" }));
105
+ });
106
+ HStack.displayName = "HStack";
107
+ var VStack = (0, import_react.forwardRef)((props, ref) => {
108
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stack, __spreadProps(__spreadValues({ ref }, props), { direction: "column" }));
109
+ });
110
+ VStack.displayName = "VStack";
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ HStack,
114
+ Stack,
115
+ VStack
116
+ });
117
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/layout/stack/index.tsx","../../../src/layout/stack/stack.tsx","../../../src/layout/spacing.ts","../../../src/layout/responsive.ts"],"sourcesContent":["export { Stack, HStack, VStack } from \"./stack\";\nexport type * from \"./stack\";\n","import * as React from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef } from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { getSpacingVariable, type ResponsiveSpacingSizes, type SpacingSizes } from \"../spacing\";\nimport { getResponsiveProps, type ResponsiveProp } from \"../responsive\";\n\ntype CSSPropertiesWithVar = React.CSSProperties & {\n \"--hds-stack-gap\"?: string;\n \"--hds-stack-direction\"?: string;\n \"--hds-stack-wrap\"?: string;\n \"--hds-stack-align\"?: string;\n \"--hds-stack-justify\"?: string;\n};\n\nexport interface StackProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n\n gap?: ResponsiveProp<SpacingSizes> | ResponsiveSpacingSizes;\n direction?: ResponsiveProp<React.CSSProperties[\"flexDirection\"]>;\n wrap?: ResponsiveProp<boolean>;\n align?: ResponsiveProp<React.CSSProperties[\"alignItems\"]>;\n justify?: ResponsiveProp<React.CSSProperties[\"justifyContent\"]>;\n\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean;\n}\n\n/**\n * 🚨 WORK IN PROGRESS 🚨\n *\n * TODO\n * - [ ] Add more examples\n * - [ ] Document usage\n * - [ ] Document props\n */\nexport const Stack = forwardRef<HTMLDivElement, StackProps>(\n (\n { children, asChild, className, style: _style, gap, direction, wrap, align, justify, ...rest },\n ref,\n ) => {\n const Component = asChild ? Slot : \"div\";\n const style: CSSPropertiesWithVar = {\n ..._style,\n ...getResponsiveProps(\"--hds-stack-gap\", gap, getSpacingVariable),\n ...getResponsiveProps(\"--hds-stack-direction\", direction),\n ...getResponsiveProps(\"--hds-stack-wrap\", wrap, (value) => (value ? \"wrap\" : \"nowrap\")),\n ...getResponsiveProps(\"--hds-stack-align\", align),\n ...getResponsiveProps(\"--hds-stack-justify\", justify),\n };\n return (\n <Component\n style={style}\n className={clsx(\"hds-stack\", className as undefined)}\n ref={ref}\n {...rest}\n >\n {children}\n </Component>\n );\n },\n);\nStack.displayName = \"Stack\";\n\n/**\n * 🚨 WORK IN PROGRESS 🚨\n *\n * TODO\n * - [ ] Add more examples\n * - [ ] Document usage\n * - [ ] Document props\n */\nexport const HStack = forwardRef<HTMLDivElement, Omit<StackProps, \"direction\">>((props, ref) => {\n return <Stack ref={ref} {...props} direction=\"row\" />;\n});\nHStack.displayName = \"HStack\";\n\n/**\n * 🚨 WORK IN PROGRESS 🚨\n *\n * TODO\n * - [ ] Add more examples\n * - [ ] Document usage\n * - [ ] Document props\n */\nexport const VStack = forwardRef<HTMLDivElement, Omit<StackProps, \"direction\">>((props, ref) => {\n return <Stack ref={ref} {...props} direction=\"column\" />;\n});\nVStack.displayName = \"VStack\";\n","// TODO: Get from tokens package\n// For now it's fine, since it's still in this monorepo\nconst spacingSizes = {\n \"4\": \"4\",\n \"8\": \"8\",\n \"12\": \"12\",\n \"16\": \"16\",\n \"20\": \"20\",\n \"24\": \"24\",\n \"32\": \"32\",\n \"40\": \"40\",\n \"48\": \"48\",\n \"64\": \"64\",\n \"80\": \"80\",\n \"120\": \"120\",\n} as const;\nexport type SpacingSizes = keyof typeof spacingSizes;\n\nconst responsiveSpacingSizes = {\n \"4-8\": \"4-8\",\n \"8-12\": \"8-12\",\n \"12-16\": \"12-16\",\n \"16-20\": \"16-20\",\n \"20-24\": \"20-24\",\n \"24-32\": \"24-32\",\n \"32-40\": \"32-40\",\n \"40-48\": \"40-48\",\n \"48-64\": \"48-64\",\n \"64-80\": \"64-80\",\n \"80-120\": \"80-120\",\n \"120-160\": \"120-160\",\n} as const;\nexport type ResponsiveSpacingSizes = keyof typeof responsiveSpacingSizes;\n\nexport function getSpacingVariable(size: SpacingSizes | ResponsiveSpacingSizes) {\n return `var(--hds-spacing-${size})`;\n}\n","type Breakpoints = \"xsmall\" | \"small\" | \"medium\" | \"large\" | \"xlarge\";\n\ntype ResponsiveValues<T> = {\n [Breakpoint in Breakpoints]?: T;\n};\n\nexport type ResponsiveProp<T> = T | ResponsiveValues<T>;\n\nexport function getResponsiveProps<T>(\n variable: `--hds-${string}`,\n inputValues?: ResponsiveProp<T>,\n valueTransformer: (value: T) => string = (value) => String(value),\n) {\n if (!inputValues) return {};\n\n if (typeof inputValues !== \"object\") {\n return { [`${variable}-xsmall`]: valueTransformer(inputValues) };\n }\n\n const result: Record<string, string> = {};\n for (const [key, value] of Object.entries(inputValues as ResponsiveValues<T>)) {\n result[`${variable}-${key}`] = valueTransformer(value);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,6BAAqB;AACrB,mBAA2B;AAC3B,wBAAqB;;;AC+Bd,SAAS,mBAAmB,MAA6C;AAC9E,SAAO,qBAAqB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,SAAO,4CAAC,sCAAM,OAAc,QAApB,EAA2B,WAAU,WAAS;AACxD,CAAC;AACD,OAAO,cAAc;","names":[]}
@@ -0,0 +1,14 @@
1
+ import {
2
+ HStack,
3
+ Stack,
4
+ VStack
5
+ } from "../../chunk-27XJO7E4.mjs";
6
+ import "../../chunk-ZTYEOZLK.mjs";
7
+ import "../../chunk-NE6W2PCD.mjs";
8
+ import "../../chunk-R4SQKVDQ.mjs";
9
+ export {
10
+ HStack,
11
+ Stack,
12
+ VStack
13
+ };
14
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,4 @@
1
+ export { StackProps_alias_4 as StackProps } from '../../_tsup-dts-rollup';
2
+ export { Stack_alias_4 as Stack } from '../../_tsup-dts-rollup';
3
+ export { HStack_alias_4 as HStack } from '../../_tsup-dts-rollup';
4
+ export { VStack_alias_4 as VStack } from '../../_tsup-dts-rollup';
@@ -0,0 +1,4 @@
1
+ export { StackProps_alias_4 as StackProps } from '../../_tsup-dts-rollup';
2
+ export { Stack_alias_4 as Stack } from '../../_tsup-dts-rollup';
3
+ export { HStack_alias_4 as HStack } from '../../_tsup-dts-rollup';
4
+ export { VStack_alias_4 as VStack } from '../../_tsup-dts-rollup';
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __objRest = (source, exclude) => {
24
+ var target = {};
25
+ for (var prop in source)
26
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
27
+ target[prop] = source[prop];
28
+ if (source != null && __getOwnPropSymbols)
29
+ for (var prop of __getOwnPropSymbols(source)) {
30
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
31
+ target[prop] = source[prop];
32
+ }
33
+ return target;
34
+ };
35
+ var __export = (target, all) => {
36
+ for (var name in all)
37
+ __defProp(target, name, { get: all[name], enumerable: true });
38
+ };
39
+ var __copyProps = (to, from, except, desc) => {
40
+ if (from && typeof from === "object" || typeof from === "function") {
41
+ for (let key of __getOwnPropNames(from))
42
+ if (!__hasOwnProp.call(to, key) && key !== except)
43
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
44
+ }
45
+ return to;
46
+ };
47
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
48
+
49
+ // src/layout/stack/stack.tsx
50
+ var stack_exports = {};
51
+ __export(stack_exports, {
52
+ HStack: () => HStack,
53
+ Stack: () => Stack,
54
+ VStack: () => VStack
55
+ });
56
+ module.exports = __toCommonJS(stack_exports);
57
+ var React = require("react");
58
+ var import_typed_classname = require("@postenbring/hedwig-css/typed-classname");
59
+ var import_react = require("react");
60
+ var import_react_slot = require("@radix-ui/react-slot");
61
+
62
+ // src/layout/spacing.ts
63
+ function getSpacingVariable(size) {
64
+ return `var(--hds-spacing-${size})`;
65
+ }
66
+
67
+ // src/layout/responsive.ts
68
+ function getResponsiveProps(variable, inputValues, valueTransformer = (value) => String(value)) {
69
+ if (!inputValues)
70
+ return {};
71
+ if (typeof inputValues !== "object") {
72
+ return { [`${variable}-xsmall`]: valueTransformer(inputValues) };
73
+ }
74
+ const result = {};
75
+ for (const [key, value] of Object.entries(inputValues)) {
76
+ result[`${variable}-${key}`] = valueTransformer(value);
77
+ }
78
+ return result;
79
+ }
80
+
81
+ // src/layout/stack/stack.tsx
82
+ var import_jsx_runtime = require("react/jsx-runtime");
83
+ var Stack = (0, import_react.forwardRef)(
84
+ (_a, ref) => {
85
+ var _b = _a, { children, asChild, className, style: _style, gap, direction, wrap, align, justify } = _b, rest = __objRest(_b, ["children", "asChild", "className", "style", "gap", "direction", "wrap", "align", "justify"]);
86
+ const Component = asChild ? import_react_slot.Slot : "div";
87
+ const style = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, _style), getResponsiveProps("--hds-stack-gap", gap, getSpacingVariable)), getResponsiveProps("--hds-stack-direction", direction)), getResponsiveProps("--hds-stack-wrap", wrap, (value) => value ? "wrap" : "nowrap")), getResponsiveProps("--hds-stack-align", align)), getResponsiveProps("--hds-stack-justify", justify));
88
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
89
+ Component,
90
+ __spreadProps(__spreadValues({
91
+ style,
92
+ className: (0, import_typed_classname.clsx)("hds-stack", className),
93
+ ref
94
+ }, rest), {
95
+ children
96
+ })
97
+ );
98
+ }
99
+ );
100
+ Stack.displayName = "Stack";
101
+ var HStack = (0, import_react.forwardRef)((props, ref) => {
102
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stack, __spreadProps(__spreadValues({ ref }, props), { direction: "row" }));
103
+ });
104
+ HStack.displayName = "HStack";
105
+ var VStack = (0, import_react.forwardRef)((props, ref) => {
106
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stack, __spreadProps(__spreadValues({ ref }, props), { direction: "column" }));
107
+ });
108
+ VStack.displayName = "VStack";
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ HStack,
112
+ Stack,
113
+ VStack
114
+ });
115
+ //# sourceMappingURL=stack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/layout/stack/stack.tsx","../../../src/layout/spacing.ts","../../../src/layout/responsive.ts"],"sourcesContent":["import * as React from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef } from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { getSpacingVariable, type ResponsiveSpacingSizes, type SpacingSizes } from \"../spacing\";\nimport { getResponsiveProps, type ResponsiveProp } from \"../responsive\";\n\ntype CSSPropertiesWithVar = React.CSSProperties & {\n \"--hds-stack-gap\"?: string;\n \"--hds-stack-direction\"?: string;\n \"--hds-stack-wrap\"?: string;\n \"--hds-stack-align\"?: string;\n \"--hds-stack-justify\"?: string;\n};\n\nexport interface StackProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n\n gap?: ResponsiveProp<SpacingSizes> | ResponsiveSpacingSizes;\n direction?: ResponsiveProp<React.CSSProperties[\"flexDirection\"]>;\n wrap?: ResponsiveProp<boolean>;\n align?: ResponsiveProp<React.CSSProperties[\"alignItems\"]>;\n justify?: ResponsiveProp<React.CSSProperties[\"justifyContent\"]>;\n\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n */\n asChild?: boolean;\n}\n\n/**\n * 🚨 WORK IN PROGRESS 🚨\n *\n * TODO\n * - [ ] Add more examples\n * - [ ] Document usage\n * - [ ] Document props\n */\nexport const Stack = forwardRef<HTMLDivElement, StackProps>(\n (\n { children, asChild, className, style: _style, gap, direction, wrap, align, justify, ...rest },\n ref,\n ) => {\n const Component = asChild ? Slot : \"div\";\n const style: CSSPropertiesWithVar = {\n ..._style,\n ...getResponsiveProps(\"--hds-stack-gap\", gap, getSpacingVariable),\n ...getResponsiveProps(\"--hds-stack-direction\", direction),\n ...getResponsiveProps(\"--hds-stack-wrap\", wrap, (value) => (value ? \"wrap\" : \"nowrap\")),\n ...getResponsiveProps(\"--hds-stack-align\", align),\n ...getResponsiveProps(\"--hds-stack-justify\", justify),\n };\n return (\n <Component\n style={style}\n className={clsx(\"hds-stack\", className as undefined)}\n ref={ref}\n {...rest}\n >\n {children}\n </Component>\n );\n },\n);\nStack.displayName = \"Stack\";\n\n/**\n * 🚨 WORK IN PROGRESS 🚨\n *\n * TODO\n * - [ ] Add more examples\n * - [ ] Document usage\n * - [ ] Document props\n */\nexport const HStack = forwardRef<HTMLDivElement, Omit<StackProps, \"direction\">>((props, ref) => {\n return <Stack ref={ref} {...props} direction=\"row\" />;\n});\nHStack.displayName = \"HStack\";\n\n/**\n * 🚨 WORK IN PROGRESS 🚨\n *\n * TODO\n * - [ ] Add more examples\n * - [ ] Document usage\n * - [ ] Document props\n */\nexport const VStack = forwardRef<HTMLDivElement, Omit<StackProps, \"direction\">>((props, ref) => {\n return <Stack ref={ref} {...props} direction=\"column\" />;\n});\nVStack.displayName = \"VStack\";\n","// TODO: Get from tokens package\n// For now it's fine, since it's still in this monorepo\nconst spacingSizes = {\n \"4\": \"4\",\n \"8\": \"8\",\n \"12\": \"12\",\n \"16\": \"16\",\n \"20\": \"20\",\n \"24\": \"24\",\n \"32\": \"32\",\n \"40\": \"40\",\n \"48\": \"48\",\n \"64\": \"64\",\n \"80\": \"80\",\n \"120\": \"120\",\n} as const;\nexport type SpacingSizes = keyof typeof spacingSizes;\n\nconst responsiveSpacingSizes = {\n \"4-8\": \"4-8\",\n \"8-12\": \"8-12\",\n \"12-16\": \"12-16\",\n \"16-20\": \"16-20\",\n \"20-24\": \"20-24\",\n \"24-32\": \"24-32\",\n \"32-40\": \"32-40\",\n \"40-48\": \"40-48\",\n \"48-64\": \"48-64\",\n \"64-80\": \"64-80\",\n \"80-120\": \"80-120\",\n \"120-160\": \"120-160\",\n} as const;\nexport type ResponsiveSpacingSizes = keyof typeof responsiveSpacingSizes;\n\nexport function getSpacingVariable(size: SpacingSizes | ResponsiveSpacingSizes) {\n return `var(--hds-spacing-${size})`;\n}\n","type Breakpoints = \"xsmall\" | \"small\" | \"medium\" | \"large\" | \"xlarge\";\n\ntype ResponsiveValues<T> = {\n [Breakpoint in Breakpoints]?: T;\n};\n\nexport type ResponsiveProp<T> = T | ResponsiveValues<T>;\n\nexport function getResponsiveProps<T>(\n variable: `--hds-${string}`,\n inputValues?: ResponsiveProp<T>,\n valueTransformer: (value: T) => string = (value) => String(value),\n) {\n if (!inputValues) return {};\n\n if (typeof inputValues !== \"object\") {\n return { [`${variable}-xsmall`]: valueTransformer(inputValues) };\n }\n\n const result: Record<string, string> = {};\n for (const [key, value] of Object.entries(inputValues as ResponsiveValues<T>)) {\n result[`${variable}-${key}`] = valueTransformer(value);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AACvB,6BAAqB;AACrB,mBAA2B;AAC3B,wBAAqB;;;AC+Bd,SAAS,mBAAmB,MAA6C;AAC9E,SAAO,qBAAqB,IAAI;AAClC;;;AC5BO,SAAS,mBACd,UACA,aACA,mBAAyC,CAAC,UAAU,OAAO,KAAK,GAChE;AACA,MAAI,CAAC;AAAa,WAAO,CAAC;AAE1B,MAAI,OAAO,gBAAgB,UAAU;AACnC,WAAO,EAAE,CAAC,GAAG,QAAQ,SAAS,GAAG,iBAAiB,WAAW,EAAE;AAAA,EACjE;AAEA,QAAM,SAAiC,CAAC;AACxC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAkC,GAAG;AAC7E,WAAO,GAAG,QAAQ,IAAI,GAAG,EAAE,IAAI,iBAAiB,KAAK;AAAA,EACvD;AAEA,SAAO;AACT;;;AF4BM;AAfC,IAAM,YAAQ;AAAA,EACnB,CACE,IACA,QACG;AAFH,iBAAE,YAAU,SAAS,WAAW,OAAO,QAAQ,KAAK,WAAW,MAAM,OAAO,QAxChF,IAwCI,IAAwF,iBAAxF,IAAwF,CAAtF,YAAU,WAAS,aAAW,SAAe,OAAK,aAAW,QAAM,SAAO;AAG5E,UAAM,YAAY,UAAU,yBAAO;AACnC,UAAM,QAA8B,8FAC/B,SACA,mBAAmB,mBAAmB,KAAK,kBAAkB,IAC7D,mBAAmB,yBAAyB,SAAS,IACrD,mBAAmB,oBAAoB,MAAM,CAAC,UAAW,QAAQ,SAAS,QAAS,IACnF,mBAAmB,qBAAqB,KAAK,IAC7C,mBAAmB,uBAAuB,OAAO;AAEtD,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,eAAW,6BAAK,aAAa,SAAsB;AAAA,QACnD;AAAA,SACI,OAJL;AAAA,QAME;AAAA;AAAA,IACH;AAAA,EAEJ;AACF;AACA,MAAM,cAAc;AAUb,IAAM,aAAS,yBAA0D,CAAC,OAAO,QAAQ;AAC9F,SAAO,4CAAC,sCAAM,OAAc,QAApB,EAA2B,WAAU,QAAM;AACrD,CAAC;AACD,OAAO,cAAc;AAUd,IAAM,aAAS,yBAA0D,CAAC,OAAO,QAAQ;AAC9F,SAAO,4CAAC,sCAAM,OAAc,QAApB,EAA2B,WAAU,WAAS;AACxD,CAAC;AACD,OAAO,cAAc;","names":[]}
@@ -0,0 +1,14 @@
1
+ import {
2
+ HStack,
3
+ Stack,
4
+ VStack
5
+ } from "../../chunk-27XJO7E4.mjs";
6
+ import "../../chunk-ZTYEOZLK.mjs";
7
+ import "../../chunk-NE6W2PCD.mjs";
8
+ import "../../chunk-R4SQKVDQ.mjs";
9
+ export {
10
+ HStack,
11
+ Stack,
12
+ VStack
13
+ };
14
+ //# sourceMappingURL=stack.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/modal/index.tsx","../../src/modal/modal.tsx","../../src/box/box.tsx","../../src/utils.ts"],"sourcesContent":["import { Modal, ModalHeader, ModalContent, ModalFooter } from \"./modal\";\n\nconst ModalComponent = Modal as typeof Modal & {\n Header: typeof ModalHeader;\n Content: typeof ModalContent;\n Footer: typeof ModalFooter;\n};\nModalComponent.Header = ModalHeader;\nModalComponent.Content = ModalContent;\nModalComponent.Footer = ModalFooter;\n\nexport { ModalComponent as Modal };\nexport type * from \"./modal\";\n","import { forwardRef, useEffect, useRef } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Box } from \"../box/box\";\nimport type { OverridableComponent } from \"../utils\";\nimport { useMergeRefs } from \"../utils\";\n\nexport interface ModalProps extends React.HTMLAttributes<HTMLDialogElement> {\n children: React.ReactNode;\n\n /**\n * Controls the open state of the modal\n */\n open?: boolean;\n\n /**\n * Whether to close when clicking on the backdrop.\n */\n closeOnBackdropClick?: boolean;\n}\n\n/**\n * A modal dialog is a window that forces the user to interact with it before they can return to other parts of the application.\n *\n * Uses the native [`dialog`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog) element.\n *\n * Example\n * ```\n const modalRef = useRef<HTMLDialogElement>(null);\n const onClose = () => modalRef.current?.close();\n\n return (\n <>\n <PrimaryButton onClick={() => modalRef.current?.showModal()}>Open Modal</PrimaryButton>\n <Modal ref={modalRef}>\n <Modal.Header>Dialog header</Modal.Header>\n <Modal.Content>\n <p>\n Dialog header Dialog description - a description of what is about to happen and maybe\n something about the consequences.\n </p>\n </Modal.Content>\n <Modal.Footer style={{ display: \"flex\", gap: 16 }}>\n <PrimaryButton fill=\"outline\" onClick={onClose}>\n Close\n </PrimaryButton>\n </Modal.Footer>\n </Modal>\n </>\n );\n * ```\n */\nexport const Modal = forwardRef<HTMLDialogElement, ModalProps>(\n ({ children, className, open, closeOnBackdropClick, onClick, ...rest }, ref) => {\n const modalRef = useRef<HTMLDialogElement>(null);\n const mergedRef = useMergeRefs([modalRef, ref]);\n\n // The X close button that comes from the `Box` component\n function onCloseButtonClick() {\n modalRef.current?.close();\n return false;\n }\n\n // No scroll when modal is open\n useScrollLock(modalRef, \"hds-modal-scroll-lock\");\n\n // `open` prop\n useEffect(() => {\n if (modalRef.current && open !== undefined) {\n if (open && !modalRef.current.open) {\n modalRef.current.showModal();\n } else if (!open && modalRef.current.open) {\n modalRef.current.close();\n }\n }\n }, [modalRef, open]);\n\n function onDialogClick(e: React.MouseEvent<HTMLElement>) {\n if (closeOnBackdropClick && e.target === modalRef.current) {\n modalRef.current.close();\n }\n onClick?.(e as React.MouseEvent<HTMLDialogElement>);\n }\n\n return (\n <Box\n as=\"dialog\"\n className={clsx(\"hds-modal\", className as undefined)}\n closeable\n onClick={onDialogClick}\n onClose={onCloseButtonClick}\n ref={mergedRef}\n variant=\"white\"\n {\n ...(rest as object) /* TODO remove type casting */\n }\n >\n {children}\n </Box>\n );\n },\n);\nModal.displayName = \"Modal\";\n\nexport const ModalHeader: OverridableComponent<object, HTMLHeadingElement> = forwardRef(\n ({ as: Component = \"h1\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__header\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalHeader.displayName = \"Modal.Header\";\n\nexport const ModalContent: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"div\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__content\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalContent.displayName = \"Modal.Content\";\n\nexport const ModalFooter: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"footer\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__footer\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalFooter.displayName = \"Modal.Footer\";\n\nexport function useScrollLock(modalRef: React.RefObject<HTMLDialogElement>, bodyClass: string) {\n useEffect(() => {\n if (!modalRef.current) return;\n if (modalRef.current.open) document.body.classList.add(bodyClass);\n\n const observer = new MutationObserver(() => {\n if (modalRef.current?.open) document.body.classList.add(bodyClass);\n else document.body.classList.remove(bodyClass);\n });\n observer.observe(modalRef.current, {\n attributes: true,\n attributeFilter: [\"open\"],\n });\n return () => {\n observer.disconnect();\n document.body.classList.remove(bodyClass);\n };\n }, [bodyClass, modalRef]);\n}\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport type { OverridableComponent } from \"../utils\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n variant?: \"light-grey\" | \"lighter\" | \"white\" | \"warning\";\n children?: React.ReactNode;\n\n /**\n * If `true`, a close button will be shown.\n * Use when you want to control the close button using the BoxCloseButton component.\n */\n closeable?: boolean;\n\n /**\n * Callback fired when the component requests to be closed.\n * If not set, the component will be closed without any user interaction.\n *\n * If set, and the handler returns non-true value, the component will not be closed.\n * Use this if you want to control the closing of the component, using the `closed` prop\n *\n * If set, and the handler returns the true, the component will be closed.\n * Use this with `window.confirm()` to ask the user to confirm closing the component.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents -- It's fine, I want to have the boolean in the type\n onClose?: () => boolean | unknown;\n\n /**\n * If `true`, the box will be closed and hidden from view\n */\n closed?: boolean;\n\n /**\n * Props applied to the close button element.\n */\n closeButtonProps?: BoxCloseButtonProps;\n}\n\nexport const Box: OverridableComponent<BoxProps, HTMLDivElement> = forwardRef(\n (\n {\n as: Component = \"div\",\n variant,\n closeable = false,\n onClose: onCloseProp,\n closed: closedProp,\n closeButtonProps,\n children,\n className,\n ...rest\n },\n ref,\n ) => {\n const [closedState, setClosedState] = useState(false);\n const onClose = useCallback(() => {\n if (onCloseProp) {\n const result = onCloseProp();\n if (result === true) {\n setClosedState(true);\n }\n } else {\n setClosedState(true);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- I know better\n }, []);\n const closed = closedProp ?? closedState;\n\n return (\n <Component\n className={clsx(\n \"hds-box\",\n variant && `hds-box--${variant}`,\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n {children}\n </Component>\n );\n },\n);\nBox.displayName = \"Box\";\n\nexport type BoxCloseButtonProps = Omit<React.HTMLAttributes<HTMLButtonElement>, \"children\">;\nexport const BoxCloseButton = forwardRef<HTMLButtonElement, BoxCloseButtonProps>(\n ({ className, ...rest }, ref) => {\n return (\n <button\n className={clsx(\"hds-box__close-button\", className as undefined)}\n ref={ref}\n type=\"button\"\n {...rest}\n />\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n","import type { ComponentPropsWithRef, ElementType, FC, RefAttributes } from \"react\";\nimport * as React from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\n/**\n * OverridableComponent makes the `as` prop available,\n * to be used to override the html element being used for a component\n *\n * Taken from digdir design system: https://github.com/digdir/designsystem/blob/main/packages/react/src/types/OverridableComponent.ts\n */\nexport type OverridableComponent<ComponentProps, Element extends HTMLElement> = {\n (props: ComponentProps & RefAttributes<Element>): ReturnType<FC>;\n\n <As extends ElementType>(\n props: {\n /** Override html element */\n as?: As;\n } & ComponentProps &\n Omit<ComponentPropsWithRef<As>, keyof ComponentProps>,\n ): ReturnType<FC>;\n} & Pick<FC, \"displayName\">;\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8C;AAC9C,IAAAC,0BAAqB;;;ACDrB,mBAAkD;AAClD,6BAAqB;AAmEf;AA9BC,IAAM,UAAsD;AAAA,EACjE,CACE,IAWA,QACG;AAZH,iBACE;AAAA,UAAI,YAAY;AAAA,MAChB;AAAA,MACA,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IAhDN,IAwCI,IASK,iBATL,IASK;AAAA,MARH;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAKF,UAAM,CAAC,aAAa,cAAc,QAAI,uBAAS,KAAK;AACpD,UAAM,cAAU,0BAAY,MAAM;AAChC,UAAI,aAAa;AACf,cAAM,SAAS,YAAY;AAC3B,YAAI,WAAW,MAAM;AACnB,yBAAe,IAAI;AAAA,QACrB;AAAA,MACF,OAAO;AACL,uBAAe,IAAI;AAAA,MACrB;AAAA,IAEF,GAAG,CAAC,CAAC;AACL,UAAM,SAAS,kCAAc;AAE7B,WACE;AAAA,MAAC;AAAA;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BAAK,sBAAsB,SAAsB;AAAA,QAC5D;AAAA,SACI;AAAA,IACN;AAAA,EAEJ;AACF;AACA,aAAa,cAAc;AAEpB,IAAM,kBAA4D;AAAA,EACvE,CAAC,IAAkD,QAAQ;AAA1D,iBAAE,MAAI,YAAY,UAAU,UAlI/B,IAkIG,IAA0C,iBAA1C,IAA0C,CAAxC,MAA0B;AAC3B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,8BAAK,qBAAqB,SAAsB;AAAA,QAC3D;AAAA,SACI;AAAA,IACN;AAAA,EAEJ;AACF;AACA,YAAY,cAAc;AAEnB,SAAS,cAAc,UAA8C,WAAmB;AAC7F,+BAAU,MAAM;AACd,QAAI,CAAC,SAAS;AAAS;AACvB,QAAI,SAAS,QAAQ;AAAM,eAAS,KAAK,UAAU,IAAI,SAAS;AAEhE,UAAM,WAAW,IAAI,iBAAiB,MAAM;AAnJhD;AAoJM,WAAI,cAAS,YAAT,mBAAkB;AAAM,iBAAS,KAAK,UAAU,IAAI,SAAS;AAAA;AAC5D,iBAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC/C,CAAC;AACD,aAAS,QAAQ,SAAS,SAAS;AAAA,MACjC,YAAY;AAAA,MACZ,iBAAiB,CAAC,MAAM;AAAA,IAC1B,CAAC;AACD,WAAO,MAAM;AACX,eAAS,WAAW;AACpB,eAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC1C;AAAA,EACF,GAAG,CAAC,WAAW,QAAQ,CAAC;AAC1B;;;AD9JA,IAAM,iBAAiB;AAKvB,eAAe,SAAS;AACxB,eAAe,UAAU;AACzB,eAAe,SAAS;","names":["import_react","import_typed_classname","import_react","import_jsx_runtime","_a"]}
1
+ {"version":3,"sources":["../../src/modal/index.tsx","../../src/modal/modal.tsx","../../src/box/box.tsx","../../src/utils.ts"],"sourcesContent":["import { Modal, ModalHeader, ModalContent, ModalFooter } from \"./modal\";\n\nconst ModalComponent = Modal as typeof Modal & {\n Header: typeof ModalHeader;\n Content: typeof ModalContent;\n Footer: typeof ModalFooter;\n};\nModalComponent.Header = ModalHeader;\nModalComponent.Content = ModalContent;\nModalComponent.Footer = ModalFooter;\n\nexport { ModalComponent as Modal };\nexport type * from \"./modal\";\n","import { forwardRef, useEffect, useRef } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Box } from \"../box/box\";\nimport type { OverridableComponent } from \"../utils\";\nimport { useMergeRefs } from \"../utils\";\n\nexport interface ModalProps extends React.HTMLAttributes<HTMLDialogElement> {\n children: React.ReactNode;\n\n /**\n * Controls the open state of the modal\n */\n open?: boolean;\n\n /**\n * Whether to close when clicking on the backdrop.\n */\n closeOnBackdropClick?: boolean;\n}\n\n/**\n * A modal dialog is a window that forces the user to interact with it before they can return to other parts of the application.\n *\n * Uses the native [`dialog`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog) element.\n *\n * Example\n * ```\n const modalRef = useRef<HTMLDialogElement>(null);\n const onClose = () => modalRef.current?.close();\n\n return (\n <>\n <PrimaryButton onClick={() => modalRef.current?.showModal()}>Open Modal</PrimaryButton>\n <Modal ref={modalRef}>\n <Modal.Header>Dialog header</Modal.Header>\n <Modal.Content>\n <p>\n Dialog header Dialog description - a description of what is about to happen and maybe\n something about the consequences.\n </p>\n </Modal.Content>\n <Modal.Footer>\n <HStack gap=\"16\" wrap>\n <PrimaryButton onClick={onMainAction}>Main action</PrimaryButton>\n <PrimaryButton fill=\"outline\" onClick={onClose}>\n Cancel\n </PrimaryButton>\n </HStack>\n </Modal.Footer>\n </Modal>\n </>\n );\n * ```\n */\nexport const Modal = forwardRef<HTMLDialogElement, ModalProps>(\n ({ children, className, open, closeOnBackdropClick, onClick, ...rest }, ref) => {\n const modalRef = useRef<HTMLDialogElement>(null);\n const mergedRef = useMergeRefs([modalRef, ref]);\n\n // The X close button that comes from the `Box` component\n function onCloseButtonClick() {\n modalRef.current?.close();\n return false;\n }\n\n // No scroll when modal is open\n useScrollLock(modalRef, \"hds-modal-scroll-lock\");\n\n // `open` prop\n useEffect(() => {\n if (modalRef.current && open !== undefined) {\n if (open && !modalRef.current.open) {\n modalRef.current.showModal();\n } else if (!open && modalRef.current.open) {\n modalRef.current.close();\n }\n }\n }, [modalRef, open]);\n\n function onDialogClick(e: React.MouseEvent<HTMLElement>) {\n if (closeOnBackdropClick && e.target === modalRef.current) {\n modalRef.current.close();\n }\n onClick?.(e as React.MouseEvent<HTMLDialogElement>);\n }\n\n return (\n <Box\n as=\"dialog\"\n className={clsx(\"hds-modal\", className as undefined)}\n closeable\n onClick={onDialogClick}\n onClose={onCloseButtonClick}\n ref={mergedRef}\n variant=\"white\"\n {\n ...(rest as object) /* TODO remove type casting */\n }\n >\n {children}\n </Box>\n );\n },\n);\nModal.displayName = \"Modal\";\n\nexport const ModalHeader: OverridableComponent<object, HTMLHeadingElement> = forwardRef(\n ({ as: Component = \"h1\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__header\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalHeader.displayName = \"Modal.Header\";\n\nexport const ModalContent: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"div\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__content\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalContent.displayName = \"Modal.Content\";\n\nexport const ModalFooter: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"footer\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__footer\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalFooter.displayName = \"Modal.Footer\";\n\nexport function useScrollLock(modalRef: React.RefObject<HTMLDialogElement>, bodyClass: string) {\n useEffect(() => {\n if (!modalRef.current) return;\n if (modalRef.current.open) document.body.classList.add(bodyClass);\n\n const observer = new MutationObserver(() => {\n if (modalRef.current?.open) document.body.classList.add(bodyClass);\n else document.body.classList.remove(bodyClass);\n });\n observer.observe(modalRef.current, {\n attributes: true,\n attributeFilter: [\"open\"],\n });\n return () => {\n observer.disconnect();\n document.body.classList.remove(bodyClass);\n };\n }, [bodyClass, modalRef]);\n}\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport type { OverridableComponent } from \"../utils\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n variant?: \"light-grey\" | \"lighter\" | \"white\" | \"warning\";\n children?: React.ReactNode;\n\n /**\n * If `true`, a close button will be shown.\n * Use when you want to control the close button using the BoxCloseButton component.\n */\n closeable?: boolean;\n\n /**\n * Callback fired when the component requests to be closed.\n * If not set, the component will be closed without any user interaction.\n *\n * If set, and the handler returns non-true value, the component will not be closed.\n * Use this if you want to control the closing of the component, using the `closed` prop\n *\n * If set, and the handler returns the true, the component will be closed.\n * Use this with `window.confirm()` to ask the user to confirm closing the component.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents -- It's fine, I want to have the boolean in the type\n onClose?: () => boolean | unknown;\n\n /**\n * If `true`, the box will be closed and hidden from view\n */\n closed?: boolean;\n\n /**\n * Props applied to the close button element.\n */\n closeButtonProps?: BoxCloseButtonProps;\n}\n\nexport const Box: OverridableComponent<BoxProps, HTMLDivElement> = forwardRef(\n (\n {\n as: Component = \"div\",\n variant,\n closeable = false,\n onClose: onCloseProp,\n closed: closedProp,\n closeButtonProps,\n children,\n className,\n ...rest\n },\n ref,\n ) => {\n const [closedState, setClosedState] = useState(false);\n const onClose = useCallback(() => {\n if (onCloseProp) {\n const result = onCloseProp();\n if (result === true) {\n setClosedState(true);\n }\n } else {\n setClosedState(true);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- I know better\n }, []);\n const closed = closedProp ?? closedState;\n\n return (\n <Component\n className={clsx(\n \"hds-box\",\n variant && `hds-box--${variant}`,\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n {children}\n </Component>\n );\n },\n);\nBox.displayName = \"Box\";\n\nexport type BoxCloseButtonProps = Omit<React.HTMLAttributes<HTMLButtonElement>, \"children\">;\nexport const BoxCloseButton = forwardRef<HTMLButtonElement, BoxCloseButtonProps>(\n ({ className, ...rest }, ref) => {\n return (\n <button\n className={clsx(\"hds-box__close-button\", className as undefined)}\n ref={ref}\n type=\"button\"\n {...rest}\n />\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n","import type { ComponentPropsWithRef, ElementType, FC, RefAttributes } from \"react\";\nimport * as React from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\n/**\n * OverridableComponent makes the `as` prop available,\n * to be used to override the html element being used for a component\n *\n * Taken from digdir design system: https://github.com/digdir/designsystem/blob/main/packages/react/src/types/OverridableComponent.ts\n */\nexport type OverridableComponent<ComponentProps, Element extends HTMLElement> = {\n (props: ComponentProps & RefAttributes<Element>): ReturnType<FC>;\n\n <As extends ElementType>(\n props: {\n /** Override html element */\n as?: As;\n } & ComponentProps &\n Omit<ComponentPropsWithRef<As>, keyof ComponentProps>,\n ): ReturnType<FC>;\n} & Pick<FC, \"displayName\">;\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8C;AAC9C,IAAAC,0BAAqB;;;ACDrB,mBAAkD;AAClD,6BAAqB;AAmEf;AA9BC,IAAM,UAAsD;AAAA,EACjE,CACE,IAWA,QACG;AAZH,iBACE;AAAA,UAAI,YAAY;AAAA,MAChB;AAAA,MACA,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IAhDN,IAwCI,IASK,iBATL,IASK;AAAA,MARH;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAKF,UAAM,CAAC,aAAa,cAAc,QAAI,uBAAS,KAAK;AACpD,UAAM,cAAU,0BAAY,MAAM;AAChC,UAAI,aAAa;AACf,cAAM,SAAS,YAAY;AAC3B,YAAI,WAAW,MAAM;AACnB,yBAAe,IAAI;AAAA,QACrB;AAAA,MACF,OAAO;AACL,uBAAe,IAAI;AAAA,MACrB;AAAA,IAEF,GAAG,CAAC,CAAC;AACL,UAAM,SAAS,kCAAc;AAE7B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW;AAAA,UACT;AAAA,UACA,WAAW,YAAY,OAAO;AAAA,UAC9B,EAAE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F;AACA,aAAa,cAAc;AAEpB,IAAM,kBAA4D;AAAA,EACvE,CAAC,IAAkD,QAAQ;AAA1D,iBAAE,MAAI,YAAY,UAAU,UArI/B,IAqIG,IAA0C,iBAA1C,IAA0C,CAAxC,MAA0B;AAC3B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,8BAAK,qBAAqB,SAAsB;AAAA,QAC3D;AAAA,SACI;AAAA,IACN;AAAA,EAEJ;AACF;AACA,YAAY,cAAc;AAEnB,SAAS,cAAc,UAA8C,WAAmB;AAC7F,+BAAU,MAAM;AACd,QAAI,CAAC,SAAS;AAAS;AACvB,QAAI,SAAS,QAAQ;AAAM,eAAS,KAAK,UAAU,IAAI,SAAS;AAEhE,UAAM,WAAW,IAAI,iBAAiB,MAAM;AAtJhD;AAuJM,WAAI,cAAS,YAAT,mBAAkB;AAAM,iBAAS,KAAK,UAAU,IAAI,SAAS;AAAA;AAC5D,iBAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC/C,CAAC;AACD,aAAS,QAAQ,SAAS,SAAS;AAAA,MACjC,YAAY;AAAA,MACZ,iBAAiB,CAAC,MAAM;AAAA,IAC1B,CAAC;AACD,WAAO,MAAM;AACX,eAAS,WAAW;AACpB,eAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC1C;AAAA,EACF,GAAG,CAAC,WAAW,QAAQ,CAAC;AAC1B;;;ADjKA,IAAM,iBAAiB;AAKvB,eAAe,SAAS;AACxB,eAAe,UAAU;AACzB,eAAe,SAAS;","names":["import_react","import_typed_classname","import_react","import_jsx_runtime","_a"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ModalComponent
3
- } from "../chunk-QSYU64U4.mjs";
4
- import "../chunk-POJTVNEO.mjs";
3
+ } from "../chunk-MRCE2Q7A.mjs";
4
+ import "../chunk-2ICZ3Q7N.mjs";
5
5
  import "../chunk-EGXM575K.mjs";
6
6
  import "../chunk-WCA2WPFS.mjs";
7
7
  import "../chunk-R4SQKVDQ.mjs";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/modal/modal.tsx","../../src/box/box.tsx","../../src/utils.ts"],"sourcesContent":["import { forwardRef, useEffect, useRef } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Box } from \"../box/box\";\nimport type { OverridableComponent } from \"../utils\";\nimport { useMergeRefs } from \"../utils\";\n\nexport interface ModalProps extends React.HTMLAttributes<HTMLDialogElement> {\n children: React.ReactNode;\n\n /**\n * Controls the open state of the modal\n */\n open?: boolean;\n\n /**\n * Whether to close when clicking on the backdrop.\n */\n closeOnBackdropClick?: boolean;\n}\n\n/**\n * A modal dialog is a window that forces the user to interact with it before they can return to other parts of the application.\n *\n * Uses the native [`dialog`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog) element.\n *\n * Example\n * ```\n const modalRef = useRef<HTMLDialogElement>(null);\n const onClose = () => modalRef.current?.close();\n\n return (\n <>\n <PrimaryButton onClick={() => modalRef.current?.showModal()}>Open Modal</PrimaryButton>\n <Modal ref={modalRef}>\n <Modal.Header>Dialog header</Modal.Header>\n <Modal.Content>\n <p>\n Dialog header Dialog description - a description of what is about to happen and maybe\n something about the consequences.\n </p>\n </Modal.Content>\n <Modal.Footer style={{ display: \"flex\", gap: 16 }}>\n <PrimaryButton fill=\"outline\" onClick={onClose}>\n Close\n </PrimaryButton>\n </Modal.Footer>\n </Modal>\n </>\n );\n * ```\n */\nexport const Modal = forwardRef<HTMLDialogElement, ModalProps>(\n ({ children, className, open, closeOnBackdropClick, onClick, ...rest }, ref) => {\n const modalRef = useRef<HTMLDialogElement>(null);\n const mergedRef = useMergeRefs([modalRef, ref]);\n\n // The X close button that comes from the `Box` component\n function onCloseButtonClick() {\n modalRef.current?.close();\n return false;\n }\n\n // No scroll when modal is open\n useScrollLock(modalRef, \"hds-modal-scroll-lock\");\n\n // `open` prop\n useEffect(() => {\n if (modalRef.current && open !== undefined) {\n if (open && !modalRef.current.open) {\n modalRef.current.showModal();\n } else if (!open && modalRef.current.open) {\n modalRef.current.close();\n }\n }\n }, [modalRef, open]);\n\n function onDialogClick(e: React.MouseEvent<HTMLElement>) {\n if (closeOnBackdropClick && e.target === modalRef.current) {\n modalRef.current.close();\n }\n onClick?.(e as React.MouseEvent<HTMLDialogElement>);\n }\n\n return (\n <Box\n as=\"dialog\"\n className={clsx(\"hds-modal\", className as undefined)}\n closeable\n onClick={onDialogClick}\n onClose={onCloseButtonClick}\n ref={mergedRef}\n variant=\"white\"\n {\n ...(rest as object) /* TODO remove type casting */\n }\n >\n {children}\n </Box>\n );\n },\n);\nModal.displayName = \"Modal\";\n\nexport const ModalHeader: OverridableComponent<object, HTMLHeadingElement> = forwardRef(\n ({ as: Component = \"h1\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__header\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalHeader.displayName = \"Modal.Header\";\n\nexport const ModalContent: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"div\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__content\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalContent.displayName = \"Modal.Content\";\n\nexport const ModalFooter: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"footer\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__footer\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalFooter.displayName = \"Modal.Footer\";\n\nexport function useScrollLock(modalRef: React.RefObject<HTMLDialogElement>, bodyClass: string) {\n useEffect(() => {\n if (!modalRef.current) return;\n if (modalRef.current.open) document.body.classList.add(bodyClass);\n\n const observer = new MutationObserver(() => {\n if (modalRef.current?.open) document.body.classList.add(bodyClass);\n else document.body.classList.remove(bodyClass);\n });\n observer.observe(modalRef.current, {\n attributes: true,\n attributeFilter: [\"open\"],\n });\n return () => {\n observer.disconnect();\n document.body.classList.remove(bodyClass);\n };\n }, [bodyClass, modalRef]);\n}\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport type { OverridableComponent } from \"../utils\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n variant?: \"light-grey\" | \"lighter\" | \"white\" | \"warning\";\n children?: React.ReactNode;\n\n /**\n * If `true`, a close button will be shown.\n * Use when you want to control the close button using the BoxCloseButton component.\n */\n closeable?: boolean;\n\n /**\n * Callback fired when the component requests to be closed.\n * If not set, the component will be closed without any user interaction.\n *\n * If set, and the handler returns non-true value, the component will not be closed.\n * Use this if you want to control the closing of the component, using the `closed` prop\n *\n * If set, and the handler returns the true, the component will be closed.\n * Use this with `window.confirm()` to ask the user to confirm closing the component.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents -- It's fine, I want to have the boolean in the type\n onClose?: () => boolean | unknown;\n\n /**\n * If `true`, the box will be closed and hidden from view\n */\n closed?: boolean;\n\n /**\n * Props applied to the close button element.\n */\n closeButtonProps?: BoxCloseButtonProps;\n}\n\nexport const Box: OverridableComponent<BoxProps, HTMLDivElement> = forwardRef(\n (\n {\n as: Component = \"div\",\n variant,\n closeable = false,\n onClose: onCloseProp,\n closed: closedProp,\n closeButtonProps,\n children,\n className,\n ...rest\n },\n ref,\n ) => {\n const [closedState, setClosedState] = useState(false);\n const onClose = useCallback(() => {\n if (onCloseProp) {\n const result = onCloseProp();\n if (result === true) {\n setClosedState(true);\n }\n } else {\n setClosedState(true);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- I know better\n }, []);\n const closed = closedProp ?? closedState;\n\n return (\n <Component\n className={clsx(\n \"hds-box\",\n variant && `hds-box--${variant}`,\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n {children}\n </Component>\n );\n },\n);\nBox.displayName = \"Box\";\n\nexport type BoxCloseButtonProps = Omit<React.HTMLAttributes<HTMLButtonElement>, \"children\">;\nexport const BoxCloseButton = forwardRef<HTMLButtonElement, BoxCloseButtonProps>(\n ({ className, ...rest }, ref) => {\n return (\n <button\n className={clsx(\"hds-box__close-button\", className as undefined)}\n ref={ref}\n type=\"button\"\n {...rest}\n />\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n","import type { ComponentPropsWithRef, ElementType, FC, RefAttributes } from \"react\";\nimport * as React from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\n/**\n * OverridableComponent makes the `as` prop available,\n * to be used to override the html element being used for a component\n *\n * Taken from digdir design system: https://github.com/digdir/designsystem/blob/main/packages/react/src/types/OverridableComponent.ts\n */\nexport type OverridableComponent<ComponentProps, Element extends HTMLElement> = {\n (props: ComponentProps & RefAttributes<Element>): ReturnType<FC>;\n\n <As extends ElementType>(\n props: {\n /** Override html element */\n as?: As;\n } & ComponentProps &\n Omit<ComponentPropsWithRef<As>, keyof ComponentProps>,\n ): ReturnType<FC>;\n} & Pick<FC, \"displayName\">;\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA8C;AAC9C,IAAAC,0BAAqB;;;ACDrB,mBAAkD;AAClD,6BAAqB;AAmEf;AA9BC,IAAM,UAAsD;AAAA,EACjE,CACE,IAWA,QACG;AAZH,iBACE;AAAA,UAAI,YAAY;AAAA,MAChB;AAAA,MACA,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IAhDN,IAwCI,IASK,iBATL,IASK;AAAA,MARH;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAKF,UAAM,CAAC,aAAa,cAAc,QAAI,uBAAS,KAAK;AACpD,UAAM,cAAU,0BAAY,MAAM;AAChC,UAAI,aAAa;AACf,cAAM,SAAS,YAAY;AAC3B,YAAI,WAAW,MAAM;AACnB,yBAAe,IAAI;AAAA,QACrB;AAAA,MACF,OAAO;AACL,uBAAe,IAAI;AAAA,MACrB;AAAA,IAEF,GAAG,CAAC,CAAC;AACL,UAAM,SAAS,kCAAc;AAE7B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW;AAAA,UACT;AAAA,UACA,WAAW,YAAY,OAAO;AAAA,UAC9B,EAAE,mBAAmB,OAAO;AAAA,UAC5B;AAAA,QACF;AAAA,QACA;AAAA,SACI,OARL;AAAA,QAUE;AA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AAE,MAAI,YAAY,UAAU,UAlI/B,IAkIG,IAA0C,iBAA1C,IAA0C,CAAxC,MAA0B;AAC3B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,8BAAK,qBAAqB,SAAsB;AAAA,QAC3D;AAAA,SACI;AAAA,IACN;AAAA,EAEJ;AACF;AACA,YAAY,cAAc;AAEnB,SAAS,cAAc,UAA8C,WAAmB;AAC7F,+BAAU,MAAM;AACd,QAAI,CAAC,SAAS;AAAS;AACvB,QAAI,SAAS,QAAQ;AAAM,eAAS,KAAK,UAAU,IAAI,SAAS;AAEhE,UAAM,WAAW,IAAI,iBAAiB,MAAM;AAnJhD;AAoJM,WAAI,cAAS,YAAT,mBAAkB;AAAM,iBAAS,KAAK,UAAU,IAAI,SAAS;AAAA;AAC5D,iBAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC/C,CAAC;AACD,aAAS,QAAQ,SAAS,SAAS;AAAA,MACjC,YAAY;AAAA,MACZ,iBAAiB,CAAC,MAAM;AAAA,IAC1B,CAAC;AACD,WAAO,MAAM;AACX,eAAS,WAAW;AACpB,eAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC1C;AAAA,EACF,GAAG,CAAC,WAAW,QAAQ,CAAC;AAC1B;","names":["import_react","import_typed_classname","import_react","import_jsx_runtime","_a"]}
1
+ {"version":3,"sources":["../../src/modal/modal.tsx","../../src/box/box.tsx","../../src/utils.ts"],"sourcesContent":["import { forwardRef, useEffect, useRef } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Box } from \"../box/box\";\nimport type { OverridableComponent } from \"../utils\";\nimport { useMergeRefs } from \"../utils\";\n\nexport interface ModalProps extends React.HTMLAttributes<HTMLDialogElement> {\n children: React.ReactNode;\n\n /**\n * Controls the open state of the modal\n */\n open?: boolean;\n\n /**\n * Whether to close when clicking on the backdrop.\n */\n closeOnBackdropClick?: boolean;\n}\n\n/**\n * A modal dialog is a window that forces the user to interact with it before they can return to other parts of the application.\n *\n * Uses the native [`dialog`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog) element.\n *\n * Example\n * ```\n const modalRef = useRef<HTMLDialogElement>(null);\n const onClose = () => modalRef.current?.close();\n\n return (\n <>\n <PrimaryButton onClick={() => modalRef.current?.showModal()}>Open Modal</PrimaryButton>\n <Modal ref={modalRef}>\n <Modal.Header>Dialog header</Modal.Header>\n <Modal.Content>\n <p>\n Dialog header Dialog description - a description of what is about to happen and maybe\n something about the consequences.\n </p>\n </Modal.Content>\n <Modal.Footer>\n <HStack gap=\"16\" wrap>\n <PrimaryButton onClick={onMainAction}>Main action</PrimaryButton>\n <PrimaryButton fill=\"outline\" onClick={onClose}>\n Cancel\n </PrimaryButton>\n </HStack>\n </Modal.Footer>\n </Modal>\n </>\n );\n * ```\n */\nexport const Modal = forwardRef<HTMLDialogElement, ModalProps>(\n ({ children, className, open, closeOnBackdropClick, onClick, ...rest }, ref) => {\n const modalRef = useRef<HTMLDialogElement>(null);\n const mergedRef = useMergeRefs([modalRef, ref]);\n\n // The X close button that comes from the `Box` component\n function onCloseButtonClick() {\n modalRef.current?.close();\n return false;\n }\n\n // No scroll when modal is open\n useScrollLock(modalRef, \"hds-modal-scroll-lock\");\n\n // `open` prop\n useEffect(() => {\n if (modalRef.current && open !== undefined) {\n if (open && !modalRef.current.open) {\n modalRef.current.showModal();\n } else if (!open && modalRef.current.open) {\n modalRef.current.close();\n }\n }\n }, [modalRef, open]);\n\n function onDialogClick(e: React.MouseEvent<HTMLElement>) {\n if (closeOnBackdropClick && e.target === modalRef.current) {\n modalRef.current.close();\n }\n onClick?.(e as React.MouseEvent<HTMLDialogElement>);\n }\n\n return (\n <Box\n as=\"dialog\"\n className={clsx(\"hds-modal\", className as undefined)}\n closeable\n onClick={onDialogClick}\n onClose={onCloseButtonClick}\n ref={mergedRef}\n variant=\"white\"\n {\n ...(rest as object) /* TODO remove type casting */\n }\n >\n {children}\n </Box>\n );\n },\n);\nModal.displayName = \"Modal\";\n\nexport const ModalHeader: OverridableComponent<object, HTMLHeadingElement> = forwardRef(\n ({ as: Component = \"h1\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__header\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalHeader.displayName = \"Modal.Header\";\n\nexport const ModalContent: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"div\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__content\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalContent.displayName = \"Modal.Content\";\n\nexport const ModalFooter: OverridableComponent<object, HTMLDivElement> = forwardRef(\n ({ as: Component = \"footer\", className, ...rest }, ref) => {\n return (\n <Component\n className={clsx(\"hds-modal__footer\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nModalFooter.displayName = \"Modal.Footer\";\n\nexport function useScrollLock(modalRef: React.RefObject<HTMLDialogElement>, bodyClass: string) {\n useEffect(() => {\n if (!modalRef.current) return;\n if (modalRef.current.open) document.body.classList.add(bodyClass);\n\n const observer = new MutationObserver(() => {\n if (modalRef.current?.open) document.body.classList.add(bodyClass);\n else document.body.classList.remove(bodyClass);\n });\n observer.observe(modalRef.current, {\n attributes: true,\n attributeFilter: [\"open\"],\n });\n return () => {\n observer.disconnect();\n document.body.classList.remove(bodyClass);\n };\n }, [bodyClass, modalRef]);\n}\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport type { OverridableComponent } from \"../utils\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n variant?: \"light-grey\" | \"lighter\" | \"white\" | \"warning\";\n children?: React.ReactNode;\n\n /**\n * If `true`, a close button will be shown.\n * Use when you want to control the close button using the BoxCloseButton component.\n */\n closeable?: boolean;\n\n /**\n * Callback fired when the component requests to be closed.\n * If not set, the component will be closed without any user interaction.\n *\n * If set, and the handler returns non-true value, the component will not be closed.\n * Use this if you want to control the closing of the component, using the `closed` prop\n *\n * If set, and the handler returns the true, the component will be closed.\n * Use this with `window.confirm()` to ask the user to confirm closing the component.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents -- It's fine, I want to have the boolean in the type\n onClose?: () => boolean | unknown;\n\n /**\n * If `true`, the box will be closed and hidden from view\n */\n closed?: boolean;\n\n /**\n * Props applied to the close button element.\n */\n closeButtonProps?: BoxCloseButtonProps;\n}\n\nexport const Box: OverridableComponent<BoxProps, HTMLDivElement> = forwardRef(\n (\n {\n as: Component = \"div\",\n variant,\n closeable = false,\n onClose: onCloseProp,\n closed: closedProp,\n closeButtonProps,\n children,\n className,\n ...rest\n },\n ref,\n ) => {\n const [closedState, setClosedState] = useState(false);\n const onClose = useCallback(() => {\n if (onCloseProp) {\n const result = onCloseProp();\n if (result === true) {\n setClosedState(true);\n }\n } else {\n setClosedState(true);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- I know better\n }, []);\n const closed = closedProp ?? closedState;\n\n return (\n <Component\n className={clsx(\n \"hds-box\",\n variant && `hds-box--${variant}`,\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n {children}\n </Component>\n );\n },\n);\nBox.displayName = \"Box\";\n\nexport type BoxCloseButtonProps = Omit<React.HTMLAttributes<HTMLButtonElement>, \"children\">;\nexport const BoxCloseButton = forwardRef<HTMLButtonElement, BoxCloseButtonProps>(\n ({ className, ...rest }, ref) => {\n return (\n <button\n className={clsx(\"hds-box__close-button\", className as undefined)}\n ref={ref}\n type=\"button\"\n {...rest}\n />\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n","import type { ComponentPropsWithRef, ElementType, FC, RefAttributes } from \"react\";\nimport * as React from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\n/**\n * OverridableComponent makes the `as` prop available,\n * to be used to override the html element being used for a component\n *\n * Taken from digdir design system: https://github.com/digdir/designsystem/blob/main/packages/react/src/types/OverridableComponent.ts\n */\nexport type OverridableComponent<ComponentProps, Element extends HTMLElement> = {\n (props: ComponentProps & RefAttributes<Element>): ReturnType<FC>;\n\n <As extends ElementType>(\n props: {\n /** Override html element */\n as?: As;\n } & ComponentProps &\n Omit<ComponentPropsWithRef<As>, keyof ComponentProps>,\n ): ReturnType<FC>;\n} & Pick<FC, \"displayName\">;\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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I,iBAAiB,MAAM;AAtJhD;AAuJM,WAAI,cAAS,YAAT,mBAAkB;AAAM,iBAAS,KAAK,UAAU,IAAI,SAAS;AAAA;AAC5D,iBAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC/C,CAAC;AACD,aAAS,QAAQ,SAAS,SAAS;AAAA,MACjC,YAAY;AAAA,MACZ,iBAAiB,CAAC,MAAM;AAAA,IAC1B,CAAC;AACD,WAAO,MAAM;AACX,eAAS,WAAW;AACpB,eAAS,KAAK,UAAU,OAAO,SAAS;AAAA,IAC1C;AAAA,EACF,GAAG,CAAC,WAAW,QAAQ,CAAC;AAC1B;","names":["import_react","import_typed_classname","import_react","import_jsx_runtime","_a"]}
@@ -4,7 +4,7 @@ import {
4
4
  ModalFooter,
5
5
  ModalHeader,
6
6
  useScrollLock
7
- } from "../chunk-POJTVNEO.mjs";
7
+ } from "../chunk-2ICZ3Q7N.mjs";
8
8
  import "../chunk-EGXM575K.mjs";
9
9
  import "../chunk-WCA2WPFS.mjs";
10
10
  import "../chunk-R4SQKVDQ.mjs";
@@ -1,4 +1,5 @@
1
1
  export { Navbar_alias_2 as Navbar } from '../_tsup-dts-rollup';
2
+ export { useNavbarExpendableMenuContext_alias_2 as useNavbarExpendableMenuContext } from '../_tsup-dts-rollup';
2
3
  export { NavbarProps_alias_2 as NavbarProps } from '../_tsup-dts-rollup';
3
4
  export { NavbarLogo_alias_2 as NavbarLogo } from '../_tsup-dts-rollup';
4
5
  export { NavbarLogoAndServiceText_alias_2 as NavbarLogoAndServiceText } from '../_tsup-dts-rollup';
@@ -1,4 +1,5 @@
1
1
  export { Navbar_alias_2 as Navbar } from '../_tsup-dts-rollup';
2
+ export { useNavbarExpendableMenuContext_alias_2 as useNavbarExpendableMenuContext } from '../_tsup-dts-rollup';
2
3
  export { NavbarProps_alias_2 as NavbarProps } from '../_tsup-dts-rollup';
3
4
  export { NavbarLogo_alias_2 as NavbarLogo } from '../_tsup-dts-rollup';
4
5
  export { NavbarLogoAndServiceText_alias_2 as NavbarLogoAndServiceText } from '../_tsup-dts-rollup';
@@ -59,7 +59,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
59
59
  // src/navbar/index.tsx
60
60
  var navbar_exports = {};
61
61
  __export(navbar_exports, {
62
- Navbar: () => NavbarComponent
62
+ Navbar: () => NavbarComponent,
63
+ useNavbarExpendableMenuContext: () => useNavbarExpendableMenuContext
63
64
  });
64
65
  module.exports = __toCommonJS(navbar_exports);
65
66
 
@@ -162,11 +163,12 @@ function MenuIcon() {
162
163
 
163
164
  // src/navbar/navbar-expandable-menu.tsx
164
165
  var import_jsx_runtime3 = require("react/jsx-runtime");
165
- var navbarContext = (0, import_react2.createContext)([
166
+ var expandableMenuContext = (0, import_react2.createContext)([
166
167
  false,
167
168
  () => {
168
169
  }
169
170
  ]);
171
+ var useNavbarExpendableMenuContext = () => (0, import_react2.useContext)(expandableMenuContext);
170
172
  function NavbarExpandableMenu({ children }) {
171
173
  const [open, setOpen] = (0, import_react2.useState)(false);
172
174
  const toggleOpen = () => {
@@ -180,7 +182,7 @@ function NavbarExpandableMenu({ children }) {
180
182
  }
181
183
  };
182
184
  const navbarElement = document.getElementsByClassName((0, import_typed_classname2.clsx)("hds-navbar"))[0];
183
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(navbarContext.Provider, { value: [open, toggleOpen], children: [
185
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(expandableMenuContext.Provider, { value: [open, toggleOpen], children: [
184
186
  open ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_focus_trap_react.default, { containerElements: [navbarElement] }) : null,
185
187
  children
186
188
  ] });
@@ -219,7 +221,7 @@ function RenderButton(_a) {
219
221
  type: "button"
220
222
  }, rest), {
221
223
  children: [
222
- text,
224
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: (0, import_typed_classname2.clsx)("hds-navbar__button-responsive-text"), children: text }),
223
225
  " ",
224
226
  icon
225
227
  ]
@@ -241,7 +243,7 @@ var NavbarExpandableMenuTrigger = (0, import_react2.forwardRef)(
241
243
  "whenOpenHelperTitle",
242
244
  "className"
243
245
  ]);
244
- const [open, toggleOpen] = (0, import_react2.useContext)(navbarContext);
246
+ const [open, toggleOpen] = useNavbarExpendableMenuContext();
245
247
  const [width, setWidth] = (0, import_react2.useState)(0);
246
248
  const measureButtonRef = (0, import_react2.useRef)(null);
247
249
  const text = open ? whenOpenText : whenClosedText;
@@ -308,12 +310,13 @@ var NavbarExpandableMenuTrigger = (0, import_react2.forwardRef)(
308
310
  NavbarExpandableMenuTrigger.displayName = "Navbar.ExpandableMenu.Trigger";
309
311
  var NavbarExpandableMenuContent = (0, import_react2.forwardRef)((_a, ref) => {
310
312
  var _b = _a, { as: Component = "section", children, className } = _b, rest = __objRest(_b, ["as", "children", "className"]);
311
- const [open] = (0, import_react2.useContext)(navbarContext);
313
+ const [open] = useNavbarExpendableMenuContext();
312
314
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
313
315
  Component,
314
316
  __spreadProps(__spreadValues({}, rest), {
315
317
  className: (0, import_typed_classname2.clsx)("hds-navbar__expandable-menu-content", className),
316
318
  "data-state": open ? "open" : "closed",
319
+ inert: open ? void 0 : "true",
317
320
  ref,
318
321
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: (0, import_typed_classname2.clsx)("hds-navbar__expandable-menu-content-inner"), children })
319
322
  })
@@ -333,6 +336,7 @@ NavbarComponent.Button = NavbarButton;
333
336
  NavbarComponent.Navigation = NavbarNavigation;
334
337
  // Annotate the CommonJS export names for ESM import in node:
335
338
  0 && (module.exports = {
336
- Navbar
339
+ Navbar,
340
+ useNavbarExpendableMenuContext
337
341
  });
338
342
  //# sourceMappingURL=index.js.map