@glob-ui/button 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +126 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +101 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Martínez E
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glob-ui/button
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A button that can render as a link, and shows a loading state without changing its width.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @glob-ui/button
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
Full docs, examples and the accessibility table: [Button](https://github.com/kevin-martineze/GlobUI/tree/main/apps/docs/content/docs/components/button.mdx).
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT. See [LICENSE](./LICENSE).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
declare const buttonVariants: (props?: ({
|
|
6
|
+
variant?: "primary" | "secondary" | "ghost" | "outline" | "link" | null | undefined;
|
|
7
|
+
size?: "sm" | "md" | "lg" | "icon" | null | undefined;
|
|
8
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
9
|
+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
10
|
+
/** Render the single child (e.g. an <a>) with the button's styles and props instead of a <button>. */
|
|
11
|
+
asChild?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Shows a spinner over the content, disables the button and sets aria-busy. Width stays the same.
|
|
14
|
+
* With asChild only aria-busy/aria-disabled are set: the child is rendered as is.
|
|
15
|
+
*/
|
|
16
|
+
loading?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare const Button: react.ForwardRefExoticComponent<ButtonProps & react.RefAttributes<HTMLButtonElement>>;
|
|
19
|
+
|
|
20
|
+
export { Button, type ButtonProps, buttonVariants };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
declare const buttonVariants: (props?: ({
|
|
6
|
+
variant?: "primary" | "secondary" | "ghost" | "outline" | "link" | null | undefined;
|
|
7
|
+
size?: "sm" | "md" | "lg" | "icon" | null | undefined;
|
|
8
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
9
|
+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
10
|
+
/** Render the single child (e.g. an <a>) with the button's styles and props instead of a <button>. */
|
|
11
|
+
asChild?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Shows a spinner over the content, disables the button and sets aria-busy. Width stays the same.
|
|
14
|
+
* With asChild only aria-busy/aria-disabled are set: the child is rendered as is.
|
|
15
|
+
*/
|
|
16
|
+
loading?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare const Button: react.ForwardRefExoticComponent<ButtonProps & react.RefAttributes<HTMLButtonElement>>;
|
|
19
|
+
|
|
20
|
+
export { Button, type ButtonProps, buttonVariants };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __export = (target, all) => {
|
|
36
|
+
for (var name in all)
|
|
37
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
+
};
|
|
39
|
+
var __copyProps = (to, from, except, desc) => {
|
|
40
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
+
for (let key of __getOwnPropNames(from))
|
|
42
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
43
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
44
|
+
}
|
|
45
|
+
return to;
|
|
46
|
+
};
|
|
47
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
+
|
|
49
|
+
// src/index.ts
|
|
50
|
+
var index_exports = {};
|
|
51
|
+
__export(index_exports, {
|
|
52
|
+
Button: () => Button,
|
|
53
|
+
buttonVariants: () => buttonVariants
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(index_exports);
|
|
56
|
+
|
|
57
|
+
// src/button.tsx
|
|
58
|
+
var import_react = require("react");
|
|
59
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
60
|
+
var import_utils = require("@glob-ui/utils");
|
|
61
|
+
var import_spinner = require("@glob-ui/spinner");
|
|
62
|
+
var import_slot = require("@glob-ui/slot");
|
|
63
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
64
|
+
var buttonVariants = (0, import_class_variance_authority.cva)(
|
|
65
|
+
"inline-flex items-center justify-center gap-2 rounded-glob-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50",
|
|
66
|
+
{
|
|
67
|
+
variants: {
|
|
68
|
+
variant: {
|
|
69
|
+
primary: "bg-glob-primary text-glob-primary-foreground hover:bg-glob-primary-hover",
|
|
70
|
+
secondary: "bg-glob-text text-glob-surface hover:opacity-80",
|
|
71
|
+
ghost: "text-glob-text hover:bg-glob-surface-hover",
|
|
72
|
+
outline: "border border-glob-border text-glob-text hover:bg-glob-surface-hover",
|
|
73
|
+
link: "text-glob-primary underline-offset-4 hover:underline"
|
|
74
|
+
},
|
|
75
|
+
size: {
|
|
76
|
+
sm: "h-8 px-3 text-xs",
|
|
77
|
+
md: "h-10 px-4 text-sm",
|
|
78
|
+
lg: "h-12 px-6 text-base",
|
|
79
|
+
icon: "h-10 w-10"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
defaultVariants: {
|
|
83
|
+
variant: "primary",
|
|
84
|
+
size: "md"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
var Button = (0, import_react.forwardRef)(
|
|
89
|
+
(_a, ref) => {
|
|
90
|
+
var _b = _a, { className, variant, size, asChild = false, loading = false, disabled, children } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild", "loading", "disabled", "children"]);
|
|
91
|
+
if (asChild) {
|
|
92
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
93
|
+
import_slot.Slot,
|
|
94
|
+
__spreadProps(__spreadValues({
|
|
95
|
+
className: (0, import_utils.cn)(buttonVariants({ variant, size, className })),
|
|
96
|
+
ref,
|
|
97
|
+
"aria-disabled": disabled || loading || void 0,
|
|
98
|
+
"aria-busy": loading || void 0
|
|
99
|
+
}, props), {
|
|
100
|
+
children
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
105
|
+
"button",
|
|
106
|
+
__spreadProps(__spreadValues({
|
|
107
|
+
className: (0, import_utils.cn)(buttonVariants({ variant, size, className }), loading && "relative"),
|
|
108
|
+
ref,
|
|
109
|
+
disabled: disabled || loading,
|
|
110
|
+
"aria-busy": loading || void 0
|
|
111
|
+
}, props), {
|
|
112
|
+
children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
113
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "inline-flex items-center gap-2 opacity-0", children }),
|
|
114
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { size: size === "lg" ? "md" : "sm" }) })
|
|
115
|
+
] }) : children
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
Button.displayName = "Button";
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
Button,
|
|
124
|
+
buttonVariants
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/button.tsx"],"sourcesContent":["export { Button, buttonVariants } from \"./button\"\nexport type { ButtonProps } from \"./button\"\n","import { forwardRef } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\nimport { Spinner } from \"@glob-ui/spinner\"\nimport { Slot } from \"@glob-ui/slot\"\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 rounded-glob-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50\",\n {\n variants: {\n variant: {\n primary: \"bg-glob-primary text-glob-primary-foreground hover:bg-glob-primary-hover\",\n secondary: \"bg-glob-text text-glob-surface hover:opacity-80\",\n ghost: \"text-glob-text hover:bg-glob-surface-hover\",\n outline: \"border border-glob-border text-glob-text hover:bg-glob-surface-hover\",\n link: \"text-glob-primary underline-offset-4 hover:underline\",\n },\n size: {\n sm: \"h-8 px-3 text-xs\",\n md: \"h-10 px-4 text-sm\",\n lg: \"h-12 px-6 text-base\",\n icon: \"h-10 w-10\",\n },\n },\n defaultVariants: {\n variant: \"primary\",\n size: \"md\",\n },\n }\n)\n\nexport interface ButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n /** Render the single child (e.g. an <a>) with the button's styles and props instead of a <button>. */\n asChild?: boolean\n /**\n * Shows a spinner over the content, disables the button and sets aria-busy. Width stays the same.\n * With asChild only aria-busy/aria-disabled are set: the child is rendered as is.\n */\n loading?: boolean\n}\n\nconst Button = forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild = false, loading = false, disabled, children, ...props }, ref) => {\n if (asChild) {\n // Links and other elements have no disabled attribute; aria-disabled carries the state and style.\n return (\n <Slot\n className={cn(buttonVariants({ variant, size, className }))}\n ref={ref}\n aria-disabled={disabled || loading || undefined}\n aria-busy={loading || undefined}\n {...props}\n >\n {children}\n </Slot>\n )\n }\n\n return (\n <button\n className={cn(buttonVariants({ variant, size, className }), loading && \"relative\")}\n ref={ref}\n disabled={disabled || loading}\n aria-busy={loading || undefined}\n {...props}\n >\n {loading ? (\n <>\n {/* opacity-0 (not invisible) keeps the width and keeps the label in the accessible name. */}\n <span className=\"inline-flex items-center gap-2 opacity-0\">{children}</span>\n <span className=\"absolute inset-0 flex items-center justify-center\">\n <Spinner size={size === \"lg\" ? \"md\" : \"sm\"} />\n </span>\n </>\n ) : (\n children\n )}\n </button>\n )\n }\n)\nButton.displayName = \"Button\"\n\nexport { Button, buttonVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA2B;AAC3B,sCAAuC;AACvC,mBAAmB;AACnB,qBAAwB;AACxB,kBAAqB;AA4Cb;AA1CR,IAAM,qBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,WAAW;AAAA,QACX,OAAO;AAAA,QACP,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAcA,IAAM,aAAS;AAAA,EACb,CAAC,IAA8F,QAAQ;AAAtG,iBAAE,aAAW,SAAS,MAAM,UAAU,OAAO,UAAU,OAAO,UAAU,SA5C3E,IA4CG,IAAqF,kBAArF,IAAqF,CAAnF,aAAW,WAAS,QAAM,WAAiB,WAAiB,YAAU;AACvE,QAAI,SAAS;AAEX,aACE;AAAA,QAAC;AAAA;AAAA,UACC,eAAW,iBAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,CAAC;AAAA,UAC1D;AAAA,UACA,iBAAe,YAAY,WAAW;AAAA,UACtC,aAAW,WAAW;AAAA,WAClB,QALL;AAAA,UAOE;AAAA;AAAA,MACH;AAAA,IAEJ;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,iBAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,GAAG,WAAW,UAAU;AAAA,QACjF;AAAA,QACA,UAAU,YAAY;AAAA,QACtB,aAAW,WAAW;AAAA,SAClB,QALL;AAAA,QAOE,oBACC,4EAEE;AAAA,sDAAC,UAAK,WAAU,4CAA4C,UAAS;AAAA,UACrE,4CAAC,UAAK,WAAU,qDACd,sDAAC,0BAAQ,MAAM,SAAS,OAAO,OAAO,MAAM,GAC9C;AAAA,WACF,IAEA;AAAA;AAAA,IAEJ;AAAA,EAEJ;AACF;AACA,OAAO,cAAc;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/button.tsx
|
|
34
|
+
import { forwardRef } from "react";
|
|
35
|
+
import { cva } from "class-variance-authority";
|
|
36
|
+
import { cn } from "@glob-ui/utils";
|
|
37
|
+
import { Spinner } from "@glob-ui/spinner";
|
|
38
|
+
import { Slot } from "@glob-ui/slot";
|
|
39
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
40
|
+
var buttonVariants = cva(
|
|
41
|
+
"inline-flex items-center justify-center gap-2 rounded-glob-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50",
|
|
42
|
+
{
|
|
43
|
+
variants: {
|
|
44
|
+
variant: {
|
|
45
|
+
primary: "bg-glob-primary text-glob-primary-foreground hover:bg-glob-primary-hover",
|
|
46
|
+
secondary: "bg-glob-text text-glob-surface hover:opacity-80",
|
|
47
|
+
ghost: "text-glob-text hover:bg-glob-surface-hover",
|
|
48
|
+
outline: "border border-glob-border text-glob-text hover:bg-glob-surface-hover",
|
|
49
|
+
link: "text-glob-primary underline-offset-4 hover:underline"
|
|
50
|
+
},
|
|
51
|
+
size: {
|
|
52
|
+
sm: "h-8 px-3 text-xs",
|
|
53
|
+
md: "h-10 px-4 text-sm",
|
|
54
|
+
lg: "h-12 px-6 text-base",
|
|
55
|
+
icon: "h-10 w-10"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
defaultVariants: {
|
|
59
|
+
variant: "primary",
|
|
60
|
+
size: "md"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
var Button = forwardRef(
|
|
65
|
+
(_a, ref) => {
|
|
66
|
+
var _b = _a, { className, variant, size, asChild = false, loading = false, disabled, children } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild", "loading", "disabled", "children"]);
|
|
67
|
+
if (asChild) {
|
|
68
|
+
return /* @__PURE__ */ jsx(
|
|
69
|
+
Slot,
|
|
70
|
+
__spreadProps(__spreadValues({
|
|
71
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
72
|
+
ref,
|
|
73
|
+
"aria-disabled": disabled || loading || void 0,
|
|
74
|
+
"aria-busy": loading || void 0
|
|
75
|
+
}, props), {
|
|
76
|
+
children
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return /* @__PURE__ */ jsx(
|
|
81
|
+
"button",
|
|
82
|
+
__spreadProps(__spreadValues({
|
|
83
|
+
className: cn(buttonVariants({ variant, size, className }), loading && "relative"),
|
|
84
|
+
ref,
|
|
85
|
+
disabled: disabled || loading,
|
|
86
|
+
"aria-busy": loading || void 0
|
|
87
|
+
}, props), {
|
|
88
|
+
children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
89
|
+
/* @__PURE__ */ jsx("span", { className: "inline-flex items-center gap-2 opacity-0", children }),
|
|
90
|
+
/* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsx(Spinner, { size: size === "lg" ? "md" : "sm" }) })
|
|
91
|
+
] }) : children
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
Button.displayName = "Button";
|
|
97
|
+
export {
|
|
98
|
+
Button,
|
|
99
|
+
buttonVariants
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/button.tsx"],"sourcesContent":["import { forwardRef } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\nimport { Spinner } from \"@glob-ui/spinner\"\nimport { Slot } from \"@glob-ui/slot\"\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 rounded-glob-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50\",\n {\n variants: {\n variant: {\n primary: \"bg-glob-primary text-glob-primary-foreground hover:bg-glob-primary-hover\",\n secondary: \"bg-glob-text text-glob-surface hover:opacity-80\",\n ghost: \"text-glob-text hover:bg-glob-surface-hover\",\n outline: \"border border-glob-border text-glob-text hover:bg-glob-surface-hover\",\n link: \"text-glob-primary underline-offset-4 hover:underline\",\n },\n size: {\n sm: \"h-8 px-3 text-xs\",\n md: \"h-10 px-4 text-sm\",\n lg: \"h-12 px-6 text-base\",\n icon: \"h-10 w-10\",\n },\n },\n defaultVariants: {\n variant: \"primary\",\n size: \"md\",\n },\n }\n)\n\nexport interface ButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n /** Render the single child (e.g. an <a>) with the button's styles and props instead of a <button>. */\n asChild?: boolean\n /**\n * Shows a spinner over the content, disables the button and sets aria-busy. Width stays the same.\n * With asChild only aria-busy/aria-disabled are set: the child is rendered as is.\n */\n loading?: boolean\n}\n\nconst Button = forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild = false, loading = false, disabled, children, ...props }, ref) => {\n if (asChild) {\n // Links and other elements have no disabled attribute; aria-disabled carries the state and style.\n return (\n <Slot\n className={cn(buttonVariants({ variant, size, className }))}\n ref={ref}\n aria-disabled={disabled || loading || undefined}\n aria-busy={loading || undefined}\n {...props}\n >\n {children}\n </Slot>\n )\n }\n\n return (\n <button\n className={cn(buttonVariants({ variant, size, className }), loading && \"relative\")}\n ref={ref}\n disabled={disabled || loading}\n aria-busy={loading || undefined}\n {...props}\n >\n {loading ? (\n <>\n {/* opacity-0 (not invisible) keeps the width and keeps the label in the accessible name. */}\n <span className=\"inline-flex items-center gap-2 opacity-0\">{children}</span>\n <span className=\"absolute inset-0 flex items-center justify-center\">\n <Spinner size={size === \"lg\" ? \"md\" : \"sm\"} />\n </span>\n </>\n ) : (\n children\n )}\n </button>\n )\n }\n)\nButton.displayName = \"Button\"\n\nexport { Button, buttonVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,WAA8B;AACvC,SAAS,UAAU;AACnB,SAAS,eAAe;AACxB,SAAS,YAAY;AA4Cb,SAqBE,UArBF,KAqBE,YArBF;AA1CR,IAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,WAAW;AAAA,QACX,OAAO;AAAA,QACP,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAcA,IAAM,SAAS;AAAA,EACb,CAAC,IAA8F,QAAQ;AAAtG,iBAAE,aAAW,SAAS,MAAM,UAAU,OAAO,UAAU,OAAO,UAAU,SA5C3E,IA4CG,IAAqF,kBAArF,IAAqF,CAAnF,aAAW,WAAS,QAAM,WAAiB,WAAiB,YAAU;AACvE,QAAI,SAAS;AAEX,aACE;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,GAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,CAAC;AAAA,UAC1D;AAAA,UACA,iBAAe,YAAY,WAAW;AAAA,UACtC,aAAW,WAAW;AAAA,WAClB,QALL;AAAA,UAOE;AAAA;AAAA,MACH;AAAA,IAEJ;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,GAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,GAAG,WAAW,UAAU;AAAA,QACjF;AAAA,QACA,UAAU,YAAY;AAAA,QACtB,aAAW,WAAW;AAAA,SAClB,QALL;AAAA,QAOE,oBACC,iCAEE;AAAA,8BAAC,UAAK,WAAU,4CAA4C,UAAS;AAAA,UACrE,oBAAC,UAAK,WAAU,qDACd,8BAAC,WAAQ,MAAM,SAAS,OAAO,OAAO,MAAM,GAC9C;AAAA,WACF,IAEA;AAAA;AAAA,IAEJ;AAAA,EAEJ;AACF;AACA,OAAO,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glob-ui/button",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^19"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@glob-ui/slot": "0.1.0",
|
|
30
|
+
"@glob-ui/spinner": "0.1.0",
|
|
31
|
+
"@glob-ui/utils": "0.1.0",
|
|
32
|
+
"class-variance-authority": "^0.7.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.5.1"
|
|
36
|
+
},
|
|
37
|
+
"description": "A button that can render as a link, and shows a loading state without changing its width.",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"react",
|
|
40
|
+
"glob-ui",
|
|
41
|
+
"components",
|
|
42
|
+
"accessible",
|
|
43
|
+
"tailwind",
|
|
44
|
+
"button"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"author": "Kevin Martínez E",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/kevin-martineze/GlobUI.git",
|
|
51
|
+
"directory": "packages/button"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/kevin-martineze/GlobUI#readme",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/kevin-martineze/GlobUI/issues"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public",
|
|
59
|
+
"provenance": true
|
|
60
|
+
},
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"type": "commonjs",
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18.18"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsup",
|
|
68
|
+
"dev": "tsup --watch --no-clean"
|
|
69
|
+
}
|
|
6
70
|
}
|