@edux-design/buttons 0.1.3 → 0.2.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/index.js ADDED
@@ -0,0 +1,850 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ Button: () => Button,
33
+ ButtonCounter: () => ButtonCounter,
34
+ ButtonGroup: () => ButtonGroup,
35
+ ButtonGroupItem: () => ButtonGroupItem,
36
+ IconButton: () => IconButton,
37
+ MenuButton: () => MenuButton
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/elements/IconButton.jsx
42
+ var import_react = __toESM(require("react"));
43
+ var import_utils = require("@edux-design/utils");
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ var IconButton = (0, import_react.forwardRef)(
46
+ ({
47
+ icon,
48
+ size = "medium",
49
+ isSecondary,
50
+ isDanger,
51
+ isBare,
52
+ disabled,
53
+ className,
54
+ ...props
55
+ }, ref) => {
56
+ let variant = "primary";
57
+ if (isBare) variant = "bare";
58
+ if (isSecondary) variant = "secondary";
59
+ if (isDanger) variant = "danger";
60
+ if (disabled) variant = "disabled";
61
+ if (process.env.NODE_ENV !== "production") {
62
+ const count = [isSecondary, isDanger, isBare].filter(Boolean).length;
63
+ if (count > 1) {
64
+ console.warn(
65
+ "[IconButton]: Multiple variant props passed. Using the highest priority only."
66
+ );
67
+ }
68
+ const hasAccessibleName = Boolean(
69
+ props["aria-label"] || props["aria-labelledby"]
70
+ );
71
+ if (!hasAccessibleName) {
72
+ console.warn(
73
+ "[IconButton]: Provide an accessible name with aria-label or aria-labelledby."
74
+ );
75
+ }
76
+ }
77
+ const defaults = "flex justify-center items-center focus:shadow-focus focus-visible:shadow-focus outline-none transition-all duration-300 ease-in-out rounded-full cursor-pointer";
78
+ const sizes = {
79
+ small: "size-control-sm text-sm",
80
+ medium: "size-control-md text-base",
81
+ large: "size-control-lg text-lg"
82
+ };
83
+ const variants = {
84
+ primary: "border-2 border-border-primary-emphasis bg-bg-primary-base text-white hover:bg-border-focus hover:text-fg-focus hover:border-border-emphasis hover:shadow-md active:bg-border-focus active:bg-bg-focus-overlay active:text-fg-focus",
85
+ secondary: "border-2 border-border-primary-base bg-bg-base text-fg-primary-emphasis hover:shadow-md hover:bg-bg-primary-subtle active:bg-bg-primary-subtle-90",
86
+ bare: "bg-bg-base text-fg-primary-emphasis hover:bg-bg-minimal active:bg-bg-minimal-5",
87
+ danger: "bg-bg-danger-base border-2 border-border-danger-emphasis text-white hover:bg-bg-danger-base-5 active:bg-bg-danger-base-10",
88
+ disabled: "border-2 border-border-subtle bg-bg-inactive text-fg-inactive hover:no-underline cursor-not-allowed"
89
+ };
90
+ const STYLES = (0, import_utils.cx)(defaults, sizes[size], variants[variant], className);
91
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
+ "button",
93
+ {
94
+ role: "button",
95
+ type: "button",
96
+ "aria-disabled": disabled,
97
+ disabled,
98
+ className: STYLES,
99
+ ref,
100
+ ...props,
101
+ children: icon
102
+ }
103
+ );
104
+ }
105
+ );
106
+
107
+ // src/elements/Button.jsx
108
+ var import_react2 = __toESM(require("react"));
109
+ var import_utils2 = require("@edux-design/utils");
110
+ var import_jsx_runtime2 = require("react/jsx-runtime");
111
+ var Button = (0, import_react2.forwardRef)(
112
+ ({
113
+ children,
114
+ startIcon,
115
+ endIcon,
116
+ size = "medium",
117
+ isSecondary,
118
+ isDanger,
119
+ isBare,
120
+ isStretched,
121
+ disabled,
122
+ className,
123
+ ...props
124
+ }, ref) => {
125
+ let variant = "primary";
126
+ if (disabled) {
127
+ variant = "disabled";
128
+ } else if (isDanger && isBare) {
129
+ variant = "dangerBare";
130
+ } else if (isDanger) {
131
+ variant = "danger";
132
+ } else if (isSecondary) {
133
+ variant = "secondary";
134
+ } else if (isBare) {
135
+ variant = "bare";
136
+ }
137
+ if (process.env.NODE_ENV !== "production") {
138
+ const count = [isSecondary, isDanger, isBare].filter(Boolean).length;
139
+ const hasAllowedCombo = isDanger && isBare && count === 2;
140
+ if (count > 1 && !hasAllowedCombo) {
141
+ console.warn(
142
+ "[Button]: Multiple variant props passed. Using the highest priority only."
143
+ );
144
+ }
145
+ }
146
+ const defaults = "flex justify-center items-center gap-8 focus:shadow-focus focus-visible:shadow-focus outline-none transition-all duration-300 ease-in-out cursor-pointer";
147
+ const fonts = "text-bold tracking-normal hover:underline hover:underline-offset-(--underline-offset-btn) active:underline active:underline-offset-(--underline-offset-btn)";
148
+ const sizes = {
149
+ small: "h-control-sm py-8 px-16 rounded-lg text-sm",
150
+ medium: "h-control-md py-8 px-16 rounded-lg text-base",
151
+ large: "h-control-lg py-8 px-16 rounded-lg text-lg"
152
+ };
153
+ const width = isStretched ? "w-full" : "w-fit-content";
154
+ const variants = {
155
+ primary: "border-2 border-border-primary-emphasis bg-bg-primary-base text-white hover:bg-border-focus hover:text-fg-focus hover:border-border-emphasis hover:shadow-md active:bg-border-focus active:bg-bg-focus-overlay active:text-fg-focus",
156
+ secondary: "border-2 border-border-primary-base bg-bg-base text-fg-primary-emphasis hover:shadow-md hover:bg-bg-primary-subtle active:bg-bg-primary-subtle-90",
157
+ bare: "bg-bg-base text-fg-primary-emphasis hover:bg-bg-minimal active:bg-bg-minimal-5",
158
+ dangerBare: "bg-bg-base text-fg-danger-emphasis hover:bg-bg-danger-subtle active:bg-bg-danger-subtle",
159
+ danger: "bg-bg-danger-base border-2 border-border-danger-emphasis text-white hover:bg-bg-danger-base-5 active:bg-bg-danger-base-10",
160
+ disabled: "border-2 border-border-subtle bg-bg-inactive text-fg-inactive hover:no-underline"
161
+ };
162
+ const STYLES = (0, import_utils2.cx)(defaults, sizes[size], width, fonts, variants[variant]);
163
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
164
+ "button",
165
+ {
166
+ role: "button",
167
+ type: "button",
168
+ "aria-disabled": disabled,
169
+ disabled,
170
+ className: STYLES,
171
+ ref,
172
+ ...props,
173
+ children: [
174
+ startIcon,
175
+ children ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children }) : null,
176
+ endIcon
177
+ ]
178
+ }
179
+ );
180
+ }
181
+ );
182
+
183
+ // src/elements/MenuButton.jsx
184
+ var import_react3 = __toESM(require("react"));
185
+ var import_utils3 = require("@edux-design/utils");
186
+
187
+ // ../icons/dist/index.mjs
188
+ var import_jsx_runtime3 = require("react/jsx-runtime");
189
+ var SvgChevron = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
190
+ "svg",
191
+ {
192
+ xmlns: "http://www.w3.org/2000/svg",
193
+ width: "1em",
194
+ height: "1em",
195
+ fill: "none",
196
+ viewBox: "0 0 24 24",
197
+ ...props,
198
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
199
+ "path",
200
+ {
201
+ fill: "currentColor",
202
+ fillRule: "evenodd",
203
+ d: "M13.586 12 9.293 7.707a1 1 0 0 1 1.414-1.414l5 5a1 1 0 0 1 0 1.414l-5 5a1 1 0 0 1-1.414-1.414z",
204
+ clipRule: "evenodd"
205
+ }
206
+ )
207
+ }
208
+ );
209
+ var Chevron_default = SvgChevron;
210
+
211
+ // src/elements/MenuButton.jsx
212
+ var import_jsx_runtime4 = require("react/jsx-runtime");
213
+ var MenuButton = (0, import_react3.forwardRef)(function MenuButton2({
214
+ children,
215
+ caret,
216
+ size = "medium",
217
+ className,
218
+ type = "button",
219
+ "aria-haspopup": ariaHasPopup = "menu",
220
+ ...props
221
+ }, ref) {
222
+ const styles = (0, import_utils3.cx)(
223
+ "inline-flex items-center justify-center gap-8 rounded-lg border-2 border-border-primary-base bg-bg-base px-16 text-fg-primary-emphasis transition-all duration-300 ease-in-out outline-none focus:shadow-focus focus-visible:shadow-focus disabled:cursor-not-allowed disabled:border-border-subtle disabled:bg-bg-inactive disabled:text-fg-inactive",
224
+ {
225
+ "min-h-control-sm text-sm": size === "small",
226
+ "min-h-control-md text-base": size === "medium"
227
+ },
228
+ className
229
+ );
230
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
231
+ "button",
232
+ {
233
+ ...props,
234
+ ref,
235
+ type,
236
+ "aria-haspopup": ariaHasPopup,
237
+ className: styles,
238
+ children: [
239
+ children ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children }) : null,
240
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", className: "flex items-center text-current", children: caret ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Chevron_default, {}) })
241
+ ]
242
+ }
243
+ );
244
+ });
245
+
246
+ // src/elements/ButtonGroup.jsx
247
+ var import_react4 = __toESM(require("react"));
248
+ var import_utils4 = require("@edux-design/utils");
249
+ var import_jsx_runtime5 = require("react/jsx-runtime");
250
+ var SIZE_STYLES = {
251
+ small: {
252
+ button: "text-xs px-12 py-6 rounded-md "
253
+ },
254
+ medium: {
255
+ button: "text-sm px-12 py-6 rounded-md "
256
+ },
257
+ large: {
258
+ button: "text-base px-12 py-6 rounded-md"
259
+ }
260
+ };
261
+ var isBrowser = typeof window !== "undefined";
262
+ var useIsomorphicLayoutEffect = isBrowser ? import_react4.useLayoutEffect : import_react4.useEffect;
263
+ var ButtonGroup = (0, import_react4.forwardRef)(function ButtonGroup2({
264
+ value,
265
+ defaultValue,
266
+ onChange,
267
+ size = "medium",
268
+ isStretched = false,
269
+ className,
270
+ children,
271
+ ...rest
272
+ }, forwardedRef) {
273
+ const normalizedOptions = (0, import_react4.useMemo)(() => {
274
+ const childItems = (0, import_utils4.filterChildrenByDisplayName)(children, "ButtonGroupItem");
275
+ return childItems.map((child, index) => {
276
+ const props = child.props || {};
277
+ const hasValue = props.value !== void 0;
278
+ const safeValue = hasValue && props.value !== null ? props.value : index;
279
+ return {
280
+ ...props,
281
+ label: props.label ?? props.children ?? `Option ${index + 1}`,
282
+ value: safeValue
283
+ };
284
+ });
285
+ }, [children]);
286
+ const sizeStyles = SIZE_STYLES[size] ?? SIZE_STYLES.medium;
287
+ const initialValue = value ?? defaultValue ?? (normalizedOptions.length ? normalizedOptions[0].value : void 0);
288
+ const [internalValue, setInternalValue] = (0, import_react4.useState)(initialValue);
289
+ const isControlled = value !== void 0;
290
+ const selectedValue = isControlled ? value : internalValue;
291
+ (0, import_react4.useEffect)(() => {
292
+ if (!isControlled && defaultValue !== void 0) {
293
+ setInternalValue(defaultValue);
294
+ }
295
+ }, [defaultValue, isControlled]);
296
+ (0, import_react4.useEffect)(() => {
297
+ if (isControlled) return;
298
+ if (normalizedOptions.length && !normalizedOptions.some((option) => option.value === internalValue)) {
299
+ setInternalValue(normalizedOptions[0].value);
300
+ }
301
+ }, [internalValue, isControlled, normalizedOptions]);
302
+ const buttonRefs = (0, import_react4.useRef)(/* @__PURE__ */ new Map());
303
+ const containerRef = (0, import_react4.useRef)(null);
304
+ const indicatorRef = (0, import_react4.useRef)({ width: 0, height: 0, x: 0, y: 0 });
305
+ const [indicator, setIndicator] = (0, import_react4.useState)({
306
+ width: 0,
307
+ height: 0,
308
+ x: 0,
309
+ y: 0
310
+ });
311
+ const setContainerRef = (0, import_react4.useCallback)(
312
+ (node) => {
313
+ containerRef.current = node;
314
+ if (typeof forwardedRef === "function") {
315
+ forwardedRef(node);
316
+ } else if (forwardedRef) {
317
+ forwardedRef.current = node;
318
+ }
319
+ },
320
+ [forwardedRef]
321
+ );
322
+ const registerButtonRef = (0, import_react4.useCallback)((optionValue) => {
323
+ return (node) => {
324
+ if (!buttonRefs.current) return;
325
+ if (node) {
326
+ buttonRefs.current.set(optionValue, node);
327
+ } else {
328
+ buttonRefs.current.delete(optionValue);
329
+ }
330
+ };
331
+ }, []);
332
+ const updateIndicator = (0, import_react4.useCallback)(() => {
333
+ const container = containerRef.current;
334
+ const target = buttonRefs.current.get(selectedValue);
335
+ if (!container || !target) {
336
+ if (indicatorRef.current.width !== 0) {
337
+ indicatorRef.current = { width: 0, height: 0, x: 0, y: 0 };
338
+ setIndicator(indicatorRef.current);
339
+ }
340
+ return;
341
+ }
342
+ const containerRect = container.getBoundingClientRect();
343
+ const targetRect = target.getBoundingClientRect();
344
+ const next = {
345
+ width: targetRect.width,
346
+ height: targetRect.height,
347
+ x: targetRect.left - containerRect.left,
348
+ y: targetRect.top - containerRect.top
349
+ };
350
+ const prev = indicatorRef.current;
351
+ if (prev.width !== next.width || prev.height !== next.height || prev.x !== next.x || prev.y !== next.y) {
352
+ indicatorRef.current = next;
353
+ setIndicator(next);
354
+ }
355
+ }, [selectedValue]);
356
+ useIsomorphicLayoutEffect(() => {
357
+ updateIndicator();
358
+ }, [updateIndicator, normalizedOptions.length, size]);
359
+ (0, import_react4.useEffect)(() => {
360
+ if (!isBrowser) return;
361
+ const handleResize = () => updateIndicator();
362
+ window.addEventListener("resize", handleResize);
363
+ return () => window.removeEventListener("resize", handleResize);
364
+ }, [updateIndicator]);
365
+ (0, import_react4.useEffect)(() => {
366
+ if (!isBrowser) return;
367
+ const node = containerRef.current;
368
+ if (!node || typeof ResizeObserver === "undefined") return;
369
+ const observer = new ResizeObserver(() => {
370
+ updateIndicator();
371
+ });
372
+ observer.observe(node);
373
+ return () => observer.disconnect();
374
+ }, [updateIndicator]);
375
+ const focusOption = (0, import_react4.useCallback)((option) => {
376
+ const node = buttonRefs.current.get(option.value);
377
+ if (node) {
378
+ node.focus();
379
+ }
380
+ }, []);
381
+ const handleSelect = (0, import_react4.useCallback)(
382
+ (option) => {
383
+ if (option.disabled || option.value === selectedValue) {
384
+ return;
385
+ }
386
+ if (!isControlled) {
387
+ setInternalValue(option.value);
388
+ }
389
+ if (typeof onChange === "function") {
390
+ onChange(option.value, option);
391
+ }
392
+ },
393
+ [isControlled, onChange, selectedValue]
394
+ );
395
+ const getNextEnabledIndex = (0, import_react4.useCallback)(
396
+ (startIndex, direction) => {
397
+ if (!normalizedOptions.length) return -1;
398
+ let nextIndex = startIndex;
399
+ for (let i = 0; i < normalizedOptions.length; i += 1) {
400
+ nextIndex = (nextIndex + direction + normalizedOptions.length) % normalizedOptions.length;
401
+ if (!normalizedOptions[nextIndex].disabled) {
402
+ return nextIndex;
403
+ }
404
+ }
405
+ return startIndex;
406
+ },
407
+ [normalizedOptions]
408
+ );
409
+ const findFirstEnabledIndex = (0, import_react4.useCallback)(() => {
410
+ return normalizedOptions.findIndex((option) => !option.disabled);
411
+ }, [normalizedOptions]);
412
+ const findLastEnabledIndex = (0, import_react4.useCallback)(() => {
413
+ for (let i = normalizedOptions.length - 1; i >= 0; i -= 1) {
414
+ if (!normalizedOptions[i].disabled) {
415
+ return i;
416
+ }
417
+ }
418
+ return -1;
419
+ }, [normalizedOptions]);
420
+ const indicatorVisible = indicator.width > 0 && indicator.height > 0;
421
+ const selectedIndex = normalizedOptions.findIndex(
422
+ (option) => option.value === selectedValue && !option.disabled
423
+ );
424
+ const firstEnabledIndex = normalizedOptions.findIndex(
425
+ (option) => !option.disabled
426
+ );
427
+ const activeTabStopIndex = selectedIndex >= 0 ? selectedIndex : firstEnabledIndex;
428
+ const rootClasses = (0, import_utils4.cx)(
429
+ "inline-flex h-control-md rounded-lg border-2 border-border-subtle bg-bg-base/90 p-2 shadow-inner",
430
+ isStretched ? "w-full" : "w-auto",
431
+ className
432
+ );
433
+ const trackClasses = (0, import_utils4.cx)(
434
+ "relative isolate flex w-full items-center gap-8",
435
+ !isStretched && "w-auto"
436
+ );
437
+ const buttonBaseClasses = (0, import_utils4.cx)(
438
+ "relative z-10 h-control-sm inline-flex items-center justify-center gap-2 whitespace-nowrap font-semibold tracking-tight transition-colors duration-200 ease-out focus-visible:outline-none focus-visible:shadow-focus motion-reduce:duration-0",
439
+ sizeStyles.button,
440
+ isStretched ? "flex-1" : "w-auto"
441
+ );
442
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
443
+ "div",
444
+ {
445
+ ...rest,
446
+ ref: setContainerRef,
447
+ role: "radiogroup",
448
+ "aria-orientation": "horizontal",
449
+ className: rootClasses,
450
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: trackClasses, children: [
451
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
452
+ "span",
453
+ {
454
+ "aria-hidden": "true",
455
+ className: (0, import_utils4.cx)(
456
+ "pointer-events-none h-control-md absolute rounded-md border-2 border-border-primary-emphasis bg-bg-base shadow-[0_8px_20px_rgb(22_92_131/0.18)] transition-[transform,width,height] duration-300 ease-out motion-reduce:duration-0",
457
+ !indicatorVisible && "opacity-0"
458
+ ),
459
+ style: {
460
+ width: indicator.width || void 0,
461
+ height: indicator.height || void 0,
462
+ transform: `translate(${indicator.x - 4}px, ${indicator.y - 4}px)`
463
+ }
464
+ }
465
+ ),
466
+ normalizedOptions.map((option, index) => {
467
+ const isActive = option.value === selectedValue;
468
+ const handleKeyDown = (event) => {
469
+ if (option.disabled) return;
470
+ if (event.key === "ArrowRight" || event.key === "ArrowDown") {
471
+ event.preventDefault();
472
+ const nextIndex = getNextEnabledIndex(index, 1);
473
+ const nextOption = normalizedOptions[nextIndex];
474
+ if (nextOption && nextOption !== option) {
475
+ focusOption(nextOption);
476
+ handleSelect(nextOption);
477
+ }
478
+ } else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
479
+ event.preventDefault();
480
+ const prevIndex = getNextEnabledIndex(index, -1);
481
+ const prevOption = normalizedOptions[prevIndex];
482
+ if (prevOption && prevOption !== option) {
483
+ focusOption(prevOption);
484
+ handleSelect(prevOption);
485
+ }
486
+ } else if (event.key === "Home") {
487
+ event.preventDefault();
488
+ const firstIndex = findFirstEnabledIndex();
489
+ const firstOption = firstIndex >= 0 ? normalizedOptions[firstIndex] : void 0;
490
+ if (firstOption && firstOption !== option) {
491
+ focusOption(firstOption);
492
+ handleSelect(firstOption);
493
+ }
494
+ } else if (event.key === "End") {
495
+ event.preventDefault();
496
+ const lastIndex = findLastEnabledIndex();
497
+ const lastOption = lastIndex >= 0 ? normalizedOptions[lastIndex] : void 0;
498
+ if (lastOption && lastOption !== option) {
499
+ focusOption(lastOption);
500
+ handleSelect(lastOption);
501
+ }
502
+ }
503
+ };
504
+ const buttonClasses = (0, import_utils4.cx)(
505
+ buttonBaseClasses,
506
+ option.disabled ? "cursor-not-allowed text-fg-inactive opacity-60" : "cursor-pointer text-fg-subtle hover:text-fg-base",
507
+ isActive && "text-fg-primary-emphasis",
508
+ !isActive && "hover:bg-bg-minimal-5 active:bg-bg-inactive"
509
+ );
510
+ const hasStartAdornment = option.startAdornment !== void 0 && option.startAdornment !== null;
511
+ const endAdornment = option.endAdornment ?? option.endIcon;
512
+ const hasEndAdornment = endAdornment !== void 0 && endAdornment !== null;
513
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
514
+ "button",
515
+ {
516
+ ref: registerButtonRef(option.value),
517
+ type: "button",
518
+ role: "radio",
519
+ "aria-checked": isActive,
520
+ tabIndex: option.disabled ? -1 : index === activeTabStopIndex ? 0 : -1,
521
+ disabled: option.disabled,
522
+ className: buttonClasses,
523
+ onClick: () => handleSelect(option),
524
+ onKeyDown: handleKeyDown,
525
+ "data-state": isActive ? "active" : "inactive",
526
+ children: [
527
+ hasStartAdornment && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
528
+ "span",
529
+ {
530
+ "aria-hidden": "true",
531
+ className: "flex items-center text-current",
532
+ children: option.startAdornment
533
+ }
534
+ ),
535
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "flex items-center gap-1 leading-none text-current", children: option.label ?? `Option ${index + 1}` }),
536
+ hasEndAdornment && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
537
+ "span",
538
+ {
539
+ "aria-hidden": "true",
540
+ className: "flex items-center text-current",
541
+ children: endAdornment
542
+ }
543
+ )
544
+ ]
545
+ },
546
+ String(option.value)
547
+ );
548
+ })
549
+ ] })
550
+ }
551
+ );
552
+ });
553
+
554
+ // src/elements/ButtonGroupItem.jsx
555
+ var import_react5 = __toESM(require("react"));
556
+ function ButtonGroupItem(_props) {
557
+ return null;
558
+ }
559
+ ButtonGroupItem.displayName = "ButtonGroupItem";
560
+
561
+ // src/elements/ButtonCounter.jsx
562
+ var import_react6 = __toESM(require("react"));
563
+ var import_utils5 = require("@edux-design/utils");
564
+ var import_jsx_runtime6 = require("react/jsx-runtime");
565
+ var ButtonCounter = (0, import_react6.forwardRef)(function ButtonCounter2({
566
+ value,
567
+ defaultValue = 1,
568
+ onChange,
569
+ min = Number.NEGATIVE_INFINITY,
570
+ max = Number.POSITIVE_INFINITY,
571
+ step = 1,
572
+ children,
573
+ size = "medium",
574
+ isSecondary,
575
+ isDanger,
576
+ isBare,
577
+ isStretched,
578
+ disabled,
579
+ isEditable = false,
580
+ inputProps,
581
+ decrementIcon,
582
+ incrementIcon,
583
+ startIcon,
584
+ endIcon,
585
+ decrementButtonProps,
586
+ incrementButtonProps,
587
+ className,
588
+ "aria-label": ariaLabel,
589
+ ...rest
590
+ }, ref) {
591
+ const isControlled = value !== void 0;
592
+ const [internalValue, setInternalValue] = (0, import_react6.useState)(defaultValue);
593
+ const currentValue = isControlled ? value : internalValue;
594
+ const clampedValue = (0, import_react6.useMemo)(() => {
595
+ const safe = Number.isFinite(currentValue) ? currentValue : defaultValue;
596
+ return Math.min(max, Math.max(min, safe));
597
+ }, [currentValue, defaultValue, max, min]);
598
+ const commitValue = (0, import_react6.useCallback)(
599
+ (next) => {
600
+ const clamped = Math.min(max, Math.max(min, next));
601
+ if (!isControlled) setInternalValue(clamped);
602
+ onChange == null ? void 0 : onChange(clamped);
603
+ },
604
+ [isControlled, max, min, onChange]
605
+ );
606
+ const decrementDisabled = !!disabled || !Number.isFinite(clampedValue) || clampedValue - step < min;
607
+ const incrementDisabled = !!disabled || !Number.isFinite(clampedValue) || clampedValue + step > max;
608
+ let variant = "primary";
609
+ if (disabled) {
610
+ variant = "disabled";
611
+ } else if (isDanger && isBare) {
612
+ variant = "dangerBare";
613
+ } else if (isDanger) {
614
+ variant = "danger";
615
+ } else if (isSecondary) {
616
+ variant = "secondary";
617
+ } else if (isBare) {
618
+ variant = "bare";
619
+ }
620
+ if (process.env.NODE_ENV !== "production") {
621
+ const count = [isSecondary, isDanger, isBare].filter(Boolean).length;
622
+ const hasAllowedCombo = isDanger && isBare && count === 2;
623
+ if (count > 1 && !hasAllowedCombo) {
624
+ console.warn(
625
+ "[ButtonCounter]: Multiple variant props passed. Using the highest priority only."
626
+ );
627
+ }
628
+ if (step <= 0) {
629
+ console.warn("[ButtonCounter]: step should be > 0.");
630
+ }
631
+ }
632
+ const CONTROL_SIZES = {
633
+ small: {
634
+ button: "size-control-sm text-sm",
635
+ display: "h-control-sm min-w-[48px] px-12 text-sm"
636
+ },
637
+ medium: {
638
+ button: "size-control-md text-base",
639
+ display: "h-control-md min-w-[56px] px-12 text-base"
640
+ },
641
+ large: {
642
+ button: "size-control-lg text-lg",
643
+ display: "h-control-lg min-w-[72px] px-16 text-lg"
644
+ }
645
+ };
646
+ const defaultsButton = "flex justify-center items-center focus:shadow-focus focus-visible:shadow-focus outline-none transition-all duration-300 ease-in-out cursor-pointer";
647
+ const defaultsDisplay = "flex items-center justify-center text-bold tracking-normal";
648
+ const width = isStretched ? "w-full" : "w-fit-content";
649
+ const variants = {
650
+ primary: {
651
+ button: "border-2 border-border-primary-emphasis bg-bg-primary-base text-white hover:bg-border-focus hover:text-fg-focus hover:border-border-emphasis hover:shadow-md active:bg-border-focus active:bg-bg-focus-overlay active:text-fg-focus",
652
+ display: "border-y-2 border-x-2 border-border-primary-emphasis bg-bg-primary-base text-white"
653
+ },
654
+ secondary: {
655
+ button: "border-2 border-border-primary-base bg-bg-base text-fg-primary-emphasis hover:shadow-md hover:bg-bg-primary-subtle active:bg-bg-primary-subtle-90",
656
+ display: "border-y-2 border-x-2 border-border-primary-base bg-bg-base text-fg-primary-emphasis"
657
+ },
658
+ bare: {
659
+ button: "bg-bg-base text-fg-primary-emphasis hover:bg-bg-minimal active:bg-bg-minimal-5",
660
+ display: "bg-bg-base text-fg-primary-emphasis"
661
+ },
662
+ dangerBare: {
663
+ button: "bg-bg-base text-fg-danger-emphasis hover:bg-bg-danger-subtle active:bg-bg-danger-subtle",
664
+ display: "bg-bg-base text-fg-danger-emphasis"
665
+ },
666
+ danger: {
667
+ button: "bg-bg-danger-base border-2 border-border-danger-emphasis text-white hover:bg-bg-danger-base-5 active:bg-bg-danger-base-10",
668
+ display: "border-y-2 border-x-2 border-border-danger-emphasis bg-bg-danger-base text-white"
669
+ },
670
+ disabled: {
671
+ button: "border-2 border-border-subtle bg-bg-inactive text-fg-inactive hover:no-underline cursor-not-allowed",
672
+ display: "border-y-2 border-x-2 border-border-subtle bg-bg-inactive text-fg-inactive"
673
+ }
674
+ };
675
+ const sizeStyles = CONTROL_SIZES[size] ?? CONTROL_SIZES.medium;
676
+ const variantStyles = variants[variant] ?? variants.primary;
677
+ const leftButtonStyles = (0, import_utils5.cx)(
678
+ defaultsButton,
679
+ sizeStyles.button,
680
+ "rounded-l-lg",
681
+ "relative z-10",
682
+ variantStyles.button,
683
+ variant !== "bare" && variant !== "dangerBare" ? "border-r-0" : null
684
+ );
685
+ const rightButtonStyles = (0, import_utils5.cx)(
686
+ defaultsButton,
687
+ sizeStyles.button,
688
+ "rounded-r-lg",
689
+ variantStyles.button,
690
+ variant !== "bare" && variant !== "dangerBare" ? "border-l-0" : null
691
+ );
692
+ const displayStyles = (0, import_utils5.cx)(
693
+ defaultsDisplay,
694
+ sizeStyles.display,
695
+ "relative z-0",
696
+ variantStyles.display,
697
+ isStretched ? "flex-1" : null
698
+ );
699
+ const effectiveDecrementIcon = decrementIcon ?? startIcon ?? "-";
700
+ const effectiveIncrementIcon = incrementIcon ?? endIcon ?? "+";
701
+ const generatedValueId = (0, import_react6.useId)();
702
+ const valueElementId = (inputProps == null ? void 0 : inputProps.id) ?? generatedValueId;
703
+ const valueAriaLabel = (inputProps == null ? void 0 : inputProps["aria-label"]) ?? ariaLabel ?? "Value";
704
+ const [draftValue, setDraftValue] = (0, import_react6.useState)(String(clampedValue));
705
+ const [isEditing, setIsEditing] = (0, import_react6.useState)(false);
706
+ const inputRef = (0, import_react6.useRef)(null);
707
+ (0, import_react6.useEffect)(() => {
708
+ if (isEditing) return;
709
+ setDraftValue(String(clampedValue));
710
+ }, [clampedValue, isEditing]);
711
+ const commitDraft = (0, import_react6.useCallback)(() => {
712
+ const trimmed = String(draftValue).trim();
713
+ if (trimmed === "") {
714
+ setDraftValue(String(clampedValue));
715
+ return;
716
+ }
717
+ const next = Number(trimmed);
718
+ if (!Number.isFinite(next)) {
719
+ setDraftValue(String(clampedValue));
720
+ return;
721
+ }
722
+ commitValue(next);
723
+ }, [clampedValue, commitValue, draftValue]);
724
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
725
+ "div",
726
+ {
727
+ ref,
728
+ className: (0, import_utils5.cx)("inline-flex items-stretch", width, className),
729
+ ...rest,
730
+ children: [
731
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
732
+ "button",
733
+ {
734
+ ...decrementButtonProps,
735
+ type: "button",
736
+ "aria-label": (decrementButtonProps == null ? void 0 : decrementButtonProps["aria-label"]) ?? "Decrease",
737
+ "aria-controls": valueElementId,
738
+ "aria-disabled": decrementDisabled,
739
+ disabled: decrementDisabled,
740
+ className: (0, import_utils5.cx)(
741
+ leftButtonStyles,
742
+ decrementDisabled && variant !== "disabled" ? variants.disabled.button : null,
743
+ decrementButtonProps == null ? void 0 : decrementButtonProps.className
744
+ ),
745
+ onClick: (event) => {
746
+ var _a;
747
+ (_a = decrementButtonProps == null ? void 0 : decrementButtonProps.onClick) == null ? void 0 : _a.call(decrementButtonProps, event);
748
+ if (event.defaultPrevented) return;
749
+ commitValue(clampedValue - step);
750
+ },
751
+ children: effectiveDecrementIcon
752
+ }
753
+ ),
754
+ isEditable && children == null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
755
+ "input",
756
+ {
757
+ ...inputProps,
758
+ ref: inputRef,
759
+ type: "number",
760
+ inputMode: "numeric",
761
+ id: valueElementId,
762
+ disabled: !!disabled,
763
+ "aria-label": valueAriaLabel,
764
+ className: (0, import_utils5.cx)(
765
+ displayStyles,
766
+ "w-[44px] text-center outline-none bg-transparent text-fg-base",
767
+ "[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:m-0 [&::-webkit-inner-spin-button]:m-0",
768
+ "focus:shadow-focus focus-visible:shadow-focus focus:z-15 focus-within:z-15",
769
+ inputProps == null ? void 0 : inputProps.className
770
+ ),
771
+ value: draftValue,
772
+ onChange: (event) => {
773
+ var _a;
774
+ (_a = inputProps == null ? void 0 : inputProps.onChange) == null ? void 0 : _a.call(inputProps, event);
775
+ if (event.defaultPrevented) return;
776
+ setDraftValue(event.target.value);
777
+ },
778
+ onFocus: (event) => {
779
+ var _a;
780
+ (_a = inputProps == null ? void 0 : inputProps.onFocus) == null ? void 0 : _a.call(inputProps, event);
781
+ if (event.defaultPrevented) return;
782
+ setIsEditing(true);
783
+ },
784
+ onBlur: (event) => {
785
+ var _a;
786
+ (_a = inputProps == null ? void 0 : inputProps.onBlur) == null ? void 0 : _a.call(inputProps, event);
787
+ if (event.defaultPrevented) return;
788
+ setIsEditing(false);
789
+ commitDraft();
790
+ },
791
+ onKeyDown: (event) => {
792
+ var _a;
793
+ (_a = inputProps == null ? void 0 : inputProps.onKeyDown) == null ? void 0 : _a.call(inputProps, event);
794
+ if (event.defaultPrevented) return;
795
+ if (event.key === "Enter") {
796
+ event.currentTarget.blur();
797
+ }
798
+ if (event.key === "Escape") {
799
+ setDraftValue(String(clampedValue));
800
+ event.currentTarget.blur();
801
+ }
802
+ }
803
+ }
804
+ ) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
805
+ "output",
806
+ {
807
+ id: valueElementId,
808
+ "aria-label": valueAriaLabel,
809
+ "aria-live": "polite",
810
+ "aria-atomic": "true",
811
+ className: (0, import_utils5.cx)(displayStyles, "select-none"),
812
+ children: children ?? clampedValue
813
+ }
814
+ ),
815
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
816
+ "button",
817
+ {
818
+ ...incrementButtonProps,
819
+ type: "button",
820
+ "aria-label": (incrementButtonProps == null ? void 0 : incrementButtonProps["aria-label"]) ?? "Increase",
821
+ "aria-controls": valueElementId,
822
+ "aria-disabled": incrementDisabled,
823
+ disabled: incrementDisabled,
824
+ className: (0, import_utils5.cx)(
825
+ rightButtonStyles,
826
+ incrementDisabled && variant !== "disabled" ? variants.disabled.button : null,
827
+ incrementButtonProps == null ? void 0 : incrementButtonProps.className
828
+ ),
829
+ onClick: (event) => {
830
+ var _a;
831
+ (_a = incrementButtonProps == null ? void 0 : incrementButtonProps.onClick) == null ? void 0 : _a.call(incrementButtonProps, event);
832
+ if (event.defaultPrevented) return;
833
+ commitValue(clampedValue + step);
834
+ },
835
+ children: effectiveIncrementIcon
836
+ }
837
+ )
838
+ ]
839
+ }
840
+ );
841
+ });
842
+ // Annotate the CommonJS export names for ESM import in node:
843
+ 0 && (module.exports = {
844
+ Button,
845
+ ButtonCounter,
846
+ ButtonGroup,
847
+ ButtonGroupItem,
848
+ IconButton,
849
+ MenuButton
850
+ });