@postenbring/hedwig-react 4.5.1 → 4.6.0
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.
- package/dist/alert/alert.js +82 -33
- package/dist/alert/alert.js.map +1 -1
- package/dist/alert/alert.mjs +3 -2
- package/dist/alert/index.js +82 -33
- package/dist/alert/index.js.map +1 -1
- package/dist/alert/index.mjs +3 -2
- package/dist/box/box.d.ts.map +1 -1
- package/dist/box/box.js +69 -20
- package/dist/box/box.js.map +1 -1
- package/dist/box/box.mjs +2 -1
- package/dist/box/index.js +69 -20
- package/dist/box/index.js.map +1 -1
- package/dist/box/index.mjs +2 -1
- package/dist/{chunk-ILN2L5NX.mjs → chunk-B2DZ6JJ4.mjs} +2 -2
- package/dist/{chunk-INDTHGWZ.mjs → chunk-KAVKFO2R.mjs} +2 -2
- package/dist/{chunk-DEABU7DB.mjs → chunk-P4AKOVM7.mjs} +9 -9
- package/dist/chunk-P4AKOVM7.mjs.map +1 -0
- package/dist/{chunk-NAXSP4VU.mjs → chunk-PKEPSKTZ.mjs} +2 -2
- package/dist/{chunk-YQT2TN3U.mjs → chunk-QQKPLLCE.mjs} +4 -3
- package/dist/chunk-QQKPLLCE.mjs.map +1 -0
- package/dist/{chunk-QDG2QLFV.mjs → chunk-UXZKGAZ2.mjs} +4 -4
- package/dist/{chunk-PZUJLRG4.mjs → chunk-WFIS2ZYQ.mjs} +2 -2
- package/dist/footer/footer.mjs +2 -2
- package/dist/footer/index.mjs +2 -2
- package/dist/form/error-summary/error-summary.js +104 -55
- package/dist/form/error-summary/error-summary.js.map +1 -1
- package/dist/form/error-summary/error-summary.mjs +3 -2
- package/dist/form/error-summary/index.js +104 -55
- package/dist/form/error-summary/index.js.map +1 -1
- package/dist/form/error-summary/index.mjs +3 -2
- package/dist/form/index.js +166 -117
- package/dist/form/index.js.map +1 -1
- package/dist/form/index.mjs +16 -15
- package/dist/help-text/help-text.js +79 -30
- package/dist/help-text/help-text.js.map +1 -1
- package/dist/help-text/help-text.mjs +3 -2
- package/dist/help-text/index.js +79 -30
- package/dist/help-text/index.js.map +1 -1
- package/dist/help-text/index.mjs +3 -2
- package/dist/index.js +104 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -42
- package/dist/message/index.js +83 -34
- package/dist/message/index.js.map +1 -1
- package/dist/message/index.mjs +3 -2
- package/dist/message/message.js +83 -34
- package/dist/message/message.js.map +1 -1
- package/dist/message/message.mjs +3 -2
- package/dist/modal/index.js +95 -45
- package/dist/modal/index.js.map +1 -1
- package/dist/modal/index.mjs +3 -2
- package/dist/modal/modal.d.ts +5 -0
- package/dist/modal/modal.d.ts.map +1 -1
- package/dist/modal/modal.js +95 -45
- package/dist/modal/modal.js.map +1 -1
- package/dist/modal/modal.mjs +3 -2
- package/dist/navbar/icons.d.ts +2 -2
- package/dist/navbar/icons.d.ts.map +1 -1
- package/dist/navbar/navbar-expandable-menu.d.ts +1 -1
- package/dist/navbar/navbar-expandable-menu.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/box/box.tsx +8 -8
- package/src/modal/modal.tsx +12 -1
- package/dist/chunk-DEABU7DB.mjs.map +0 -1
- package/dist/chunk-YQT2TN3U.mjs.map +0 -1
- /package/dist/{chunk-ILN2L5NX.mjs.map → chunk-B2DZ6JJ4.mjs.map} +0 -0
- /package/dist/{chunk-INDTHGWZ.mjs.map → chunk-KAVKFO2R.mjs.map} +0 -0
- /package/dist/{chunk-NAXSP4VU.mjs.map → chunk-PKEPSKTZ.mjs.map} +0 -0
- /package/dist/{chunk-QDG2QLFV.mjs.map → chunk-UXZKGAZ2.mjs.map} +0 -0
- /package/dist/{chunk-PZUJLRG4.mjs.map → chunk-WFIS2ZYQ.mjs.map} +0 -0
|
@@ -63,34 +63,83 @@ __export(help_text_exports, {
|
|
|
63
63
|
});
|
|
64
64
|
module.exports = __toCommonJS(help_text_exports);
|
|
65
65
|
var Popover = __toESM(require("@radix-ui/react-popover"));
|
|
66
|
-
var
|
|
67
|
-
var
|
|
66
|
+
var import_typed_classname3 = require("@postenbring/hedwig-css/typed-classname");
|
|
67
|
+
var import_react3 = require("react");
|
|
68
68
|
|
|
69
69
|
// src/box/box.tsx
|
|
70
|
+
var import_react2 = require("react");
|
|
71
|
+
var import_typed_classname2 = require("@postenbring/hedwig-css/typed-classname");
|
|
72
|
+
var import_react_slot2 = require("@radix-ui/react-slot");
|
|
73
|
+
|
|
74
|
+
// src/button/button.tsx
|
|
70
75
|
var import_react = require("react");
|
|
71
76
|
var import_typed_classname = require("@postenbring/hedwig-css/typed-classname");
|
|
72
77
|
var import_react_slot = require("@radix-ui/react-slot");
|
|
73
78
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
79
|
+
var Button = (0, import_react.forwardRef)(
|
|
80
|
+
(_a, ref) => {
|
|
81
|
+
var _b = _a, {
|
|
82
|
+
asChild,
|
|
83
|
+
children,
|
|
84
|
+
variant = "primary",
|
|
85
|
+
size = "large",
|
|
86
|
+
fullWidth = false,
|
|
87
|
+
icon = false,
|
|
88
|
+
className
|
|
89
|
+
} = _b, rest = __objRest(_b, [
|
|
90
|
+
"asChild",
|
|
91
|
+
"children",
|
|
92
|
+
"variant",
|
|
93
|
+
"size",
|
|
94
|
+
"fullWidth",
|
|
95
|
+
"icon",
|
|
96
|
+
"className"
|
|
97
|
+
]);
|
|
98
|
+
const Component = asChild ? import_react_slot.Slot : "button";
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
100
|
+
Component,
|
|
101
|
+
__spreadProps(__spreadValues({
|
|
102
|
+
className: (0, import_typed_classname.clsx)(
|
|
103
|
+
"hds-button",
|
|
104
|
+
`hds-button--${size}`,
|
|
105
|
+
`hds-button--${variant}`,
|
|
106
|
+
{
|
|
107
|
+
"hds-button--full": fullWidth === true,
|
|
108
|
+
"hds-button--mobile-full": fullWidth === "mobile",
|
|
109
|
+
"hds-button--only-icon": icon === true,
|
|
110
|
+
"hds-button--leading-icon": icon === "leading",
|
|
111
|
+
"hds-button--trailing-icon": icon === "trailing"
|
|
112
|
+
},
|
|
113
|
+
className
|
|
114
|
+
),
|
|
115
|
+
ref
|
|
116
|
+
}, rest), {
|
|
117
|
+
children
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
Button.displayName = "Button";
|
|
123
|
+
|
|
124
|
+
// src/box/box.tsx
|
|
125
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
74
126
|
function CloseIcon() {
|
|
75
|
-
return /* @__PURE__ */ (0,
|
|
76
|
-
"path",
|
|
77
|
-
{
|
|
78
|
-
d: "M17.5469 16.3333L22.375 11.5521L23.3594 10.5677C23.5 10.4271 23.5 10.1927 23.3594 10.0052L22.3281 8.97394C22.1406 8.83331 21.9062 8.83331 21.7656 8.97394L16 14.7864L10.1875 8.97394C10.0469 8.83331 9.8125 8.83331 9.625 8.97394L8.59375 10.0052C8.45312 10.1927 8.45312 10.4271 8.59375 10.5677L14.4062 16.3333L8.59375 22.1458C8.45312 22.2864 8.45312 22.5208 8.59375 22.7083L9.625 23.7396C9.8125 23.8802 10.0469 23.8802 10.1875 23.7396L16 17.9271L20.7812 22.7552L21.7656 23.7396C21.9062 23.8802 22.1406 23.8802 22.3281 23.7396L23.3594 22.7083C23.5 22.5208 23.5 22.2864 23.3594 22.1458L17.5469 16.3333Z",
|
|
79
|
-
fill: "currentColor"
|
|
80
|
-
}
|
|
81
|
-
) });
|
|
127
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 640 640", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M183.1 137.4C170.6 124.9 150.3 124.9 137.8 137.4C125.3 149.9 125.3 170.2 137.8 182.7L275.2 320L137.9 457.4C125.4 469.9 125.4 490.2 137.9 502.7C150.4 515.2 170.7 515.2 183.2 502.7L320.5 365.3L457.9 502.6C470.4 515.1 490.7 515.1 503.2 502.6C515.7 490.1 515.7 469.8 503.2 457.3L365.8 320L503.1 182.6C515.6 170.1 515.6 149.8 503.1 137.3C490.6 124.8 470.3 124.8 457.8 137.3L320.5 274.7L183.1 137.4z" }) });
|
|
82
128
|
}
|
|
83
|
-
var BoxCloseButton = (0,
|
|
129
|
+
var BoxCloseButton = (0, import_react2.forwardRef)(
|
|
84
130
|
(_a, ref) => {
|
|
85
131
|
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
86
|
-
return /* @__PURE__ */ (0,
|
|
87
|
-
|
|
132
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
133
|
+
Button,
|
|
88
134
|
__spreadProps(__spreadValues({
|
|
89
|
-
className: (0,
|
|
135
|
+
className: (0, import_typed_classname2.clsx)("hds-box__close-button", className),
|
|
136
|
+
variant: "tertiary",
|
|
137
|
+
size: "small",
|
|
138
|
+
icon: true,
|
|
90
139
|
ref,
|
|
91
140
|
type: "button"
|
|
92
141
|
}, rest), {
|
|
93
|
-
children: /* @__PURE__ */ (0,
|
|
142
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CloseIcon, {})
|
|
94
143
|
})
|
|
95
144
|
);
|
|
96
145
|
}
|
|
@@ -108,7 +157,7 @@ var convertVariantToColor = (variant) => {
|
|
|
108
157
|
return "neutral";
|
|
109
158
|
}
|
|
110
159
|
};
|
|
111
|
-
var Box = (0,
|
|
160
|
+
var Box = (0, import_react2.forwardRef)(
|
|
112
161
|
(_a, ref) => {
|
|
113
162
|
var _b = _a, {
|
|
114
163
|
"data-color": color = "",
|
|
@@ -131,8 +180,8 @@ var Box = (0, import_react.forwardRef)(
|
|
|
131
180
|
"children",
|
|
132
181
|
"className"
|
|
133
182
|
]);
|
|
134
|
-
const [closedState, setClosedState] = (0,
|
|
135
|
-
const onClose = (0,
|
|
183
|
+
const [closedState, setClosedState] = (0, import_react2.useState)(false);
|
|
184
|
+
const onClose = (0, import_react2.useCallback)(() => {
|
|
136
185
|
if (onCloseProp) {
|
|
137
186
|
const result = onCloseProp();
|
|
138
187
|
if (result === true) {
|
|
@@ -143,13 +192,13 @@ var Box = (0, import_react.forwardRef)(
|
|
|
143
192
|
}
|
|
144
193
|
}, []);
|
|
145
194
|
const closed = closedProp != null ? closedProp : closedState;
|
|
146
|
-
const Component = asChild ?
|
|
195
|
+
const Component = asChild ? import_react_slot2.Slot : "div";
|
|
147
196
|
const resolvedColor = color && color !== "" ? color : convertVariantToColor(variant);
|
|
148
|
-
return /* @__PURE__ */ (0,
|
|
197
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
149
198
|
Component,
|
|
150
199
|
__spreadProps(__spreadValues({
|
|
151
200
|
"data-color": resolvedColor,
|
|
152
|
-
className: (0,
|
|
201
|
+
className: (0, import_typed_classname2.clsx)(
|
|
153
202
|
"hds-box",
|
|
154
203
|
{ "hds-box--lighter": variant === "lighter" },
|
|
155
204
|
{ "hds-box--white": variant === "white" },
|
|
@@ -159,8 +208,8 @@ var Box = (0, import_react.forwardRef)(
|
|
|
159
208
|
ref
|
|
160
209
|
}, rest), {
|
|
161
210
|
children: [
|
|
162
|
-
closeable ? /* @__PURE__ */ (0,
|
|
163
|
-
/* @__PURE__ */ (0,
|
|
211
|
+
closeable ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BoxCloseButton, __spreadValues({ onClick: onClose }, closeButtonProps)) : null,
|
|
212
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_slot2.Slottable, { children })
|
|
164
213
|
]
|
|
165
214
|
})
|
|
166
215
|
);
|
|
@@ -170,8 +219,8 @@ Box.displayName = "Box";
|
|
|
170
219
|
Box.CloseButton = BoxCloseButton;
|
|
171
220
|
|
|
172
221
|
// src/help-text/help-text.tsx
|
|
173
|
-
var
|
|
174
|
-
var HelpText = (0,
|
|
222
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
223
|
+
var HelpText = (0, import_react3.forwardRef)(
|
|
175
224
|
(_a, ref) => {
|
|
176
225
|
var _b = _a, { children, className, helpText, title, side = "top", align = "start", boxProps } = _b, rest = __objRest(_b, ["children", "className", "helpText", "title", "side", "align", "boxProps"]);
|
|
177
226
|
return (
|
|
@@ -179,24 +228,24 @@ var HelpText = (0, import_react2.forwardRef)(
|
|
|
179
228
|
// In the future we can use the native popover api, but as of writing, though all browsers support it
|
|
180
229
|
// it's not far enough back to be used in production
|
|
181
230
|
// https://caniuse.com/mdn-html_elements_input_popovertarget
|
|
182
|
-
/* @__PURE__ */ (0,
|
|
183
|
-
/* @__PURE__ */ (0,
|
|
231
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Popover.Root, { children: [
|
|
232
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
184
233
|
"button",
|
|
185
234
|
__spreadProps(__spreadValues({
|
|
186
235
|
ref,
|
|
187
|
-
className: (0,
|
|
236
|
+
className: (0, import_typed_classname3.clsx)("hds-help-text-button", className),
|
|
188
237
|
title,
|
|
189
238
|
type: "button"
|
|
190
239
|
}, rest), {
|
|
191
240
|
children
|
|
192
241
|
})
|
|
193
242
|
) }),
|
|
194
|
-
/* @__PURE__ */ (0,
|
|
243
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Content, { asChild: true, side, align, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
195
244
|
Box,
|
|
196
245
|
__spreadProps(__spreadValues({}, boxProps), {
|
|
197
|
-
className: (0,
|
|
246
|
+
className: (0, import_typed_classname3.clsx)("hds-help-text-box", boxProps == null ? void 0 : boxProps.className),
|
|
198
247
|
children: [
|
|
199
|
-
/* @__PURE__ */ (0,
|
|
248
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Close, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box.CloseButton, {}) }),
|
|
200
249
|
helpText
|
|
201
250
|
]
|
|
202
251
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/help-text/help-text.tsx","../../src/box/box.tsx"],"sourcesContent":["import * as Popover from \"@radix-ui/react-popover\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef } from \"react\";\nimport { Box } from \"../box\";\n\ninterface HelpTextProps extends React.HTMLAttributes<HTMLButtonElement> {\n className?: string;\n\n /**\n * The content of the help text, often a word or phrase that could use some explanation\n */\n children: React.ReactNode;\n\n /**\n * The help text that will be shown when the user clicks the trigger\n */\n helpText: React.ReactNode;\n\n /**\n * The title of the help text. Used by screen readers and if the user hover over the help text\n */\n title?: string;\n\n /**\n * Props for the `Box` that contains the help text\n */\n boxProps?: React.ComponentProps<typeof Box>;\n\n /**\n * The side of the trigger the popover should be attached to\n *\n * @default \"top\"\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n\n /**\n * The alignment of the popover content\n *\n * @default \"start\"\n */\n align?: \"center\" | \"end\" | \"start\";\n}\n\n/**\n * Show a help text for a word or phrase when clicked\n *\n * Useful for providing explanations for domain-specific terms, acronyms or phrases that could do with further elaboration\n *\n * @example\n * ```tsx\n * <p>\n * En annen avgjørende faktor for avgifter er om nettbutikken er registrert i{\" \"}\n * <HelpText helpText={`VOEC er en forkortelse for \"VAT on E-commerce\" (mva. på e-handel).`}>\n * VOEC\n * </HelpText>\n * </p>\n * ```\n */\nexport const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(\n (\n { children, className, helpText, title, side = \"top\", align = \"start\", boxProps, ...rest },\n ref,\n ) => {\n return (\n // NOTE: Using radix's [Popover component](https://www.radix-ui.com/primitives/docs/components/popover)\n // In the future we can use the native popover api, but as of writing, though all browsers support it\n // it's not far enough back to be used in production\n // https://caniuse.com/mdn-html_elements_input_popovertarget\n <Popover.Root>\n <Popover.Trigger asChild>\n <button\n ref={ref}\n className={clsx(\"hds-help-text-button\", className as undefined)}\n title={title}\n type=\"button\"\n {...rest}\n >\n {children}\n </button>\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Content asChild side={side} align={align}>\n <Box\n {...boxProps}\n className={clsx(\"hds-help-text-box\", boxProps?.className as undefined)}\n >\n <Popover.Close asChild>\n <Box.CloseButton />\n </Popover.Close>\n {helpText}\n </Box>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n },\n);\nHelpText.displayName = \"HelpText\";\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Slot, Slottable } from \"@radix-ui/react-slot\";\n\nfunction CloseIcon() {\n return (\n <svg aria-hidden xmlns=\"http://www.w3.org/2000/svg\" width={32} height={32} viewBox=\"0 0 32 32\">\n <path\n d=\"M17.5469 16.3333L22.375 11.5521L23.3594 10.5677C23.5 10.4271 23.5 10.1927 23.3594 10.0052L22.3281 8.97394C22.1406 8.83331 21.9062 8.83331 21.7656 8.97394L16 14.7864L10.1875 8.97394C10.0469 8.83331 9.8125 8.83331 9.625 8.97394L8.59375 10.0052C8.45312 10.1927 8.45312 10.4271 8.59375 10.5677L14.4062 16.3333L8.59375 22.1458C8.45312 22.2864 8.45312 22.5208 8.59375 22.7083L9.625 23.7396C9.8125 23.8802 10.0469 23.8802 10.1875 23.7396L16 17.9271L20.7812 22.7552L21.7656 23.7396C21.9062 23.8802 22.1406 23.8802 22.3281 23.7396L23.3594 22.7083C23.5 22.5208 23.5 22.2864 23.3594 22.1458L17.5469 16.3333Z\"\n fill=\"currentColor\"\n />\n </svg>\n );\n}\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 <CloseIcon />\n </button>\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n children?: React.ReactNode;\n\n /**\n * Posten/Bring-spesific variant of the box. NB: warning variant is deprecated, use data-color=\"warning\" instead.\n *\n * @default \"light-grey\"\n */\n variant?:\n | \"light-grey\"\n | \"lighter\"\n | \"white\"\n /** @deprecated use data-color=\"warning\" instead */\n | \"warning\";\n\n /**\n * Color variant of the box\n *\n */\n\n \"data-color\"?: \"neutral\" | \"info\" | \"success\" | \"warning\" | \"error\";\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 * @default false\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 /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\n\nconst convertVariantToColor = (variant: BoxProps[\"variant\"] | \"\") => {\n switch (variant) {\n case \"lighter\":\n return \"\";\n case \"white\":\n return \"\";\n case \"warning\":\n return \"warning\";\n default:\n return \"neutral\";\n }\n};\n\nexport const Box = forwardRef<HTMLDivElement, BoxProps>(\n (\n {\n \"data-color\": color = \"\",\n asChild,\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 const Component = asChild ? Slot : \"div\";\n\n const resolvedColor = color && color !== \"\" ? color : convertVariantToColor(variant);\n\n return (\n <Component\n data-color={resolvedColor}\n className={clsx(\n \"hds-box\",\n { \"hds-box--lighter\": variant === \"lighter\" },\n { \"hds-box--white\": variant === \"white\" },\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n <Slottable>{children}</Slottable>\n </Component>\n );\n },\n) as BoxType;\nBox.displayName = \"Box\";\n\nBox.CloseButton = BoxCloseButton;\n\ntype BoxType = ReturnType<typeof forwardRef<HTMLDivElement, BoxProps>> & {\n CloseButton: typeof BoxCloseButton;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAAyB;AACzB,IAAAA,0BAAqB;AACrB,IAAAC,gBAA2B;;;ACF3B,mBAAkD;AAClD,6BAAqB;AACrB,wBAAgC;AAK1B;AAHN,SAAS,YAAY;AACnB,SACE,4CAAC,SAAI,eAAW,MAAC,OAAM,8BAA6B,OAAO,IAAI,QAAQ,IAAI,SAAQ,aACjF;AAAA,IAAC;AAAA;AAAA,MACC,GAAE;AAAA,MACF,MAAK;AAAA;AAAA,EACP,GACF;AAEJ;AAGO,IAAM,qBAAiB;AAAA,EAC5B,CAAC,IAAwB,QAAQ;AAAhC,iBAAE,YAjBL,IAiBG,IAAgB,iBAAhB,IAAgB,CAAd;AACD,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,6BAAK,yBAAyB,SAAsB;AAAA,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;AAAA,QAYE;AAAA,sBAAY,4CAAC,iCAAe,SAAS,WAAa,iBAAkB,IAAK;AAAA,UAC1E,4CAAC,+BAAW,UAAS;AAAA;AAAA;AAAA,IACvB;AAAA,EAEJ;AACF;AACA,IAAI,cAAc;AAElB,IAAI,cAAc;;;AD1FR,IAAAC,sBAAA;AAZH,IAAM,eAAW;AAAA,EACtB,CACE,IACA,QACG;AAFH,iBAAE,YAAU,WAAW,UAAU,OAAO,OAAO,OAAO,QAAQ,SAAS,SA5D3E,IA4DI,IAAoF,iBAApF,IAAoF,CAAlF,YAAU,aAAW,YAAU,SAAO,QAAc,SAAiB;AAGvE;AAAA;AAAA;AAAA;AAAA;AAAA,MAKE,8CAAS,cAAR,EACC;AAAA,qDAAS,iBAAR,EAAgB,SAAO,MACtB;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA,eAAW,8BAAK,wBAAwB,SAAsB;AAAA,YAC9D;AAAA,YACA,MAAK;AAAA,aACD,OALL;AAAA,YAOE;AAAA;AAAA,QACH,GACF;AAAA,QACA,6CAAS,gBAAR,EACC,uDAAS,iBAAR,EAAgB,SAAO,MAAC,MAAY,OACnC;AAAA,UAAC;AAAA,2CACK,WADL;AAAA,YAEC,eAAW,8BAAK,qBAAqB,qCAAU,SAAsB;AAAA,YAErE;AAAA,2DAAS,eAAR,EAAc,SAAO,MACpB,uDAAC,IAAI,aAAJ,EAAgB,GACnB;AAAA,cACC;AAAA;AAAA;AAAA,QACH,GACF,GACF;AAAA,SACF;AAAA;AAAA,EAEJ;AACF;AACA,SAAS,cAAc;","names":["import_typed_classname","import_react","import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../../src/help-text/help-text.tsx","../../src/box/box.tsx","../../src/button/button.tsx"],"sourcesContent":["import * as Popover from \"@radix-ui/react-popover\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef } from \"react\";\nimport { Box } from \"../box\";\n\ninterface HelpTextProps extends React.HTMLAttributes<HTMLButtonElement> {\n className?: string;\n\n /**\n * The content of the help text, often a word or phrase that could use some explanation\n */\n children: React.ReactNode;\n\n /**\n * The help text that will be shown when the user clicks the trigger\n */\n helpText: React.ReactNode;\n\n /**\n * The title of the help text. Used by screen readers and if the user hover over the help text\n */\n title?: string;\n\n /**\n * Props for the `Box` that contains the help text\n */\n boxProps?: React.ComponentProps<typeof Box>;\n\n /**\n * The side of the trigger the popover should be attached to\n *\n * @default \"top\"\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n\n /**\n * The alignment of the popover content\n *\n * @default \"start\"\n */\n align?: \"center\" | \"end\" | \"start\";\n}\n\n/**\n * Show a help text for a word or phrase when clicked\n *\n * Useful for providing explanations for domain-specific terms, acronyms or phrases that could do with further elaboration\n *\n * @example\n * ```tsx\n * <p>\n * En annen avgjørende faktor for avgifter er om nettbutikken er registrert i{\" \"}\n * <HelpText helpText={`VOEC er en forkortelse for \"VAT on E-commerce\" (mva. på e-handel).`}>\n * VOEC\n * </HelpText>\n * </p>\n * ```\n */\nexport const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(\n (\n { children, className, helpText, title, side = \"top\", align = \"start\", boxProps, ...rest },\n ref,\n ) => {\n return (\n // NOTE: Using radix's [Popover component](https://www.radix-ui.com/primitives/docs/components/popover)\n // In the future we can use the native popover api, but as of writing, though all browsers support it\n // it's not far enough back to be used in production\n // https://caniuse.com/mdn-html_elements_input_popovertarget\n <Popover.Root>\n <Popover.Trigger asChild>\n <button\n ref={ref}\n className={clsx(\"hds-help-text-button\", className as undefined)}\n title={title}\n type=\"button\"\n {...rest}\n >\n {children}\n </button>\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Content asChild side={side} align={align}>\n <Box\n {...boxProps}\n className={clsx(\"hds-help-text-box\", boxProps?.className as undefined)}\n >\n <Popover.Close asChild>\n <Box.CloseButton />\n </Popover.Close>\n {helpText}\n </Box>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n },\n);\nHelpText.displayName = \"HelpText\";\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Slot, Slottable } from \"@radix-ui/react-slot\";\nimport { Button } from \"../button/button\";\n\nfunction CloseIcon() {\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 640 640\">\n <path d=\"M183.1 137.4C170.6 124.9 150.3 124.9 137.8 137.4C125.3 149.9 125.3 170.2 137.8 182.7L275.2 320L137.9 457.4C125.4 469.9 125.4 490.2 137.9 502.7C150.4 515.2 170.7 515.2 183.2 502.7L320.5 365.3L457.9 502.6C470.4 515.1 490.7 515.1 503.2 502.6C515.7 490.1 515.7 469.8 503.2 457.3L365.8 320L503.1 182.6C515.6 170.1 515.6 149.8 503.1 137.3C490.6 124.8 470.3 124.8 457.8 137.3L320.5 274.7L183.1 137.4z\" />\n </svg>\n );\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 variant=\"tertiary\"\n size=\"small\"\n icon\n ref={ref}\n type=\"button\"\n {...rest}\n >\n <CloseIcon />\n </Button>\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n children?: React.ReactNode;\n\n /**\n * Posten/Bring-spesific variant of the box. NB: warning variant is deprecated, use data-color=\"warning\" instead.\n *\n * @default \"light-grey\"\n */\n variant?:\n | \"light-grey\"\n | \"lighter\"\n | \"white\"\n /** @deprecated use data-color=\"warning\" instead */\n | \"warning\";\n\n /**\n * Color variant of the box\n *\n */\n\n \"data-color\"?: \"neutral\" | \"info\" | \"success\" | \"warning\" | \"error\";\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 * @default false\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 /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\n\nconst convertVariantToColor = (variant: BoxProps[\"variant\"] | \"\") => {\n switch (variant) {\n case \"lighter\":\n return \"\";\n case \"white\":\n return \"\";\n case \"warning\":\n return \"warning\";\n default:\n return \"neutral\";\n }\n};\n\nexport const Box = forwardRef<HTMLDivElement, BoxProps>(\n (\n {\n \"data-color\": color = \"\",\n asChild,\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 const Component = asChild ? Slot : \"div\";\n\n const resolvedColor = color && color !== \"\" ? color : convertVariantToColor(variant);\n\n return (\n <Component\n data-color={resolvedColor}\n className={clsx(\n \"hds-box\",\n { \"hds-box--lighter\": variant === \"lighter\" },\n { \"hds-box--white\": variant === \"white\" },\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n <Slottable>{children}</Slottable>\n </Component>\n );\n },\n) as BoxType;\nBox.displayName = \"Box\";\n\nBox.CloseButton = BoxCloseButton;\n\ntype BoxType = ReturnType<typeof forwardRef<HTMLDivElement, BoxProps>> & {\n CloseButton: typeof BoxCloseButton;\n};\n","import { forwardRef } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Slot } from \"@radix-ui/react-slot\";\n\n/**\n * @deprecated The \"inverted\" variant is deprecated. Use \"primary\", \"secondary\", or \"tertiary\" instead.\n */\nexport type DeprecatedVariant = \"inverted\";\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /**\n * The height, font size and padding of the button\n *\n * @default \"large\"\n */\n size?: \"small\" | \"large\";\n\n /**\n * The background and fill of the button\n *\n * @default \"primary\"\n */\n variant?: \"primary\" | \"secondary\" | \"tertiary\" | DeprecatedVariant;\n\n /**\n * Make the button use 100% width available.\n * Using the \"mobile\" it only stretch to full width on smaller screens\n */\n fullWidth?: boolean | \"mobile\";\n\n /**\n * Specify that there is an icon in the button.\n * `icon`: There is only an icon in the button.\n * `icon=\"leading\"`: There is an icon before the text.\n * `icon=\"trailing\"`: There is an icon after the text.\n *\n * @default false\n */\n icon?: boolean | \"leading\" | \"trailing\";\n\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\n\n/**\n * Button component\n *\n * @example\n * <Button variant=\"primary\">Primary</Button>\n * <Button variant=\"secondary\" size=\"large\">Secondary</Button>\n * <Button variant=\"tertiary\" fullWidth=\"mobile\">Tertiary</Button>\n * <Button icon=\"leading\"><LeadingIcon />Leading icon</Button>\n *\n * @example\n * // If used for navigation use the `asChild` prop with a anchor element as a child.\n * <Button asChild><a href=\"/home\">Home</a></Button>\n */\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n asChild,\n children,\n variant = \"primary\",\n size = \"large\",\n fullWidth = false,\n icon = false,\n className,\n ...rest\n },\n ref,\n ) => {\n const Component = asChild ? Slot : \"button\";\n\n return (\n <Component\n className={clsx(\n \"hds-button\",\n `hds-button--${size}`,\n `hds-button--${variant}`,\n {\n \"hds-button--full\": fullWidth === true,\n \"hds-button--mobile-full\": fullWidth === \"mobile\",\n \"hds-button--only-icon\": icon === true,\n \"hds-button--leading-icon\": icon === \"leading\",\n \"hds-button--trailing-icon\": icon === \"trailing\",\n },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {children}\n </Component>\n );\n },\n);\nButton.displayName = \"Button\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAAyB;AACzB,IAAAA,0BAAqB;AACrB,IAAAC,gBAA2B;;;ACF3B,IAAAC,gBAAkD;AAClD,IAAAC,0BAAqB;AACrB,IAAAC,qBAAgC;;;ACFhC,mBAA2B;AAC3B,6BAAqB;AACrB,wBAAqB;AA4Ef;AAjBC,IAAM,aAAS;AAAA,EACpB,CACE,IAUA,QACG;AAXH,iBACE;AAAA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,OAAO;AAAA,MACP;AAAA,IAtEN,IA+DI,IAQK,iBARL,IAQK;AAAA,MAPH;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAKF,UAAM,YAAY,UAAU,yBAAO;AAEnC,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW;AAAA,UACT;AAAA,UACA,eAAe,IAAI;AAAA,UACnB,eAAe,OAAO;AAAA,UACtB;AAAA,YACE,oBAAoB,cAAc;AAAA,YAClC,2BAA2B,cAAc;AAAA,YACzC,yBAAyB,SAAS;AAAA,YAClC,4BAA4B,SAAS;AAAA,YACrC,6BAA6B,SAAS;AAAA,UACxC;AAAA,UACA;AAAA,QACF;AAAA,QAC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AqB,qCAAU,SAAsB;AAAA,YAErE;AAAA,2DAAS,eAAR,EAAc,SAAO,MACpB,uDAAC,IAAI,aAAJ,EAAgB,GACnB;AAAA,cACC;AAAA;AAAA;AAAA,QACH,GACF,GACF;AAAA,SACF;AAAA;AAAA,EAEJ;AACF;AACA,SAAS,cAAc;","names":["import_typed_classname","import_react","import_react","import_typed_classname","import_react_slot","import_jsx_runtime","import_jsx_runtime"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HelpText
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-KAVKFO2R.mjs";
|
|
4
4
|
import "../chunk-BCFV6VOE.mjs";
|
|
5
|
-
import "../chunk-
|
|
5
|
+
import "../chunk-P4AKOVM7.mjs";
|
|
6
|
+
import "../chunk-45Q2TCH6.mjs";
|
|
6
7
|
import "../chunk-YOSPWY5K.mjs";
|
|
7
8
|
export {
|
|
8
9
|
HelpText
|
package/dist/help-text/index.js
CHANGED
|
@@ -65,34 +65,83 @@ module.exports = __toCommonJS(help_text_exports);
|
|
|
65
65
|
|
|
66
66
|
// src/help-text/help-text.tsx
|
|
67
67
|
var Popover = __toESM(require("@radix-ui/react-popover"));
|
|
68
|
-
var
|
|
69
|
-
var
|
|
68
|
+
var import_typed_classname3 = require("@postenbring/hedwig-css/typed-classname");
|
|
69
|
+
var import_react3 = require("react");
|
|
70
70
|
|
|
71
71
|
// src/box/box.tsx
|
|
72
|
+
var import_react2 = require("react");
|
|
73
|
+
var import_typed_classname2 = require("@postenbring/hedwig-css/typed-classname");
|
|
74
|
+
var import_react_slot2 = require("@radix-ui/react-slot");
|
|
75
|
+
|
|
76
|
+
// src/button/button.tsx
|
|
72
77
|
var import_react = require("react");
|
|
73
78
|
var import_typed_classname = require("@postenbring/hedwig-css/typed-classname");
|
|
74
79
|
var import_react_slot = require("@radix-ui/react-slot");
|
|
75
80
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
81
|
+
var Button = (0, import_react.forwardRef)(
|
|
82
|
+
(_a, ref) => {
|
|
83
|
+
var _b = _a, {
|
|
84
|
+
asChild,
|
|
85
|
+
children,
|
|
86
|
+
variant = "primary",
|
|
87
|
+
size = "large",
|
|
88
|
+
fullWidth = false,
|
|
89
|
+
icon = false,
|
|
90
|
+
className
|
|
91
|
+
} = _b, rest = __objRest(_b, [
|
|
92
|
+
"asChild",
|
|
93
|
+
"children",
|
|
94
|
+
"variant",
|
|
95
|
+
"size",
|
|
96
|
+
"fullWidth",
|
|
97
|
+
"icon",
|
|
98
|
+
"className"
|
|
99
|
+
]);
|
|
100
|
+
const Component = asChild ? import_react_slot.Slot : "button";
|
|
101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
102
|
+
Component,
|
|
103
|
+
__spreadProps(__spreadValues({
|
|
104
|
+
className: (0, import_typed_classname.clsx)(
|
|
105
|
+
"hds-button",
|
|
106
|
+
`hds-button--${size}`,
|
|
107
|
+
`hds-button--${variant}`,
|
|
108
|
+
{
|
|
109
|
+
"hds-button--full": fullWidth === true,
|
|
110
|
+
"hds-button--mobile-full": fullWidth === "mobile",
|
|
111
|
+
"hds-button--only-icon": icon === true,
|
|
112
|
+
"hds-button--leading-icon": icon === "leading",
|
|
113
|
+
"hds-button--trailing-icon": icon === "trailing"
|
|
114
|
+
},
|
|
115
|
+
className
|
|
116
|
+
),
|
|
117
|
+
ref
|
|
118
|
+
}, rest), {
|
|
119
|
+
children
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
Button.displayName = "Button";
|
|
125
|
+
|
|
126
|
+
// src/box/box.tsx
|
|
127
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
76
128
|
function CloseIcon() {
|
|
77
|
-
return /* @__PURE__ */ (0,
|
|
78
|
-
"path",
|
|
79
|
-
{
|
|
80
|
-
d: "M17.5469 16.3333L22.375 11.5521L23.3594 10.5677C23.5 10.4271 23.5 10.1927 23.3594 10.0052L22.3281 8.97394C22.1406 8.83331 21.9062 8.83331 21.7656 8.97394L16 14.7864L10.1875 8.97394C10.0469 8.83331 9.8125 8.83331 9.625 8.97394L8.59375 10.0052C8.45312 10.1927 8.45312 10.4271 8.59375 10.5677L14.4062 16.3333L8.59375 22.1458C8.45312 22.2864 8.45312 22.5208 8.59375 22.7083L9.625 23.7396C9.8125 23.8802 10.0469 23.8802 10.1875 23.7396L16 17.9271L20.7812 22.7552L21.7656 23.7396C21.9062 23.8802 22.1406 23.8802 22.3281 23.7396L23.3594 22.7083C23.5 22.5208 23.5 22.2864 23.3594 22.1458L17.5469 16.3333Z",
|
|
81
|
-
fill: "currentColor"
|
|
82
|
-
}
|
|
83
|
-
) });
|
|
129
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 640 640", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M183.1 137.4C170.6 124.9 150.3 124.9 137.8 137.4C125.3 149.9 125.3 170.2 137.8 182.7L275.2 320L137.9 457.4C125.4 469.9 125.4 490.2 137.9 502.7C150.4 515.2 170.7 515.2 183.2 502.7L320.5 365.3L457.9 502.6C470.4 515.1 490.7 515.1 503.2 502.6C515.7 490.1 515.7 469.8 503.2 457.3L365.8 320L503.1 182.6C515.6 170.1 515.6 149.8 503.1 137.3C490.6 124.8 470.3 124.8 457.8 137.3L320.5 274.7L183.1 137.4z" }) });
|
|
84
130
|
}
|
|
85
|
-
var BoxCloseButton = (0,
|
|
131
|
+
var BoxCloseButton = (0, import_react2.forwardRef)(
|
|
86
132
|
(_a, ref) => {
|
|
87
133
|
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
88
|
-
return /* @__PURE__ */ (0,
|
|
89
|
-
|
|
134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
135
|
+
Button,
|
|
90
136
|
__spreadProps(__spreadValues({
|
|
91
|
-
className: (0,
|
|
137
|
+
className: (0, import_typed_classname2.clsx)("hds-box__close-button", className),
|
|
138
|
+
variant: "tertiary",
|
|
139
|
+
size: "small",
|
|
140
|
+
icon: true,
|
|
92
141
|
ref,
|
|
93
142
|
type: "button"
|
|
94
143
|
}, rest), {
|
|
95
|
-
children: /* @__PURE__ */ (0,
|
|
144
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CloseIcon, {})
|
|
96
145
|
})
|
|
97
146
|
);
|
|
98
147
|
}
|
|
@@ -110,7 +159,7 @@ var convertVariantToColor = (variant) => {
|
|
|
110
159
|
return "neutral";
|
|
111
160
|
}
|
|
112
161
|
};
|
|
113
|
-
var Box = (0,
|
|
162
|
+
var Box = (0, import_react2.forwardRef)(
|
|
114
163
|
(_a, ref) => {
|
|
115
164
|
var _b = _a, {
|
|
116
165
|
"data-color": color = "",
|
|
@@ -133,8 +182,8 @@ var Box = (0, import_react.forwardRef)(
|
|
|
133
182
|
"children",
|
|
134
183
|
"className"
|
|
135
184
|
]);
|
|
136
|
-
const [closedState, setClosedState] = (0,
|
|
137
|
-
const onClose = (0,
|
|
185
|
+
const [closedState, setClosedState] = (0, import_react2.useState)(false);
|
|
186
|
+
const onClose = (0, import_react2.useCallback)(() => {
|
|
138
187
|
if (onCloseProp) {
|
|
139
188
|
const result = onCloseProp();
|
|
140
189
|
if (result === true) {
|
|
@@ -145,13 +194,13 @@ var Box = (0, import_react.forwardRef)(
|
|
|
145
194
|
}
|
|
146
195
|
}, []);
|
|
147
196
|
const closed = closedProp != null ? closedProp : closedState;
|
|
148
|
-
const Component = asChild ?
|
|
197
|
+
const Component = asChild ? import_react_slot2.Slot : "div";
|
|
149
198
|
const resolvedColor = color && color !== "" ? color : convertVariantToColor(variant);
|
|
150
|
-
return /* @__PURE__ */ (0,
|
|
199
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
151
200
|
Component,
|
|
152
201
|
__spreadProps(__spreadValues({
|
|
153
202
|
"data-color": resolvedColor,
|
|
154
|
-
className: (0,
|
|
203
|
+
className: (0, import_typed_classname2.clsx)(
|
|
155
204
|
"hds-box",
|
|
156
205
|
{ "hds-box--lighter": variant === "lighter" },
|
|
157
206
|
{ "hds-box--white": variant === "white" },
|
|
@@ -161,8 +210,8 @@ var Box = (0, import_react.forwardRef)(
|
|
|
161
210
|
ref
|
|
162
211
|
}, rest), {
|
|
163
212
|
children: [
|
|
164
|
-
closeable ? /* @__PURE__ */ (0,
|
|
165
|
-
/* @__PURE__ */ (0,
|
|
213
|
+
closeable ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BoxCloseButton, __spreadValues({ onClick: onClose }, closeButtonProps)) : null,
|
|
214
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_slot2.Slottable, { children })
|
|
166
215
|
]
|
|
167
216
|
})
|
|
168
217
|
);
|
|
@@ -172,8 +221,8 @@ Box.displayName = "Box";
|
|
|
172
221
|
Box.CloseButton = BoxCloseButton;
|
|
173
222
|
|
|
174
223
|
// src/help-text/help-text.tsx
|
|
175
|
-
var
|
|
176
|
-
var HelpText = (0,
|
|
224
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
225
|
+
var HelpText = (0, import_react3.forwardRef)(
|
|
177
226
|
(_a, ref) => {
|
|
178
227
|
var _b = _a, { children, className, helpText, title, side = "top", align = "start", boxProps } = _b, rest = __objRest(_b, ["children", "className", "helpText", "title", "side", "align", "boxProps"]);
|
|
179
228
|
return (
|
|
@@ -181,24 +230,24 @@ var HelpText = (0, import_react2.forwardRef)(
|
|
|
181
230
|
// In the future we can use the native popover api, but as of writing, though all browsers support it
|
|
182
231
|
// it's not far enough back to be used in production
|
|
183
232
|
// https://caniuse.com/mdn-html_elements_input_popovertarget
|
|
184
|
-
/* @__PURE__ */ (0,
|
|
185
|
-
/* @__PURE__ */ (0,
|
|
233
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Popover.Root, { children: [
|
|
234
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
186
235
|
"button",
|
|
187
236
|
__spreadProps(__spreadValues({
|
|
188
237
|
ref,
|
|
189
|
-
className: (0,
|
|
238
|
+
className: (0, import_typed_classname3.clsx)("hds-help-text-button", className),
|
|
190
239
|
title,
|
|
191
240
|
type: "button"
|
|
192
241
|
}, rest), {
|
|
193
242
|
children
|
|
194
243
|
})
|
|
195
244
|
) }),
|
|
196
|
-
/* @__PURE__ */ (0,
|
|
245
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Content, { asChild: true, side, align, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
197
246
|
Box,
|
|
198
247
|
__spreadProps(__spreadValues({}, boxProps), {
|
|
199
|
-
className: (0,
|
|
248
|
+
className: (0, import_typed_classname3.clsx)("hds-help-text-box", boxProps == null ? void 0 : boxProps.className),
|
|
200
249
|
children: [
|
|
201
|
-
/* @__PURE__ */ (0,
|
|
250
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Popover.Close, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box.CloseButton, {}) }),
|
|
202
251
|
helpText
|
|
203
252
|
]
|
|
204
253
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/help-text/index.ts","../../src/help-text/help-text.tsx","../../src/box/box.tsx"],"sourcesContent":["export { HelpText } from \"./help-text\";\nexport type * from \"./help-text\";\n","import * as Popover from \"@radix-ui/react-popover\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef } from \"react\";\nimport { Box } from \"../box\";\n\ninterface HelpTextProps extends React.HTMLAttributes<HTMLButtonElement> {\n className?: string;\n\n /**\n * The content of the help text, often a word or phrase that could use some explanation\n */\n children: React.ReactNode;\n\n /**\n * The help text that will be shown when the user clicks the trigger\n */\n helpText: React.ReactNode;\n\n /**\n * The title of the help text. Used by screen readers and if the user hover over the help text\n */\n title?: string;\n\n /**\n * Props for the `Box` that contains the help text\n */\n boxProps?: React.ComponentProps<typeof Box>;\n\n /**\n * The side of the trigger the popover should be attached to\n *\n * @default \"top\"\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n\n /**\n * The alignment of the popover content\n *\n * @default \"start\"\n */\n align?: \"center\" | \"end\" | \"start\";\n}\n\n/**\n * Show a help text for a word or phrase when clicked\n *\n * Useful for providing explanations for domain-specific terms, acronyms or phrases that could do with further elaboration\n *\n * @example\n * ```tsx\n * <p>\n * En annen avgjørende faktor for avgifter er om nettbutikken er registrert i{\" \"}\n * <HelpText helpText={`VOEC er en forkortelse for \"VAT on E-commerce\" (mva. på e-handel).`}>\n * VOEC\n * </HelpText>\n * </p>\n * ```\n */\nexport const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(\n (\n { children, className, helpText, title, side = \"top\", align = \"start\", boxProps, ...rest },\n ref,\n ) => {\n return (\n // NOTE: Using radix's [Popover component](https://www.radix-ui.com/primitives/docs/components/popover)\n // In the future we can use the native popover api, but as of writing, though all browsers support it\n // it's not far enough back to be used in production\n // https://caniuse.com/mdn-html_elements_input_popovertarget\n <Popover.Root>\n <Popover.Trigger asChild>\n <button\n ref={ref}\n className={clsx(\"hds-help-text-button\", className as undefined)}\n title={title}\n type=\"button\"\n {...rest}\n >\n {children}\n </button>\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Content asChild side={side} align={align}>\n <Box\n {...boxProps}\n className={clsx(\"hds-help-text-box\", boxProps?.className as undefined)}\n >\n <Popover.Close asChild>\n <Box.CloseButton />\n </Popover.Close>\n {helpText}\n </Box>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n },\n);\nHelpText.displayName = \"HelpText\";\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Slot, Slottable } from \"@radix-ui/react-slot\";\n\nfunction CloseIcon() {\n return (\n <svg aria-hidden xmlns=\"http://www.w3.org/2000/svg\" width={32} height={32} viewBox=\"0 0 32 32\">\n <path\n d=\"M17.5469 16.3333L22.375 11.5521L23.3594 10.5677C23.5 10.4271 23.5 10.1927 23.3594 10.0052L22.3281 8.97394C22.1406 8.83331 21.9062 8.83331 21.7656 8.97394L16 14.7864L10.1875 8.97394C10.0469 8.83331 9.8125 8.83331 9.625 8.97394L8.59375 10.0052C8.45312 10.1927 8.45312 10.4271 8.59375 10.5677L14.4062 16.3333L8.59375 22.1458C8.45312 22.2864 8.45312 22.5208 8.59375 22.7083L9.625 23.7396C9.8125 23.8802 10.0469 23.8802 10.1875 23.7396L16 17.9271L20.7812 22.7552L21.7656 23.7396C21.9062 23.8802 22.1406 23.8802 22.3281 23.7396L23.3594 22.7083C23.5 22.5208 23.5 22.2864 23.3594 22.1458L17.5469 16.3333Z\"\n fill=\"currentColor\"\n />\n </svg>\n );\n}\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 <CloseIcon />\n </button>\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n children?: React.ReactNode;\n\n /**\n * Posten/Bring-spesific variant of the box. NB: warning variant is deprecated, use data-color=\"warning\" instead.\n *\n * @default \"light-grey\"\n */\n variant?:\n | \"light-grey\"\n | \"lighter\"\n | \"white\"\n /** @deprecated use data-color=\"warning\" instead */\n | \"warning\";\n\n /**\n * Color variant of the box\n *\n */\n\n \"data-color\"?: \"neutral\" | \"info\" | \"success\" | \"warning\" | \"error\";\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 * @default false\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 /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\n\nconst convertVariantToColor = (variant: BoxProps[\"variant\"] | \"\") => {\n switch (variant) {\n case \"lighter\":\n return \"\";\n case \"white\":\n return \"\";\n case \"warning\":\n return \"warning\";\n default:\n return \"neutral\";\n }\n};\n\nexport const Box = forwardRef<HTMLDivElement, BoxProps>(\n (\n {\n \"data-color\": color = \"\",\n asChild,\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 const Component = asChild ? Slot : \"div\";\n\n const resolvedColor = color && color !== \"\" ? color : convertVariantToColor(variant);\n\n return (\n <Component\n data-color={resolvedColor}\n className={clsx(\n \"hds-box\",\n { \"hds-box--lighter\": variant === \"lighter\" },\n { \"hds-box--white\": variant === \"white\" },\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n <Slottable>{children}</Slottable>\n </Component>\n );\n },\n) as BoxType;\nBox.displayName = \"Box\";\n\nBox.CloseButton = BoxCloseButton;\n\ntype BoxType = ReturnType<typeof forwardRef<HTMLDivElement, BoxProps>> & {\n CloseButton: typeof BoxCloseButton;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,cAAyB;AACzB,IAAAA,0BAAqB;AACrB,IAAAC,gBAA2B;;;ACF3B,mBAAkD;AAClD,6BAAqB;AACrB,wBAAgC;AAK1B;AAHN,SAAS,YAAY;AACnB,SACE,4CAAC,SAAI,eAAW,MAAC,OAAM,8BAA6B,OAAO,IAAI,QAAQ,IAAI,SAAQ,aACjF;AAAA,IAAC;AAAA;AAAA,MACC,GAAE;AAAA,MACF,MAAK;AAAA;AAAA,EACP,GACF;AAEJ;AAGO,IAAM,qBAAiB;AAAA,EAC5B,CAAC,IAAwB,QAAQ;AAAhC,iBAAE,YAjBL,IAiBG,IAAgB,iBAAhB,IAAgB,CAAd;AACD,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,6BAAK,yBAAyB,SAAsB;AAAA,QAC/D;AAAA,QACA,MAAK;AAAA,SACD,OAJL;AAAA,QAMC,sDAAC,aAAU;AAAA;AAAA,IACb;AAAA,EAEJ;AACF;AACA,eAAe,cAAc;AA+D7B,IAAM,wBAAwB,CAAC,YAAsC;AACnE,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,IAAM,UAAM;AAAA,EACjB,CACE,IAYA,QACG;AAbH,iBACE;AAAA,oBAAc,QAAQ;AAAA,MACtB;AAAA,MACA;AAAA,MACA,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AAA;AAAA;AAAA;AAAA,MAKE,8CAAS,cAAR,EACC;AAAA,qDAAS,iBAAR,EAAgB,SAAO,MACtB;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA,eAAW,8BAAK,wBAAwB,SAAsB;AAAA,YAC9D;AAAA,YACA,MAAK;AAAA,aACD,OALL;AAAA,YAOE;AAAA;AAAA,QACH,GACF;AAAA,QACA,6CAAS,gBAAR,EACC,uDAAS,iBAAR,EAAgB,SAAO,MAAC,MAAY,OACnC;AAAA,UAAC;AAAA,2CACK,WADL;AAAA,YAEC,eAAW,8BAAK,qBAAqB,qCAAU,SAAsB;AAAA,YAErE;AAAA,2DAAS,eAAR,EAAc,SAAO,MACpB,uDAAC,IAAI,aAAJ,EAAgB,GACnB;AAAA,cACC;AAAA;AAAA;AAAA,QACH,GACF,GACF;AAAA,SACF;AAAA;AAAA,EAEJ;AACF;AACA,SAAS,cAAc;","names":["import_typed_classname","import_react","import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../../src/help-text/index.ts","../../src/help-text/help-text.tsx","../../src/box/box.tsx","../../src/button/button.tsx"],"sourcesContent":["export { HelpText } from \"./help-text\";\nexport type * from \"./help-text\";\n","import * as Popover from \"@radix-ui/react-popover\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef } from \"react\";\nimport { Box } from \"../box\";\n\ninterface HelpTextProps extends React.HTMLAttributes<HTMLButtonElement> {\n className?: string;\n\n /**\n * The content of the help text, often a word or phrase that could use some explanation\n */\n children: React.ReactNode;\n\n /**\n * The help text that will be shown when the user clicks the trigger\n */\n helpText: React.ReactNode;\n\n /**\n * The title of the help text. Used by screen readers and if the user hover over the help text\n */\n title?: string;\n\n /**\n * Props for the `Box` that contains the help text\n */\n boxProps?: React.ComponentProps<typeof Box>;\n\n /**\n * The side of the trigger the popover should be attached to\n *\n * @default \"top\"\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n\n /**\n * The alignment of the popover content\n *\n * @default \"start\"\n */\n align?: \"center\" | \"end\" | \"start\";\n}\n\n/**\n * Show a help text for a word or phrase when clicked\n *\n * Useful for providing explanations for domain-specific terms, acronyms or phrases that could do with further elaboration\n *\n * @example\n * ```tsx\n * <p>\n * En annen avgjørende faktor for avgifter er om nettbutikken er registrert i{\" \"}\n * <HelpText helpText={`VOEC er en forkortelse for \"VAT on E-commerce\" (mva. på e-handel).`}>\n * VOEC\n * </HelpText>\n * </p>\n * ```\n */\nexport const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(\n (\n { children, className, helpText, title, side = \"top\", align = \"start\", boxProps, ...rest },\n ref,\n ) => {\n return (\n // NOTE: Using radix's [Popover component](https://www.radix-ui.com/primitives/docs/components/popover)\n // In the future we can use the native popover api, but as of writing, though all browsers support it\n // it's not far enough back to be used in production\n // https://caniuse.com/mdn-html_elements_input_popovertarget\n <Popover.Root>\n <Popover.Trigger asChild>\n <button\n ref={ref}\n className={clsx(\"hds-help-text-button\", className as undefined)}\n title={title}\n type=\"button\"\n {...rest}\n >\n {children}\n </button>\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Content asChild side={side} align={align}>\n <Box\n {...boxProps}\n className={clsx(\"hds-help-text-box\", boxProps?.className as undefined)}\n >\n <Popover.Close asChild>\n <Box.CloseButton />\n </Popover.Close>\n {helpText}\n </Box>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n },\n);\nHelpText.displayName = \"HelpText\";\n","import { forwardRef, useCallback, useState } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Slot, Slottable } from \"@radix-ui/react-slot\";\nimport { Button } from \"../button/button\";\n\nfunction CloseIcon() {\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 640 640\">\n <path d=\"M183.1 137.4C170.6 124.9 150.3 124.9 137.8 137.4C125.3 149.9 125.3 170.2 137.8 182.7L275.2 320L137.9 457.4C125.4 469.9 125.4 490.2 137.9 502.7C150.4 515.2 170.7 515.2 183.2 502.7L320.5 365.3L457.9 502.6C470.4 515.1 490.7 515.1 503.2 502.6C515.7 490.1 515.7 469.8 503.2 457.3L365.8 320L503.1 182.6C515.6 170.1 515.6 149.8 503.1 137.3C490.6 124.8 470.3 124.8 457.8 137.3L320.5 274.7L183.1 137.4z\" />\n </svg>\n );\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 variant=\"tertiary\"\n size=\"small\"\n icon\n ref={ref}\n type=\"button\"\n {...rest}\n >\n <CloseIcon />\n </Button>\n );\n },\n);\nBoxCloseButton.displayName = \"Box.CloseButton\";\n\nexport interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {\n children?: React.ReactNode;\n\n /**\n * Posten/Bring-spesific variant of the box. NB: warning variant is deprecated, use data-color=\"warning\" instead.\n *\n * @default \"light-grey\"\n */\n variant?:\n | \"light-grey\"\n | \"lighter\"\n | \"white\"\n /** @deprecated use data-color=\"warning\" instead */\n | \"warning\";\n\n /**\n * Color variant of the box\n *\n */\n\n \"data-color\"?: \"neutral\" | \"info\" | \"success\" | \"warning\" | \"error\";\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 * @default false\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 /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\n\nconst convertVariantToColor = (variant: BoxProps[\"variant\"] | \"\") => {\n switch (variant) {\n case \"lighter\":\n return \"\";\n case \"white\":\n return \"\";\n case \"warning\":\n return \"warning\";\n default:\n return \"neutral\";\n }\n};\n\nexport const Box = forwardRef<HTMLDivElement, BoxProps>(\n (\n {\n \"data-color\": color = \"\",\n asChild,\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 const Component = asChild ? Slot : \"div\";\n\n const resolvedColor = color && color !== \"\" ? color : convertVariantToColor(variant);\n\n return (\n <Component\n data-color={resolvedColor}\n className={clsx(\n \"hds-box\",\n { \"hds-box--lighter\": variant === \"lighter\" },\n { \"hds-box--white\": variant === \"white\" },\n { \"hds-box--closed\": closed },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {closeable ? <BoxCloseButton onClick={onClose} {...closeButtonProps} /> : null}\n <Slottable>{children}</Slottable>\n </Component>\n );\n },\n) as BoxType;\nBox.displayName = \"Box\";\n\nBox.CloseButton = BoxCloseButton;\n\ntype BoxType = ReturnType<typeof forwardRef<HTMLDivElement, BoxProps>> & {\n CloseButton: typeof BoxCloseButton;\n};\n","import { forwardRef } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Slot } from \"@radix-ui/react-slot\";\n\n/**\n * @deprecated The \"inverted\" variant is deprecated. Use \"primary\", \"secondary\", or \"tertiary\" instead.\n */\nexport type DeprecatedVariant = \"inverted\";\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /**\n * The height, font size and padding of the button\n *\n * @default \"large\"\n */\n size?: \"small\" | \"large\";\n\n /**\n * The background and fill of the button\n *\n * @default \"primary\"\n */\n variant?: \"primary\" | \"secondary\" | \"tertiary\" | DeprecatedVariant;\n\n /**\n * Make the button use 100% width available.\n * Using the \"mobile\" it only stretch to full width on smaller screens\n */\n fullWidth?: boolean | \"mobile\";\n\n /**\n * Specify that there is an icon in the button.\n * `icon`: There is only an icon in the button.\n * `icon=\"leading\"`: There is an icon before the text.\n * `icon=\"trailing\"`: There is an icon after the text.\n *\n * @default false\n */\n icon?: boolean | \"leading\" | \"trailing\";\n\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\n\n/**\n * Button component\n *\n * @example\n * <Button variant=\"primary\">Primary</Button>\n * <Button variant=\"secondary\" size=\"large\">Secondary</Button>\n * <Button variant=\"tertiary\" fullWidth=\"mobile\">Tertiary</Button>\n * <Button icon=\"leading\"><LeadingIcon />Leading icon</Button>\n *\n * @example\n * // If used for navigation use the `asChild` prop with a anchor element as a child.\n * <Button asChild><a href=\"/home\">Home</a></Button>\n */\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n asChild,\n children,\n variant = \"primary\",\n size = \"large\",\n fullWidth = false,\n icon = false,\n className,\n ...rest\n },\n ref,\n ) => {\n const Component = asChild ? Slot : \"button\";\n\n return (\n <Component\n className={clsx(\n \"hds-button\",\n `hds-button--${size}`,\n `hds-button--${variant}`,\n {\n \"hds-button--full\": fullWidth === true,\n \"hds-button--mobile-full\": fullWidth === \"mobile\",\n \"hds-button--only-icon\": icon === true,\n \"hds-button--leading-icon\": icon === \"leading\",\n \"hds-button--trailing-icon\": icon === \"trailing\",\n },\n className as undefined,\n )}\n ref={ref}\n {...rest}\n >\n {children}\n </Component>\n );\n },\n);\nButton.displayName = \"Button\";\n"],"mapp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,EAAE,kBAAkB,YAAY,QAAQ;AAAA,UACxC,EAAE,mBAAmB,OAAO;AAAA,UAC5B;AAAA,QACF;AAAA,QACA;AAAA,SACI,OAVL;AAAA,QAYE;AAAA,sBAAY,6CAAC,iCAAe,SAAS,WAAa,iBAAkB,IAAK;AAAA,UAC1E,6CAAC,gCAAW,UAAS;AAAA;AAAA;AAAA,IACvB;AAAA,EAEJ;AACF;AACA,IAAI,cAAc;AAElB,IAAI,cAAc;;;AD1FR,IAAAC,sBAAA;AAZH,IAAM,eAAW;AAAA,EACtB,CACE,IACA,QACG;AAFH,iBAAE,YAAU,WAAW,UAAU,OAAO,OAAO,OAAO,QAAQ,SAAS,SA5D3E,IA4DI,IAAoF,iBAApF,IAAoF,CAAlF,YAAU,aAAW,YAAU,SAAO,QAAc,SAAiB;AAGvE;AAAA;AAAA;AAAA;AAAA;AAAA,MAKE,8CAAS,cAAR,EACC;AAAA,qDAAS,iBAAR,EAAgB,SAAO,MACtB;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA,eAAW,8BAAK,wBAAwB,SAAsB;AAAA,YAC9D;AAAA,YACA,MAAK;AAAA,aACD,OALL;AAAA,YAOE;AAAA;AAAA,QACH,GACF;AAAA,QACA,6CAAS,gBAAR,EACC,uDAAS,iBAAR,EAAgB,SAAO,MAAC,MAAY,OACnC;AAAA,UAAC;AAAA,2CACK,WADL;AAAA,YAEC,eAAW,8BAAK,qBAAqB,qCAAU,SAAsB;AAAA,YAErE;AAAA,2DAAS,eAAR,EAAc,SAAO,MACpB,uDAAC,IAAI,aAAJ,EAAgB,GACnB;AAAA,cACC;AAAA;AAAA;AAAA,QACH,GACF,GACF;AAAA,SACF;AAAA;AAAA,EAEJ;AACF;AACA,SAAS,cAAc;","names":["import_typed_classname","import_react","import_react","import_typed_classname","import_react_slot","import_jsx_runtime","import_jsx_runtime"]}
|
package/dist/help-text/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import "../chunk-CFAH2LID.mjs";
|
|
2
2
|
import {
|
|
3
3
|
HelpText
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-KAVKFO2R.mjs";
|
|
5
5
|
import "../chunk-BCFV6VOE.mjs";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-P4AKOVM7.mjs";
|
|
7
|
+
import "../chunk-45Q2TCH6.mjs";
|
|
7
8
|
import "../chunk-YOSPWY5K.mjs";
|
|
8
9
|
export {
|
|
9
10
|
HelpText
|