@thesage/ui 0.1.0 → 1.0.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/.claude/CLAUDE.md +224 -0
- package/README.md +96 -61
- package/dist/dates.d.mts +20 -0
- package/dist/dates.d.ts +20 -0
- package/dist/dates.js +230 -0
- package/dist/dates.js.map +1 -0
- package/dist/dates.mjs +193 -0
- package/dist/dates.mjs.map +1 -0
- package/dist/dnd.d.mts +126 -0
- package/dist/dnd.d.ts +126 -0
- package/dist/dnd.js +274 -0
- package/dist/dnd.js.map +1 -0
- package/dist/dnd.mjs +250 -0
- package/dist/dnd.mjs.map +1 -0
- package/dist/forms.d.mts +38 -0
- package/dist/forms.d.ts +38 -0
- package/dist/forms.js +198 -0
- package/dist/forms.js.map +1 -0
- package/dist/forms.mjs +159 -0
- package/dist/forms.mjs.map +1 -0
- package/dist/hooks.js +6 -5
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +6 -5
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +484 -352
- package/dist/index.d.ts +484 -352
- package/dist/index.js +2674 -2092
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2548 -1966
- package/dist/index.mjs.map +1 -1
- package/dist/providers.js +6 -5
- package/dist/providers.js.map +1 -1
- package/dist/providers.mjs +6 -5
- package/dist/providers.mjs.map +1 -1
- package/dist/tables.d.mts +10 -0
- package/dist/tables.d.ts +10 -0
- package/dist/tables.js +248 -0
- package/dist/tables.js.map +1 -0
- package/dist/tables.mjs +218 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +2 -1
- package/dist/utils.mjs.map +1 -1
- package/dist/webgl.d.mts +104 -0
- package/dist/webgl.d.ts +104 -0
- package/dist/webgl.js +226 -0
- package/dist/webgl.js.map +1 -0
- package/dist/webgl.mjs +195 -0
- package/dist/webgl.mjs.map +1 -0
- package/package.json +146 -16
package/dist/dnd.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/forms/DragDrop.tsx","../src/lib/utils.ts"],"sourcesContent":["'use client';\n\nimport React, { createContext, useContext } from 'react';\nimport {\n DndContext,\n closestCenter,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors,\n DragEndEvent,\n DragOverlay,\n DragStartEvent,\n} from '@dnd-kit/core';\nimport {\n arrayMove,\n SortableContext,\n sortableKeyboardCoordinates,\n useSortable,\n verticalListSortingStrategy,\n rectSortingStrategy,\n SortingStrategy,\n} from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport { GripVertical } from 'lucide-react';\nimport { cn } from '../../lib/utils';\n\n/**\n * Item interface for drag and drop lists\n */\nexport interface DragDropItem {\n id: string;\n [key: string]: any;\n}\n\n/**\n * Context for sharing drag handle listeners\n */\ninterface DragHandleContextValue {\n attributes: any;\n listeners: any;\n setActivatorNodeRef?: (element: HTMLElement | null) => void;\n}\n\nconst DragHandleContext = createContext<DragHandleContextValue | null>(null);\n\n/**\n * Props for DragDropList component\n */\nexport interface DragDropListProps<T extends DragDropItem> {\n /**\n * Array of items to display\n */\n items: T[];\n /**\n * Callback fired when items are reordered\n */\n onReorder: (items: T[]) => void;\n /**\n * Render function for each item\n */\n renderItem: (item: T, isDragging: boolean) => React.ReactNode;\n /**\n * Enable drag handle mode (only drag from handle)\n * @default false\n */\n withHandle?: boolean;\n /**\n * Custom class name for the list container\n */\n className?: string;\n /**\n * Custom class name for list items\n */\n itemClassName?: string;\n /**\n * Sorting strategy for the drag & drop behavior\n * - verticalListSortingStrategy: For vertical lists (default)\n * - rectSortingStrategy: For grid layouts\n * @default verticalListSortingStrategy\n */\n strategy?: SortingStrategy;\n}\n\n/**\n * Props for sortable item\n */\ninterface SortableItemProps {\n id: string;\n children: React.ReactNode;\n withHandle?: boolean;\n className?: string;\n}\n\n/**\n * Internal sortable item component\n */\nfunction SortableItem({ id, children, withHandle, className }: SortableItemProps) {\n const {\n attributes,\n listeners,\n setNodeRef,\n setActivatorNodeRef,\n transform,\n transition,\n isDragging,\n } = useSortable({ id });\n\n const style = {\n transform: CSS.Transform.toString(transform),\n transition,\n opacity: isDragging ? 0.5 : 1,\n };\n\n // If using handle, don't attach listeners to the item\n const itemProps = withHandle ? {} : { ...listeners, ...attributes };\n\n const content = withHandle ? (\n <DragHandleContext.Provider value={{ attributes, listeners, setActivatorNodeRef }}>\n {children}\n </DragHandleContext.Provider>\n ) : (\n children\n );\n\n return (\n <div\n ref={setNodeRef}\n style={style}\n className={cn(\n 'relative transition-opacity',\n isDragging && 'z-50',\n className\n )}\n {...itemProps}\n >\n {content}\n </div>\n );\n}\n\n/**\n * Drag handle component for manual drag control\n * Must be used within a DragDropList with withHandle={true}\n */\nexport interface DragDropHandleProps {\n /**\n * Custom class name\n */\n className?: string;\n /**\n * Handle icon\n */\n icon?: React.ReactNode;\n}\n\nexport function DragDropHandle({ className, icon }: DragDropHandleProps) {\n const context = useContext(DragHandleContext);\n\n if (!context) {\n console.warn('DragDropHandle must be used within a DragDropList with withHandle={true}');\n return null;\n }\n\n const { attributes, listeners, setActivatorNodeRef } = context;\n\n return (\n <div\n ref={setActivatorNodeRef}\n {...attributes}\n {...listeners}\n className={cn(\n 'flex items-center justify-center cursor-grab active:cursor-grabbing',\n 'text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)]',\n 'transition-colors',\n className\n )}\n >\n {icon || <GripVertical className=\"w-4 h-4\" />}\n </div>\n );\n}\n\n/**\n * DragDropList - Sortable list component with drag and drop functionality\n *\n * @example\n * ```tsx\n * const [items, setItems] = useState([\n * { id: '1', name: 'Item 1' },\n * { id: '2', name: 'Item 2' },\n * ]);\n *\n * <DragDropList\n * items={items}\n * onReorder={setItems}\n * renderItem={(item) => (\n * <div className=\"p-4 bg-surface rounded\">{item.name}</div>\n * )}\n * />\n * ```\n */\nexport function DragDropList<T extends DragDropItem>({\n items,\n onReorder,\n renderItem,\n withHandle = false,\n className,\n itemClassName,\n strategy = verticalListSortingStrategy,\n}: DragDropListProps<T>) {\n const [activeId, setActiveId] = React.useState<string | null>(null);\n\n // Configure sensors for touch/mouse/keyboard support\n const sensors = useSensors(\n useSensor(PointerSensor, {\n activationConstraint: {\n distance: 5, // Prevents accidental drags on mobile\n },\n }),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n })\n );\n\n const handleDragStart = (event: DragStartEvent) => {\n setActiveId(event.active.id as string);\n };\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n\n if (over && active.id !== over.id) {\n const oldIndex = items.findIndex((item) => item.id === active.id);\n const newIndex = items.findIndex((item) => item.id === over.id);\n onReorder(arrayMove(items, oldIndex, newIndex));\n }\n\n setActiveId(null);\n };\n\n const activeItem = items.find((item) => item.id === activeId);\n\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n >\n <SortableContext items={items} strategy={strategy}>\n <div className={cn(strategy === verticalListSortingStrategy && 'space-y-2', className)}>\n {items.map((item) => (\n <SortableItem\n key={item.id}\n id={item.id}\n withHandle={withHandle}\n className={itemClassName}\n >\n {renderItem(item, item.id === activeId)}\n </SortableItem>\n ))}\n </div>\n </SortableContext>\n\n <DragOverlay>\n {activeId && activeItem ? (\n <div className=\"opacity-80 shadow-lg\">\n {renderItem(activeItem, true)}\n </div>\n ) : null}\n </DragOverlay>\n </DndContext>\n );\n}\n\n/**\n * Props for DragDropTable component\n */\nexport interface DragDropTableProps<T extends DragDropItem> {\n /**\n * Array of items to display\n */\n items: T[];\n /**\n * Callback fired when items are reordered\n */\n onReorder: (items: T[]) => void;\n /**\n * Table columns configuration\n */\n columns: {\n key: string;\n header: string;\n render?: (item: T) => React.ReactNode;\n }[];\n /**\n * Custom class name for the table\n */\n className?: string;\n}\n\n/**\n * DragDropTable - Sortable table with draggable rows\n *\n * @example\n * ```tsx\n * <DragDropTable\n * items={data}\n * onReorder={setData}\n * columns={[\n * { key: 'name', header: 'Name' },\n * { key: 'email', header: 'Email' },\n * ]}\n * />\n * ```\n */\nexport function DragDropTable<T extends DragDropItem>({\n items,\n onReorder,\n columns,\n className,\n}: DragDropTableProps<T>) {\n const [activeId, setActiveId] = React.useState<string | null>(null);\n\n const sensors = useSensors(\n useSensor(PointerSensor, {\n activationConstraint: {\n distance: 5,\n },\n }),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n })\n );\n\n const handleDragStart = (event: DragStartEvent) => {\n setActiveId(event.active.id as string);\n };\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n\n if (over && active.id !== over.id) {\n const oldIndex = items.findIndex((item) => item.id === active.id);\n const newIndex = items.findIndex((item) => item.id === over.id);\n onReorder(arrayMove(items, oldIndex, newIndex));\n }\n\n setActiveId(null);\n };\n\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n >\n <div className={cn('overflow-x-auto', className)}>\n <table className=\"w-full border-collapse\">\n <thead>\n <tr className=\"border-b border-[var(--color-border)]\">\n <th className=\"w-12\"></th>\n {columns.map((column) => (\n <th\n key={column.key}\n className=\"text-left p-3 text-sm font-medium text-[var(--color-text-secondary)]\"\n >\n {column.header}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n <SortableContext items={items} strategy={verticalListSortingStrategy}>\n {items.map((item) => (\n <TableRow\n key={item.id}\n item={item}\n columns={columns}\n isDragging={item.id === activeId}\n />\n ))}\n </SortableContext>\n </tbody>\n </table>\n </div>\n </DndContext>\n );\n}\n\ninterface TableRowProps<T extends DragDropItem> {\n item: T;\n columns: { key: string; header: string; render?: (item: T) => React.ReactNode }[];\n isDragging: boolean;\n}\n\nfunction TableRow<T extends DragDropItem>({ item, columns, isDragging }: TableRowProps<T>) {\n const {\n attributes,\n listeners,\n setNodeRef,\n transform,\n transition,\n } = useSortable({ id: item.id });\n\n const style = {\n transform: CSS.Transform.toString(transform),\n transition,\n opacity: isDragging ? 0.5 : 1,\n };\n\n return (\n <tr\n ref={setNodeRef}\n style={style}\n className={cn(\n 'border-b border-[var(--color-border)] hover:bg-[var(--color-hover)]',\n 'transition-colors',\n isDragging && 'bg-[var(--color-active)]'\n )}\n >\n <td className=\"p-3\">\n <div\n {...attributes}\n {...listeners}\n className=\"cursor-grab active:cursor-grabbing text-[var(--color-text-secondary)] hover:text-[var(--color-foreground)] transition-colors\"\n >\n <GripVertical className=\"w-4 h-4\" />\n </div>\n </td>\n {columns.map((column) => (\n <td key={column.key} className=\"p-3 text-sm\">\n {column.render ? column.render(item) : (item as any)[column.key]}\n </td>\n ))}\n </tr>\n );\n}\n","import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";;;AAEA,OAAO,SAAS,eAAe,kBAAkB;AACjD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,WAAW;AACpB,SAAS,oBAAoB;;;ACxB7B,SAA0B,YAAY;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AACxC,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC/B;;;ADiHI,cA8HA,YA9HA;AA1EJ,IAAM,oBAAoB,cAA6C,IAAI;AAqD3E,SAAS,aAAa,EAAE,IAAI,UAAU,YAAY,UAAU,GAAsB;AAChF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,YAAY,EAAE,GAAG,CAAC;AAEtB,QAAM,QAAQ;AAAA,IACZ,WAAW,IA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,IACA;AAAA,EACF,IAAI,YAAY,EAAE,IAAI,KAAK,GAAG,CAAC;AAE/B,QAAM,QAAQ;AAAA,IACZ,WAAW,IAAI,UAAU,SAAS,SAAS;AAAA,IAC3C;AAAA,IACA,SAAS,aAAa,MAAM;AAAA,EAC9B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA,cAAc;AAAA,MAChB;AAAA,MAEA;AAAA,4BAAC,QAAG,WAAU,OACZ;AAAA,UAAC;AAAA;AAAA,YACE,GAAG;AAAA,YACH,GAAG;AAAA,YACJ,WAAU;AAAA,YAEV,8BAAC,gBAAa,WAAU,WAAU;AAAA;AAAA,QACpC,GACF;AAAA,QACC,QAAQ,IAAI,CAAC,WACZ,oBAAC,QAAoB,WAAU,eAC5B,iBAAO,SAAS,OAAO,OAAO,IAAI,IAAK,KAAa,OAAO,GAAG,KADxD,OAAO,GAEhB,CACD;AAAA;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
package/dist/forms.d.mts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FormProvider, FieldValues, FieldPath, ControllerProps } from 'react-hook-form';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
6
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
7
|
+
|
|
8
|
+
declare const Form: typeof FormProvider;
|
|
9
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
declare const useFormField: () => {
|
|
11
|
+
invalid: boolean;
|
|
12
|
+
isDirty: boolean;
|
|
13
|
+
isTouched: boolean;
|
|
14
|
+
isValidating: boolean;
|
|
15
|
+
error?: react_hook_form.FieldError;
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
formItemId: string;
|
|
19
|
+
formDescriptionId: string;
|
|
20
|
+
formMessageId: string;
|
|
21
|
+
};
|
|
22
|
+
declare const FormItem: ({ ref, className, ...props }: React.HTMLAttributes<HTMLDivElement> & {
|
|
23
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
24
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
25
|
+
declare const FormLabel: ({ ref, className, ...props }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {
|
|
26
|
+
ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;
|
|
27
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
28
|
+
declare const FormControl: ({ ref, ...props }: React.ComponentPropsWithoutRef<typeof Slot> & {
|
|
29
|
+
ref?: React.Ref<React.ElementRef<typeof Slot>>;
|
|
30
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
31
|
+
declare const FormDescription: ({ ref, className, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
32
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
33
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
34
|
+
declare const FormMessage: ({ ref, className, children, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
35
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
36
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
37
|
+
|
|
38
|
+
export { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField };
|
package/dist/forms.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FormProvider, FieldValues, FieldPath, ControllerProps } from 'react-hook-form';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
6
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
7
|
+
|
|
8
|
+
declare const Form: typeof FormProvider;
|
|
9
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
declare const useFormField: () => {
|
|
11
|
+
invalid: boolean;
|
|
12
|
+
isDirty: boolean;
|
|
13
|
+
isTouched: boolean;
|
|
14
|
+
isValidating: boolean;
|
|
15
|
+
error?: react_hook_form.FieldError;
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
formItemId: string;
|
|
19
|
+
formDescriptionId: string;
|
|
20
|
+
formMessageId: string;
|
|
21
|
+
};
|
|
22
|
+
declare const FormItem: ({ ref, className, ...props }: React.HTMLAttributes<HTMLDivElement> & {
|
|
23
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
24
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
25
|
+
declare const FormLabel: ({ ref, className, ...props }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {
|
|
26
|
+
ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;
|
|
27
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
28
|
+
declare const FormControl: ({ ref, ...props }: React.ComponentPropsWithoutRef<typeof Slot> & {
|
|
29
|
+
ref?: React.Ref<React.ElementRef<typeof Slot>>;
|
|
30
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
31
|
+
declare const FormDescription: ({ ref, className, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
32
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
33
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
34
|
+
declare const FormMessage: ({ ref, className, children, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
35
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
36
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
37
|
+
|
|
38
|
+
export { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField };
|
package/dist/forms.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/forms.ts
|
|
32
|
+
var forms_exports = {};
|
|
33
|
+
__export(forms_exports, {
|
|
34
|
+
Form: () => Form,
|
|
35
|
+
FormControl: () => FormControl,
|
|
36
|
+
FormDescription: () => FormDescription,
|
|
37
|
+
FormField: () => FormField,
|
|
38
|
+
FormItem: () => FormItem,
|
|
39
|
+
FormLabel: () => FormLabel,
|
|
40
|
+
FormMessage: () => FormMessage,
|
|
41
|
+
useFormField: () => useFormField
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(forms_exports);
|
|
44
|
+
|
|
45
|
+
// src/components/forms/Form.tsx
|
|
46
|
+
var React = __toESM(require("react"));
|
|
47
|
+
var import_react_slot = require("@radix-ui/react-slot");
|
|
48
|
+
var import_react_hook_form = require("react-hook-form");
|
|
49
|
+
|
|
50
|
+
// src/lib/utils.ts
|
|
51
|
+
var import_clsx = require("clsx");
|
|
52
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
53
|
+
function cn(...inputs) {
|
|
54
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/components/forms/Label.tsx
|
|
58
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
59
|
+
var LabelPrimitive = __toESM(require("@radix-ui/react-label"));
|
|
60
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
61
|
+
var labelVariants = (0, import_class_variance_authority.cva)(
|
|
62
|
+
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
63
|
+
);
|
|
64
|
+
var Label = ({
|
|
65
|
+
ref,
|
|
66
|
+
className,
|
|
67
|
+
...props
|
|
68
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
69
|
+
LabelPrimitive.Root,
|
|
70
|
+
{
|
|
71
|
+
ref,
|
|
72
|
+
className: cn(labelVariants(), className),
|
|
73
|
+
...props
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// src/components/forms/Form.tsx
|
|
78
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
79
|
+
var Form = import_react_hook_form.FormProvider;
|
|
80
|
+
var FormFieldContext = React.createContext(
|
|
81
|
+
{}
|
|
82
|
+
);
|
|
83
|
+
var FormField = ({
|
|
84
|
+
...props
|
|
85
|
+
}) => {
|
|
86
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_hook_form.Controller, { ...props }) });
|
|
87
|
+
};
|
|
88
|
+
var useFormField = () => {
|
|
89
|
+
const fieldContext = React.useContext(FormFieldContext);
|
|
90
|
+
const itemContext = React.useContext(FormItemContext);
|
|
91
|
+
const { getFieldState, formState } = (0, import_react_hook_form.useFormContext)();
|
|
92
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
93
|
+
if (!fieldContext) {
|
|
94
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
95
|
+
}
|
|
96
|
+
const { id } = itemContext;
|
|
97
|
+
return {
|
|
98
|
+
id,
|
|
99
|
+
name: fieldContext.name,
|
|
100
|
+
formItemId: `${id}-form-item`,
|
|
101
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
102
|
+
formMessageId: `${id}-form-item-message`,
|
|
103
|
+
...fieldState
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
var FormItemContext = React.createContext(
|
|
107
|
+
{}
|
|
108
|
+
);
|
|
109
|
+
var FormItem = ({
|
|
110
|
+
ref,
|
|
111
|
+
className,
|
|
112
|
+
...props
|
|
113
|
+
}) => {
|
|
114
|
+
const id = React.useId();
|
|
115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref, className: cn("space-y-2", className), ...props }) });
|
|
116
|
+
};
|
|
117
|
+
var FormLabel = ({
|
|
118
|
+
ref,
|
|
119
|
+
className,
|
|
120
|
+
...props
|
|
121
|
+
}) => {
|
|
122
|
+
const { error, formItemId } = useFormField();
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
124
|
+
Label,
|
|
125
|
+
{
|
|
126
|
+
ref,
|
|
127
|
+
className: cn(error && "text-destructive", className),
|
|
128
|
+
htmlFor: formItemId,
|
|
129
|
+
...props
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
var FormControl = ({
|
|
134
|
+
ref,
|
|
135
|
+
...props
|
|
136
|
+
}) => {
|
|
137
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
138
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
139
|
+
import_react_slot.Slot,
|
|
140
|
+
{
|
|
141
|
+
ref,
|
|
142
|
+
id: formItemId,
|
|
143
|
+
"aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
|
|
144
|
+
"aria-invalid": !!error,
|
|
145
|
+
...props
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
var FormDescription = ({
|
|
150
|
+
ref,
|
|
151
|
+
className,
|
|
152
|
+
...props
|
|
153
|
+
}) => {
|
|
154
|
+
const { formDescriptionId } = useFormField();
|
|
155
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
156
|
+
"p",
|
|
157
|
+
{
|
|
158
|
+
ref,
|
|
159
|
+
id: formDescriptionId,
|
|
160
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
161
|
+
...props
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
var FormMessage = ({
|
|
166
|
+
ref,
|
|
167
|
+
className,
|
|
168
|
+
children,
|
|
169
|
+
...props
|
|
170
|
+
}) => {
|
|
171
|
+
const { error, formMessageId } = useFormField();
|
|
172
|
+
const body = error ? String(error?.message) : children;
|
|
173
|
+
if (!body) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
177
|
+
"p",
|
|
178
|
+
{
|
|
179
|
+
ref,
|
|
180
|
+
id: formMessageId,
|
|
181
|
+
className: cn("text-sm font-medium text-destructive", className),
|
|
182
|
+
...props,
|
|
183
|
+
children: body
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
Form,
|
|
190
|
+
FormControl,
|
|
191
|
+
FormDescription,
|
|
192
|
+
FormField,
|
|
193
|
+
FormItem,
|
|
194
|
+
FormLabel,
|
|
195
|
+
FormMessage,
|
|
196
|
+
useFormField
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=forms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/forms.ts","../src/components/forms/Form.tsx","../src/lib/utils.ts","../src/components/forms/Label.tsx"],"sourcesContent":["export * from './components/forms/Form';\n","\"use client\";\nimport * as React from \"react\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { Slot } from \"@radix-ui/react-slot\"\nimport {\n Controller,\n ControllerProps,\n FieldPath,\n FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\"\n\nimport { cn } from \"../../lib/utils\"\nimport { Label } from \"./Label\"\n\nconst Form: typeof FormProvider = FormProvider\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = {\n name: TName\n}\n\nconst FormFieldContext = React.createContext<FormFieldContextValue>(\n {} as FormFieldContextValue\n)\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n )\n}\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext)\n const itemContext = React.useContext(FormItemContext)\n const { getFieldState, formState } = useFormContext()\n\n const fieldState = getFieldState(fieldContext.name, formState)\n\n if (!fieldContext) {\n throw new Error(\"useFormField should be used within <FormField>\")\n }\n\n const { id } = itemContext\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n }\n}\n\ntype FormItemContextValue = {\n id: string\n}\n\nconst FormItemContext = React.createContext<FormItemContextValue>(\n {} as FormItemContextValue\n)\n\nconst FormItem = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n }\n) => {\n const id = React.useId()\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn(\"space-y-2\", className)} {...props} />\n </FormItemContext.Provider>\n )\n}\n\nconst FormLabel = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => {\n const { error, formItemId } = useFormField()\n\n return (\n <Label\n ref={ref}\n className={cn(error && \"text-destructive\", className)}\n htmlFor={formItemId}\n {...props}\n />\n )\n}\n\nconst FormControl = (\n {\n ref,\n ...props\n }: React.ComponentPropsWithoutRef<typeof Slot> & {\n ref?: React.Ref<React.ElementRef<typeof Slot>>;\n }\n) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField()\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={\n !error\n ? `${formDescriptionId}`\n : `${formDescriptionId} ${formMessageId}`\n }\n aria-invalid={!!error}\n {...props}\n />\n )\n}\n\nconst FormDescription = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { formDescriptionId } = useFormField()\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn(\"text-sm text-muted-foreground\", className)}\n {...props}\n />\n )\n}\n\nconst FormMessage = (\n {\n ref,\n className,\n children,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { error, formMessageId } = useFormField()\n const body = error ? String(error?.message) : children\n\n if (!body) {\n return null\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn(\"text-sm font-medium text-destructive\", className)}\n {...props}\n >\n {body}\n </p>\n )\n}\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n}\n","import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { cn } from \"../../lib/utils\"\n\nconst labelVariants = cva(\n \"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\"\n)\n\nconst Label = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &\n VariantProps<typeof labelVariants> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => (<LabelPrimitive.Root\n ref={ref}\n className={cn(labelVariants(), className)}\n {...props}\n/>)\n\nexport { Label }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,YAAuB;AAEvB,wBAAqB;AACrB,6BAOO;;;ACXP,kBAAsC;AACtC,4BAAwB;AAEjB,SAA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A,MAC9D,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":["import_jsx_runtime"]}
|
package/dist/forms.mjs
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/forms/Form.tsx
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
6
|
+
import {
|
|
7
|
+
Controller,
|
|
8
|
+
FormProvider,
|
|
9
|
+
useFormContext
|
|
10
|
+
} from "react-hook-form";
|
|
11
|
+
|
|
12
|
+
// src/lib/utils.ts
|
|
13
|
+
import { clsx } from "clsx";
|
|
14
|
+
import { twMerge } from "tailwind-merge";
|
|
15
|
+
function cn(...inputs) {
|
|
16
|
+
return twMerge(clsx(inputs));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/components/forms/Label.tsx
|
|
20
|
+
import { cva } from "class-variance-authority";
|
|
21
|
+
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
22
|
+
import { jsx } from "react/jsx-runtime";
|
|
23
|
+
var labelVariants = cva(
|
|
24
|
+
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
25
|
+
);
|
|
26
|
+
var Label = ({
|
|
27
|
+
ref,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}) => /* @__PURE__ */ jsx(
|
|
31
|
+
LabelPrimitive.Root,
|
|
32
|
+
{
|
|
33
|
+
ref,
|
|
34
|
+
className: cn(labelVariants(), className),
|
|
35
|
+
...props
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// src/components/forms/Form.tsx
|
|
40
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
41
|
+
var Form = FormProvider;
|
|
42
|
+
var FormFieldContext = React.createContext(
|
|
43
|
+
{}
|
|
44
|
+
);
|
|
45
|
+
var FormField = ({
|
|
46
|
+
...props
|
|
47
|
+
}) => {
|
|
48
|
+
return /* @__PURE__ */ jsx2(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx2(Controller, { ...props }) });
|
|
49
|
+
};
|
|
50
|
+
var useFormField = () => {
|
|
51
|
+
const fieldContext = React.useContext(FormFieldContext);
|
|
52
|
+
const itemContext = React.useContext(FormItemContext);
|
|
53
|
+
const { getFieldState, formState } = useFormContext();
|
|
54
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
55
|
+
if (!fieldContext) {
|
|
56
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
57
|
+
}
|
|
58
|
+
const { id } = itemContext;
|
|
59
|
+
return {
|
|
60
|
+
id,
|
|
61
|
+
name: fieldContext.name,
|
|
62
|
+
formItemId: `${id}-form-item`,
|
|
63
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
64
|
+
formMessageId: `${id}-form-item-message`,
|
|
65
|
+
...fieldState
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var FormItemContext = React.createContext(
|
|
69
|
+
{}
|
|
70
|
+
);
|
|
71
|
+
var FormItem = ({
|
|
72
|
+
ref,
|
|
73
|
+
className,
|
|
74
|
+
...props
|
|
75
|
+
}) => {
|
|
76
|
+
const id = React.useId();
|
|
77
|
+
return /* @__PURE__ */ jsx2(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx2("div", { ref, className: cn("space-y-2", className), ...props }) });
|
|
78
|
+
};
|
|
79
|
+
var FormLabel = ({
|
|
80
|
+
ref,
|
|
81
|
+
className,
|
|
82
|
+
...props
|
|
83
|
+
}) => {
|
|
84
|
+
const { error, formItemId } = useFormField();
|
|
85
|
+
return /* @__PURE__ */ jsx2(
|
|
86
|
+
Label,
|
|
87
|
+
{
|
|
88
|
+
ref,
|
|
89
|
+
className: cn(error && "text-destructive", className),
|
|
90
|
+
htmlFor: formItemId,
|
|
91
|
+
...props
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
var FormControl = ({
|
|
96
|
+
ref,
|
|
97
|
+
...props
|
|
98
|
+
}) => {
|
|
99
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
100
|
+
return /* @__PURE__ */ jsx2(
|
|
101
|
+
Slot,
|
|
102
|
+
{
|
|
103
|
+
ref,
|
|
104
|
+
id: formItemId,
|
|
105
|
+
"aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
|
|
106
|
+
"aria-invalid": !!error,
|
|
107
|
+
...props
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
var FormDescription = ({
|
|
112
|
+
ref,
|
|
113
|
+
className,
|
|
114
|
+
...props
|
|
115
|
+
}) => {
|
|
116
|
+
const { formDescriptionId } = useFormField();
|
|
117
|
+
return /* @__PURE__ */ jsx2(
|
|
118
|
+
"p",
|
|
119
|
+
{
|
|
120
|
+
ref,
|
|
121
|
+
id: formDescriptionId,
|
|
122
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
123
|
+
...props
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
var FormMessage = ({
|
|
128
|
+
ref,
|
|
129
|
+
className,
|
|
130
|
+
children,
|
|
131
|
+
...props
|
|
132
|
+
}) => {
|
|
133
|
+
const { error, formMessageId } = useFormField();
|
|
134
|
+
const body = error ? String(error?.message) : children;
|
|
135
|
+
if (!body) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return /* @__PURE__ */ jsx2(
|
|
139
|
+
"p",
|
|
140
|
+
{
|
|
141
|
+
ref,
|
|
142
|
+
id: formMessageId,
|
|
143
|
+
className: cn("text-sm font-medium text-destructive", className),
|
|
144
|
+
...props,
|
|
145
|
+
children: body
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
export {
|
|
150
|
+
Form,
|
|
151
|
+
FormControl,
|
|
152
|
+
FormDescription,
|
|
153
|
+
FormField,
|
|
154
|
+
FormItem,
|
|
155
|
+
FormLabel,
|
|
156
|
+
FormMessage,
|
|
157
|
+
useFormField
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=forms.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/forms/Form.tsx","../src/lib/utils.ts","../src/components/forms/Label.tsx"],"sourcesContent":["\"use client\";\nimport * as React from \"react\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { Slot } from \"@radix-ui/react-slot\"\nimport {\n Controller,\n ControllerProps,\n FieldPath,\n FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\"\n\nimport { cn } from \"../../lib/utils\"\nimport { Label } from \"./Label\"\n\nconst Form: typeof FormProvider = FormProvider\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = {\n name: TName\n}\n\nconst FormFieldContext = React.createContext<FormFieldContextValue>(\n {} as FormFieldContextValue\n)\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n )\n}\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext)\n const itemContext = React.useContext(FormItemContext)\n const { getFieldState, formState } = useFormContext()\n\n const fieldState = getFieldState(fieldContext.name, formState)\n\n if (!fieldContext) {\n throw new Error(\"useFormField should be used within <FormField>\")\n }\n\n const { id } = itemContext\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n }\n}\n\ntype FormItemContextValue = {\n id: string\n}\n\nconst FormItemContext = React.createContext<FormItemContextValue>(\n {} as FormItemContextValue\n)\n\nconst FormItem = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n }\n) => {\n const id = React.useId()\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn(\"space-y-2\", className)} {...props} />\n </FormItemContext.Provider>\n )\n}\n\nconst FormLabel = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => {\n const { error, formItemId } = useFormField()\n\n return (\n <Label\n ref={ref}\n className={cn(error && \"text-destructive\", className)}\n htmlFor={formItemId}\n {...props}\n />\n )\n}\n\nconst FormControl = (\n {\n ref,\n ...props\n }: React.ComponentPropsWithoutRef<typeof Slot> & {\n ref?: React.Ref<React.ElementRef<typeof Slot>>;\n }\n) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField()\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={\n !error\n ? `${formDescriptionId}`\n : `${formDescriptionId} ${formMessageId}`\n }\n aria-invalid={!!error}\n {...props}\n />\n )\n}\n\nconst FormDescription = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { formDescriptionId } = useFormField()\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn(\"text-sm text-muted-foreground\", className)}\n {...props}\n />\n )\n}\n\nconst FormMessage = (\n {\n ref,\n className,\n children,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { error, formMessageId } = useFormField()\n const body = error ? String(error?.message) : children\n\n if (!body) {\n return null\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn(\"text-sm font-medium text-destructive\", className)}\n {...props}\n >\n {body}\n </p>\n )\n}\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n}\n","import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { cn } from \"../../lib/utils\"\n\nconst labelVariants = cva(\n \"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\"\n)\n\nconst Label = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &\n VariantProps<typeof labelVariants> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => (<LabelPrimitive.Root\n ref={ref}\n className={cn(labelVariants(), className)}\n {...props}\n/>)\n\nexport { Label }\n"],"mappings":";;;AACA,YAAY,WAAW;AAEvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EAIA;AAAA,EACA;AAAA,OACK;;;ACXP,SAA0B,YAAY;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AACxC,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC/B;;;ACJA,SAAS,WAA8B;AACvC,YAAY,oBAAoB;AAgB1B;AAbN,IAAM,gBAAgB;AAAA,EAClB;AACJ;AAEA,IAAM,QAAQ,CACV;AAAA,EACI;AAAA,EACA;AAAA,EACA,GAAG;AACP,MAIE;AAAA,EAAgB;AAAA,EAAf;AAAA,IACH;AAAA,IACA,WAAW,GAAG,cAAc,GAAG,SAAS;AAAA,IACvC,GAAG;AAAA;AACR;;;AFeM,gBAAAA,YAAA;AArBN,IAAM,OAA4B;AASlC,IAAM,mBAAyB;AAAA,EAC7B,CAAC;AACH;AAEA,IAAM,YAAY,CAGhB;AAAA,EACA,GAAG;AACL,MAA4C;AAC1C,SACE,gBAAAA,KAAC,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,MAAM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AAA,MACC;AAAA,MACA,IAAI;AAAA,MACJ,oBACE,CAAC,QACG,GAAG,iBAAiB,KACpB,GAAG,iBAAiB,IAAI,aAAa;AAAA,MAE3C,gBAAc,CAAC,CAAC;AAAA,MACf,GAAG;AAAA;AAAA,EACN;AAEJ;AAEA,IAAM,kBAAkB,CACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAGG;AACH,QAAM,EAAE,kBAAkB,IAAI,aAAa;AAE3C,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,IAAI;AAAA,MACJ,WAAW,GAAG,iCAAiC,SAAS;AAAA,MACvD,GAAG;AAAA;AAAA,EACN;AAEJ;AAEA,IAAM,cAAc,CAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAGG;AACH,QAAM,EAAE,OAAO,cAAc,IAAI,aAAa;AAC9C,QAAM,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI;AAE9C,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,IAAI;AAAA,MACJ,WAAW,GAAG,wCAAwC,SAAS;AAAA,MAC9D,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":["jsx"]}
|
package/dist/hooks.js
CHANGED
|
@@ -823,7 +823,8 @@ function hexToHSL2(hex) {
|
|
|
823
823
|
const b = rgb.b / 255;
|
|
824
824
|
const max = Math.max(r, g, b);
|
|
825
825
|
const min = Math.min(r, g, b);
|
|
826
|
-
let h = 0, s = 0
|
|
826
|
+
let h = 0, s = 0;
|
|
827
|
+
const l = (max + min) / 2;
|
|
827
828
|
if (max !== min) {
|
|
828
829
|
const d = max - min;
|
|
829
830
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
@@ -988,14 +989,14 @@ var useCustomizer = (0, import_zustand2.create)()(
|
|
|
988
989
|
const scale = generateColorScale(colors.primary);
|
|
989
990
|
const primaryForeground = getOptimalForeground2(colors.primary);
|
|
990
991
|
let derivedTokens = computeDerivedTokens("--color-primary", colors.primary, mode);
|
|
991
|
-
|
|
992
|
-
|
|
992
|
+
const secondary = colors.secondary;
|
|
993
|
+
const secondaryForeground = secondary ? getOptimalForeground2(secondary) : void 0;
|
|
993
994
|
if (secondary) {
|
|
994
995
|
const secondaryDerived = computeDerivedTokens("--color-secondary", secondary, mode);
|
|
995
996
|
derivedTokens = { ...derivedTokens, ...secondaryDerived };
|
|
996
997
|
}
|
|
997
|
-
|
|
998
|
-
|
|
998
|
+
const accent = colors.accent;
|
|
999
|
+
const accentForeground = accent ? getOptimalForeground2(accent) : void 0;
|
|
999
1000
|
if (accent) {
|
|
1000
1001
|
const accentDerived = computeDerivedTokens("--color-accent", accent, mode);
|
|
1001
1002
|
derivedTokens = { ...derivedTokens, ...accentDerived };
|