@kopexa/button 3.0.0 → 5.0.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/button.d.mts +20 -1
- package/dist/button.d.ts +20 -1
- package/dist/button.js +37 -6
- package/dist/button.mjs +1 -1
- package/dist/{chunk-JCUHIKMH.mjs → chunk-LUQR5CDX.mjs} +42 -7
- package/dist/chunk-TYBPWI6V.mjs +31 -0
- package/dist/icon-button.d.mts +11 -0
- package/dist/icon-button.d.ts +11 -0
- package/dist/icon-button.js +158 -0
- package/dist/icon-button.mjs +8 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +64 -8
- package/dist/index.mjs +6 -2
- package/package.json +7 -5
package/dist/button.d.mts
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ButtonVariantProps } from '@kopexa/theme';
|
|
3
|
-
import { ComponentProps } from 'react';
|
|
3
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
type ButtonProps = ComponentProps<"button"> & ButtonVariantProps & {
|
|
6
|
+
/**
|
|
7
|
+
* The button start content.
|
|
8
|
+
*/
|
|
9
|
+
startContent?: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* The button end content.
|
|
12
|
+
*/
|
|
13
|
+
endContent?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The spinner placement.
|
|
16
|
+
* @default "start"
|
|
17
|
+
*/
|
|
18
|
+
spinnerPlacement?: "start" | "end";
|
|
19
|
+
/**
|
|
20
|
+
* render the button as a different component.
|
|
21
|
+
* @default false
|
|
22
|
+
* @example
|
|
23
|
+
* <Button asChild><Link to="/path">Link</Link></Button>
|
|
24
|
+
*/
|
|
6
25
|
asChild?: boolean;
|
|
7
26
|
/**
|
|
8
27
|
* Whether the button should display a ripple effect on press.
|
package/dist/button.d.ts
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ButtonVariantProps } from '@kopexa/theme';
|
|
3
|
-
import { ComponentProps } from 'react';
|
|
3
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
type ButtonProps = ComponentProps<"button"> & ButtonVariantProps & {
|
|
6
|
+
/**
|
|
7
|
+
* The button start content.
|
|
8
|
+
*/
|
|
9
|
+
startContent?: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* The button end content.
|
|
12
|
+
*/
|
|
13
|
+
endContent?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The spinner placement.
|
|
16
|
+
* @default "start"
|
|
17
|
+
*/
|
|
18
|
+
spinnerPlacement?: "start" | "end";
|
|
19
|
+
/**
|
|
20
|
+
* render the button as a different component.
|
|
21
|
+
* @default false
|
|
22
|
+
* @example
|
|
23
|
+
* <Button asChild><Link to="/path">Link</Link></Button>
|
|
24
|
+
*/
|
|
6
25
|
asChild?: boolean;
|
|
7
26
|
/**
|
|
8
27
|
* Whether the button should display a ripple effect on press.
|
package/dist/button.js
CHANGED
|
@@ -36,6 +36,8 @@ __export(button_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(button_exports);
|
|
37
37
|
var import_react_utils = require("@kopexa/react-utils");
|
|
38
38
|
var import_ripple = require("@kopexa/ripple");
|
|
39
|
+
var import_shared_utils = require("@kopexa/shared-utils");
|
|
40
|
+
var import_spinner = require("@kopexa/spinner");
|
|
39
41
|
var import_theme = require("@kopexa/theme");
|
|
40
42
|
var Slot = __toESM(require("@radix-ui/react-slot"));
|
|
41
43
|
var import_react = require("react");
|
|
@@ -51,8 +53,15 @@ var Button = (props) => {
|
|
|
51
53
|
ref,
|
|
52
54
|
isLoading,
|
|
53
55
|
variant,
|
|
54
|
-
size,
|
|
56
|
+
size = "md",
|
|
55
57
|
className,
|
|
58
|
+
color,
|
|
59
|
+
radius,
|
|
60
|
+
fullWidth,
|
|
61
|
+
startContent,
|
|
62
|
+
endContent,
|
|
63
|
+
isIconOnly,
|
|
64
|
+
spinnerPlacement = "start",
|
|
56
65
|
...rest
|
|
57
66
|
} = props;
|
|
58
67
|
const Comp = asChild ? Slot.Root : "button";
|
|
@@ -63,11 +72,17 @@ var Button = (props) => {
|
|
|
63
72
|
onClear: onClearRipple,
|
|
64
73
|
ripples
|
|
65
74
|
} = (0, import_ripple.useRipple)();
|
|
66
|
-
const styles = (0,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
const styles = (0, import_react.useMemo)(() => {
|
|
76
|
+
return (0, import_theme.button)({
|
|
77
|
+
variant,
|
|
78
|
+
size,
|
|
79
|
+
color,
|
|
80
|
+
radius,
|
|
81
|
+
fullWidth,
|
|
82
|
+
isIconOnly,
|
|
83
|
+
className
|
|
84
|
+
});
|
|
85
|
+
}, [variant, size, color, radius, isIconOnly, fullWidth, className]);
|
|
71
86
|
const handleClick = (0, import_react.useCallback)(
|
|
72
87
|
(e) => {
|
|
73
88
|
if (disableRipple || isDisabled) return;
|
|
@@ -80,6 +95,14 @@ var Button = (props) => {
|
|
|
80
95
|
() => ({ ripples, onClear: onClearRipple }),
|
|
81
96
|
[ripples, onClearRipple]
|
|
82
97
|
);
|
|
98
|
+
const spinnerSize = (0, import_react.useMemo)(() => {
|
|
99
|
+
const buttonSpinnerSizeMap = {
|
|
100
|
+
sm: "sm",
|
|
101
|
+
md: "sm",
|
|
102
|
+
lg: "md"
|
|
103
|
+
};
|
|
104
|
+
return buttonSpinnerSizeMap[size];
|
|
105
|
+
}, [size]);
|
|
83
106
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
84
107
|
Comp,
|
|
85
108
|
{
|
|
@@ -88,9 +111,17 @@ var Button = (props) => {
|
|
|
88
111
|
onClick: handleClick,
|
|
89
112
|
ref: (0, import_react_utils.mergeRefs)(domRef, ref),
|
|
90
113
|
disabled: isDisabled,
|
|
114
|
+
"data-disabled": (0, import_shared_utils.dataAttr)(isDisabled),
|
|
115
|
+
"data-loading": (0, import_shared_utils.dataAttr)(isLoading),
|
|
116
|
+
"aria-disabled": isDisabled,
|
|
117
|
+
tabIndex: isDisabled ? -1 : void 0,
|
|
91
118
|
...rest,
|
|
92
119
|
children: [
|
|
120
|
+
startContent,
|
|
121
|
+
isLoading && spinnerPlacement === "start" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { color: "current", size: spinnerSize }),
|
|
93
122
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot.Slottable, { children }),
|
|
123
|
+
isLoading && spinnerPlacement === "end" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { color: "current", size: spinnerSize }),
|
|
124
|
+
endContent,
|
|
94
125
|
!disableRipple && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ripple.Ripple, { ...getRippleProps() })
|
|
95
126
|
]
|
|
96
127
|
}
|
package/dist/button.mjs
CHANGED
|
@@ -3,9 +3,15 @@
|
|
|
3
3
|
// src/button.tsx
|
|
4
4
|
import { mergeRefs } from "@kopexa/react-utils";
|
|
5
5
|
import { Ripple, useRipple } from "@kopexa/ripple";
|
|
6
|
+
import { dataAttr } from "@kopexa/shared-utils";
|
|
7
|
+
import { Spinner } from "@kopexa/spinner";
|
|
6
8
|
import { button } from "@kopexa/theme";
|
|
7
9
|
import * as Slot from "@radix-ui/react-slot";
|
|
8
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
useCallback,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef
|
|
14
|
+
} from "react";
|
|
9
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
16
|
var Button = (props) => {
|
|
11
17
|
const {
|
|
@@ -18,8 +24,15 @@ var Button = (props) => {
|
|
|
18
24
|
ref,
|
|
19
25
|
isLoading,
|
|
20
26
|
variant,
|
|
21
|
-
size,
|
|
27
|
+
size = "md",
|
|
22
28
|
className,
|
|
29
|
+
color,
|
|
30
|
+
radius,
|
|
31
|
+
fullWidth,
|
|
32
|
+
startContent,
|
|
33
|
+
endContent,
|
|
34
|
+
isIconOnly,
|
|
35
|
+
spinnerPlacement = "start",
|
|
23
36
|
...rest
|
|
24
37
|
} = props;
|
|
25
38
|
const Comp = asChild ? Slot.Root : "button";
|
|
@@ -30,11 +43,17 @@ var Button = (props) => {
|
|
|
30
43
|
onClear: onClearRipple,
|
|
31
44
|
ripples
|
|
32
45
|
} = useRipple();
|
|
33
|
-
const styles =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
const styles = useMemo(() => {
|
|
47
|
+
return button({
|
|
48
|
+
variant,
|
|
49
|
+
size,
|
|
50
|
+
color,
|
|
51
|
+
radius,
|
|
52
|
+
fullWidth,
|
|
53
|
+
isIconOnly,
|
|
54
|
+
className
|
|
55
|
+
});
|
|
56
|
+
}, [variant, size, color, radius, isIconOnly, fullWidth, className]);
|
|
38
57
|
const handleClick = useCallback(
|
|
39
58
|
(e) => {
|
|
40
59
|
if (disableRipple || isDisabled) return;
|
|
@@ -47,6 +66,14 @@ var Button = (props) => {
|
|
|
47
66
|
() => ({ ripples, onClear: onClearRipple }),
|
|
48
67
|
[ripples, onClearRipple]
|
|
49
68
|
);
|
|
69
|
+
const spinnerSize = useMemo(() => {
|
|
70
|
+
const buttonSpinnerSizeMap = {
|
|
71
|
+
sm: "sm",
|
|
72
|
+
md: "sm",
|
|
73
|
+
lg: "md"
|
|
74
|
+
};
|
|
75
|
+
return buttonSpinnerSizeMap[size];
|
|
76
|
+
}, [size]);
|
|
50
77
|
return /* @__PURE__ */ jsxs(
|
|
51
78
|
Comp,
|
|
52
79
|
{
|
|
@@ -55,9 +82,17 @@ var Button = (props) => {
|
|
|
55
82
|
onClick: handleClick,
|
|
56
83
|
ref: mergeRefs(domRef, ref),
|
|
57
84
|
disabled: isDisabled,
|
|
85
|
+
"data-disabled": dataAttr(isDisabled),
|
|
86
|
+
"data-loading": dataAttr(isLoading),
|
|
87
|
+
"aria-disabled": isDisabled,
|
|
88
|
+
tabIndex: isDisabled ? -1 : void 0,
|
|
58
89
|
...rest,
|
|
59
90
|
children: [
|
|
91
|
+
startContent,
|
|
92
|
+
isLoading && spinnerPlacement === "start" && /* @__PURE__ */ jsx(Spinner, { color: "current", size: spinnerSize }),
|
|
60
93
|
/* @__PURE__ */ jsx(Slot.Slottable, { children }),
|
|
94
|
+
isLoading && spinnerPlacement === "end" && /* @__PURE__ */ jsx(Spinner, { color: "current", size: spinnerSize }),
|
|
95
|
+
endContent,
|
|
61
96
|
!disableRipple && /* @__PURE__ */ jsx(Ripple, { ...getRippleProps() })
|
|
62
97
|
]
|
|
63
98
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Button
|
|
4
|
+
} from "./chunk-LUQR5CDX.mjs";
|
|
5
|
+
|
|
6
|
+
// src/icon-button.tsx
|
|
7
|
+
import { Tooltip } from "@kopexa/tooltip";
|
|
8
|
+
import { cloneElement, isValidElement, useMemo } from "react";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
var IconButton = (props) => {
|
|
11
|
+
const { "aria-label": ariaLabel, children, ...rest } = props;
|
|
12
|
+
const label = ariaLabel || children;
|
|
13
|
+
const toolip = useMemo(() => {
|
|
14
|
+
if (label && typeof label === "string") {
|
|
15
|
+
return label;
|
|
16
|
+
}
|
|
17
|
+
return void 0;
|
|
18
|
+
}, [label]);
|
|
19
|
+
const clonedChildren = isValidElement(children) ? (
|
|
20
|
+
// biome-ignore lint/suspicious/noExplicitAny: forcing type to any
|
|
21
|
+
cloneElement(children, { "aria-hidden": true })
|
|
22
|
+
) : children;
|
|
23
|
+
if (toolip) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Tooltip, { content: toolip, children: /* @__PURE__ */ jsx(Button, { ...rest, "aria-label": ariaLabel, isIconOnly: true, children: clonedChildren }) });
|
|
25
|
+
}
|
|
26
|
+
return /* @__PURE__ */ jsx(Button, { ...rest, "aria-label": ariaLabel, isIconOnly: true, children: clonedChildren });
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
IconButton
|
|
31
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ButtonProps } from './button.mjs';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import '@kopexa/theme';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type IconButtonProps = Omit<ButtonProps, "isIconOnly"> & {
|
|
7
|
+
"aria-label": string;
|
|
8
|
+
};
|
|
9
|
+
declare const IconButton: (props: IconButtonProps) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { IconButton, type IconButtonProps };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ButtonProps } from './button.js';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import '@kopexa/theme';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type IconButtonProps = Omit<ButtonProps, "isIconOnly"> & {
|
|
7
|
+
"aria-label": string;
|
|
8
|
+
};
|
|
9
|
+
declare const IconButton: (props: IconButtonProps) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { IconButton, type IconButtonProps };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/icon-button.tsx
|
|
32
|
+
var icon_button_exports = {};
|
|
33
|
+
__export(icon_button_exports, {
|
|
34
|
+
IconButton: () => IconButton
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(icon_button_exports);
|
|
37
|
+
var import_tooltip = require("@kopexa/tooltip");
|
|
38
|
+
var import_react2 = require("react");
|
|
39
|
+
|
|
40
|
+
// src/button.tsx
|
|
41
|
+
var import_react_utils = require("@kopexa/react-utils");
|
|
42
|
+
var import_ripple = require("@kopexa/ripple");
|
|
43
|
+
var import_shared_utils = require("@kopexa/shared-utils");
|
|
44
|
+
var import_spinner = require("@kopexa/spinner");
|
|
45
|
+
var import_theme = require("@kopexa/theme");
|
|
46
|
+
var Slot = __toESM(require("@radix-ui/react-slot"));
|
|
47
|
+
var import_react = require("react");
|
|
48
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
49
|
+
var Button = (props) => {
|
|
50
|
+
const {
|
|
51
|
+
type = "button",
|
|
52
|
+
asChild,
|
|
53
|
+
children,
|
|
54
|
+
onClick,
|
|
55
|
+
disabled,
|
|
56
|
+
disableRipple,
|
|
57
|
+
ref,
|
|
58
|
+
isLoading,
|
|
59
|
+
variant,
|
|
60
|
+
size = "md",
|
|
61
|
+
className,
|
|
62
|
+
color,
|
|
63
|
+
radius,
|
|
64
|
+
fullWidth,
|
|
65
|
+
startContent,
|
|
66
|
+
endContent,
|
|
67
|
+
isIconOnly,
|
|
68
|
+
spinnerPlacement = "start",
|
|
69
|
+
...rest
|
|
70
|
+
} = props;
|
|
71
|
+
const Comp = asChild ? Slot.Root : "button";
|
|
72
|
+
const domRef = (0, import_react.useRef)(null);
|
|
73
|
+
const isDisabled = disabled || isLoading;
|
|
74
|
+
const {
|
|
75
|
+
onClick: onRippleClickHandler,
|
|
76
|
+
onClear: onClearRipple,
|
|
77
|
+
ripples
|
|
78
|
+
} = (0, import_ripple.useRipple)();
|
|
79
|
+
const styles = (0, import_react.useMemo)(() => {
|
|
80
|
+
return (0, import_theme.button)({
|
|
81
|
+
variant,
|
|
82
|
+
size,
|
|
83
|
+
color,
|
|
84
|
+
radius,
|
|
85
|
+
fullWidth,
|
|
86
|
+
isIconOnly,
|
|
87
|
+
className
|
|
88
|
+
});
|
|
89
|
+
}, [variant, size, color, radius, isIconOnly, fullWidth, className]);
|
|
90
|
+
const handleClick = (0, import_react.useCallback)(
|
|
91
|
+
(e) => {
|
|
92
|
+
if (disableRipple || isDisabled) return;
|
|
93
|
+
domRef.current && onRippleClickHandler(e);
|
|
94
|
+
onClick == null ? void 0 : onClick(e);
|
|
95
|
+
},
|
|
96
|
+
[onClick, disableRipple, isDisabled, onRippleClickHandler]
|
|
97
|
+
);
|
|
98
|
+
const getRippleProps = (0, import_react.useCallback)(
|
|
99
|
+
() => ({ ripples, onClear: onClearRipple }),
|
|
100
|
+
[ripples, onClearRipple]
|
|
101
|
+
);
|
|
102
|
+
const spinnerSize = (0, import_react.useMemo)(() => {
|
|
103
|
+
const buttonSpinnerSizeMap = {
|
|
104
|
+
sm: "sm",
|
|
105
|
+
md: "sm",
|
|
106
|
+
lg: "md"
|
|
107
|
+
};
|
|
108
|
+
return buttonSpinnerSizeMap[size];
|
|
109
|
+
}, [size]);
|
|
110
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
111
|
+
Comp,
|
|
112
|
+
{
|
|
113
|
+
type,
|
|
114
|
+
className: styles,
|
|
115
|
+
onClick: handleClick,
|
|
116
|
+
ref: (0, import_react_utils.mergeRefs)(domRef, ref),
|
|
117
|
+
disabled: isDisabled,
|
|
118
|
+
"data-disabled": (0, import_shared_utils.dataAttr)(isDisabled),
|
|
119
|
+
"data-loading": (0, import_shared_utils.dataAttr)(isLoading),
|
|
120
|
+
"aria-disabled": isDisabled,
|
|
121
|
+
tabIndex: isDisabled ? -1 : void 0,
|
|
122
|
+
...rest,
|
|
123
|
+
children: [
|
|
124
|
+
startContent,
|
|
125
|
+
isLoading && spinnerPlacement === "start" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { color: "current", size: spinnerSize }),
|
|
126
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot.Slottable, { children }),
|
|
127
|
+
isLoading && spinnerPlacement === "end" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { color: "current", size: spinnerSize }),
|
|
128
|
+
endContent,
|
|
129
|
+
!disableRipple && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ripple.Ripple, { ...getRippleProps() })
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/icon-button.tsx
|
|
136
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
137
|
+
var IconButton = (props) => {
|
|
138
|
+
const { "aria-label": ariaLabel, children, ...rest } = props;
|
|
139
|
+
const label = ariaLabel || children;
|
|
140
|
+
const toolip = (0, import_react2.useMemo)(() => {
|
|
141
|
+
if (label && typeof label === "string") {
|
|
142
|
+
return label;
|
|
143
|
+
}
|
|
144
|
+
return void 0;
|
|
145
|
+
}, [label]);
|
|
146
|
+
const clonedChildren = (0, import_react2.isValidElement)(children) ? (
|
|
147
|
+
// biome-ignore lint/suspicious/noExplicitAny: forcing type to any
|
|
148
|
+
(0, import_react2.cloneElement)(children, { "aria-hidden": true })
|
|
149
|
+
) : children;
|
|
150
|
+
if (toolip) {
|
|
151
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_tooltip.Tooltip, { content: toolip, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { ...rest, "aria-label": ariaLabel, isIconOnly: true, children: clonedChildren }) });
|
|
152
|
+
}
|
|
153
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { ...rest, "aria-label": ariaLabel, isIconOnly: true, children: clonedChildren });
|
|
154
|
+
};
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
IconButton
|
|
158
|
+
});
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -31,13 +31,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
Button: () => Button
|
|
34
|
+
Button: () => Button,
|
|
35
|
+
IconButton: () => IconButton
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(index_exports);
|
|
37
38
|
|
|
38
39
|
// src/button.tsx
|
|
39
40
|
var import_react_utils = require("@kopexa/react-utils");
|
|
40
41
|
var import_ripple = require("@kopexa/ripple");
|
|
42
|
+
var import_shared_utils = require("@kopexa/shared-utils");
|
|
43
|
+
var import_spinner = require("@kopexa/spinner");
|
|
41
44
|
var import_theme = require("@kopexa/theme");
|
|
42
45
|
var Slot = __toESM(require("@radix-ui/react-slot"));
|
|
43
46
|
var import_react = require("react");
|
|
@@ -53,8 +56,15 @@ var Button = (props) => {
|
|
|
53
56
|
ref,
|
|
54
57
|
isLoading,
|
|
55
58
|
variant,
|
|
56
|
-
size,
|
|
59
|
+
size = "md",
|
|
57
60
|
className,
|
|
61
|
+
color,
|
|
62
|
+
radius,
|
|
63
|
+
fullWidth,
|
|
64
|
+
startContent,
|
|
65
|
+
endContent,
|
|
66
|
+
isIconOnly,
|
|
67
|
+
spinnerPlacement = "start",
|
|
58
68
|
...rest
|
|
59
69
|
} = props;
|
|
60
70
|
const Comp = asChild ? Slot.Root : "button";
|
|
@@ -65,11 +75,17 @@ var Button = (props) => {
|
|
|
65
75
|
onClear: onClearRipple,
|
|
66
76
|
ripples
|
|
67
77
|
} = (0, import_ripple.useRipple)();
|
|
68
|
-
const styles = (0,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
const styles = (0, import_react.useMemo)(() => {
|
|
79
|
+
return (0, import_theme.button)({
|
|
80
|
+
variant,
|
|
81
|
+
size,
|
|
82
|
+
color,
|
|
83
|
+
radius,
|
|
84
|
+
fullWidth,
|
|
85
|
+
isIconOnly,
|
|
86
|
+
className
|
|
87
|
+
});
|
|
88
|
+
}, [variant, size, color, radius, isIconOnly, fullWidth, className]);
|
|
73
89
|
const handleClick = (0, import_react.useCallback)(
|
|
74
90
|
(e) => {
|
|
75
91
|
if (disableRipple || isDisabled) return;
|
|
@@ -82,6 +98,14 @@ var Button = (props) => {
|
|
|
82
98
|
() => ({ ripples, onClear: onClearRipple }),
|
|
83
99
|
[ripples, onClearRipple]
|
|
84
100
|
);
|
|
101
|
+
const spinnerSize = (0, import_react.useMemo)(() => {
|
|
102
|
+
const buttonSpinnerSizeMap = {
|
|
103
|
+
sm: "sm",
|
|
104
|
+
md: "sm",
|
|
105
|
+
lg: "md"
|
|
106
|
+
};
|
|
107
|
+
return buttonSpinnerSizeMap[size];
|
|
108
|
+
}, [size]);
|
|
85
109
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
86
110
|
Comp,
|
|
87
111
|
{
|
|
@@ -90,15 +114,47 @@ var Button = (props) => {
|
|
|
90
114
|
onClick: handleClick,
|
|
91
115
|
ref: (0, import_react_utils.mergeRefs)(domRef, ref),
|
|
92
116
|
disabled: isDisabled,
|
|
117
|
+
"data-disabled": (0, import_shared_utils.dataAttr)(isDisabled),
|
|
118
|
+
"data-loading": (0, import_shared_utils.dataAttr)(isLoading),
|
|
119
|
+
"aria-disabled": isDisabled,
|
|
120
|
+
tabIndex: isDisabled ? -1 : void 0,
|
|
93
121
|
...rest,
|
|
94
122
|
children: [
|
|
123
|
+
startContent,
|
|
124
|
+
isLoading && spinnerPlacement === "start" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { color: "current", size: spinnerSize }),
|
|
95
125
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot.Slottable, { children }),
|
|
126
|
+
isLoading && spinnerPlacement === "end" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { color: "current", size: spinnerSize }),
|
|
127
|
+
endContent,
|
|
96
128
|
!disableRipple && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ripple.Ripple, { ...getRippleProps() })
|
|
97
129
|
]
|
|
98
130
|
}
|
|
99
131
|
);
|
|
100
132
|
};
|
|
133
|
+
|
|
134
|
+
// src/icon-button.tsx
|
|
135
|
+
var import_tooltip = require("@kopexa/tooltip");
|
|
136
|
+
var import_react2 = require("react");
|
|
137
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
138
|
+
var IconButton = (props) => {
|
|
139
|
+
const { "aria-label": ariaLabel, children, ...rest } = props;
|
|
140
|
+
const label = ariaLabel || children;
|
|
141
|
+
const toolip = (0, import_react2.useMemo)(() => {
|
|
142
|
+
if (label && typeof label === "string") {
|
|
143
|
+
return label;
|
|
144
|
+
}
|
|
145
|
+
return void 0;
|
|
146
|
+
}, [label]);
|
|
147
|
+
const clonedChildren = (0, import_react2.isValidElement)(children) ? (
|
|
148
|
+
// biome-ignore lint/suspicious/noExplicitAny: forcing type to any
|
|
149
|
+
(0, import_react2.cloneElement)(children, { "aria-hidden": true })
|
|
150
|
+
) : children;
|
|
151
|
+
if (toolip) {
|
|
152
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_tooltip.Tooltip, { content: toolip, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { ...rest, "aria-label": ariaLabel, isIconOnly: true, children: clonedChildren }) });
|
|
153
|
+
}
|
|
154
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { ...rest, "aria-label": ariaLabel, isIconOnly: true, children: clonedChildren });
|
|
155
|
+
};
|
|
101
156
|
// Annotate the CommonJS export names for ESM import in node:
|
|
102
157
|
0 && (module.exports = {
|
|
103
|
-
Button
|
|
158
|
+
Button,
|
|
159
|
+
IconButton
|
|
104
160
|
});
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kopexa/button",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Buttons allow users to perform actions and choose with a single tap.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"button"
|
|
@@ -28,13 +28,15 @@
|
|
|
28
28
|
"motion": ">=12.23.6",
|
|
29
29
|
"react": ">=19.0.0-rc.0",
|
|
30
30
|
"react-dom": ">=19.0.0-rc.0",
|
|
31
|
-
"@kopexa/theme": "1.
|
|
31
|
+
"@kopexa/theme": "1.4.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@radix-ui/react-slot": "^1.2.3",
|
|
35
|
-
"@kopexa/shared-utils": "1.1.
|
|
36
|
-
"@kopexa/react-utils": "2.0.
|
|
37
|
-
"@kopexa/
|
|
35
|
+
"@kopexa/shared-utils": "1.1.1",
|
|
36
|
+
"@kopexa/react-utils": "2.0.1",
|
|
37
|
+
"@kopexa/spinner": "3.0.0",
|
|
38
|
+
"@kopexa/tooltip": "3.0.0",
|
|
39
|
+
"@kopexa/ripple": "7.0.0"
|
|
38
40
|
},
|
|
39
41
|
"clean-package": "../../../clean-package.config.json",
|
|
40
42
|
"module": "dist/index.mjs",
|