@vela-ui/react
Version:
Vela UI React components
289 lines (280 loc) • 10.4 kB
JavaScript
;
"use client";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components/button.tsx
var button_exports = {};
__export(button_exports, {
Button: () => Button,
buttonVariants: () => buttonVariants
});
module.exports = __toCommonJS(button_exports);
var import_react_aria_components2 = require("react-aria-components");
var import_tailwind_variants3 = require("tailwind-variants");
// src/lib/classes.ts
var import_tailwind_variants = require("tailwind-variants");
var focusRing = (0, import_tailwind_variants.tv)({
base: "outline-hidden",
variants: {
isFocusVisible: {
true: "border-ring ring-ring/50 ring-[3px]"
},
isInvalid: {
true: "ring-destructive/20 dark:ring-destructive/40 border-destructive"
}
}
});
// src/components/loader.tsx
var import_tailwind_variants2 = require("tailwind-variants");
// src/icons/loader-circle.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var LoaderCircleIcon = (props) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"svg",
{
fill: "none",
stroke: "currentColor",
strokeWidth: 2,
strokeLinecap: "round",
strokeLinejoin: "round",
width: "1em",
height: "1em",
viewBox: "0 0 24 24",
xmlns: "http://www.w3.org/2000/svg",
...props,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
}
);
};
// src/icons/loader-ring.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var LoaderRingIcon = (props) => {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
"svg",
{
fill: "none",
width: "1em",
height: "1em",
viewBox: "0 0 24 24",
xmlns: "http://www.w3.org/2000/svg",
...props,
children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"path",
{
stroke: "currentColor",
strokeOpacity: "0.25",
strokeWidth: "3.636",
d: "M11.909 21a9.09 9.09 0 1 0 0-18.182 9.09 9.09 0 0 0 0 18.182Z"
}
),
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"path",
{
fill: "currentColor",
d: "M4.636 11.91a7.273 7.273 0 0 1 7.273-7.274V1C5.885 1 1 5.885 1 11.91zm1.819 4.81a7.24 7.24 0 0 1-1.819-4.81H1c0 2.764 1.032 5.294 2.727 7.215z"
}
)
]
}
);
};
// src/lib/utils.ts
var import_clsx = require("clsx");
var import_react_aria_components = require("react-aria-components");
var import_tailwind_merge = require("tailwind-merge");
var cn = (...inputs) => (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(...inputs));
// src/components/loader.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
var loaderVariants = (0, import_tailwind_variants2.tv)({
base: "relative",
variants: {
size: {
sm: "size-4",
md: "size-6",
lg: "size-8",
xl: "size-10"
}
},
defaultVariants: {
size: "sm"
}
});
function Default({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
LoaderCircleIcon,
{
className: cn("size-4 animate-spin", className),
"data-slot": "icon",
...props
}
);
}
var Ring = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LoaderRingIcon, { className: cn("size-4 animate-spin", className), "data-slot": "icon", ...props });
function Spin({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"svg",
{
className: cn("size-4 stroke-current", className),
"data-slot": "icon",
viewBox: "0 0 2400 2400",
...props,
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("g", { strokeWidth: "200", strokeLinecap: "round", fill: "none", children: [
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "1200", y1: "600", x2: "1200", y2: "100" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.5", x1: "1200", y1: "2300", x2: "1200", y2: "1800" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.917", x1: "900", y1: "680.4", x2: "650", y2: "247.4" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.417", x1: "1750", y1: "2152.6", x2: "1500", y2: "1719.6" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.833", x1: "680.4", y1: "900", x2: "247.4", y2: "650" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.333", x1: "2152.6", y1: "1750", x2: "1719.6", y2: "1500" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.75", x1: "600", y1: "1200", x2: "100", y2: "1200" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.25", x1: "2300", y1: "1200", x2: "1800", y2: "1200" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.667", x1: "680.4", y1: "1500", x2: "247.4", y2: "1750" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.167", x1: "2152.6", y1: "650", x2: "1719.6", y2: "900" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.583", x1: "900", y1: "1719.6", x2: "650", y2: "2152.6" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { opacity: "0.083", x1: "1750", y1: "247.4", x2: "1500", y2: "680.4" }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"animateTransform",
{
attributeName: "transform",
attributeType: "XML",
type: "rotate",
keyTimes: "0;0.08333;0.16667;0.25;0.33333;0.41667;0.5;0.58333;0.66667;0.75;0.83333;0.91667",
values: "0 1199 1199;30 1199 1199;60 1199 1199;90 1199 1199;120 1199 1199;150 1199 1199;180 1199 1199;210 1199 1199;240 1199 1199;270 1199 1199;300 1199 1199;330 1199 1199",
dur: "0.83333s",
begin: "0.08333s",
repeatCount: "indefinite",
calcMode: "discrete"
}
)
] })
}
);
}
var LOADERS = {
default: Default,
ring: Ring,
spin: Spin
};
var DEFAULT_VARIANT = "default";
function Loader(props) {
const { className, size, ref, variant, ...otherProps } = props;
const LoaderComponent = LOADERS[variant != null ? variant : DEFAULT_VARIANT];
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
LoaderComponent,
{
role: "presentation",
ref,
className: loaderVariants({ size, className }),
...otherProps
}
);
}
// src/components/button.tsx
var import_jsx_runtime4 = require("react/jsx-runtime");
var buttonVariants = (0, import_tailwind_variants3.tv)({
extend: focusRing,
base: "inline-flex shrink-0 items-center justify-center rounded-md font-medium whitespace-nowrap transition-all [&_svg]:pointer-events-none [&_svg]:shrink-0",
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90 shadow-xs",
destructive: "bg-destructive hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60 text-white shadow-xs",
outline: "bg-background hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50 border shadow-xs",
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 shadow-xs",
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
link: "text-primary underline-offset-4 hover:underline"
},
size: {
xs: "size-8 gap-1 text-xs [&_svg:not([class*='size-'])]:size-4",
sm: "size-9 gap-2 text-sm [&_svg:not([class*='size-'])]:size-4",
md: "size-10 gap-2 text-sm [&_svg:not([class*='size-'])]:size-5",
lg: "size-11 gap-2.5 text-base [&_svg:not([class*='size-'])]:size-5",
xl: "size-12 gap-2.5 text-base [&_svg:not([class*='size-'])]:size-5"
},
shape: {
rectangle: "",
square: "",
circle: "rounded-full"
},
isDisabled: {
true: "pointer-events-none opacity-50"
},
isPending: {
true: "pointer-events-none opacity-50"
}
},
compoundVariants: [
{
size: "xs",
shape: "rectangle",
className: "w-auto px-2.5"
},
{
size: "sm",
shape: "rectangle",
className: "w-auto px-3.5"
},
{
size: "md",
shape: "rectangle",
className: "w-auto px-4"
},
{
size: "lg",
shape: "rectangle",
className: "w-auto px-5"
},
{
size: "xl",
shape: "rectangle",
className: "w-auto px-5"
}
],
defaultVariants: {
variant: "default",
size: "md",
shape: "rectangle"
}
});
function Button({ className, variant, size, shape, loader = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Loader, {}), ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_react_aria_components2.Button,
{
"data-slot": "button",
className: (0, import_react_aria_components2.composeRenderProps)(
className,
(className2, renderProps) => buttonVariants({
...renderProps,
variant,
size,
shape,
className: className2
})
),
...props,
children: (0, import_react_aria_components2.composeRenderProps)(props.children, (children) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
props.isPending && loader,
children
] }))
}
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Button,
buttonVariants
});