@lykomi/web-primitives 0.0.0-stage → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -2
- package/dist/button.d.ts +11 -0
- package/dist/button.js +33 -0
- package/dist/checkbox.d.ts +4 -0
- package/dist/checkbox.js +13 -0
- package/dist/field-control.d.ts +2 -0
- package/dist/field-control.js +10 -0
- package/dist/field.d.ts +11 -0
- package/dist/field.js +43 -0
- package/dist/form-actions.d.ts +3 -0
- package/dist/form-actions.js +6 -0
- package/dist/form-header.d.ts +8 -0
- package/dist/form-header.js +8 -0
- package/dist/form-layout.d.ts +6 -0
- package/dist/form-layout.js +7 -0
- package/dist/form-section.d.ts +7 -0
- package/dist/form-section.js +10 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +11 -0
- package/dist/input.d.ts +4 -0
- package/dist/input.js +11 -0
- package/dist/read-only-field.d.ts +10 -0
- package/dist/read-only-field.js +29 -0
- package/dist/textarea.d.ts +4 -0
- package/dist/textarea.js +11 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +5 -0
- package/package.json +62 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iLoveAgents, a brand of Leitwolf GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lykomi/web-primitives
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Leaf React primitives used by LYKOMI UI.
|
|
4
|
+
|
|
5
|
+
Exports small building blocks such as `Button`, `Input`, `Textarea`, `Field`,
|
|
6
|
+
`FieldSet`, `Checkbox`, and `cn`. Higher-level chat, shell, panel, and runtime
|
|
7
|
+
components live in `@lykomi/web-ui`.
|
|
8
|
+
|
|
9
|
+
This package publishes built ESM JavaScript and `.d.ts` declarations. Host apps
|
|
10
|
+
using Tailwind v4 should scan `@lykomi/web-primitives/dist`.
|
package/dist/button.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type VariantProps } from "class-variance-authority";
|
|
3
|
+
declare const buttonVariants: (props?: ({
|
|
4
|
+
variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined;
|
|
5
|
+
size?: "default" | "sm" | "lg" | "icon" | null | undefined;
|
|
6
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
|
+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
8
|
+
asChild?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
11
|
+
export { Button, buttonVariants };
|
package/dist/button.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
5
|
+
import { cn } from "./utils.js";
|
|
6
|
+
const buttonVariants = cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", {
|
|
7
|
+
variants: {
|
|
8
|
+
variant: {
|
|
9
|
+
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
10
|
+
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
11
|
+
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
12
|
+
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
13
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
14
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
15
|
+
},
|
|
16
|
+
size: {
|
|
17
|
+
default: "h-9 px-4 py-2",
|
|
18
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
|
19
|
+
lg: "h-10 rounded-md px-8",
|
|
20
|
+
icon: "h-9 w-9",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: {
|
|
24
|
+
variant: "default",
|
|
25
|
+
size: "default",
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const Button = React.forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
29
|
+
const Comp = asChild ? Slot : "button";
|
|
30
|
+
return (_jsx(Comp, { className: cn(buttonVariants({ variant, size, className })), ref: ref, ...props }));
|
|
31
|
+
});
|
|
32
|
+
Button.displayName = "Button";
|
|
33
|
+
export { Button, buttonVariants };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
3
|
+
declare const Checkbox: React.ForwardRefExoticComponent<Omit<CheckboxPrimitive.CheckboxProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
4
|
+
export { Checkbox };
|
package/dist/checkbox.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
4
|
+
import { Check, Minus } from "lucide-react";
|
|
5
|
+
import { cn } from "./utils.js";
|
|
6
|
+
import { markFieldControl } from "./field-control.js";
|
|
7
|
+
const Checkbox = React.forwardRef(({ className, ...props }, ref) => (_jsx(CheckboxPrimitive.Root, { ref: ref, className: cn("peer size-4 shrink-0 rounded border border-border bg-background shadow-sm outline-none transition", "focus-visible:ring-2 focus-visible:ring-primary/15 disabled:cursor-not-allowed disabled:opacity-50", "data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
|
8
|
+
// "Some of these" is a state of its own. Left unstyled it drew a tick
|
|
9
|
+
// on a white box — the one shape that reads as "not selected".
|
|
10
|
+
"data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground", className), ...props, children: _jsxs(CheckboxPrimitive.Indicator, { className: cn("flex items-center justify-center text-current", "data-[state=indeterminate]:[&_[data-glyph=check]]:hidden", "data-[state=indeterminate]:[&_[data-glyph=minus]]:block"), children: [_jsx(Check, { "data-glyph": "check", className: "size-3.5" }), _jsx(Minus, { "data-glyph": "minus", className: "hidden size-3.5" })] }) })));
|
|
11
|
+
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
|
|
12
|
+
markFieldControl(Checkbox);
|
|
13
|
+
export { Checkbox };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Internal identity shared by controls and Field; Field imports no implementations.
|
|
2
|
+
const FIELD_CONTROL = Symbol.for("@lykomi/web-primitives/field-control");
|
|
3
|
+
export function markFieldControl(control) {
|
|
4
|
+
Object.defineProperty(control, FIELD_CONTROL, { value: true });
|
|
5
|
+
}
|
|
6
|
+
export function isFieldControl(control) {
|
|
7
|
+
return (control !== null &&
|
|
8
|
+
(typeof control === "object" || typeof control === "function") &&
|
|
9
|
+
control[FIELD_CONTROL] === true);
|
|
10
|
+
}
|
package/dist/field.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactNode } from "react";
|
|
2
|
+
export declare function Field({ label, hint, error, htmlFor, action, className, children, }: {
|
|
3
|
+
label?: ReactNode;
|
|
4
|
+
hint?: ReactNode;
|
|
5
|
+
error?: ReactNode;
|
|
6
|
+
htmlFor?: string;
|
|
7
|
+
action?: ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function FieldSet({ className, ...props }: ComponentPropsWithoutRef<"div">): import("react/jsx-runtime").JSX.Element;
|
package/dist/field.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, cloneElement, Fragment, isValidElement, useId, } from "react";
|
|
3
|
+
import { isFieldControl } from "./field-control.js";
|
|
4
|
+
import { cn } from "./utils.js";
|
|
5
|
+
function unwrapSingleChild(children) {
|
|
6
|
+
const nodes = Children.toArray(children);
|
|
7
|
+
if (nodes.length !== 1)
|
|
8
|
+
return null;
|
|
9
|
+
const child = nodes[0];
|
|
10
|
+
return isValidElement(child) && child.type === Fragment
|
|
11
|
+
? unwrapSingleChild(child.props.children)
|
|
12
|
+
: child;
|
|
13
|
+
}
|
|
14
|
+
// A named control with associated help/error; actions stay outside its label.
|
|
15
|
+
export function Field({ label, hint, error, htmlFor, action, className, children, }) {
|
|
16
|
+
const id = useId();
|
|
17
|
+
const singleChild = unwrapSingleChild(children);
|
|
18
|
+
const child = isValidElement(singleChild)
|
|
19
|
+
? singleChild
|
|
20
|
+
: null;
|
|
21
|
+
const singleControl = child &&
|
|
22
|
+
(["input", "select", "textarea"].includes(String(child.type)) || isFieldControl(child.type));
|
|
23
|
+
const controlId = htmlFor ?? child?.props.id ?? `${id}-control`;
|
|
24
|
+
const required = child?.props.required ||
|
|
25
|
+
child?.props["aria-required"] === true ||
|
|
26
|
+
child?.props["aria-required"] === "true";
|
|
27
|
+
const labelContent = (_jsxs(_Fragment, { children: [label, required && (_jsxs("span", { "aria-hidden": "true", className: "font-normal", children: [" ", "(Required)"] }))] }));
|
|
28
|
+
const labelClass = "text-xs font-medium text-muted-foreground";
|
|
29
|
+
const descriptions = [child?.props["aria-describedby"], hint && `${id}-hint`, error && `${id}-error`]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join(" ") || undefined;
|
|
32
|
+
const control = singleControl && child
|
|
33
|
+
? cloneElement(child, {
|
|
34
|
+
id: controlId,
|
|
35
|
+
"aria-describedby": descriptions,
|
|
36
|
+
"aria-invalid": error ? true : child.props["aria-invalid"],
|
|
37
|
+
})
|
|
38
|
+
: children;
|
|
39
|
+
return (_jsxs("div", { className: cn("grid gap-1.5", className), children: [singleControl || htmlFor ? (_jsxs(_Fragment, { children: [(label || action) && (_jsxs("div", { className: "flex items-center justify-between gap-3", children: [label ? (_jsx("label", { htmlFor: controlId, className: labelClass, children: labelContent })) : (_jsx("span", {})), action] })), control] })) : (_jsxs(_Fragment, { children: [action && _jsx("div", { className: "flex justify-end", children: action }), _jsxs("label", { className: "grid gap-1.5", children: [label && _jsx("span", { className: labelClass, children: labelContent }), control] })] })), hint && (_jsx("span", { id: `${id}-hint`, className: "block text-xs text-muted-foreground", children: hint })), error && (_jsx("span", { id: `${id}-error`, className: "block text-xs text-destructive", children: error }))] }));
|
|
40
|
+
}
|
|
41
|
+
export function FieldSet({ className, ...props }) {
|
|
42
|
+
return _jsx("div", { className: cn("grid gap-4", className), ...props });
|
|
43
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "./utils.js";
|
|
3
|
+
/** Actions wrap in narrow panes; the primary action belongs last. */
|
|
4
|
+
export function FormActions({ className, ...props }) {
|
|
5
|
+
return _jsx("div", { ...props, className: cn("flex flex-wrap items-center gap-2", className) });
|
|
6
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
/** Identity and related actions share one wrapping, theme-aware title row. */
|
|
3
|
+
export declare function FormHeader({ title, description, actions, level, className, ...props }: Omit<ComponentPropsWithoutRef<"header">, "title"> & {
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
actions?: ReactNode;
|
|
7
|
+
level?: 1 | 2 | 3;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "./utils.js";
|
|
3
|
+
import { FormActions } from "./form-actions.js";
|
|
4
|
+
/** Identity and related actions share one wrapping, theme-aware title row. */
|
|
5
|
+
export function FormHeader({ title, description, actions, level = 2, className, ...props }) {
|
|
6
|
+
const Heading = `h${level}`;
|
|
7
|
+
return (_jsxs("header", { ...props, className: cn("flex min-w-0 flex-wrap items-start justify-between gap-4", className), children: [_jsxs("div", { className: "min-w-0", children: [_jsx(Heading, { className: "break-words text-base font-semibold leading-6 text-foreground", children: title }), description && (_jsx("p", { className: "mt-2 text-sm leading-6 text-muted-foreground", children: description }))] }), actions && _jsx(FormActions, { children: actions })] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
/** Opinionated single-column form body. Does not create a nested HTML form.
|
|
3
|
+
* Uses the host's Tailwind spacing unit, surface colors and radius tokens. */
|
|
4
|
+
export declare function FormLayout({ density, className, ...props }: ComponentPropsWithoutRef<"div"> & {
|
|
5
|
+
density?: "comfortable" | "compact";
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "./utils.js";
|
|
3
|
+
/** Opinionated single-column form body. Does not create a nested HTML form.
|
|
4
|
+
* Uses the host's Tailwind spacing unit, surface colors and radius tokens. */
|
|
5
|
+
export function FormLayout({ density = "comfortable", className, ...props }) {
|
|
6
|
+
return (_jsx("div", { ...props, "data-form-layout": true, "data-form-density": density, className: cn("grid min-w-0 text-foreground", density === "compact" ? "gap-4" : "gap-8", className) }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactNode } from "react";
|
|
2
|
+
/** One logical group. Keep this mounted while the field values change mode. */
|
|
3
|
+
export declare function FormSection({ title, description, level, children, className, ...props }: Omit<ComponentPropsWithoutRef<"section">, "title"> & {
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
level?: 2 | 3 | 4;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
import { FieldSet } from "./field.js";
|
|
5
|
+
/** One logical group. Keep this mounted while the field values change mode. */
|
|
6
|
+
export function FormSection({ title, description, level = 3, children, className, ...props }) {
|
|
7
|
+
const titleId = useId();
|
|
8
|
+
const Heading = `h${level}`;
|
|
9
|
+
return (_jsxs("section", { ...props, "aria-labelledby": titleId, className: cn("grid min-w-0 gap-4", className), children: [_jsxs("div", { children: [_jsx(Heading, { id: titleId, className: "text-sm font-semibold text-foreground", children: title }), description && (_jsx("p", { className: "mt-2 text-sm leading-6 text-muted-foreground", children: description }))] }), _jsx(FieldSet, { children: children })] }));
|
|
10
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { cn } from "./utils.js";
|
|
2
|
+
export { Button, buttonVariants } from "./button.js";
|
|
3
|
+
export type { ButtonProps } from "./button.js";
|
|
4
|
+
export { Checkbox } from "./checkbox.js";
|
|
5
|
+
export { Input, inputClassName } from "./input.js";
|
|
6
|
+
export { Textarea, textareaClassName } from "./textarea.js";
|
|
7
|
+
export { Field, FieldSet } from "./field.js";
|
|
8
|
+
export { FormLayout } from "./form-layout.js";
|
|
9
|
+
export { FormSection } from "./form-section.js";
|
|
10
|
+
export { FormHeader } from "./form-header.js";
|
|
11
|
+
export { FormActions } from "./form-actions.js";
|
|
12
|
+
export { ReadOnlyField } from "./read-only-field.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { cn } from "./utils.js";
|
|
2
|
+
export { Button, buttonVariants } from "./button.js";
|
|
3
|
+
export { Checkbox } from "./checkbox.js";
|
|
4
|
+
export { Input, inputClassName } from "./input.js";
|
|
5
|
+
export { Textarea, textareaClassName } from "./textarea.js";
|
|
6
|
+
export { Field, FieldSet } from "./field.js";
|
|
7
|
+
export { FormLayout } from "./form-layout.js";
|
|
8
|
+
export { FormSection } from "./form-section.js";
|
|
9
|
+
export { FormHeader } from "./form-header.js";
|
|
10
|
+
export { FormActions } from "./form-actions.js";
|
|
11
|
+
export { ReadOnlyField } from "./read-only-field.js";
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare const inputClassName = "flex h-10 w-full rounded-xl border border-border bg-background px-3 py-2 text-sm outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/15 disabled:cursor-not-allowed disabled:opacity-50";
|
|
3
|
+
declare const Input: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
4
|
+
export { Input, inputClassName };
|
package/dist/input.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
import { markFieldControl } from "./field-control.js";
|
|
5
|
+
const inputClassName = "flex h-10 w-full rounded-xl border border-border bg-background px-3 py-2 text-sm outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/15 disabled:cursor-not-allowed disabled:opacity-50";
|
|
6
|
+
const Input = React.forwardRef(({ className, type = "text", ...props }, ref) => {
|
|
7
|
+
return _jsx("input", { ref: ref, type: type, className: cn(inputClassName, className), ...props });
|
|
8
|
+
});
|
|
9
|
+
Input.displayName = "Input";
|
|
10
|
+
markFieldControl(Input);
|
|
11
|
+
export { Input, inputClassName };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactNode } from "react";
|
|
2
|
+
/** Readable label/value pair; keeps the Field rhythm without a disabled input. */
|
|
3
|
+
export declare function ReadOnlyField({ label, hint, emptyLabel, children, multiline, valueAppearance, className, ...props }: ComponentPropsWithoutRef<"dl"> & {
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
multiline?: boolean;
|
|
6
|
+
/** Field preserves an editable slot; content presents fixed information without input chrome. */
|
|
7
|
+
valueAppearance?: "field" | "content";
|
|
8
|
+
hint?: ReactNode;
|
|
9
|
+
emptyLabel?: ReactNode;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cloneElement, Fragment, isValidElement, } from "react";
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
function isEmptyValue(value) {
|
|
5
|
+
if (isValidElement(value) &&
|
|
6
|
+
(value.type === Fragment || (typeof value.type === "string" && "children" in value.props)))
|
|
7
|
+
return isEmptyValue(value.props.children);
|
|
8
|
+
return Array.isArray(value)
|
|
9
|
+
? value.every(isEmptyValue)
|
|
10
|
+
: value === null || value === undefined || value === "";
|
|
11
|
+
}
|
|
12
|
+
// Boolean data must survive the arrays/fragments React otherwise suppresses.
|
|
13
|
+
function displayValue(value) {
|
|
14
|
+
if (typeof value === "boolean")
|
|
15
|
+
return String(value);
|
|
16
|
+
if (Array.isArray(value))
|
|
17
|
+
return value.map(displayValue);
|
|
18
|
+
if (isValidElement(value) &&
|
|
19
|
+
(value.type === Fragment || typeof value.type === "string"))
|
|
20
|
+
return cloneElement(value, {}, displayValue(value.props.children));
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
/** Readable label/value pair; keeps the Field rhythm without a disabled input. */
|
|
24
|
+
export function ReadOnlyField({ label, hint, emptyLabel = "Not set", children, multiline = false, valueAppearance = "field", className, ...props }) {
|
|
25
|
+
const empty = isEmptyValue(children);
|
|
26
|
+
return (_jsxs("dl", { ...props, className: cn("grid min-w-0 gap-1.5", className), children: [_jsx("dt", { className: "text-xs font-medium text-muted-foreground", children: label }), _jsx("dd", { "data-value-appearance": valueAppearance, className: cn("m-0 min-w-0 break-words whitespace-pre-wrap text-sm text-foreground", valueAppearance === "field"
|
|
27
|
+
? "min-h-10 rounded-xl border border-border bg-background px-3 py-2 leading-5"
|
|
28
|
+
: "leading-6", multiline && valueAppearance === "field" && "min-h-24 leading-6"), children: empty ? (_jsx("span", { className: "text-muted-foreground", children: emptyLabel })) : (displayValue(children)) }), hint && _jsx("dd", { className: "m-0 text-xs text-muted-foreground", children: hint })] }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare const textareaClassName = "flex [field-sizing:content] leading-6 min-h-24 w-full rounded-xl border border-border bg-background px-3 py-2 text-sm outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/15 disabled:cursor-not-allowed disabled:opacity-50";
|
|
3
|
+
declare const Textarea: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
4
|
+
export { Textarea, textareaClassName };
|
package/dist/textarea.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
import { markFieldControl } from "./field-control.js";
|
|
5
|
+
const textareaClassName = "flex [field-sizing:content] leading-6 min-h-24 w-full rounded-xl border border-border bg-background px-3 py-2 text-sm outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/15 disabled:cursor-not-allowed disabled:opacity-50";
|
|
6
|
+
const Textarea = React.forwardRef(({ className, ...props }, ref) => {
|
|
7
|
+
return _jsx("textarea", { ref: ref, className: cn(textareaClassName, className), ...props });
|
|
8
|
+
});
|
|
9
|
+
Textarea.displayName = "Textarea";
|
|
10
|
+
markFieldControl(Textarea);
|
|
11
|
+
export { Textarea, textareaClassName };
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lykomi/web-primitives",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.49.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Leaf React UI primitives for LYKOMI UI — Button, Checkbox, Input, Textarea, Field, FieldSet, cn().",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"ui",
|
|
9
|
+
"primitives",
|
|
10
|
+
"tailwind",
|
|
11
|
+
"lykomi-ui",
|
|
12
|
+
"ag-ui"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/lykomi/ui.git",
|
|
17
|
+
"directory": "packages/web-primitives"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/lykomi/ui/tree/main/packages/web-primitives#readme",
|
|
20
|
+
"bugs": "https://github.com/lykomi/ui/issues",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^19.0.0",
|
|
41
|
+
"react-dom": "^19.0.0",
|
|
42
|
+
"lucide-react": ">=0.400.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@radix-ui/react-checkbox": "^1.3.3",
|
|
46
|
+
"@radix-ui/react-slot": "^1.2.0",
|
|
47
|
+
"class-variance-authority": "^0.7.0",
|
|
48
|
+
"clsx": "^2.1.0",
|
|
49
|
+
"tailwind-merge": "^3.5.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/react": "^19.2.2",
|
|
53
|
+
"jsdom": "^28.1.0",
|
|
54
|
+
"lucide-react": ">=0.400.0",
|
|
55
|
+
"react": "^19.0.0",
|
|
56
|
+
"react-dom": "^19.0.0",
|
|
57
|
+
"typescript": "~5.9.3",
|
|
58
|
+
"vitest": "^4.1.4"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/fix-dts-extensions.mjs dist",
|
|
62
|
+
"test:unit": "vitest run --passWithNoTests",
|
|
63
|
+
"typecheck": "tsc --noEmit"
|
|
64
|
+
}
|
|
6
65
|
}
|