@vela-ui/react
Version:
Vela UI React components
214 lines (207 loc) • 7.77 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/radio.tsx
var radio_exports = {};
__export(radio_exports, {
Radio: () => Radio,
RadioGroup: () => RadioGroup,
RadioGroupRoot: () => RadioGroupRoot
});
module.exports = __toCommonJS(radio_exports);
var import_react_aria_components3 = require("react-aria-components");
var import_tailwind_variants3 = require("tailwind-variants");
// src/icons/circle.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var CircleIcon = (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)("circle", { cx: "12", cy: "12", r: "10" })
}
);
};
// 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/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));
function composeTailwindRenderProps(className, tailwind) {
return (0, import_react_aria_components.composeRenderProps)(className, (className2) => (0, import_tailwind_merge.twMerge)(tailwind, className2));
}
// src/components/field.tsx
var import_react_aria_components2 = require("react-aria-components");
var import_tailwind_variants2 = require("tailwind-variants");
var import_jsx_runtime2 = require("react/jsx-runtime");
var fieldVariants = (0, import_tailwind_variants2.tv)({
slots: {
label: "group-data-[invalid]:text-destructive flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50",
description: "text-muted-foreground text-sm",
fieldError: "text-destructive text-sm"
}
});
var { label, description, fieldError } = fieldVariants();
function Label({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.Label, { "data-slot": "label", className: label({ className }), ...props });
}
function Description({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.Text, { slot: "description", className: description({ className }), ...props });
}
function FieldError({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_react_aria_components2.FieldError,
{
className: (0, import_react_aria_components2.composeRenderProps)(className, (className2) => fieldError({ className: className2 })),
...props
}
);
}
var fieldGroupVariants = (0, import_tailwind_variants2.tv)({
extend: focusRing,
base: "group border-input relative flex h-10 items-center overflow-hidden rounded-lg border shadow-xs",
variants: {
isFocusWithin: {
true: "border-ring"
},
isInvalid: {
true: "border-destructive"
},
isDisabled: {
true: "opacity-50"
}
}
});
// src/components/radio.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
function RadioGroupRoot({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components3.RadioGroup,
{
"data-slot": "radio-group",
className: composeTailwindRenderProps(className, "group flex flex-col gap-2"),
...props
}
);
}
function RadioGroup({
wrapperClassName,
children,
label: label2,
description: description2,
errorMessage,
...props
}) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(RadioGroupRoot, { ...props, children: (0, import_react_aria_components3.composeRenderProps)(children, (children2) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
label2 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Label, { children: label2 }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"div",
{
"data-slot": "radio-group-wrapper",
className: cn(
"flex gap-2 select-none group-data-[orientation=horizontal]:flex-wrap group-data-[orientation=vertical]:flex-col",
wrapperClassName
),
children: children2
}
),
description2 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Description, { children: description2 }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldError, { children: errorMessage })
] })) });
}
var radioVariants = (0, import_tailwind_variants3.tv)({
base: "group flex items-center gap-2 text-sm transition",
variants: {
isDisabled: {
true: "text-foreground/50 cursor-not-allowed"
}
}
});
var radioIndicatorVariants = (0, import_tailwind_variants3.tv)({
extend: focusRing,
base: "border-input text-primary dark:bg-input/30 relative flex aspect-square shrink-0 items-center justify-center rounded-full border shadow-xs transition-[color,box-shadow]",
variants: {
size: {
sm: "size-4 [&_svg]:size-2",
md: "size-5 [&_svg]:size-2.5",
lg: "size-6 [&_svg]:size-3"
},
isDisabled: {
true: "cursor-not-allowed opacity-50"
}
},
defaultVariants: {
size: "md"
}
});
function Radio({ className, children, indicatorClassName, size, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components3.Radio,
{
className: (0, import_react_aria_components3.composeRenderProps)(
className,
(className2, renderProps) => radioVariants({ ...renderProps, className: className2 })
),
...props,
children: (0, import_react_aria_components3.composeRenderProps)(children, (children2, { isSelected, ...renderProps }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"div",
{
"data-slot": "radio-indicator",
className: radioIndicatorVariants({
size,
...renderProps,
className: indicatorClassName
}),
children: isSelected ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CircleIcon, { className: "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-current" }) : null
}
),
children2
] }))
}
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Radio,
RadioGroup,
RadioGroupRoot
});