@marigold/components 16.1.0 → 17.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,503 @@
1
+ const require_index = require('./index.cjs');
2
+ let react_aria_components = require("react-aria-components");
3
+ let __marigold_system = require("@marigold/system");
4
+ let react = require("react");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ let __react_aria_i18n = require("@react-aria/i18n");
7
+ let __react_aria_utils = require("@react-aria/utils");
8
+
9
+ //#region src/intl/messages.ts
10
+ const intlMessages = {
11
+ "de-DE": {
12
+ bulkActionsAriaLabel: "Massenaktionen",
13
+ cancel: "Abbrechen",
14
+ close: "Schließen",
15
+ clearSelectionAriaLabel: "Auswahl löschen",
16
+ dropZoneLabel: "Dateien hierher ziehen",
17
+ edit: "Bearbeiten",
18
+ editCell: "Zelle bearbeiten",
19
+ help: "Hilfe",
20
+ hiddenBreadcrumbs: "Diese Breadcrumbs sind ausgeblendet",
21
+ items: "Elemente",
22
+ loadingMessage: "Lade...",
23
+ moreInfo: "Mehr Informationen",
24
+ noResultsFound: "Kein Ergebnis gefunden",
25
+ save: "Speichern",
26
+ removeAll: "Alle entfernen",
27
+ removeFile: "Datei entfernen",
28
+ showLess: "Weniger anzeigen",
29
+ showLessCount: "{count} weniger anzeigen",
30
+ showMore: "Mehr anzeigen",
31
+ showMoreCount: "{count} weitere anzeigen",
32
+ uploadLabel: "Hochladen"
33
+ },
34
+ "en-US": {
35
+ bulkActionsAriaLabel: "Bulk Actions",
36
+ cancel: "Cancel",
37
+ close: "Close",
38
+ clearSelectionAriaLabel: "Clear selection",
39
+ dropZoneLabel: "Drop files here",
40
+ edit: "Edit",
41
+ editCell: "Edit cell",
42
+ help: "Help",
43
+ hiddenBreadcrumbs: "These breadcrumbs are hidden",
44
+ items: "Items",
45
+ loadingMessage: "Loading...",
46
+ moreInfo: "More information",
47
+ noResultsFound: "No result found",
48
+ save: "Save",
49
+ removeAll: "Remove all",
50
+ removeFile: "Remove file",
51
+ showLess: "Show less",
52
+ showLessCount: "Show {count} less",
53
+ showMore: "Show more",
54
+ showMoreCount: "Show {count} more",
55
+ uploadLabel: "Upload"
56
+ }
57
+ };
58
+
59
+ //#endregion
60
+ //#region src/icons/TriangleAlert.tsx
61
+ const TriangleAlert = ({ size = 24, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
62
+ xmlns: "http://www.w3.org/2000/svg",
63
+ width: size,
64
+ height: size,
65
+ viewBox: "0 0 24 24",
66
+ fill: "none",
67
+ stroke: "currentColor",
68
+ strokeWidth: "2",
69
+ strokeLinecap: "round",
70
+ strokeLinejoin: "round",
71
+ className: (0, __marigold_system.cn)("shrink-0", className),
72
+ ...props,
73
+ children: [
74
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" }),
75
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 9v4" }),
76
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 17h.01" })
77
+ ]
78
+ });
79
+
80
+ //#endregion
81
+ //#region src/HelpText/HelpText.tsx
82
+ const HelpText = ({ variant, size, description, errorMessage, ...props }) => {
83
+ const classNames = (0, __marigold_system.useClassNames)({
84
+ component: "HelpText",
85
+ variant,
86
+ size
87
+ });
88
+ const ctx = (0, react.useContext)(react_aria_components.FieldErrorContext);
89
+ if (!description && !ctx?.isInvalid) return null;
90
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
91
+ className: (0, __marigold_system.cn)(classNames.container),
92
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.FieldError, {
93
+ ...props,
94
+ className: "flex flex-col",
95
+ children: (validation) => {
96
+ /**
97
+ * Prefer custom error messages, fallback to native errors ones.
98
+ *
99
+ * Note that we can not merge custom and native error messages,
100
+ * because we can not distinguish the type of error messages
101
+ * in the native ones since it is just an array of strings.
102
+ */
103
+ const messages = (typeof errorMessage === "function" ? errorMessage(validation) : errorMessage) || validation.validationErrors;
104
+ return Array.isArray(messages) ? messages.map((msg, idx) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
105
+ className: "flex items-center justify-start gap-1",
106
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TriangleAlert, { className: (0, __marigold_system.cn)("h-4 w-4 shrink-0", classNames.icon) }), msg]
107
+ }, idx)) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
108
+ className: "flex items-start justify-start gap-1",
109
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TriangleAlert, { className: (0, __marigold_system.cn)("h-4 w-4 shrink-0", classNames.icon) }), messages]
110
+ });
111
+ }
112
+ }), ctx && ctx.isInvalid ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Text, {
113
+ slot: "description",
114
+ children: description
115
+ })]
116
+ });
117
+ };
118
+
119
+ //#endregion
120
+ //#region src/Label/Label.tsx
121
+ const _Label = ({ size, variant, children, ...props }) => {
122
+ const className = (0, __marigold_system.useClassNames)({
123
+ component: "Label",
124
+ size,
125
+ variant
126
+ });
127
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Label, {
128
+ ...props,
129
+ className: (0, __marigold_system.cn)(className, "inline-flex"),
130
+ children
131
+ });
132
+ };
133
+
134
+ //#endregion
135
+ //#region src/FieldBase/FieldBase.tsx
136
+ const fixedForwardRef = react.forwardRef;
137
+ const _FieldBase = (props, ref) => {
138
+ const { as: Component = "div", children, label, size, variant, width, description, errorMessage, className, ...rest } = props;
139
+ const classNames = (0, __marigold_system.useClassNames)({
140
+ component: "Field",
141
+ variant,
142
+ size
143
+ });
144
+ const isFractionWidth = width ? (0, __marigold_system.isFraction)(`${width}`) : false;
145
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Component, {
146
+ ref,
147
+ className: (0, __marigold_system.cn)(
148
+ "group/field flex min-w-0 flex-col",
149
+ /**
150
+ * Width handling strategy:
151
+ * - For fixed widths (numeric scale values) and keyword widths (fit, full): Use `w-auto` to prevent layout shifts
152
+ * - For fraction widths (e.g., "1/2", "2/3"): Use the corresponding Tailwind class
153
+ * (e.g., `w-1/2`) which allows the field to properly respond to its container's width
154
+ */
155
+ width && !isFractionWidth ? "w-auto" : `w-(--container-width)`,
156
+ classNames,
157
+ className
158
+ ),
159
+ style: {
160
+ ...(0, __marigold_system.createWidthVar)("container-width", width ? `${width}` : "full"),
161
+ ...(0, __marigold_system.createWidthVar)("field-width", width && !isFractionWidth ? `${width}` : "full")
162
+ },
163
+ "data-required": props.isRequired ? true : void 0,
164
+ "data-error": props.isInvalid ? true : void 0,
165
+ ...rest,
166
+ children: [
167
+ label ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_Label, {
168
+ variant,
169
+ size,
170
+ children: label
171
+ }) : null,
172
+ children,
173
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HelpText, {
174
+ variant,
175
+ size,
176
+ description,
177
+ errorMessage
178
+ })
179
+ ]
180
+ });
181
+ };
182
+ const FieldBase = fixedForwardRef(_FieldBase);
183
+
184
+ //#endregion
185
+ //#region src/icons/Check.tsx
186
+ const Check = ({ size = 24, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
187
+ xmlns: "http://www.w3.org/2000/svg",
188
+ width: size,
189
+ height: size,
190
+ viewBox: "0 0 24 24",
191
+ fill: "none",
192
+ stroke: "currentColor",
193
+ strokeWidth: "2",
194
+ strokeLinecap: "round",
195
+ strokeLinejoin: "round",
196
+ className: (0, __marigold_system.cn)("shrink-0", className),
197
+ ...props,
198
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M20 6 9 17l-5-5" })
199
+ });
200
+
201
+ //#endregion
202
+ //#region src/Collapsible/Context.tsx
203
+ const CollapsibleContext = (0, react.createContext)(void 0);
204
+ const CollapsibleProvider = ({ value, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CollapsibleContext.Provider, {
205
+ value,
206
+ children
207
+ });
208
+
209
+ //#endregion
210
+ //#region src/Collapsible/CollapsibleContent.tsx
211
+ const CollapsibleContent = ({ variant, size, children, ...props }) => {
212
+ const classNames = (0, __marigold_system.useClassNames)({
213
+ component: "Collapsible",
214
+ variant,
215
+ size,
216
+ context: CollapsibleContext
217
+ });
218
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.DisclosurePanel, {
219
+ ...props,
220
+ className: classNames.content,
221
+ children
222
+ });
223
+ };
224
+
225
+ //#endregion
226
+ //#region src/Collapsible/CollapsibleTrigger.tsx
227
+ const CollapsibleTrigger = ({ variant, size, children, level, ...props }) => {
228
+ const classNames = (0, __marigold_system.useClassNames)({
229
+ component: "Collapsible",
230
+ variant,
231
+ size,
232
+ context: CollapsibleContext
233
+ });
234
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Heading, {
235
+ level,
236
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
237
+ ...props,
238
+ slot: "trigger",
239
+ className: classNames.trigger,
240
+ children
241
+ })
242
+ });
243
+ };
244
+
245
+ //#endregion
246
+ //#region src/Collapsible/Collapsible.tsx
247
+ const Collapsible = ({ variant, size, children, unstyled, ...props }) => {
248
+ const classNames = (0, __marigold_system.useClassNames)({
249
+ component: "Collapsible",
250
+ variant,
251
+ size
252
+ });
253
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CollapsibleProvider, {
254
+ value: {
255
+ variant,
256
+ size
257
+ },
258
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Disclosure, {
259
+ ...props,
260
+ className: (0, __marigold_system.cn)(classNames.container, unstyled && "expanded:contents expanded:[&_[role=group]]:contents"),
261
+ children
262
+ })
263
+ });
264
+ };
265
+ Collapsible.Trigger = CollapsibleTrigger;
266
+ Collapsible.Content = CollapsibleContent;
267
+
268
+ //#endregion
269
+ //#region src/Collapsible/More.tsx
270
+ const More = ({ children, defaultExpanded = false, unstyled = true, showCount = false, ...props }) => {
271
+ /**
272
+ * We need to add state here, because toggling on a checkbox will
273
+ * force a rerender and without the state the <Collapsible> will be collapsed.
274
+ */
275
+ const [isExpanded, setIsExpanded] = (0, react.useState)(defaultExpanded);
276
+ const stringFormatter = (0, __react_aria_i18n.useLocalizedStringFormatter)(intlMessages, "marigold");
277
+ const count = `${react.Children.count(children)}`;
278
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Collapsible, {
279
+ variant: "link",
280
+ unstyled,
281
+ isExpanded,
282
+ ...props,
283
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Collapsible.Content, { children }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Collapsible.Trigger, {
284
+ onPress: () => setIsExpanded(!isExpanded),
285
+ children: isExpanded ? stringFormatter.format(showCount ? "showLessCount" : "showLess").replace("{count}", count) : stringFormatter.format(showCount ? "showMoreCount" : "showMore").replace("{count}", count)
286
+ })]
287
+ });
288
+ };
289
+
290
+ //#endregion
291
+ //#region src/utils/children.utils.ts
292
+ const splitChildren = (children, at) => {
293
+ const childArray = react.Children.toArray(children);
294
+ if (at === void 0) return [childArray, []];
295
+ return [childArray.slice(0, at), childArray.slice(at)];
296
+ };
297
+
298
+ //#endregion
299
+ //#region src/Checkbox/Context.tsx
300
+ const CheckboxGroupContext = (0, react.createContext)(null);
301
+ const useCheckboxGroupContext = () => (0, react.useContext)(CheckboxGroupContext);
302
+
303
+ //#endregion
304
+ //#region src/Checkbox/CheckboxGroup.tsx
305
+ const CollapsibleGroup = ({ children }) => {
306
+ const state = (0, react.useContext)(react_aria_components.CheckboxGroupStateContext);
307
+ if (!children || children.length === 0) return null;
308
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(More, {
309
+ defaultExpanded: children.some((child) => (0, react.isValidElement)(child) && state.value.includes(child.props.value)),
310
+ showCount: true,
311
+ children
312
+ });
313
+ };
314
+ const _CheckboxGroup = ({ children, variant, size, required, disabled, readOnly, error, width, orientation = "vertical", collapseAt, ...rest }) => {
315
+ const classNames = (0, __marigold_system.useClassNames)({
316
+ component: "Checkbox",
317
+ variant,
318
+ size,
319
+ className: { group: "gap-x-2" }
320
+ });
321
+ const props = {
322
+ className: classNames.group,
323
+ isRequired: required,
324
+ isDisabled: disabled,
325
+ isReadOnly: readOnly,
326
+ isInvalid: error,
327
+ ...rest
328
+ };
329
+ const [visibleChildren, collapsedChildren] = splitChildren(children, collapseAt);
330
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldBase, {
331
+ as: react_aria_components.CheckboxGroup,
332
+ width,
333
+ ...props,
334
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
335
+ role: "presentation",
336
+ "data-orientation": orientation,
337
+ className: (0, __marigold_system.cn)(classNames.group, "group/checkboxgroup flex items-start", orientation === "vertical" ? "flex-col gap-[0.5ch]" : "flex-row gap-[1.5ch]"),
338
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CheckboxGroupContext.Provider, {
339
+ value: {
340
+ width,
341
+ variant,
342
+ size
343
+ },
344
+ children: [visibleChildren, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CollapsibleGroup, { children: collapsedChildren })]
345
+ })
346
+ })
347
+ });
348
+ };
349
+
350
+ //#endregion
351
+ //#region src/icons/Minus.tsx
352
+ const Minus = ({ size = 24, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
353
+ xmlns: "http://www.w3.org/2000/svg",
354
+ width: size,
355
+ height: size,
356
+ viewBox: "0 0 24 24",
357
+ fill: "none",
358
+ stroke: "currentColor",
359
+ strokeWidth: "2",
360
+ strokeLinecap: "round",
361
+ strokeLinejoin: "round",
362
+ className: (0, __marigold_system.cn)("shrink-0", className),
363
+ ...props,
364
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M5 12h14" })
365
+ });
366
+
367
+ //#endregion
368
+ //#region src/Checkbox/Checkbox.tsx
369
+ const Field = ({ description, children }) => {
370
+ const className = (0, __marigold_system.useClassNames)({ component: "Field" });
371
+ const descriptionId = (0, __react_aria_utils.useId)();
372
+ if (!description) return children;
373
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
374
+ className,
375
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Provider, {
376
+ values: [[react_aria_components.CheckboxContext, { "aria-describedby": descriptionId }], [react_aria_components.TextContext, { id: descriptionId }]],
377
+ children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HelpText, { description })]
378
+ })
379
+ });
380
+ };
381
+ const Icon = ({ className, checked, indeterminate, ...props }) => {
382
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
383
+ "aria-hidden": "true",
384
+ className: (0, __marigold_system.cn)("flex shrink-0 grow-0 basis-4 items-center justify-center", "h-4 w-4 p-px", "bg-white", "rounded-[3px] border border-solid border-black", className),
385
+ ...props,
386
+ children: indeterminate ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Minus, {
387
+ size: "12",
388
+ strokeWidth: "4"
389
+ }) : checked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Check, {
390
+ size: "12",
391
+ strokeWidth: "4"
392
+ }) : null
393
+ });
394
+ };
395
+ const _Checkbox = (0, react.forwardRef)(({ error, disabled, readOnly, required, checked, defaultChecked, indeterminate, variant, size, label, description, ...rest }, ref) => {
396
+ const props = {
397
+ isIndeterminate: indeterminate,
398
+ isDisabled: disabled,
399
+ isReadOnly: readOnly,
400
+ isRequired: required,
401
+ isInvalid: error,
402
+ isSelected: checked,
403
+ defaultSelected: defaultChecked,
404
+ ...rest
405
+ };
406
+ const group = useCheckboxGroupContext();
407
+ const classNames = (0, __marigold_system.useClassNames)({
408
+ component: "Checkbox",
409
+ variant: variant || group?.variant,
410
+ size: size || group?.size
411
+ });
412
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
413
+ description,
414
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Checkbox, {
415
+ ref,
416
+ className: (0, __marigold_system.cn)("group/checkbox flex items-center", "cursor-pointer data-disabled:cursor-not-allowed", classNames.container),
417
+ ...props,
418
+ children: ({ isSelected, isIndeterminate }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
419
+ checked: isSelected,
420
+ indeterminate: isIndeterminate,
421
+ className: classNames.checkbox
422
+ }), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
423
+ className: classNames.label,
424
+ children: label
425
+ })] })
426
+ })
427
+ });
428
+ });
429
+ _Checkbox.Group = _CheckboxGroup;
430
+
431
+ //#endregion
432
+ Object.defineProperty(exports, 'Check', {
433
+ enumerable: true,
434
+ get: function () {
435
+ return Check;
436
+ }
437
+ });
438
+ Object.defineProperty(exports, 'Collapsible', {
439
+ enumerable: true,
440
+ get: function () {
441
+ return Collapsible;
442
+ }
443
+ });
444
+ Object.defineProperty(exports, 'FieldBase', {
445
+ enumerable: true,
446
+ get: function () {
447
+ return FieldBase;
448
+ }
449
+ });
450
+ Object.defineProperty(exports, 'HelpText', {
451
+ enumerable: true,
452
+ get: function () {
453
+ return HelpText;
454
+ }
455
+ });
456
+ Object.defineProperty(exports, 'Minus', {
457
+ enumerable: true,
458
+ get: function () {
459
+ return Minus;
460
+ }
461
+ });
462
+ Object.defineProperty(exports, 'More', {
463
+ enumerable: true,
464
+ get: function () {
465
+ return More;
466
+ }
467
+ });
468
+ Object.defineProperty(exports, 'TriangleAlert', {
469
+ enumerable: true,
470
+ get: function () {
471
+ return TriangleAlert;
472
+ }
473
+ });
474
+ Object.defineProperty(exports, '_Checkbox', {
475
+ enumerable: true,
476
+ get: function () {
477
+ return _Checkbox;
478
+ }
479
+ });
480
+ Object.defineProperty(exports, '_CheckboxGroup', {
481
+ enumerable: true,
482
+ get: function () {
483
+ return _CheckboxGroup;
484
+ }
485
+ });
486
+ Object.defineProperty(exports, '_Label', {
487
+ enumerable: true,
488
+ get: function () {
489
+ return _Label;
490
+ }
491
+ });
492
+ Object.defineProperty(exports, 'intlMessages', {
493
+ enumerable: true,
494
+ get: function () {
495
+ return intlMessages;
496
+ }
497
+ });
498
+ Object.defineProperty(exports, 'splitChildren', {
499
+ enumerable: true,
500
+ get: function () {
501
+ return splitChildren;
502
+ }
503
+ });