UNPKG

@vela-ui/react

Version:

Vela UI React components

339 lines (330 loc) 11 kB
"use strict"; 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/number-field.tsx var number_field_exports = {}; __export(number_field_exports, { NumberField: () => NumberField }); module.exports = __toCommonJS(number_field_exports); var import_react_aria_components3 = require("react-aria-components"); var import_tailwind_variants4 = require("tailwind-variants"); // src/icons/chevron-down.tsx var import_jsx_runtime = require("react/jsx-runtime"); var ChevronDownIcon = (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: "m6 9 6 6 6-6" }) } ); }; // src/icons/chevron-up.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var ChevronUpIcon = (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: "m18 15-6-6-6 6" }) } ); }; // src/components/field.tsx var import_react_aria_components = require("react-aria-components"); var import_tailwind_variants2 = 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/field.tsx var import_jsx_runtime3 = 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_runtime3.jsx)(import_react_aria_components.Label, { "data-slot": "label", className: label({ className }), ...props }); } function Description({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components.Text, { slot: "description", className: description({ className }), ...props }); } function FieldError({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( import_react_aria_components.FieldError, { className: (0, import_react_aria_components.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/input.tsx var import_react = require("react"); var import_react_aria_components2 = require("react-aria-components"); var import_tailwind_variants3 = require("tailwind-variants"); var import_jsx_runtime4 = require("react/jsx-runtime"); var inputVariants = (0, import_tailwind_variants3.tv)({ extend: focusRing, base: "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input relative flex w-full min-w-0 rounded-md border bg-transparent py-1 shadow-xs transition-[color,box-shadow] file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50", variants: { size: { xs: "h-8 px-2 text-xs", sm: "h-9 px-2.5 text-sm", md: "h-10 px-3 text-sm", lg: "h-11 px-4 text-base", xl: "h-12 px-4.5 text-base" }, isFocused: focusRing.variants.isFocusVisible, hasStartElement: { true: "" }, hasEndElement: { true: "" } }, compoundVariants: [ { hasStartElement: true, size: "xs", className: "pl-8" }, { hasStartElement: true, size: "sm", className: "pl-9" }, { hasStartElement: true, size: "md", className: "pl-10" }, { hasStartElement: true, size: "lg", className: "pl-11" }, { hasStartElement: true, size: "xl", className: "pl-12" }, { hasEndElement: true, size: "xs", className: "pr-8" }, { hasEndElement: true, size: "sm", className: "pr-9" }, { hasEndElement: true, size: "md", className: "pr-10" }, { hasEndElement: true, size: "lg", className: "pr-11" }, { hasEndElement: true, size: "xl", className: "pr-12" } ], defaultVariants: { size: "md" } }); function Input({ className, size, hasStartElement, hasEndElement, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( import_react_aria_components2.Input, { "data-slot": "input", className: (0, import_react_aria_components2.composeRenderProps)( className, (className2, renderProps) => inputVariants({ ...renderProps, size, hasStartElement, hasEndElement, className: className2 }) ), ...props } ); } var inputGroupVariants = (0, import_tailwind_variants3.tv)({ slots: { root: [ "relative isolate flex w-full flex-row items-center justify-start !gap-0", "has-[[data-slot=input-addon]]:[&_:not(:first-child)]:-ml-px", "has-[[data-slot=input-addon]]:[&_:not(:first-child)]:rounded-ss-none has-[[data-slot=input-addon]]:[&_:not(:first-child)]:rounded-es-none", "has-[[data-slot=input-addon]]:[&_:not(:last-child)]:rounded-se-none has-[[data-slot=input-addon]]:[&_:not(:last-child)]:rounded-ee-none" ], addon: "border-input bg-accent flex w-auto items-center self-stretch rounded-md border whitespace-nowrap", element: "text-muted-foreground absolute inset-y-0 z-50 flex items-center has-[button]:px-0 [&_button]:scale-75" }, variants: { size: { xs: { root: "text-xs", addon: "px-2.5", element: "px-2.5" }, sm: { root: "text-sm", addon: "px-3", element: "px-3" }, md: { root: "text-sm", addon: "px-3", element: "px-3" }, lg: { root: "text-base", addon: "px-3.5", element: "px-3.5" }, xl: { root: "text-base", addon: "px-4", element: "px-4" } } }, defaultVariants: { size: "md" } }); var { root, addon, element } = inputGroupVariants(); // src/components/number-field.tsx var import_jsx_runtime5 = require("react/jsx-runtime"); var buttonVariants = (0, import_tailwind_variants4.tv)({ base: "text-muted-foreground hover:bg-accent flex flex-1 cursor-pointer items-center justify-center leading-none select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50" }); var numberFieldVariants = (0, import_tailwind_variants4.tv)({ slots: { root: "group flex flex-col gap-2", group: "relative isolate z-0", control: "absolute end-0 top-0 z-10 m-px flex h-[calc(100%-2px)] flex-col border-s-1" }, variants: { size: { xs: { control: "w-4 text-xs" }, sm: { control: "w-5 text-xs" }, md: { control: "w-6 text-sm" }, lg: { control: "w-7 text-base" }, xl: { control: "w-8 text-base" } } }, defaultVariants: { size: "md" } }); var { root: root2, group, control } = numberFieldVariants(); function NumberField({ label: label2, description: description2, errorMessage, size, className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)( import_react_aria_components3.NumberField, { ...props, className: (0, import_react_aria_components3.composeRenderProps)(className, (className2) => root2({ className: className2 })), children: [ label2 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { children: label2 }), /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_aria_components3.Group, { className: group(), children: [ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Input, { size }), /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: control({ size }), children: [ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_aria_components3.Button, { className: buttonVariants({ className: "rounded-se-md" }), slot: "increment", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronUpIcon, {}) }), /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( import_react_aria_components3.Button, { className: buttonVariants({ className: "rounded-ee-md border-t-1" }), slot: "decrement", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronDownIcon, {}) } ) ] }) ] }), description2 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Description, { children: description2 }), /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldError, { children: errorMessage }) ] } ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { NumberField });