autumn-js
Version:
Autumn JS Library
102 lines (96 loc) • 4.14 kB
JavaScript
"use client";
import {
Slot
} from "./chunk-DXHYWJOY.mjs";
import {
clsx,
cn
} from "./chunk-4J6OC4ZQ.mjs";
// src/libraries/react/components/ui/button.tsx
import * as React from "react";
// ../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.mjs
var falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
var cx = clsx;
var cva = (base, config) => (props) => {
var _config_compoundVariants;
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
const { variants, defaultVariants } = config;
const getVariantClassNames = Object.keys(variants).map((variant) => {
const variantProp = props === null || props === void 0 ? void 0 : props[variant];
const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
if (variantProp === null) return null;
const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
return variants[variant][variantKey];
});
const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
let [key, value] = param;
if (value === void 0) {
return acc;
}
acc[key] = value;
return acc;
}, {});
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param) => {
let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param;
return Object.entries(compoundVariantOptions).every((param2) => {
let [key, value] = param2;
return Array.isArray(value) ? value.includes({
...defaultVariants,
...propsWithoutUndefined
}[key]) : {
...defaultVariants,
...propsWithoutUndefined
}[key] === value;
}) ? [
...acc,
cvClass,
cvClassName
] : acc;
}, []);
return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
};
// src/libraries/react/components/ui/button.tsx
import { jsx } from "react/jsx-runtime";
var buttonVariants = cva(
"au-inline-flex au-items-center au-justify-center au-gap-2 au-whitespace-nowrap au-rounded-md au-text-sm au-font-medium au-transition-colors focus-visible:au-outline-none focus-visible:au-ring-1 focus-visible:au-ring-ring disabled:au-pointer-events-none disabled:au-opacity-50 [&_svg]:au-pointer-events-none [&_svg]:au-size-4 [&_svg]:au-shrink-0",
{
variants: {
variant: {
default: "au-bg-primary au-text-primary-foreground au-shadow hover:au-bg-primary/90",
destructive: "au-bg-destructive au-text-destructive-foreground au-shadow-sm hover:au-bg-destructive/90",
outline: "au-border au-border-input au-bg-background au-shadow-sm hover:au-bg-accent hover:au-text-accent-foreground",
secondary: "au-bg-secondary au-text-secondary-foreground au-shadow-sm hover:au-bg-secondary/80",
ghost: "hover:au-bg-accent hover:au-text-accent-foreground",
link: "au-text-primary au-underline-offset-4 hover:au-underline"
},
size: {
default: "au-h-9 au-px-4 au-py-2",
sm: "au-h-8 au-rounded-md au-px-3 au-text-xs",
lg: "au-h-10 au-rounded-md au-px-8",
icon: "au-h-9 au-w-9"
}
},
defaultVariants: {
variant: "default",
size: "default"
}
}
);
var Button = React.forwardRef(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return /* @__PURE__ */ jsx(
Comp,
{
className: cn(buttonVariants({ variant, size }), className),
ref,
...props
}
);
}
);
Button.displayName = "Button";
export {
buttonVariants,
Button
};