UNPKG

@vela-ui/react

Version:

Vela UI React components

326 lines (319 loc) 10.2 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/text-field.tsx var text_field_exports = {}; __export(text_field_exports, { TextField: () => TextField }); module.exports = __toCommonJS(text_field_exports); var import_react_aria_components3 = require("react-aria-components"); var import_tailwind_variants4 = require("tailwind-variants"); // 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_runtime = 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_runtime.jsx)(import_react_aria_components.Label, { "data-slot": "label", className: label({ className }), ...props }); } function Description({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.Text, { slot: "description", className: description({ className }), ...props }); } function FieldError({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime.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_runtime2 = 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_runtime2.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(); var InputGroup = ({ children, startElement, endElement, startAddon, endAddon, size, className, ...props }) => { const child = import_react.Children.only(children); return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)( import_react_aria_components2.Group, { "data-slot": "input-group", className: (0, import_react_aria_components2.composeRenderProps)(className, (className2) => root({ size, className: className2 })), ...props, children: [ startElement && !startAddon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(InputElement, { size, className: "left-0", children: startElement }), startAddon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(InputAddon, { size, children: startAddon }), (0, import_react.cloneElement)(child, { hasStartElement: !!startElement, hasEndElement: !!endElement, size, ...child.props }), endElement && !endAddon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(InputElement, { size, className: "right-0", children: endElement }), endAddon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(InputAddon, { size, children: endAddon }) ] } ); }; function InputAddon({ className, size, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-slot": "input-addon", className: addon({ size, className }), ...props }); } function InputElement({ className, size, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-slot": "input-element", className: element({ size, className }), ...props }); } // src/components/text-field.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); var textFieldVariants = (0, import_tailwind_variants4.tv)({ base: "group flex flex-col gap-2" }); function TextField({ placeholder, label: label2, description: description2, errorMessage, size, className, inputClassName, startElement, endElement, startAddon, endAddon, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)( import_react_aria_components3.TextField, { className: (0, import_react_aria_components3.composeRenderProps)(className, (className2) => textFieldVariants({ className: className2 })), ...props, children: [ label2 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Label, { children: label2 }), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( InputGroup, { size, startElement, endElement, startAddon, endAddon, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Input, { placeholder, className: inputClassName }) } ), description2 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Description, { children: description2 }), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldError, { children: errorMessage }) ] } ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { TextField });