@vela-ui/react
Version:
Vela UI React components
404 lines (394 loc) • 15.3 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/select.tsx
var select_exports = {};
__export(select_exports, {
Select: () => Select,
SelectDescription: () => SelectDescription,
SelectItem: () => SelectItem,
SelectLabel: () => SelectLabel,
SelectList: () => SelectList,
SelectPopover: () => SelectPopover,
SelectSection: () => SelectSection,
SelectSeparator: () => SelectSeparator,
SelectTrigger: () => SelectTrigger,
SelectValue: () => SelectValue
});
module.exports = __toCommonJS(select_exports);
var import_react_aria_components5 = require("react-aria-components");
var import_tailwind_variants5 = require("tailwind-variants");
// src/icons/check.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var CheckIcon = (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: "M20 6 9 17l-5-5" })
}
);
};
// src/icons/chevron-down.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var ChevronDownIcon = (props) => {
return /* @__PURE__ */ (0, import_jsx_runtime2.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_runtime2.jsx)("path", { d: "m6 9 6 6 6-6" })
}
);
};
// 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/dropdown.tsx
var import_react_aria_components2 = require("react-aria-components");
var import_tailwind_merge2 = require("tailwind-merge");
var import_tailwind_variants2 = require("tailwind-variants");
var import_jsx_runtime3 = require("react/jsx-runtime");
var dropdownItemVariants = (0, import_tailwind_variants2.tv)({
base: "relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[selection-mode]:pr-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
variants: {
variant: {
default: "",
destructive: "text-destructive *:[svg]:!text-destructive"
},
isFocused: {
true: "bg-accent text-accent-foreground"
},
isHovered: {
true: "bg-accent text-accent-foreground"
},
isDisabled: {
true: "pointer-events-none opacity-50"
}
},
compoundVariants: [
{
variant: "destructive",
isFocused: true,
className: "bg-destructive/10 dark:bg-destructive/20 text-destructive"
}
]
});
function DropdownSection({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_aria_components2.ListBoxSection, { className, children: [
"title" in props && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components2.Header, { className: "text-muted-foreground px-2 py-1.5 text-xs", children: props.title }),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components2.Collection, { items: props.items, children: props.children })
] });
}
function DropdownItem({ className, variant, ...props }) {
const textValue = props.textValue || (typeof props.children === "string" ? props.children : void 0);
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components2.ListBoxItem,
{
textValue,
className: (0, import_react_aria_components2.composeRenderProps)(
className,
(className2, renderProps) => dropdownItemVariants({ ...renderProps, variant, className: className2 })
),
...props,
children: (0, import_react_aria_components2.composeRenderProps)(props.children, (children, { isSelected }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
isSelected && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CheckIcon, {}) }),
children
] }))
}
);
}
function DropdownLabel({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components2.Text, { slot: "label", className, ...props });
}
function DropdownDescription({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components2.Text,
{
slot: "description",
className: (0, import_tailwind_merge2.twMerge)("text-muted-foreground text-sm", className),
...props
}
);
}
function DropdownSeparator({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components2.Separator,
{
orientation: "horizontal",
className: (0, import_tailwind_merge2.twMerge)("bg-border -mx-1 my-1 h-px", className),
...props
}
);
}
// src/components/field.tsx
var import_react_aria_components3 = require("react-aria-components");
var import_tailwind_variants3 = require("tailwind-variants");
var import_jsx_runtime4 = require("react/jsx-runtime");
var fieldVariants = (0, import_tailwind_variants3.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_runtime4.jsx)(import_react_aria_components3.Label, { "data-slot": "label", className: label({ className }), ...props });
}
function Description({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_aria_components3.Text, { slot: "description", className: description({ className }), ...props });
}
function FieldError({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_react_aria_components3.FieldError,
{
className: (0, import_react_aria_components3.composeRenderProps)(className, (className2) => fieldError({ className: className2 })),
...props
}
);
}
var fieldGroupVariants = (0, import_tailwind_variants3.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/popover.tsx
var import_react_aria_components4 = require("react-aria-components");
var import_tailwind_variants4 = require("tailwind-variants");
var import_jsx_runtime5 = require("react/jsx-runtime");
var popoverVariants = (0, import_tailwind_variants4.tv)({
base: "bg-popover text-popover-foreground z-50 rounded-md border shadow-md outline-hidden transition duration-200",
variants: {
isEntering: {
true: [
"animate-in fade-in-0 zoom-in-95",
"data-[placement=left]:slide-in-from-right-2 data-[placement=right]:slide-in-from-left-2 data-[placement=top]:slide-in-from-bottom-2 data-[placement=bottom]:slide-in-from-top-2"
]
},
isExiting: {
true: [
"animate-out fade-out-0 zoom-out-95",
"data-[placement=left]:slide-out-to-right-2 data-[placement=right]:slide-out-to-left-2 data-[placement=top]:slide-out-to-bottom-2 data-[placement=bottom]:slide-out-to-top-2"
]
}
}
});
var Popover = ({ className, showArrow, ...props }) => {
const popoverContext = (0, import_react_aria_components4.useSlottedContext)(import_react_aria_components4.PopoverContext);
const isSubmenu = (popoverContext == null ? void 0 : popoverContext.trigger) === "SubmenuTrigger";
let offset = showArrow ? 12 : 8;
offset = isSubmenu ? offset - 6 : offset;
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
import_react_aria_components4.Popover,
{
"data-slot": "popover",
offset,
className: (0, import_react_aria_components4.composeRenderProps)(
className,
(className2, renderProps) => popoverVariants({
...renderProps,
className: className2
})
),
...props,
children: (0, import_react_aria_components4.composeRenderProps)(props.children, (children) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
showArrow && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_aria_components4.OverlayArrow, { className: "group", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
"svg",
{
width: 12,
height: 12,
viewBox: "0 0 12 12",
className: "fill-popover stroke-border block stroke-1 group-data-[placement=bottom]:rotate-180 group-data-[placement=left]:-rotate-90 group-data-[placement=right]:rotate-90",
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M0 0 L6 6 L12 0" })
}
) }),
children
] }))
}
);
};
// src/components/select.tsx
var import_jsx_runtime6 = require("react/jsx-runtime");
var selectTriggerVariants = (0, import_tailwind_variants5.tv)({
extend: focusRing,
base: "border-input [&_svg:not([class*='text-'])]:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 group-data-[invalid]:ring-destructive/20 group-data-[invalid]:dark:ring-destructive/40 group-data-[invalid]:border-destructive flex w-full items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] [&_svg]:pointer-events-none [&_svg]:shrink-0",
variants: {
size: {
xs: "h-8 [&_svg:not([class*='size-'])]:size-3.5",
sm: "h-9 [&_svg:not([class*='size-'])]:size-4",
md: "h-10 [&_svg:not([class*='size-'])]:size-4",
lg: "h-11 [&_svg:not([class*='size-'])]:size-5"
},
isDisabled: {
true: "cursor-not-allowed opacity-50"
}
},
defaultVariants: {
size: "md"
}
});
function Select({
label: label2,
description: description2,
errorMessage,
className,
children,
...props
}) {
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
import_react_aria_components5.Select,
{
"data-slot": "select",
...props,
className: composeTailwindRenderProps(className, "group flex w-full flex-col gap-2"),
children: (0, import_react_aria_components5.composeRenderProps)(children, (children2) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
label2 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Label, { children: label2 }),
children2,
description2 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Description, { children: description2 }),
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FieldError, { children: errorMessage })
] }))
}
);
}
function SelectTrigger({ className, size, children, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
import_react_aria_components5.Button,
{
"data-slot": "select-trigger",
className: (0, import_react_aria_components5.composeRenderProps)(
className,
(className2, renderProps) => selectTriggerVariants({
...renderProps,
size,
className: className2
})
),
...props,
children: (0, import_react_aria_components5.composeRenderProps)(children, (children2) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
children2,
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChevronDownIcon, { "aria-hidden": "true", className: "opacity-50" })
] }))
}
);
}
function SelectValue({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
import_react_aria_components5.SelectValue,
{
"data-slot": "select-value",
className: (0, import_react_aria_components5.composeRenderProps)(
className,
(className2) => cn(
"data-[placeholder]:text-muted-foreground line-clamp-1 flex items-center gap-2",
/* Description */
"[&>[slot=description]]:hidden",
className2
)
),
...props
}
);
}
function SelectPopover({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
Popover,
{
showArrow: false,
className,
style: { minWidth: "var(--trigger-width)" },
...props
}
);
}
function SelectList({ className, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
import_react_aria_components5.ListBox,
{
className: composeTailwindRenderProps(
className,
"max-h-[inherit] min-w-[inherit] overflow-auto p-1 outline-hidden"
),
...props
}
);
}
var SelectSection = DropdownSection;
var SelectSeparator = DropdownSeparator;
var SelectLabel = DropdownLabel;
var SelectDescription = DropdownDescription;
var SelectItem = DropdownItem;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Select,
SelectDescription,
SelectItem,
SelectLabel,
SelectList,
SelectPopover,
SelectSection,
SelectSeparator,
SelectTrigger,
SelectValue
});