@versini/ui-button 15.0.4 → 15.0.5
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/{277.js → 132.js} +4 -3
- package/dist/{795.js → 352.js} +5 -3
- package/dist/components/Button/Button.d.ts +1 -1
- package/dist/components/Button/Button.js +6 -5
- package/dist/components/Button/ButtonCopy.d.ts +1 -1
- package/dist/components/Button/ButtonCopy.js +6 -4
- package/dist/components/Button/ButtonGroup.d.ts +2 -1
- package/dist/components/Button/ButtonGroup.js +7 -3
- package/dist/components/Button/ButtonIcon.d.ts +1 -1
- package/dist/components/Button/ButtonIcon.js +218 -2
- package/dist/components/Button/ButtonLink.d.ts +1 -1
- package/dist/components/Button/ButtonLink.js +7 -4
- package/dist/components/private/BaseButton.d.ts +2 -1
- package/package.json +4 -4
- package/dist/370.js +0 -221
- package/dist/726.js +0 -9
- package/dist/946.js +0 -7
package/dist/{277.js → 132.js}
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-button v15.0.
|
|
2
|
+
@versini/ui-button v15.0.5
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
|
|
7
8
|
|
|
8
9
|
const BUTTON_CLASSNAME = "av-button";
|
|
9
10
|
|
|
@@ -446,4 +447,4 @@ const getButtonClasses = ({ type, className, raw, mode, disabled, fullWidth, siz
|
|
|
446
447
|
}), className);
|
|
447
448
|
};
|
|
448
449
|
|
|
449
|
-
export {
|
|
450
|
+
export { getBadgeClasses, getButtonClasses, getButtonIconLabelClasses, getIconClasses };
|
package/dist/{795.js → 352.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ButtonTypes } from "@versini/ui-types";
|
|
2
|
-
export declare function Button({ children, disabled, mode, fullWidth, className, size, raw, noBorder, variant, truncate, radius, flat, ref, ...otherProps }: ButtonTypes.Props): import("react
|
|
2
|
+
export declare function Button({ children, disabled, mode, fullWidth, className, size, raw, noBorder, variant, truncate, radius, flat, ref, ...otherProps }: ButtonTypes.Props): import("react").JSX.Element;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-button v15.0.
|
|
2
|
+
@versini/ui-button v15.0.5
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { jsx } from "
|
|
7
|
-
import { getButtonClasses
|
|
8
|
-
import { BaseButton_private } from "../../
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { getButtonClasses } from "../../132.js";
|
|
8
|
+
import { BaseButton_private } from "../../352.js";
|
|
9
|
+
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
function Button({ children, disabled = false, mode = "system", fullWidth = false, className, size = "medium", raw = false, noBorder = false, variant = "primary", truncate = false, radius = "large", flat = false, ref, ...otherProps }) {
|
|
14
15
|
const buttonClass = getButtonClasses({
|
|
15
|
-
type: TYPE_BUTTON,
|
|
16
|
+
type: (/* inlined export .TYPE_BUTTON */"button"),
|
|
16
17
|
mode,
|
|
17
18
|
fullWidth,
|
|
18
19
|
disabled,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ButtonCopyTypes } from "@versini/ui-types";
|
|
2
|
-
export declare function ButtonCopy({ copyToClipboard, ref, ...otherProps }: ButtonCopyTypes.Props): import("react
|
|
2
|
+
export declare function ButtonCopy({ copyToClipboard, ref, ...otherProps }: ButtonCopyTypes.Props): import("react").JSX.Element;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-button v15.0.
|
|
2
|
+
@versini/ui-button v15.0.5
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
import { IconCopied, IconCopy } from "@versini/ui-icons";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import { useEffect, useState } from "react";
|
|
9
|
+
import { ButtonIcon } from "./ButtonIcon.js";
|
|
10
|
+
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { ButtonGroupTypes } from "@versini/ui-types";
|
|
2
|
-
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare function ButtonGroup({ children, gap, orientation, className, ...otherProps }: ButtonGroupTypes.Props): React.JSX.Element;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-button v15.0.
|
|
2
|
+
@versini/ui-button v15.0.5
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import react from "react";
|
|
8
|
+
import clsx from "clsx";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
8
12
|
|
|
9
13
|
|
|
10
14
|
const getButtonGroupClasses = ({ gap = "medium", className })=>{
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ButtonIconTypes } from "@versini/ui-types";
|
|
2
|
-
export declare function ButtonIcon({ children, disabled, mode, fullWidth, className, type, raw, noBorder, "aria-label": ariaLabel, label, size, labelRight, labelLeft, noBackground, align, radius, variant, iconClassName, animated, badge, flat, ref, ...otherProps }: ButtonIconTypes.Props): import("react
|
|
2
|
+
export declare function ButtonIcon({ children, disabled, mode, fullWidth, className, type, raw, noBorder, "aria-label": ariaLabel, label, size, labelRight, labelLeft, noBackground, align, radius, variant, iconClassName, animated, badge, flat, ref, ...otherProps }: ButtonIconTypes.Props): import("react").JSX.Element;
|
|
@@ -1,7 +1,223 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-button v15.0.
|
|
2
|
+
@versini/ui-button v15.0.5
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useMergeRefs } from "@versini/ui-hooks/use-merge-refs";
|
|
8
|
+
import { useResizeObserver } from "@versini/ui-hooks/use-resize-observer";
|
|
9
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
10
|
+
import { getButtonClasses, getIconClasses, getButtonIconLabelClasses, getBadgeClasses } from "../../132.js";
|
|
11
|
+
import { BaseButton_private } from "../../352.js";
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const WIDTH = {
|
|
24
|
+
small: 24,
|
|
25
|
+
medium: 32,
|
|
26
|
+
large: 48
|
|
27
|
+
};
|
|
28
|
+
const PADDINGS = {
|
|
29
|
+
small: 8 * 2,
|
|
30
|
+
medium: 12 * 2,
|
|
31
|
+
large: 16 * 2
|
|
32
|
+
};
|
|
33
|
+
const BORDERS = 2; // border x 2
|
|
34
|
+
const ANIMATION_DURATION = 300; // ms - should match the CSS transition duration
|
|
35
|
+
function ButtonIcon({ children, disabled = false, mode = "system", fullWidth = false, className, type = "button", raw = false, noBorder = false, "aria-label": ariaLabel, label, size = "medium", labelRight, labelLeft, noBackground = false, align = "center", radius = "large", variant = "secondary", iconClassName, animated = false, badge, flat = false, ref, ...otherProps }) {
|
|
36
|
+
const buttonClass = getButtonClasses({
|
|
37
|
+
type: (/* inlined export .TYPE_ICON */"icon"),
|
|
38
|
+
mode,
|
|
39
|
+
fullWidth,
|
|
40
|
+
disabled,
|
|
41
|
+
raw,
|
|
42
|
+
className,
|
|
43
|
+
noBorder,
|
|
44
|
+
size,
|
|
45
|
+
labelRight,
|
|
46
|
+
labelLeft,
|
|
47
|
+
noBackground,
|
|
48
|
+
align,
|
|
49
|
+
radius,
|
|
50
|
+
variant,
|
|
51
|
+
animated,
|
|
52
|
+
badge,
|
|
53
|
+
flat
|
|
54
|
+
});
|
|
55
|
+
const iconClass = getIconClasses({
|
|
56
|
+
mode,
|
|
57
|
+
raw,
|
|
58
|
+
iconClassName,
|
|
59
|
+
variant
|
|
60
|
+
});
|
|
61
|
+
const labelClass = getButtonIconLabelClasses({
|
|
62
|
+
animated
|
|
63
|
+
});
|
|
64
|
+
// Create a combined class for the button content wrapper
|
|
65
|
+
const contentWrapperClass = "flex items-center justify-center relative w-full h-full overflow-hidden";
|
|
66
|
+
const [labelRightRef, rectR] = useResizeObserver();
|
|
67
|
+
const [labelLeftRef, rectL] = useResizeObserver();
|
|
68
|
+
const [iconRef, rectIcon] = useResizeObserver();
|
|
69
|
+
const bufferRef = useRef(0);
|
|
70
|
+
const buttonRef = useRef(null);
|
|
71
|
+
const timeoutRef = useRef(null);
|
|
72
|
+
const mergedRef = useMergeRefs([
|
|
73
|
+
ref,
|
|
74
|
+
buttonRef
|
|
75
|
+
]);
|
|
76
|
+
/**
|
|
77
|
+
* Effect to calculate the buffer to add to the width of the button to
|
|
78
|
+
* account for the icon, paddings and borders.
|
|
79
|
+
*/ useLayoutEffect(()=>{
|
|
80
|
+
/* v8 ignore start */ if (iconRef && iconRef.current && animated) {
|
|
81
|
+
bufferRef.current = rectIcon.width + PADDINGS[size] + (noBorder ? 0 : BORDERS);
|
|
82
|
+
// Set initial button width if it hasn't been set yet
|
|
83
|
+
if (buttonRef.current && !buttonRef.current.style.width) {
|
|
84
|
+
buttonRef.current.style.width = `${WIDTH[size]}px`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/* v8 ignore stop */ }, [
|
|
88
|
+
rectIcon,
|
|
89
|
+
iconRef,
|
|
90
|
+
size,
|
|
91
|
+
noBorder,
|
|
92
|
+
animated
|
|
93
|
+
]);
|
|
94
|
+
/**
|
|
95
|
+
* Effect to update the width of the button based on the visibility of
|
|
96
|
+
* the right and left labels.
|
|
97
|
+
*/ useLayoutEffect(()=>{
|
|
98
|
+
/* v8 ignore start */ if (buttonRef && buttonRef.current && animated) {
|
|
99
|
+
// Calculate the target width first
|
|
100
|
+
let newWidth = WIDTH[size];
|
|
101
|
+
if (labelRight && labelRightRef && rectR.width > 0) {
|
|
102
|
+
newWidth = rectR.width + bufferRef.current;
|
|
103
|
+
} else if (labelLeft && labelLeftRef && rectL.width > 0) {
|
|
104
|
+
newWidth = rectL.width + bufferRef.current;
|
|
105
|
+
}
|
|
106
|
+
// Clear any existing timeout to prevent race conditions
|
|
107
|
+
if (timeoutRef.current) {
|
|
108
|
+
clearTimeout(timeoutRef.current);
|
|
109
|
+
}
|
|
110
|
+
// Start transition - expand button first
|
|
111
|
+
if (newWidth !== parseInt(buttonRef.current.style.width || "0", 10)) {
|
|
112
|
+
// Make sure labels are hidden during width transition
|
|
113
|
+
if (labelRightRef.current) {
|
|
114
|
+
labelRightRef.current.style.opacity = "0";
|
|
115
|
+
}
|
|
116
|
+
if (labelLeftRef.current) {
|
|
117
|
+
labelLeftRef.current.style.opacity = "0";
|
|
118
|
+
}
|
|
119
|
+
// Set the width to trigger the transition
|
|
120
|
+
buttonRef.current.style.width = `${newWidth}px`;
|
|
121
|
+
// After button width transition completes, show the label
|
|
122
|
+
if (newWidth > WIDTH[size]) {
|
|
123
|
+
timeoutRef.current = setTimeout(()=>{
|
|
124
|
+
if (labelRightRef.current && labelRight) {
|
|
125
|
+
labelRightRef.current.style.opacity = "1";
|
|
126
|
+
}
|
|
127
|
+
if (labelLeftRef.current && labelLeft) {
|
|
128
|
+
labelLeftRef.current.style.opacity = "1";
|
|
129
|
+
}
|
|
130
|
+
timeoutRef.current = null;
|
|
131
|
+
}, ANIMATION_DURATION * 0.8); // Wait for most of the width transition to complete
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// If transitioning to icon-only state, hide labels immediately
|
|
135
|
+
if (newWidth === WIDTH[size]) {
|
|
136
|
+
if (labelRightRef.current) {
|
|
137
|
+
labelRightRef.current.style.opacity = "0";
|
|
138
|
+
}
|
|
139
|
+
if (labelLeftRef.current) {
|
|
140
|
+
labelLeftRef.current.style.opacity = "0";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/* v8 ignore stop */ }, [
|
|
145
|
+
rectR,
|
|
146
|
+
labelRight,
|
|
147
|
+
labelRightRef,
|
|
148
|
+
rectL,
|
|
149
|
+
labelLeft,
|
|
150
|
+
labelLeftRef,
|
|
151
|
+
size,
|
|
152
|
+
animated
|
|
153
|
+
]);
|
|
154
|
+
// Clean up timeout on unmount
|
|
155
|
+
/* v8 ignore start */ useEffect(()=>{
|
|
156
|
+
return ()=>{
|
|
157
|
+
if (timeoutRef.current) {
|
|
158
|
+
clearTimeout(timeoutRef.current);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}, []);
|
|
162
|
+
/* v8 ignore stop */ const badgeInfo = getBadgeClasses({
|
|
163
|
+
size,
|
|
164
|
+
badge
|
|
165
|
+
});
|
|
166
|
+
return /*#__PURE__*/ jsxs(BaseButton_private, {
|
|
167
|
+
ref: mergedRef,
|
|
168
|
+
className: buttonClass,
|
|
169
|
+
disabled: disabled,
|
|
170
|
+
type: type,
|
|
171
|
+
"aria-label": ariaLabel || label,
|
|
172
|
+
...otherProps,
|
|
173
|
+
children: [
|
|
174
|
+
/*#__PURE__*/ jsxs("div", {
|
|
175
|
+
className: contentWrapperClass,
|
|
176
|
+
children: [
|
|
177
|
+
/*#__PURE__*/ jsx(ButtonLabel, {
|
|
178
|
+
label: labelLeft,
|
|
179
|
+
labelRef: labelLeftRef,
|
|
180
|
+
labelClass: labelClass,
|
|
181
|
+
labelInnerClass: "pr-2",
|
|
182
|
+
initiallyHidden: animated
|
|
183
|
+
}),
|
|
184
|
+
/*#__PURE__*/ jsx("span", {
|
|
185
|
+
ref: iconRef,
|
|
186
|
+
className: iconClass,
|
|
187
|
+
children: children
|
|
188
|
+
}),
|
|
189
|
+
/*#__PURE__*/ jsx(ButtonLabel, {
|
|
190
|
+
label: labelRight,
|
|
191
|
+
labelRef: labelRightRef,
|
|
192
|
+
labelClass: labelClass,
|
|
193
|
+
labelInnerClass: "pl-2",
|
|
194
|
+
initiallyHidden: animated
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
}),
|
|
198
|
+
badgeInfo && /*#__PURE__*/ jsx("span", {
|
|
199
|
+
className: badgeInfo.className,
|
|
200
|
+
"aria-hidden": "true",
|
|
201
|
+
children: badgeInfo.displayValue
|
|
202
|
+
})
|
|
203
|
+
]
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const ButtonLabel = ({ labelRef, labelClass, label, labelInnerClass, initiallyHidden = false })=>{
|
|
207
|
+
if (!label && !initiallyHidden) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
return /*#__PURE__*/ jsx("span", {
|
|
211
|
+
ref: labelRef,
|
|
212
|
+
className: labelClass,
|
|
213
|
+
style: initiallyHidden ? {
|
|
214
|
+
opacity: 0
|
|
215
|
+
} : undefined,
|
|
216
|
+
children: label && /*#__PURE__*/ jsx("span", {
|
|
217
|
+
className: labelInnerClass,
|
|
218
|
+
children: label
|
|
219
|
+
})
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export { ButtonIcon };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ButtonLinkTypes } from "@versini/ui-types";
|
|
2
|
-
export declare function ButtonLink({ children, mode, fullWidth, className, size, raw, noBorder, target, truncate, noNewWindowIcon, radius, flat, ref, ...otherProps }: ButtonLinkTypes.Props): import("react
|
|
2
|
+
export declare function ButtonLink({ children, mode, fullWidth, className, size, raw, noBorder, target, truncate, noNewWindowIcon, radius, flat, ref, ...otherProps }: ButtonLinkTypes.Props): import("react").JSX.Element;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-button v15.0.
|
|
2
|
+
@versini/ui-button v15.0.5
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import clsx from "clsx";
|
|
8
|
+
import { getButtonClasses } from "../../132.js";
|
|
9
|
+
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
function ButtonLink({ children, mode = "system", fullWidth = false, className, size = "small", raw = false, noBorder = false, target, truncate = false, noNewWindowIcon = false, radius = "large", flat = false, ref, ...otherProps }) {
|
|
13
16
|
const buttonClass = getButtonClasses({
|
|
14
|
-
type: TYPE_LINK,
|
|
17
|
+
type: (/* inlined export .TYPE_LINK */"link"),
|
|
15
18
|
mode,
|
|
16
19
|
fullWidth,
|
|
17
20
|
disabled: false,
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { ButtonTypes } from "@versini/ui-types";
|
|
2
|
-
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare function BaseButton_private(buttonProps: ButtonTypes.Props): React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/ui-button",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@versini/ui-hooks": "6.1.1",
|
|
70
|
-
"@versini/ui-icons": "4.
|
|
70
|
+
"@versini/ui-icons": "4.29.0",
|
|
71
71
|
"clsx": "2.1.1",
|
|
72
|
-
"tailwindcss": "4.3.
|
|
72
|
+
"tailwindcss": "4.3.1"
|
|
73
73
|
},
|
|
74
74
|
"sideEffects": [
|
|
75
75
|
"**/*.css"
|
|
76
76
|
],
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "f25e4b557175f745705c249d10e2e77dc02ed462"
|
|
78
78
|
}
|
package/dist/370.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
@versini/ui-button v15.0.4
|
|
3
|
-
© 2026 gizmette.com
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useMergeRefs } from "@versini/ui-hooks/use-merge-refs";
|
|
7
|
-
import { useResizeObserver } from "@versini/ui-hooks/use-resize-observer";
|
|
8
|
-
import { jsxs, jsx } from "./726.js";
|
|
9
|
-
import { useRef, useLayoutEffect, useEffect } from "./946.js";
|
|
10
|
-
import { getButtonClasses, getIconClasses, getButtonIconLabelClasses, TYPE_ICON, getBadgeClasses } from "./277.js";
|
|
11
|
-
import { BaseButton_private } from "./795.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const WIDTH = {
|
|
22
|
-
small: 24,
|
|
23
|
-
medium: 32,
|
|
24
|
-
large: 48
|
|
25
|
-
};
|
|
26
|
-
const PADDINGS = {
|
|
27
|
-
small: 8 * 2,
|
|
28
|
-
medium: 12 * 2,
|
|
29
|
-
large: 16 * 2
|
|
30
|
-
};
|
|
31
|
-
const BORDERS = 2; // border x 2
|
|
32
|
-
const ANIMATION_DURATION = 300; // ms - should match the CSS transition duration
|
|
33
|
-
function ButtonIcon({ children, disabled = false, mode = "system", fullWidth = false, className, type = "button", raw = false, noBorder = false, "aria-label": ariaLabel, label, size = "medium", labelRight, labelLeft, noBackground = false, align = "center", radius = "large", variant = "secondary", iconClassName, animated = false, badge, flat = false, ref, ...otherProps }) {
|
|
34
|
-
const buttonClass = getButtonClasses({
|
|
35
|
-
type: TYPE_ICON,
|
|
36
|
-
mode,
|
|
37
|
-
fullWidth,
|
|
38
|
-
disabled,
|
|
39
|
-
raw,
|
|
40
|
-
className,
|
|
41
|
-
noBorder,
|
|
42
|
-
size,
|
|
43
|
-
labelRight,
|
|
44
|
-
labelLeft,
|
|
45
|
-
noBackground,
|
|
46
|
-
align,
|
|
47
|
-
radius,
|
|
48
|
-
variant,
|
|
49
|
-
animated,
|
|
50
|
-
badge,
|
|
51
|
-
flat
|
|
52
|
-
});
|
|
53
|
-
const iconClass = getIconClasses({
|
|
54
|
-
mode,
|
|
55
|
-
raw,
|
|
56
|
-
iconClassName,
|
|
57
|
-
variant
|
|
58
|
-
});
|
|
59
|
-
const labelClass = getButtonIconLabelClasses({
|
|
60
|
-
animated
|
|
61
|
-
});
|
|
62
|
-
// Create a combined class for the button content wrapper
|
|
63
|
-
const contentWrapperClass = "flex items-center justify-center relative w-full h-full overflow-hidden";
|
|
64
|
-
const [labelRightRef, rectR] = useResizeObserver();
|
|
65
|
-
const [labelLeftRef, rectL] = useResizeObserver();
|
|
66
|
-
const [iconRef, rectIcon] = useResizeObserver();
|
|
67
|
-
const bufferRef = useRef(0);
|
|
68
|
-
const buttonRef = useRef(null);
|
|
69
|
-
const timeoutRef = useRef(null);
|
|
70
|
-
const mergedRef = useMergeRefs([
|
|
71
|
-
ref,
|
|
72
|
-
buttonRef
|
|
73
|
-
]);
|
|
74
|
-
/**
|
|
75
|
-
* Effect to calculate the buffer to add to the width of the button to
|
|
76
|
-
* account for the icon, paddings and borders.
|
|
77
|
-
*/ useLayoutEffect(()=>{
|
|
78
|
-
/* v8 ignore start */ if (iconRef && iconRef.current && animated) {
|
|
79
|
-
bufferRef.current = rectIcon.width + PADDINGS[size] + (noBorder ? 0 : BORDERS);
|
|
80
|
-
// Set initial button width if it hasn't been set yet
|
|
81
|
-
if (buttonRef.current && !buttonRef.current.style.width) {
|
|
82
|
-
buttonRef.current.style.width = `${WIDTH[size]}px`;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/* v8 ignore stop */ }, [
|
|
86
|
-
rectIcon,
|
|
87
|
-
iconRef,
|
|
88
|
-
size,
|
|
89
|
-
noBorder,
|
|
90
|
-
animated
|
|
91
|
-
]);
|
|
92
|
-
/**
|
|
93
|
-
* Effect to update the width of the button based on the visibility of
|
|
94
|
-
* the right and left labels.
|
|
95
|
-
*/ useLayoutEffect(()=>{
|
|
96
|
-
/* v8 ignore start */ if (buttonRef && buttonRef.current && animated) {
|
|
97
|
-
// Calculate the target width first
|
|
98
|
-
let newWidth = WIDTH[size];
|
|
99
|
-
if (labelRight && labelRightRef && rectR.width > 0) {
|
|
100
|
-
newWidth = rectR.width + bufferRef.current;
|
|
101
|
-
} else if (labelLeft && labelLeftRef && rectL.width > 0) {
|
|
102
|
-
newWidth = rectL.width + bufferRef.current;
|
|
103
|
-
}
|
|
104
|
-
// Clear any existing timeout to prevent race conditions
|
|
105
|
-
if (timeoutRef.current) {
|
|
106
|
-
clearTimeout(timeoutRef.current);
|
|
107
|
-
}
|
|
108
|
-
// Start transition - expand button first
|
|
109
|
-
if (newWidth !== parseInt(buttonRef.current.style.width || "0", 10)) {
|
|
110
|
-
// Make sure labels are hidden during width transition
|
|
111
|
-
if (labelRightRef.current) {
|
|
112
|
-
labelRightRef.current.style.opacity = "0";
|
|
113
|
-
}
|
|
114
|
-
if (labelLeftRef.current) {
|
|
115
|
-
labelLeftRef.current.style.opacity = "0";
|
|
116
|
-
}
|
|
117
|
-
// Set the width to trigger the transition
|
|
118
|
-
buttonRef.current.style.width = `${newWidth}px`;
|
|
119
|
-
// After button width transition completes, show the label
|
|
120
|
-
if (newWidth > WIDTH[size]) {
|
|
121
|
-
timeoutRef.current = setTimeout(()=>{
|
|
122
|
-
if (labelRightRef.current && labelRight) {
|
|
123
|
-
labelRightRef.current.style.opacity = "1";
|
|
124
|
-
}
|
|
125
|
-
if (labelLeftRef.current && labelLeft) {
|
|
126
|
-
labelLeftRef.current.style.opacity = "1";
|
|
127
|
-
}
|
|
128
|
-
timeoutRef.current = null;
|
|
129
|
-
}, ANIMATION_DURATION * 0.8); // Wait for most of the width transition to complete
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// If transitioning to icon-only state, hide labels immediately
|
|
133
|
-
if (newWidth === WIDTH[size]) {
|
|
134
|
-
if (labelRightRef.current) {
|
|
135
|
-
labelRightRef.current.style.opacity = "0";
|
|
136
|
-
}
|
|
137
|
-
if (labelLeftRef.current) {
|
|
138
|
-
labelLeftRef.current.style.opacity = "0";
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/* v8 ignore stop */ }, [
|
|
143
|
-
rectR,
|
|
144
|
-
labelRight,
|
|
145
|
-
labelRightRef,
|
|
146
|
-
rectL,
|
|
147
|
-
labelLeft,
|
|
148
|
-
labelLeftRef,
|
|
149
|
-
size,
|
|
150
|
-
animated
|
|
151
|
-
]);
|
|
152
|
-
// Clean up timeout on unmount
|
|
153
|
-
/* v8 ignore start */ useEffect(()=>{
|
|
154
|
-
return ()=>{
|
|
155
|
-
if (timeoutRef.current) {
|
|
156
|
-
clearTimeout(timeoutRef.current);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}, []);
|
|
160
|
-
/* v8 ignore stop */ const badgeInfo = getBadgeClasses({
|
|
161
|
-
size,
|
|
162
|
-
badge
|
|
163
|
-
});
|
|
164
|
-
return /*#__PURE__*/ jsxs(BaseButton_private, {
|
|
165
|
-
ref: mergedRef,
|
|
166
|
-
className: buttonClass,
|
|
167
|
-
disabled: disabled,
|
|
168
|
-
type: type,
|
|
169
|
-
"aria-label": ariaLabel || label,
|
|
170
|
-
...otherProps,
|
|
171
|
-
children: [
|
|
172
|
-
/*#__PURE__*/ jsxs("div", {
|
|
173
|
-
className: contentWrapperClass,
|
|
174
|
-
children: [
|
|
175
|
-
/*#__PURE__*/ jsx(ButtonLabel, {
|
|
176
|
-
label: labelLeft,
|
|
177
|
-
labelRef: labelLeftRef,
|
|
178
|
-
labelClass: labelClass,
|
|
179
|
-
labelInnerClass: "pr-2",
|
|
180
|
-
initiallyHidden: animated
|
|
181
|
-
}),
|
|
182
|
-
/*#__PURE__*/ jsx("span", {
|
|
183
|
-
ref: iconRef,
|
|
184
|
-
className: iconClass,
|
|
185
|
-
children: children
|
|
186
|
-
}),
|
|
187
|
-
/*#__PURE__*/ jsx(ButtonLabel, {
|
|
188
|
-
label: labelRight,
|
|
189
|
-
labelRef: labelRightRef,
|
|
190
|
-
labelClass: labelClass,
|
|
191
|
-
labelInnerClass: "pl-2",
|
|
192
|
-
initiallyHidden: animated
|
|
193
|
-
})
|
|
194
|
-
]
|
|
195
|
-
}),
|
|
196
|
-
badgeInfo && /*#__PURE__*/ jsx("span", {
|
|
197
|
-
className: badgeInfo.className,
|
|
198
|
-
"aria-hidden": "true",
|
|
199
|
-
children: badgeInfo.displayValue
|
|
200
|
-
})
|
|
201
|
-
]
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
const ButtonLabel = ({ labelRef, labelClass, label, labelInnerClass, initiallyHidden = false })=>{
|
|
205
|
-
if (!label && !initiallyHidden) {
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
return /*#__PURE__*/ jsx("span", {
|
|
209
|
-
ref: labelRef,
|
|
210
|
-
className: labelClass,
|
|
211
|
-
style: initiallyHidden ? {
|
|
212
|
-
opacity: 0
|
|
213
|
-
} : undefined,
|
|
214
|
-
children: label && /*#__PURE__*/ jsx("span", {
|
|
215
|
-
className: labelInnerClass,
|
|
216
|
-
children: label
|
|
217
|
-
})
|
|
218
|
-
});
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
export { ButtonIcon };
|
package/dist/726.js
DELETED