@dimaan/ui 0.0.4 → 0.0.6
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/dist/index.cjs +121 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -1
- package/dist/index.d.ts +77 -1
- package/dist/index.js +121 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { HTMLAttributes, ReactNode, ReactElement, ButtonHTMLAttributes, InputHTMLAttributes, ChangeEvent, FieldsetHTMLAttributes, AnchorHTMLAttributes, Ref, TextareaHTMLAttributes } from 'react';
|
|
4
|
+
import { FieldValues, FieldPath, Control } from 'react-hook-form';
|
|
4
5
|
import { ClassValue } from 'clsx';
|
|
5
6
|
|
|
6
7
|
interface DashboardLayoutContextValue {
|
|
@@ -124,6 +125,81 @@ interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'typ
|
|
|
124
125
|
}
|
|
125
126
|
declare const Checkbox: react.ForwardRefExoticComponent<CheckboxProps & react.RefAttributes<HTMLInputElement>>;
|
|
126
127
|
|
|
128
|
+
interface FieldRHFProps<TValues extends FieldValues = FieldValues, TName extends FieldPath<TValues> = FieldPath<TValues>> {
|
|
129
|
+
/**
|
|
130
|
+
* RHF `Control` returned from `useForm()`. Optional when `Field` is rendered
|
|
131
|
+
* inside a `<FormProvider>` — the control is read from context automatically.
|
|
132
|
+
*/
|
|
133
|
+
control?: Control<TValues>;
|
|
134
|
+
/** Path to the field within the form values. */
|
|
135
|
+
name: TName;
|
|
136
|
+
}
|
|
137
|
+
interface FieldLayoutProps {
|
|
138
|
+
/** Label rendered above the control. */
|
|
139
|
+
label?: ReactNode;
|
|
140
|
+
/** Helper text rendered under the control when there's no error. */
|
|
141
|
+
description?: ReactNode;
|
|
142
|
+
/** Marks the field as required (visual `*` + native `required`). */
|
|
143
|
+
required?: boolean;
|
|
144
|
+
/** Disables the wrapped control. */
|
|
145
|
+
disabled?: boolean;
|
|
146
|
+
/** Stretch the wrapper to fill its parent. Defaults to `true`. */
|
|
147
|
+
fullWidth?: boolean;
|
|
148
|
+
/** Class applied to the outer wrapper. */
|
|
149
|
+
className?: string;
|
|
150
|
+
/** The single control element to wrap. Receives id + aria + (in RHF mode) field props. */
|
|
151
|
+
children: ReactElement;
|
|
152
|
+
}
|
|
153
|
+
interface FieldManualProps extends FieldLayoutProps {
|
|
154
|
+
control?: never;
|
|
155
|
+
name?: never;
|
|
156
|
+
/** Error message to display. Pass falsy when valid. */
|
|
157
|
+
error?: ReactNode;
|
|
158
|
+
/** Override `aria-invalid`. Defaults to `!!error` when omitted. */
|
|
159
|
+
invalid?: boolean;
|
|
160
|
+
}
|
|
161
|
+
interface FieldRHFOnlyProps<TValues extends FieldValues, TName extends FieldPath<TValues>> extends FieldLayoutProps, FieldRHFProps<TValues, TName> {
|
|
162
|
+
error?: never;
|
|
163
|
+
invalid?: never;
|
|
164
|
+
}
|
|
165
|
+
type FieldProps<TValues extends FieldValues = FieldValues, TName extends FieldPath<TValues> = FieldPath<TValues>> = FieldManualProps | FieldRHFOnlyProps<TValues, TName>;
|
|
166
|
+
/**
|
|
167
|
+
* `Field` wraps a single form control with a label, description, and error
|
|
168
|
+
* message. It works in three modes:
|
|
169
|
+
*
|
|
170
|
+
* 1. **FormProvider context mode** (recommended): pass only `name`. The
|
|
171
|
+
* `control` is pulled from the surrounding `<FormProvider>`.
|
|
172
|
+
* 2. **Explicit control mode**: pass both `control` and `name` (useful when you
|
|
173
|
+
* don't want a `FormProvider`, or when you have multiple forms on the page).
|
|
174
|
+
* 3. **Manual mode**: omit `name`. Provide `error` / `invalid` yourself.
|
|
175
|
+
*
|
|
176
|
+
* @example FormProvider mode
|
|
177
|
+
* ```tsx
|
|
178
|
+
* <FormProvider {...form}>
|
|
179
|
+
* <form onSubmit={form.handleSubmit(onSubmit)}>
|
|
180
|
+
* <Field name="email" label="Email" description="…">
|
|
181
|
+
* <Input type="email" />
|
|
182
|
+
* </Field>
|
|
183
|
+
* </form>
|
|
184
|
+
* </FormProvider>
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @example Explicit control mode
|
|
188
|
+
* ```tsx
|
|
189
|
+
* <Field control={form.control} name="email" label="Email">
|
|
190
|
+
* <Input type="email" />
|
|
191
|
+
* </Field>
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* @example Manual mode
|
|
195
|
+
* ```tsx
|
|
196
|
+
* <Field label="Email" error={errorMessage}>
|
|
197
|
+
* <Input value={email} onChange={(e) => setEmail(e.target.value)} />
|
|
198
|
+
* </Field>
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function Field<TValues extends FieldValues = FieldValues, TName extends FieldPath<TValues> = FieldPath<TValues>>(props: FieldProps<TValues, TName>): ReactElement;
|
|
202
|
+
|
|
127
203
|
type DashboardHeaderProps = HTMLAttributes<HTMLElement>;
|
|
128
204
|
declare function DashboardHeader({ className, children, ...props }: DashboardHeaderProps): react_jsx_runtime.JSX.Element;
|
|
129
205
|
|
|
@@ -388,4 +464,4 @@ declare function useDirection(): Direction;
|
|
|
388
464
|
|
|
389
465
|
declare function cn(...inputs: ClassValue[]): string;
|
|
390
466
|
|
|
391
|
-
export { AppShell, type AppShellBrand, type AppShellNavGroup, type AppShellNavItem, type AppShellProps, Avatar, type AvatarProps, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Checkbox, type CheckboxProps, type CheckboxSize, type Column, type ColumnAlign, DashboardContent, type DashboardContentProps, DashboardHeader, type DashboardHeaderProps, DashboardLayout, type DashboardLayoutContextValue, type DashboardLayoutProps, DashboardMain, type DashboardMainProps, type Direction, HeaderActions, type HeaderActionsProps, HeaderCollapseTrigger, type HeaderCollapseTriggerProps, HeaderMobileTrigger, type HeaderMobileTriggerProps, HeaderSearch, type HeaderSearchProps, HeaderTitle, type HeaderTitleProps, Input, type InputProps, type InputSize, type InputVariant, type LanguageOption, LanguageSwitcher, type LanguageSwitcherProps, type PaginationState, type RowSelectionState, Sidebar, SidebarFooter, type SidebarFooterProps, SidebarGroup, type SidebarGroupProps, SidebarHeader, type SidebarHeaderProps, SidebarNav, SidebarNavGroup, type SidebarNavGroupProps, SidebarNavItem, type SidebarNavItemProps, type SidebarNavItemRenderProps, type SidebarNavProps, type SidebarProps, type SortDirection, type SortState, type SortableValue, Table, type TableProps, type TableSize, type TableSizeClasses, Textarea, type TextareaProps, type TextareaResize, type TextareaSize, type TextareaVariant, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
|
|
467
|
+
export { AppShell, type AppShellBrand, type AppShellNavGroup, type AppShellNavItem, type AppShellProps, Avatar, type AvatarProps, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Checkbox, type CheckboxProps, type CheckboxSize, type Column, type ColumnAlign, DashboardContent, type DashboardContentProps, DashboardHeader, type DashboardHeaderProps, DashboardLayout, type DashboardLayoutContextValue, type DashboardLayoutProps, DashboardMain, type DashboardMainProps, type Direction, Field, type FieldProps, type FieldRHFProps, HeaderActions, type HeaderActionsProps, HeaderCollapseTrigger, type HeaderCollapseTriggerProps, HeaderMobileTrigger, type HeaderMobileTriggerProps, HeaderSearch, type HeaderSearchProps, HeaderTitle, type HeaderTitleProps, Input, type InputProps, type InputSize, type InputVariant, type LanguageOption, LanguageSwitcher, type LanguageSwitcherProps, type PaginationState, type RowSelectionState, Sidebar, SidebarFooter, type SidebarFooterProps, SidebarGroup, type SidebarGroupProps, SidebarHeader, type SidebarHeaderProps, SidebarNav, SidebarNavGroup, type SidebarNavGroupProps, SidebarNavItem, type SidebarNavItemProps, type SidebarNavItemRenderProps, type SidebarNavProps, type SidebarProps, type SortDirection, type SortState, type SortableValue, Table, type TableProps, type TableSize, type TableSizeClasses, Textarea, type TextareaProps, type TextareaResize, type TextareaSize, type TextareaVariant, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { HTMLAttributes, ReactNode, ReactElement, ButtonHTMLAttributes, InputHTMLAttributes, ChangeEvent, FieldsetHTMLAttributes, AnchorHTMLAttributes, Ref, TextareaHTMLAttributes } from 'react';
|
|
4
|
+
import { FieldValues, FieldPath, Control } from 'react-hook-form';
|
|
4
5
|
import { ClassValue } from 'clsx';
|
|
5
6
|
|
|
6
7
|
interface DashboardLayoutContextValue {
|
|
@@ -124,6 +125,81 @@ interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'typ
|
|
|
124
125
|
}
|
|
125
126
|
declare const Checkbox: react.ForwardRefExoticComponent<CheckboxProps & react.RefAttributes<HTMLInputElement>>;
|
|
126
127
|
|
|
128
|
+
interface FieldRHFProps<TValues extends FieldValues = FieldValues, TName extends FieldPath<TValues> = FieldPath<TValues>> {
|
|
129
|
+
/**
|
|
130
|
+
* RHF `Control` returned from `useForm()`. Optional when `Field` is rendered
|
|
131
|
+
* inside a `<FormProvider>` — the control is read from context automatically.
|
|
132
|
+
*/
|
|
133
|
+
control?: Control<TValues>;
|
|
134
|
+
/** Path to the field within the form values. */
|
|
135
|
+
name: TName;
|
|
136
|
+
}
|
|
137
|
+
interface FieldLayoutProps {
|
|
138
|
+
/** Label rendered above the control. */
|
|
139
|
+
label?: ReactNode;
|
|
140
|
+
/** Helper text rendered under the control when there's no error. */
|
|
141
|
+
description?: ReactNode;
|
|
142
|
+
/** Marks the field as required (visual `*` + native `required`). */
|
|
143
|
+
required?: boolean;
|
|
144
|
+
/** Disables the wrapped control. */
|
|
145
|
+
disabled?: boolean;
|
|
146
|
+
/** Stretch the wrapper to fill its parent. Defaults to `true`. */
|
|
147
|
+
fullWidth?: boolean;
|
|
148
|
+
/** Class applied to the outer wrapper. */
|
|
149
|
+
className?: string;
|
|
150
|
+
/** The single control element to wrap. Receives id + aria + (in RHF mode) field props. */
|
|
151
|
+
children: ReactElement;
|
|
152
|
+
}
|
|
153
|
+
interface FieldManualProps extends FieldLayoutProps {
|
|
154
|
+
control?: never;
|
|
155
|
+
name?: never;
|
|
156
|
+
/** Error message to display. Pass falsy when valid. */
|
|
157
|
+
error?: ReactNode;
|
|
158
|
+
/** Override `aria-invalid`. Defaults to `!!error` when omitted. */
|
|
159
|
+
invalid?: boolean;
|
|
160
|
+
}
|
|
161
|
+
interface FieldRHFOnlyProps<TValues extends FieldValues, TName extends FieldPath<TValues>> extends FieldLayoutProps, FieldRHFProps<TValues, TName> {
|
|
162
|
+
error?: never;
|
|
163
|
+
invalid?: never;
|
|
164
|
+
}
|
|
165
|
+
type FieldProps<TValues extends FieldValues = FieldValues, TName extends FieldPath<TValues> = FieldPath<TValues>> = FieldManualProps | FieldRHFOnlyProps<TValues, TName>;
|
|
166
|
+
/**
|
|
167
|
+
* `Field` wraps a single form control with a label, description, and error
|
|
168
|
+
* message. It works in three modes:
|
|
169
|
+
*
|
|
170
|
+
* 1. **FormProvider context mode** (recommended): pass only `name`. The
|
|
171
|
+
* `control` is pulled from the surrounding `<FormProvider>`.
|
|
172
|
+
* 2. **Explicit control mode**: pass both `control` and `name` (useful when you
|
|
173
|
+
* don't want a `FormProvider`, or when you have multiple forms on the page).
|
|
174
|
+
* 3. **Manual mode**: omit `name`. Provide `error` / `invalid` yourself.
|
|
175
|
+
*
|
|
176
|
+
* @example FormProvider mode
|
|
177
|
+
* ```tsx
|
|
178
|
+
* <FormProvider {...form}>
|
|
179
|
+
* <form onSubmit={form.handleSubmit(onSubmit)}>
|
|
180
|
+
* <Field name="email" label="Email" description="…">
|
|
181
|
+
* <Input type="email" />
|
|
182
|
+
* </Field>
|
|
183
|
+
* </form>
|
|
184
|
+
* </FormProvider>
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @example Explicit control mode
|
|
188
|
+
* ```tsx
|
|
189
|
+
* <Field control={form.control} name="email" label="Email">
|
|
190
|
+
* <Input type="email" />
|
|
191
|
+
* </Field>
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* @example Manual mode
|
|
195
|
+
* ```tsx
|
|
196
|
+
* <Field label="Email" error={errorMessage}>
|
|
197
|
+
* <Input value={email} onChange={(e) => setEmail(e.target.value)} />
|
|
198
|
+
* </Field>
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function Field<TValues extends FieldValues = FieldValues, TName extends FieldPath<TValues> = FieldPath<TValues>>(props: FieldProps<TValues, TName>): ReactElement;
|
|
202
|
+
|
|
127
203
|
type DashboardHeaderProps = HTMLAttributes<HTMLElement>;
|
|
128
204
|
declare function DashboardHeader({ className, children, ...props }: DashboardHeaderProps): react_jsx_runtime.JSX.Element;
|
|
129
205
|
|
|
@@ -388,4 +464,4 @@ declare function useDirection(): Direction;
|
|
|
388
464
|
|
|
389
465
|
declare function cn(...inputs: ClassValue[]): string;
|
|
390
466
|
|
|
391
|
-
export { AppShell, type AppShellBrand, type AppShellNavGroup, type AppShellNavItem, type AppShellProps, Avatar, type AvatarProps, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Checkbox, type CheckboxProps, type CheckboxSize, type Column, type ColumnAlign, DashboardContent, type DashboardContentProps, DashboardHeader, type DashboardHeaderProps, DashboardLayout, type DashboardLayoutContextValue, type DashboardLayoutProps, DashboardMain, type DashboardMainProps, type Direction, HeaderActions, type HeaderActionsProps, HeaderCollapseTrigger, type HeaderCollapseTriggerProps, HeaderMobileTrigger, type HeaderMobileTriggerProps, HeaderSearch, type HeaderSearchProps, HeaderTitle, type HeaderTitleProps, Input, type InputProps, type InputSize, type InputVariant, type LanguageOption, LanguageSwitcher, type LanguageSwitcherProps, type PaginationState, type RowSelectionState, Sidebar, SidebarFooter, type SidebarFooterProps, SidebarGroup, type SidebarGroupProps, SidebarHeader, type SidebarHeaderProps, SidebarNav, SidebarNavGroup, type SidebarNavGroupProps, SidebarNavItem, type SidebarNavItemProps, type SidebarNavItemRenderProps, type SidebarNavProps, type SidebarProps, type SortDirection, type SortState, type SortableValue, Table, type TableProps, type TableSize, type TableSizeClasses, Textarea, type TextareaProps, type TextareaResize, type TextareaSize, type TextareaVariant, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
|
|
467
|
+
export { AppShell, type AppShellBrand, type AppShellNavGroup, type AppShellNavItem, type AppShellProps, Avatar, type AvatarProps, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Checkbox, type CheckboxProps, type CheckboxSize, type Column, type ColumnAlign, DashboardContent, type DashboardContentProps, DashboardHeader, type DashboardHeaderProps, DashboardLayout, type DashboardLayoutContextValue, type DashboardLayoutProps, DashboardMain, type DashboardMainProps, type Direction, Field, type FieldProps, type FieldRHFProps, HeaderActions, type HeaderActionsProps, HeaderCollapseTrigger, type HeaderCollapseTriggerProps, HeaderMobileTrigger, type HeaderMobileTriggerProps, HeaderSearch, type HeaderSearchProps, HeaderTitle, type HeaderTitleProps, Input, type InputProps, type InputSize, type InputVariant, type LanguageOption, LanguageSwitcher, type LanguageSwitcherProps, type PaginationState, type RowSelectionState, Sidebar, SidebarFooter, type SidebarFooterProps, SidebarGroup, type SidebarGroupProps, SidebarHeader, type SidebarHeaderProps, SidebarNav, SidebarNavGroup, type SidebarNavGroupProps, SidebarNavItem, type SidebarNavItemProps, type SidebarNavItemRenderProps, type SidebarNavProps, type SidebarProps, type SortDirection, type SortState, type SortableValue, Table, type TableProps, type TableSize, type TableSizeClasses, Textarea, type TextareaProps, type TextareaResize, type TextareaSize, type TextareaVariant, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { clsx } from 'clsx';
|
|
|
3
3
|
import { twMerge } from 'tailwind-merge';
|
|
4
4
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
5
5
|
import { Loader2, Check, Minus, ChevronLeft, Menu, ChevronDown, ChevronsUpDown, ChevronUp, ChevronRight } from 'lucide-react';
|
|
6
|
+
import { useFormContext, Controller } from 'react-hook-form';
|
|
6
7
|
|
|
7
8
|
// src/components/dashboard-layout/context.ts
|
|
8
9
|
var DashboardLayoutContext = createContext(null);
|
|
@@ -742,6 +743,125 @@ var Checkbox = forwardRef(function Checkbox2({
|
|
|
742
743
|
)
|
|
743
744
|
] });
|
|
744
745
|
});
|
|
746
|
+
function Field(props) {
|
|
747
|
+
const formContext = useFormContext();
|
|
748
|
+
if (props.name !== void 0) {
|
|
749
|
+
const { control: explicitControl, name, children: children2, ...layout2 } = props;
|
|
750
|
+
const control = explicitControl ?? formContext?.control;
|
|
751
|
+
if (!control) {
|
|
752
|
+
throw new Error(
|
|
753
|
+
'<Field name="..."> requires either a `control` prop OR being rendered inside <FormProvider>. Wrap your form with <FormProvider {...form}> from react-hook-form, or pass `control={form.control}` explicitly.'
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
return /* @__PURE__ */ jsx(
|
|
757
|
+
Controller,
|
|
758
|
+
{
|
|
759
|
+
control,
|
|
760
|
+
name,
|
|
761
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ jsx(FieldShell, { ...layout2, error: fieldState.error?.message, invalid: fieldState.invalid, children: cloneFieldChild(children2, {
|
|
762
|
+
name: field.name,
|
|
763
|
+
value: field.value ?? "",
|
|
764
|
+
onChange: field.onChange,
|
|
765
|
+
onBlur: field.onBlur,
|
|
766
|
+
ref: field.ref,
|
|
767
|
+
disabled: layout2.disabled ?? field.disabled
|
|
768
|
+
}) })
|
|
769
|
+
}
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
const { children, error, invalid, ...layout } = props;
|
|
773
|
+
return /* @__PURE__ */ jsx(FieldShell, { ...layout, error, invalid: invalid ?? Boolean(error), children });
|
|
774
|
+
}
|
|
775
|
+
function FieldShell({
|
|
776
|
+
label,
|
|
777
|
+
description,
|
|
778
|
+
error,
|
|
779
|
+
invalid = false,
|
|
780
|
+
required = false,
|
|
781
|
+
disabled = false,
|
|
782
|
+
fullWidth = true,
|
|
783
|
+
className,
|
|
784
|
+
children
|
|
785
|
+
}) {
|
|
786
|
+
const reactId = useId();
|
|
787
|
+
if (!isValidElement(children)) {
|
|
788
|
+
throw new Error("<Field> requires a single React element as its child.");
|
|
789
|
+
}
|
|
790
|
+
const childProps = children.props;
|
|
791
|
+
const id = childProps.id ?? reactId;
|
|
792
|
+
const descriptionId = `${id}-description`;
|
|
793
|
+
const errorId = `${id}-error`;
|
|
794
|
+
const showError = invalid && error !== void 0 && error !== null && error !== false;
|
|
795
|
+
const showDescription = !showError && description !== void 0 && description !== null;
|
|
796
|
+
const userDescribedBy = childProps["aria-describedby"];
|
|
797
|
+
const describedBy = [userDescribedBy, showDescription ? descriptionId : null, showError ? errorId : null].filter(Boolean).join(" ") || void 0;
|
|
798
|
+
const enhancedChild = cloneFieldChild(children, {
|
|
799
|
+
id,
|
|
800
|
+
"aria-invalid": childProps["aria-invalid"] ?? (invalid || void 0),
|
|
801
|
+
"aria-describedby": describedBy,
|
|
802
|
+
disabled: childProps.disabled ?? disabled,
|
|
803
|
+
required: childProps.required ?? required
|
|
804
|
+
});
|
|
805
|
+
return /* @__PURE__ */ jsxs(
|
|
806
|
+
"div",
|
|
807
|
+
{
|
|
808
|
+
"data-invalid": invalid || void 0,
|
|
809
|
+
"data-disabled": disabled || void 0,
|
|
810
|
+
className: cn("flex flex-col gap-1.5", fullWidth && "w-full", className),
|
|
811
|
+
children: [
|
|
812
|
+
label !== void 0 && label !== null && /* @__PURE__ */ jsxs(
|
|
813
|
+
"label",
|
|
814
|
+
{
|
|
815
|
+
htmlFor: id,
|
|
816
|
+
className: cn(
|
|
817
|
+
"text-sm font-medium select-none text-foreground",
|
|
818
|
+
disabled && "opacity-50",
|
|
819
|
+
invalid && "text-destructive"
|
|
820
|
+
),
|
|
821
|
+
children: [
|
|
822
|
+
label,
|
|
823
|
+
required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "ms-0.5 text-destructive", children: "*" })
|
|
824
|
+
]
|
|
825
|
+
}
|
|
826
|
+
),
|
|
827
|
+
enhancedChild,
|
|
828
|
+
showError ? /* @__PURE__ */ jsx(
|
|
829
|
+
"p",
|
|
830
|
+
{
|
|
831
|
+
id: errorId,
|
|
832
|
+
role: "alert",
|
|
833
|
+
"aria-live": "polite",
|
|
834
|
+
className: "text-xs font-medium text-destructive",
|
|
835
|
+
children: error
|
|
836
|
+
}
|
|
837
|
+
) : showDescription ? /* @__PURE__ */ jsx("p", { id: descriptionId, className: "text-xs text-muted-foreground", children: description }) : null
|
|
838
|
+
]
|
|
839
|
+
}
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
function cloneFieldChild(child, injected) {
|
|
843
|
+
const childProps = child.props;
|
|
844
|
+
const childRef = child.ref;
|
|
845
|
+
const merged = { ...injected };
|
|
846
|
+
for (const key of Object.keys(childProps)) {
|
|
847
|
+
const value = childProps[key];
|
|
848
|
+
if (value !== void 0) merged[key] = value;
|
|
849
|
+
}
|
|
850
|
+
if (injected.ref) {
|
|
851
|
+
merged.ref = mergeRefs(injected.ref, childRef);
|
|
852
|
+
} else if (childRef) {
|
|
853
|
+
merged.ref = childRef;
|
|
854
|
+
}
|
|
855
|
+
return cloneElement(child, merged);
|
|
856
|
+
}
|
|
857
|
+
function mergeRefs(...refs) {
|
|
858
|
+
return (instance) => {
|
|
859
|
+
for (const ref of refs) {
|
|
860
|
+
if (typeof ref === "function") ref(instance);
|
|
861
|
+
else if (ref && typeof ref === "object") ref.current = instance;
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
}
|
|
745
865
|
|
|
746
866
|
// src/components/input/inputVariants.ts
|
|
747
867
|
var inputVariantClass = {
|
|
@@ -1469,6 +1589,6 @@ var Textarea = forwardRef(function Textarea2({
|
|
|
1469
1589
|
] });
|
|
1470
1590
|
});
|
|
1471
1591
|
|
|
1472
|
-
export { AppShell, Avatar, Button, Checkbox, DashboardContent, DashboardHeader, DashboardLayout, DashboardMain, HeaderActions, HeaderCollapseTrigger, HeaderMobileTrigger, HeaderSearch, HeaderTitle, Input, LanguageSwitcher, Sidebar, SidebarFooter, SidebarGroup, SidebarHeader, SidebarNav, SidebarNavGroup, SidebarNavItem, Table, Textarea, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
|
|
1592
|
+
export { AppShell, Avatar, Button, Checkbox, DashboardContent, DashboardHeader, DashboardLayout, DashboardMain, Field, HeaderActions, HeaderCollapseTrigger, HeaderMobileTrigger, HeaderSearch, HeaderTitle, Input, LanguageSwitcher, Sidebar, SidebarFooter, SidebarGroup, SidebarHeader, SidebarNav, SidebarNavGroup, SidebarNavItem, Table, Textarea, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
|
|
1473
1593
|
//# sourceMappingURL=index.js.map
|
|
1474
1594
|
//# sourceMappingURL=index.js.map
|