@erxes/ui 4.0.0-v2.11 → 4.0.0-v2.12
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/CATALOG.md +9 -2
- package/dist/components/combobox.js +4 -1
- package/dist/components/dialog.d.ts +5 -2
- package/dist/components/dialog.js +19 -10
- package/dist/components/field-control.d.ts +16 -0
- package/dist/components/field-control.js +19 -0
- package/dist/components/form-layout.d.ts +19 -0
- package/dist/components/form-layout.js +56 -0
- package/dist/components/form.d.ts +9 -2
- package/dist/components/form.js +17 -7
- package/dist/components/input.js +7 -2
- package/dist/components/multiselect.js +4 -1
- package/dist/components/popover.js +17 -13
- package/dist/components/select.js +16 -11
- package/dist/components/sheet.d.ts +5 -2
- package/dist/components/sheet.js +18 -9
- package/dist/components/textarea.js +4 -1
- package/dist/hooks/use-focus-first-field.d.ts +8 -0
- package/dist/hooks/use-focus-first-field.js +15 -0
- package/dist/hooks/use-page-hotkey.d.ts +2 -0
- package/dist/hooks/use-page-hotkey.js +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/lib/render-in-dom.d.ts +6 -0
- package/dist/lib/render-in-dom.js +26 -0
- package/dist/modules/list/ListFilter.d.ts +7 -1
- package/dist/modules/list/ListFilter.js +8 -2
- package/dist/modules/list/ViewBar.d.ts +36 -4
- package/dist/modules/list/ViewBar.js +33 -9
- package/dist/modules/record-field/components/TextField.js +1 -4
- package/dist/modules/record-panel/PanelForm.d.ts +4 -2
- package/dist/modules/record-panel/PanelForm.js +73 -7
- package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/display.BlTmubjj.js +181 -0
- package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/index.D0heQG4v.js +987 -0
- package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +176 -0
- package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/run.CjdgFZiW.js +1509 -0
- package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/source-map.DakdQc29.js +687 -0
- package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/chunks/tinyrainbow.Do8I1XRG.js +85 -0
- package/dist/node_modules/.pnpm/vitest@5.1.0_@opentelemetry_api@1.10.0_@types_node@26.6.6_@vitest_browser-preview@5.1.0_d78d0f63d2a6b1c4a51a56547b330411/node_modules/vitest/dist/task-utils.js +6 -0
- package/exports.txt +7 -0
- package/package.json +4 -1
package/CATALOG.md
CHANGED
|
@@ -33,8 +33,9 @@ core's, in the erxes repo on branch `postgre`. The `ui-patterns` skill has the r
|
|
|
33
33
|
- `<DisplayMenu list displays>` The Display menu in a list's filter bar: table, board or grouped list.
|
|
34
34
|
- `EnumCursorDirection` Which way a cursor-paged table loads more rows: forward or backward.
|
|
35
35
|
- `Filter.{Trigger, Popover, Item, CommandItem, View, …}` Parts of a filter popover and bar, which `ListFilter` is built from.
|
|
36
|
-
- `<ListFilter
|
|
36
|
+
- `<ListFilter recordType>` A list's filter bar, with a field menu, search and conditions as chips.
|
|
37
37
|
- `listFilterQuery` The URL params holding a list's filter, as nuqs parsers.
|
|
38
|
+
- `<ListViewsProvider views>` Gives every list with a `recordType` saved views, as core's lists have.
|
|
38
39
|
- `RecordList.{Provider, Skeleton, useSelection}` Rows grouped under headers that fold away, such as tasks by status.
|
|
39
40
|
- `type RecordListGroup { id, label, icon, rows, action }` A run of rows under one header, such as the tasks in one status.
|
|
40
41
|
- `RecordTable.{Provider, Header, Head, InlineHead, RowList, …}` The table every record list uses; never `Table` or a plain `<table>`.
|
|
@@ -43,10 +44,14 @@ core's, in the erxes repo on branch `postgre`. The `ui-patterns` skill has the r
|
|
|
43
44
|
- `type TListDisplay` How a list shows its records: grouped rows, a table or a board.
|
|
44
45
|
- `type TListFilterField { path, label, type, options, icon, … }` A field a list can filter by, for `ListFilter`'s `fields`.
|
|
45
46
|
- `type TListFilterProps` The props of `ListFilter`: its `id`, `fields`, lookups and record count.
|
|
47
|
+
- `type TListViews { Tabs, Changes }` The host's saved views for a list.
|
|
48
|
+
- `type TPluginListType` A plugin's list: its record type, `<plugin>:<record>` (`sales:deal`).
|
|
49
|
+
- `type TViewTabsProps { recordType, allLabel }` The props of the host's saved-view tabs: the list and its "All …" label.
|
|
46
50
|
- `useFilterContext()` Controls of the enclosing `Filter`: open or close it and switch views.
|
|
47
51
|
- `useListDisplay(list, displays)` The display a list shows, as picked in its Display menu.
|
|
48
52
|
- `useListFilterParams()` `ListFilter`'s conditions and search, as params for the list's query.
|
|
49
|
-
-
|
|
53
|
+
- `useListViews()` The host's saved views, for `ViewBar` and `ListFilter`.
|
|
54
|
+
- `<ViewBar allLabel recordType tabs>` A list's one bar under its page header: views left, filter right.
|
|
50
55
|
|
|
51
56
|
## Records
|
|
52
57
|
|
|
@@ -185,6 +190,7 @@ core's, in the erxes repo on branch `postgre`. The `ui-patterns` skill has the r
|
|
|
185
190
|
- `ToggleGroup.{Item}` A row of toggle buttons where one or several stay pressed.
|
|
186
191
|
- `Tooltip.{Provider, Trigger, Content}` A short label that shows on hover or focus of its trigger.
|
|
187
192
|
- `Upload` An image upload: a preview tile, an upload button and a remove button.
|
|
193
|
+
- `useFieldControl()` A form row's label, error and state for its control.
|
|
188
194
|
|
|
189
195
|
## Plugin runtime
|
|
190
196
|
|
|
@@ -240,6 +246,7 @@ core's, in the erxes repo on branch `postgre`. The `ui-patterns` skill has the r
|
|
|
240
246
|
- `toast({ title, description, variant, action })` Shows a toast: `toast({ title, description, variant: 'success' })`.
|
|
241
247
|
- `toIsoDay(date)` A local day as stored and typed, `yyyy-MM-dd`, in every language.
|
|
242
248
|
- `useConfirm()` `confirm` shows a confirmation dialog in its own root.
|
|
249
|
+
- `useFocusFirstField(ref)` Puts the cursor in the first field under `ref` when the form opens.
|
|
243
250
|
- `useFormat()` Date, number and money formatters in the UI's language, for components.
|
|
244
251
|
- `useItemKeys(length)` Stable React keys for an editable list whose items have no id.
|
|
245
252
|
- `useMoney()` `formatMoney` in the UI's language.
|
|
@@ -5,6 +5,7 @@ import { Command } from "./command.js";
|
|
|
5
5
|
import { Skeleton } from "./skeleton.js";
|
|
6
6
|
import { Spinner } from "./spinner.js";
|
|
7
7
|
import { useCellLabel } from "../modules/record-table/components/RecordTableCell.js";
|
|
8
|
+
import { useFieldState } from "./field-control.js";
|
|
8
9
|
import { IconCheck, IconChevronDown, IconX } from "@tabler/icons-react";
|
|
9
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
11
|
import "react";
|
|
@@ -12,14 +13,16 @@ import { useOnInView } from "react-intersection-observer";
|
|
|
12
13
|
// src/components/combobox.tsx
|
|
13
14
|
const ComboboxTriggerBase = ({ ref, className, children, hideChevron = false, variant = "outline", id, ...props }) => {
|
|
14
15
|
const label = useCellLabel(id);
|
|
16
|
+
const field = useFieldState();
|
|
15
17
|
return /* @__PURE__ */ jsx(Popover.Trigger, {
|
|
16
18
|
render: /* @__PURE__ */ jsx(Button, {
|
|
19
|
+
...field,
|
|
17
20
|
...label,
|
|
18
21
|
ref,
|
|
19
22
|
variant: variant === "bordered" ? "outline" : variant,
|
|
20
23
|
...props,
|
|
21
24
|
type: "button",
|
|
22
|
-
className: cn("flex truncate h-7 rounded pl-3 transition focus-visible:shadow-focus outline-hidden focus-visible:outline-hidden focus-visible:outline-offset-0 focus-visible:outline-transparent justify-start overflow-hidden font-normal text-left w-full gap-1", variant === "outline" && "shadow-xs", variant === "bordered" && "border border-input shadow-none", variant === "ghost" && "px-2", props.size === "lg" && "gap-2", props.size === "icon" && "justify-center px-0", className)
|
|
25
|
+
className: cn("flex truncate h-7 rounded pl-3 transition focus-visible:shadow-focus outline-hidden focus-visible:outline-hidden focus-visible:outline-offset-0 focus-visible:outline-transparent justify-start overflow-hidden font-normal text-left w-full gap-1", variant === "outline" && "shadow-xs", variant === "bordered" && "border border-input shadow-none aria-invalid:border-destructive", variant === "ghost" && "px-2", props.size === "lg" && "gap-2", props.size === "icon" && "justify-center px-0", className)
|
|
23
26
|
}),
|
|
24
27
|
children
|
|
25
28
|
});
|
|
@@ -6,8 +6,11 @@ declare const DialogBackdrop: ({ className, ...props }: Dialog$1.Backdrop.Props)
|
|
|
6
6
|
declare const dialogContentVariants: (props?: ({
|
|
7
7
|
variant?: "bare" | "default" | null | undefined;
|
|
8
8
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The backdrop dims the page and the viewport centers the popup; a press on either closes the dialog.
|
|
11
|
+
* It opens with the cursor in its first field, when it has one.
|
|
12
|
+
*/
|
|
13
|
+
declare const DialogContent: ({ ref, className, variant, initialFocus, ...props }: Dialog$1.Popup.Props & VariantProps<typeof dialogContentVariants>) => React.JSX.Element;
|
|
11
14
|
declare const DialogCombinedHeader: ({ title, description, hideClose }: {
|
|
12
15
|
title: string;
|
|
13
16
|
description: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findFirstField } from "../hooks/use-focus-first-field.js";
|
|
2
|
+
import { cn, mergeRefs } from "../lib/utils.js";
|
|
2
3
|
import { Button } from "./button.js";
|
|
3
4
|
import { IconX } from "@tabler/icons-react";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import "react";
|
|
6
|
+
import React from "react";
|
|
6
7
|
import { cva } from "class-variance-authority";
|
|
7
8
|
import { useTranslation } from "react-i18next";
|
|
8
9
|
import { Dialog as Dialog$1 } from "@base-ui/react/dialog";
|
|
@@ -21,14 +22,22 @@ const dialogContentVariants = cva("grid w-full max-w-lg gap-4 data-open:animate-
|
|
|
21
22
|
} },
|
|
22
23
|
defaultVariants: { variant: "default" }
|
|
23
24
|
});
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The backdrop dims the page and the viewport centers the popup; a press on either closes the dialog.
|
|
27
|
+
* It opens with the cursor in its first field, when it has one.
|
|
28
|
+
*/
|
|
29
|
+
const DialogContent = ({ ref, className, variant, initialFocus, ...props }) => {
|
|
30
|
+
const popupRef = React.useRef(null);
|
|
31
|
+
return /* @__PURE__ */ jsxs(Dialog$1.Portal, { children: [/* @__PURE__ */ jsx(DialogBackdrop, {}), /* @__PURE__ */ jsx(Dialog$1.Viewport, {
|
|
32
|
+
className: "fixed inset-0 z-50 grid place-items-center",
|
|
33
|
+
children: /* @__PURE__ */ jsx(Dialog$1.Popup, {
|
|
34
|
+
ref: mergeRefs(popupRef, ref),
|
|
35
|
+
initialFocus: initialFocus ?? (() => findFirstField(popupRef.current) ?? true),
|
|
36
|
+
className: cn(dialogContentVariants({ variant }), className),
|
|
37
|
+
...props
|
|
38
|
+
})
|
|
39
|
+
})] });
|
|
40
|
+
};
|
|
32
41
|
const DialogCombinedHeader = ({ title, description, hideClose }) => {
|
|
33
42
|
const { t } = useTranslation();
|
|
34
43
|
return /* @__PURE__ */ jsxs(Dialog.Header, { children: [
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** What a form row tells the control inside it: its label, its error or hint, and its state. */
|
|
2
|
+
export interface FieldControlProps {
|
|
3
|
+
'aria-labelledby'?: string;
|
|
4
|
+
'aria-describedby'?: string;
|
|
5
|
+
'aria-invalid'?: boolean;
|
|
6
|
+
'aria-required'?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Set by a form row (`PanelFormRow`) for the input, text box, select or picker in it.
|
|
10
|
+
* A popover's content starts again from none, so a search box in a picker isn't the field.
|
|
11
|
+
*/
|
|
12
|
+
export declare const FieldControlContext: import("react").Context<FieldControlProps | null>;
|
|
13
|
+
/** A form row's label, error and state for its control. Spread them before the control's own props. */
|
|
14
|
+
export declare const useFieldControl: () => FieldControlProps;
|
|
15
|
+
/** The row's error and state without its label, for a trigger the cell label already names. */
|
|
16
|
+
export declare const useFieldState: () => Omit<FieldControlProps, 'aria-labelledby'>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createContext, use } from "react";
|
|
2
|
+
// src/components/field-control.ts
|
|
3
|
+
/**
|
|
4
|
+
* Set by a form row (`PanelFormRow`) for the input, text box, select or picker in it.
|
|
5
|
+
* A popover's content starts again from none, so a search box in a picker isn't the field.
|
|
6
|
+
*/
|
|
7
|
+
const FieldControlContext = createContext(null);
|
|
8
|
+
/** A form row's label, error and state for its control. Spread them before the control's own props. */
|
|
9
|
+
const useFieldControl = () => use(FieldControlContext) ?? {};
|
|
10
|
+
/** The row's error and state without its label, for a trigger the cell label already names. */
|
|
11
|
+
const useFieldState = () => {
|
|
12
|
+
const field = useFieldControl();
|
|
13
|
+
return {
|
|
14
|
+
"aria-describedby": field["aria-describedby"],
|
|
15
|
+
"aria-invalid": field["aria-invalid"],
|
|
16
|
+
"aria-required": field["aria-required"]
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export { FieldControlContext, useFieldControl, useFieldState };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/** A card of a settings page or a record's own page: a title, a line about it, then its fields. */
|
|
3
|
+
export declare const FormSection: ({ title, description, action, children }: {
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
/** A control beside the title, such as a status badge. */
|
|
7
|
+
action?: ReactNode;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* The bar at the bottom of a page's one form: Discard and Save, kept in view while it scrolls.
|
|
12
|
+
* Both are off until something changed; it says so on the left. Discard goes back to the form's
|
|
13
|
+
* defaults unless `onDiscard` does more.
|
|
14
|
+
*/
|
|
15
|
+
export declare const FormSaveBar: ({ saving, saveLabel, onDiscard }: {
|
|
16
|
+
saving?: boolean;
|
|
17
|
+
saveLabel?: string;
|
|
18
|
+
onDiscard?: () => void;
|
|
19
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Button } from "./button.js";
|
|
2
|
+
import { Spinner } from "./spinner.js";
|
|
3
|
+
import { IconDeviceFloppy } from "@tabler/icons-react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useTranslation } from "react-i18next";
|
|
6
|
+
import { useFormContext, useFormState } from "react-hook-form";
|
|
7
|
+
// src/components/form-layout.tsx
|
|
8
|
+
/** A card of a settings page or a record's own page: a title, a line about it, then its fields. */
|
|
9
|
+
const FormSection = ({ title, description, action, children }) => /* @__PURE__ */ jsxs("section", {
|
|
10
|
+
className: "space-y-4 rounded-lg border bg-background p-5",
|
|
11
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
12
|
+
className: "flex items-start justify-between gap-4",
|
|
13
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
14
|
+
className: "min-w-0 space-y-0.5",
|
|
15
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
16
|
+
className: "text-base font-semibold",
|
|
17
|
+
children: title
|
|
18
|
+
}), description && /* @__PURE__ */ jsx("p", {
|
|
19
|
+
className: "text-sm text-muted-foreground",
|
|
20
|
+
children: description
|
|
21
|
+
})]
|
|
22
|
+
}), action]
|
|
23
|
+
}), children]
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* The bar at the bottom of a page's one form: Discard and Save, kept in view while it scrolls.
|
|
27
|
+
* Both are off until something changed; it says so on the left. Discard goes back to the form's
|
|
28
|
+
* defaults unless `onDiscard` does more.
|
|
29
|
+
*/
|
|
30
|
+
const FormSaveBar = ({ saving, saveLabel, onDiscard }) => {
|
|
31
|
+
const { t } = useTranslation("common", { keyPrefix: "form" });
|
|
32
|
+
const { reset } = useFormContext();
|
|
33
|
+
const { isDirty } = useFormState();
|
|
34
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
35
|
+
className: "sticky bottom-0 z-10 flex items-center justify-end gap-2 border-t bg-background/95 py-3 backdrop-blur",
|
|
36
|
+
children: [
|
|
37
|
+
isDirty && /* @__PURE__ */ jsx("output", {
|
|
38
|
+
className: "mr-auto text-xs text-muted-foreground",
|
|
39
|
+
children: t("unsaved", "Unsaved changes")
|
|
40
|
+
}),
|
|
41
|
+
/* @__PURE__ */ jsx(Button, {
|
|
42
|
+
type: "button",
|
|
43
|
+
variant: "ghost",
|
|
44
|
+
disabled: !isDirty || saving,
|
|
45
|
+
onClick: () => onDiscard ? onDiscard() : reset(),
|
|
46
|
+
children: t("discard", "Discard")
|
|
47
|
+
}),
|
|
48
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
49
|
+
type: "submit",
|
|
50
|
+
disabled: !isDirty || saving,
|
|
51
|
+
children: [saving ? /* @__PURE__ */ jsx(Spinner, { size: "sm" }) : /* @__PURE__ */ jsx(IconDeviceFloppy, {}), saveLabel ?? t("save", "Save")]
|
|
52
|
+
})
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
export { FormSaveBar, FormSection };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FormSaveBar, FormSection } from "./form-layout.js";
|
|
1
2
|
import { Label } from "./label.js";
|
|
2
3
|
import React from "react";
|
|
3
4
|
import { VariantProps } from "class-variance-authority";
|
|
@@ -26,7 +27,10 @@ declare const formItemVariants: (props?: ({
|
|
|
26
27
|
orientation?: "horizontal" | "vertical" | null | undefined;
|
|
27
28
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
28
29
|
declare const FormItem: ({ ref, className, orientation, ...props }: React.ComponentProps<'div'> & VariantProps<typeof formItemVariants>) => React.JSX.Element;
|
|
29
|
-
declare const FormLabel: ({ className, ...props }: React.ComponentProps<typeof Label>
|
|
30
|
+
declare const FormLabel: ({ className, children, required, ...props }: React.ComponentProps<typeof Label> & {
|
|
31
|
+
/** Marks the field as one the form can't be saved without. */
|
|
32
|
+
required?: boolean;
|
|
33
|
+
}) => React.JSX.Element;
|
|
30
34
|
/** Gives its one child the field's id and its description and error wiring. */
|
|
31
35
|
declare const FormControl: ({ children, ...props }: Omit<React.HTMLAttributes<HTMLElement>, 'children'> & {
|
|
32
36
|
children: React.ReactElement;
|
|
@@ -38,7 +42,8 @@ declare const formMessageVariants: (props?: ({
|
|
|
38
42
|
declare const FormMessage: ({ ref, className, children, variant, ...props }: React.ComponentProps<'p'> & VariantProps<typeof formMessageVariants>) => React.JSX.Element | null;
|
|
39
43
|
/**
|
|
40
44
|
* react-hook-form's provider with field, label, control and error parts.
|
|
41
|
-
* A settings page lays out `Form.Item`s with `Form.Label` above and `Form.Message` below
|
|
45
|
+
* A settings page lays out `Form.Item`s with `Form.Label` above and `Form.Message` below, in
|
|
46
|
+
* `Form.Section` cards, and ends with `Form.SaveBar`.
|
|
42
47
|
*/
|
|
43
48
|
export declare const Form: (<TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>({ children, watch, getValues, getErrors, getFieldState, setError, clearErrors, setValue, setValues, trigger, formState, resetField, reset, resetDefaultValues, handleSubmit, unregister, control, register, setFocus, subscribe }: import("react-hook-form").FormProviderProps<TFieldValues, TContext, TTransformedValues>) => React.JSX.Element) & {
|
|
44
49
|
Control: typeof FormControl;
|
|
@@ -47,6 +52,8 @@ export declare const Form: (<TFieldValues extends FieldValues, TContext = any, T
|
|
|
47
52
|
Item: typeof FormItem;
|
|
48
53
|
Label: typeof FormLabel;
|
|
49
54
|
Message: typeof FormMessage;
|
|
55
|
+
SaveBar: typeof FormSaveBar;
|
|
56
|
+
Section: typeof FormSection;
|
|
50
57
|
useField: typeof useFormField;
|
|
51
58
|
};
|
|
52
59
|
export {};
|
package/dist/components/form.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { FormSaveBar, FormSection } from "./form-layout.js";
|
|
1
2
|
import { Label } from "./label.js";
|
|
2
3
|
import { cn } from "../lib/utils.js";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
5
|
import React from "react";
|
|
5
6
|
import { cva } from "class-variance-authority";
|
|
6
|
-
import { Controller, FormProvider, useFormContext } from "react-hook-form";
|
|
7
|
+
import { Controller, FormProvider, useFormContext, useFormState } from "react-hook-form";
|
|
7
8
|
import { useRender } from "@base-ui/react/use-render";
|
|
8
9
|
// src/components/form.tsx
|
|
9
10
|
const FormFieldContext = React.createContext(null);
|
|
@@ -17,7 +18,8 @@ const FormField = ({ ...props }) => {
|
|
|
17
18
|
const useFormField = () => {
|
|
18
19
|
const fieldContext = React.useContext(FormFieldContext);
|
|
19
20
|
const itemContext = React.useContext(FormItemContext);
|
|
20
|
-
const { getFieldState
|
|
21
|
+
const { getFieldState } = useFormContext();
|
|
22
|
+
const formState = useFormState({ name: fieldContext?.name });
|
|
21
23
|
const fallbackId = React.useId();
|
|
22
24
|
const fieldState = fieldContext ? getFieldState(fieldContext.name, formState) : { error: void 0 };
|
|
23
25
|
const id = itemContext?.id ?? fallbackId;
|
|
@@ -50,12 +52,17 @@ const FormItem = ({ ref, className, orientation, ...props }) => {
|
|
|
50
52
|
})
|
|
51
53
|
});
|
|
52
54
|
};
|
|
53
|
-
const FormLabel = ({ className, ...props }) => {
|
|
55
|
+
const FormLabel = ({ className, children, required, ...props }) => {
|
|
54
56
|
const { error, formItemId } = useFormField();
|
|
55
|
-
return /* @__PURE__ */
|
|
57
|
+
return /* @__PURE__ */ jsxs(Label, {
|
|
56
58
|
className: cn(error && "text-destructive", className),
|
|
57
59
|
htmlFor: formItemId,
|
|
58
|
-
...props
|
|
60
|
+
...props,
|
|
61
|
+
children: [children, required && /* @__PURE__ */ jsx("span", {
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
className: "text-destructive",
|
|
64
|
+
children: " *"
|
|
65
|
+
})]
|
|
59
66
|
});
|
|
60
67
|
};
|
|
61
68
|
/** Gives its one child the field's id and its description and error wiring. */
|
|
@@ -101,7 +108,8 @@ const FormMessage = ({ ref, className, children, variant, ...props }) => {
|
|
|
101
108
|
};
|
|
102
109
|
/**
|
|
103
110
|
* react-hook-form's provider with field, label, control and error parts.
|
|
104
|
-
* A settings page lays out `Form.Item`s with `Form.Label` above and `Form.Message` below
|
|
111
|
+
* A settings page lays out `Form.Item`s with `Form.Label` above and `Form.Message` below, in
|
|
112
|
+
* `Form.Section` cards, and ends with `Form.SaveBar`.
|
|
105
113
|
*/
|
|
106
114
|
const Form = Object.assign(FormProvider, {
|
|
107
115
|
Control: FormControl,
|
|
@@ -110,6 +118,8 @@ const Form = Object.assign(FormProvider, {
|
|
|
110
118
|
Item: FormItem,
|
|
111
119
|
Label: FormLabel,
|
|
112
120
|
Message: FormMessage,
|
|
121
|
+
SaveBar: FormSaveBar,
|
|
122
|
+
Section: FormSection,
|
|
113
123
|
useField: useFormField
|
|
114
124
|
});
|
|
115
125
|
export { Form };
|
package/dist/components/input.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.js";
|
|
2
|
+
import { useFieldControl } from "./field-control.js";
|
|
2
3
|
import { jsx } from "react/jsx-runtime";
|
|
3
4
|
import "react";
|
|
4
5
|
import { cva } from "class-variance-authority";
|
|
@@ -12,7 +13,7 @@ const fieldTextVariants = {
|
|
|
12
13
|
otp: "font-mono tracking-widest text-center",
|
|
13
14
|
title: "text-base font-medium"
|
|
14
15
|
};
|
|
15
|
-
const inputVariants = cva("flex h-7 w-full rounded-sm bg-background px-3 py-1 text-sm text-foreground shadow-xs transition placeholder:text-accent-foreground focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 focus-visible:shadow-focus aria-invalid:focus-visible:shadow-focus-destructive", {
|
|
16
|
+
const inputVariants = cva("flex h-7 w-full rounded-sm bg-background px-3 py-1 text-sm text-foreground shadow-xs transition placeholder:text-accent-foreground focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 focus-visible:shadow-focus aria-invalid:shadow-destructive aria-invalid:focus-visible:shadow-focus-destructive", {
|
|
16
17
|
variants: {
|
|
17
18
|
type: {
|
|
18
19
|
file: "file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground",
|
|
@@ -23,7 +24,7 @@ const inputVariants = cva("flex h-7 w-full rounded-sm bg-background px-3 py-1 te
|
|
|
23
24
|
variant: {
|
|
24
25
|
default: "",
|
|
25
26
|
secondary: "bg-muted shadow-none focus-visible:shadow-subtle aria-invalid:focus-visible:shadow-destructive",
|
|
26
|
-
bordered: "border border-input shadow-none",
|
|
27
|
+
bordered: "border border-input shadow-none aria-invalid:border-destructive",
|
|
27
28
|
flush: "rounded-none shadow-none"
|
|
28
29
|
},
|
|
29
30
|
text: fieldTextVariants
|
|
@@ -35,7 +36,9 @@ const inputVariants = cva("flex h-7 w-full rounded-sm bg-background px-3 py-1 te
|
|
|
35
36
|
}
|
|
36
37
|
});
|
|
37
38
|
const InputMain = ({ ref, className, type, variant, text, ...props }) => {
|
|
39
|
+
const field = useFieldControl();
|
|
38
40
|
return /* @__PURE__ */ jsx("input", {
|
|
41
|
+
...field,
|
|
39
42
|
type,
|
|
40
43
|
autoComplete: "off",
|
|
41
44
|
className: cn(inputVariants({
|
|
@@ -49,7 +52,9 @@ const InputMain = ({ ref, className, type, variant, text, ...props }) => {
|
|
|
49
52
|
};
|
|
50
53
|
/** A number with thousands separators; `onChange` gets the number, or '' when cleared. */
|
|
51
54
|
const InputNumber = ({ value, onChange, className, ...props }) => {
|
|
55
|
+
const field = useFieldControl();
|
|
52
56
|
return /* @__PURE__ */ jsx(IMaskInput, {
|
|
57
|
+
...field,
|
|
53
58
|
mask: Number,
|
|
54
59
|
onAccept: (accepted) => {
|
|
55
60
|
onChange?.(accepted ? Number(accepted) : "");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.js";
|
|
2
|
+
import { useFieldControl } from "./field-control.js";
|
|
2
3
|
import { IconX } from "@tabler/icons-react";
|
|
3
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
5
|
import { useRef, useState } from "react";
|
|
@@ -7,6 +8,7 @@ import { Combobox } from "@base-ui/react/combobox";
|
|
|
7
8
|
/** The picked badges, the input and the clear-all button. */
|
|
8
9
|
const SelectorField = ({ fieldRef, value, placeholder, hidePlaceholderWhenSelected, disabled, id, className }) => {
|
|
9
10
|
const empty = value.length === 0;
|
|
11
|
+
const field = useFieldControl();
|
|
10
12
|
return /* @__PURE__ */ jsx(Combobox.Chips, {
|
|
11
13
|
ref: fieldRef,
|
|
12
14
|
className: cn("relative min-h-7 rounded shadow-xs transition text-sm focus-within:outline-hidden focus-within:shadow-focus has-disabled:cursor-not-allowed has-disabled:opacity-50 pe-9", !empty && "py-1 ps-1", !disabled && !empty && "cursor-text", className),
|
|
@@ -28,9 +30,10 @@ const SelectorField = ({ fieldRef, value, placeholder, hidePlaceholderWhenSelect
|
|
|
28
30
|
/* @__PURE__ */ jsx("div", {
|
|
29
31
|
className: "flex items-center bg-background min-w-0 flex-1 basis-32 rounded-lg overflow-hidden",
|
|
30
32
|
children: /* @__PURE__ */ jsx(Combobox.Input, {
|
|
33
|
+
...field,
|
|
31
34
|
id,
|
|
32
35
|
placeholder: hidePlaceholderWhenSelected && !empty ? "" : placeholder,
|
|
33
|
-
className: cn("flex h-7 w-full flex-1 rounded-md bg-transparent text-sm
|
|
36
|
+
className: cn("flex h-7 w-full flex-1 rounded-md bg-transparent text-sm outline-hidden placeholder:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50", empty ? "px-3 py-2" : "ml-1 px-3")
|
|
34
37
|
})
|
|
35
38
|
}),
|
|
36
39
|
/* @__PURE__ */ jsx(Combobox.Clear, {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn, mergeRefs } from "../lib/utils.js";
|
|
2
|
+
import { FieldControlContext } from "./field-control.js";
|
|
2
3
|
import { jsx } from "react/jsx-runtime";
|
|
3
4
|
import { useRef } from "react";
|
|
4
5
|
import { cva } from "class-variance-authority";
|
|
@@ -22,19 +23,22 @@ const popoverContentVariants = cva("w-72 rounded-md bg-background text-sm shadow
|
|
|
22
23
|
const PopoverContent = ({ ref, className, side = "bottom", sideOffset = 4, align = "center", alignOffset = 0, collisionPadding = 0, anchor, variant, disableTransition, initialFocus, ...props }) => {
|
|
23
24
|
const popupRef = useRef(null);
|
|
24
25
|
const focusCommand = () => popupRef.current?.querySelector("[cmdk-root]:not(:has([cmdk-input]))") ?? true;
|
|
25
|
-
return /* @__PURE__ */ jsx(Popover$1.Portal, { children: /* @__PURE__ */ jsx(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
return /* @__PURE__ */ jsx(Popover$1.Portal, { children: /* @__PURE__ */ jsx(FieldControlContext, {
|
|
27
|
+
value: null,
|
|
28
|
+
children: /* @__PURE__ */ jsx(Popover$1.Positioner, {
|
|
29
|
+
className: "isolate z-50",
|
|
30
|
+
side,
|
|
31
|
+
sideOffset,
|
|
32
|
+
align,
|
|
33
|
+
alignOffset,
|
|
34
|
+
collisionPadding,
|
|
35
|
+
anchor,
|
|
36
|
+
children: /* @__PURE__ */ jsx(Popover$1.Popup, {
|
|
37
|
+
ref: mergeRefs(popupRef, ref),
|
|
38
|
+
initialFocus: initialFocus ?? focusCommand,
|
|
39
|
+
className: cn(popoverContentVariants({ variant }), !disableTransition && "data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className),
|
|
40
|
+
...props
|
|
41
|
+
})
|
|
38
42
|
})
|
|
39
43
|
}) });
|
|
40
44
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.js";
|
|
2
2
|
import { useCellLabel } from "../modules/record-table/components/RecordTableCell.js";
|
|
3
|
+
import { useFieldState } from "./field-control.js";
|
|
3
4
|
import { IconCheck, IconChevronDown, IconChevronUp } from "@tabler/icons-react";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
import { createContext, use, useCallback, useLayoutEffect, useState } from "react";
|
|
@@ -31,23 +32,27 @@ const SelectRoot = ({ value, defaultValue, onValueChange, ...props }) => {
|
|
|
31
32
|
});
|
|
32
33
|
};
|
|
33
34
|
const SelectGroup = (props) => use(CollectingContext) ? props.children : /* @__PURE__ */ jsx(Select$1.Group, { ...props });
|
|
34
|
-
const selectTriggerVariants = cva("flex h-7 w-full items-center font-medium justify-between whitespace-nowrap rounded bg-transparent px-3 py-1 transition text-sm shadow-xs data-placeholder:text-accent-foreground focus:outline-hidden focus:shadow-focus data-disabled:cursor-not-allowed data-disabled:opacity-50 [&>span]:line-clamp-1", {
|
|
35
|
+
const selectTriggerVariants = cva("flex h-7 w-full items-center font-medium justify-between whitespace-nowrap rounded bg-transparent px-3 py-1 transition text-sm shadow-xs data-placeholder:text-accent-foreground focus:outline-hidden focus:shadow-focus aria-invalid:shadow-destructive aria-invalid:focus:shadow-focus-destructive data-disabled:cursor-not-allowed data-disabled:opacity-50 [&>span]:line-clamp-1", {
|
|
35
36
|
variants: { variant: {
|
|
36
37
|
default: "",
|
|
37
|
-
bordered: "border border-input font-normal shadow-none",
|
|
38
|
+
bordered: "border border-input font-normal shadow-none aria-invalid:border-destructive",
|
|
38
39
|
flush: "rounded-none shadow-none"
|
|
39
40
|
} },
|
|
40
41
|
defaultVariants: { variant: "default" }
|
|
41
42
|
});
|
|
42
|
-
const SelectTrigger = ({ className, children, variant, id, ...props }) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const SelectTrigger = ({ className, children, variant, id, ...props }) => {
|
|
44
|
+
const field = useFieldState();
|
|
45
|
+
return /* @__PURE__ */ jsxs(Select$1.Trigger, {
|
|
46
|
+
...field,
|
|
47
|
+
...useCellLabel(id),
|
|
48
|
+
className: cn(selectTriggerVariants({ variant }), className),
|
|
49
|
+
...props,
|
|
50
|
+
children: [children, /* @__PURE__ */ jsx(IconChevronDown, {
|
|
51
|
+
"aria-hidden": true,
|
|
52
|
+
className: "w-4 h-4 opacity-50"
|
|
53
|
+
})]
|
|
54
|
+
});
|
|
55
|
+
};
|
|
51
56
|
const SelectContent = ({ className, children, side = "bottom", align = "center", ...props }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(CollectingContext, {
|
|
52
57
|
value: true,
|
|
53
58
|
children
|
|
@@ -10,8 +10,11 @@ declare const sheetVariants: (props?: ({
|
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
/** Dims the page under a sheet. View renders one. */
|
|
12
12
|
declare const SheetBackdrop: ({ className, ...props }: Dialog.Backdrop.Props) => React.JSX.Element;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The backdrop fades in under the panel, which slides in from its side and fades with it.
|
|
15
|
+
* It opens with the cursor in its first field, when it has one.
|
|
16
|
+
*/
|
|
17
|
+
declare const SheetView: ({ ref, side, size, className, initialFocus, ...props }: Dialog.Popup.Props & VariantProps<typeof sheetVariants>) => React.JSX.Element;
|
|
15
18
|
/** The close icon button in a sheet header. */
|
|
16
19
|
declare const SheetClose: ({ className }: {
|
|
17
20
|
className?: string;
|
package/dist/components/sheet.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Button } from "./button.js";
|
|
2
|
-
import {
|
|
2
|
+
import { findFirstField } from "../hooks/use-focus-first-field.js";
|
|
3
|
+
import { cn, mergeRefs } from "../lib/utils.js";
|
|
3
4
|
import { IconX } from "@tabler/icons-react";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
import React from "react";
|
|
@@ -54,14 +55,22 @@ const SheetBackdrop = ({ className, ...props }) => /* @__PURE__ */ jsx(Dialog.Ba
|
|
|
54
55
|
className: cn("fixed inset-0 z-50 bg-black/25 data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-open:duration-200 data-closed:duration-200 data-closed:animation-forwards", className),
|
|
55
56
|
...props
|
|
56
57
|
});
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The backdrop fades in under the panel, which slides in from its side and fades with it.
|
|
60
|
+
* It opens with the cursor in its first field, when it has one.
|
|
61
|
+
*/
|
|
62
|
+
const SheetView = ({ ref, side = "right", size, className, initialFocus, ...props }) => {
|
|
63
|
+
const popupRef = React.useRef(null);
|
|
64
|
+
return /* @__PURE__ */ jsxs(Dialog.Portal, { children: [/* @__PURE__ */ jsx(SheetBackdrop, {}), /* @__PURE__ */ jsx(Dialog.Popup, {
|
|
65
|
+
ref: mergeRefs(popupRef, ref),
|
|
66
|
+
initialFocus: initialFocus ?? (() => findFirstField(popupRef.current) ?? true),
|
|
67
|
+
className: cn(sheetVariants({
|
|
68
|
+
side,
|
|
69
|
+
size
|
|
70
|
+
}), className),
|
|
71
|
+
...props
|
|
72
|
+
})] });
|
|
73
|
+
};
|
|
65
74
|
/** The close icon button in a sheet header. */
|
|
66
75
|
const SheetClose = ({ className }) => {
|
|
67
76
|
const { t } = useTranslation();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { useFieldControl } from "./field-control.js";
|
|
1
2
|
import { fieldTextVariants } from "./input.js";
|
|
2
3
|
import { cn } from "../lib/utils.js";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
4
5
|
import "react";
|
|
5
6
|
import { cva } from "class-variance-authority";
|
|
6
7
|
// src/components/textarea.tsx
|
|
7
|
-
const textareaVariants = cva("flex min-h-15 w-full rounded bg-transparent px-3 py-1.5 text-sm shadow-xs transition placeholder:text-accent-foreground focus-visible:outline-hidden focus-visible:shadow-focus disabled:cursor-not-allowed disabled:opacity-50", {
|
|
8
|
+
const textareaVariants = cva("flex min-h-15 w-full rounded bg-transparent px-3 py-1.5 text-sm shadow-xs transition placeholder:text-accent-foreground focus-visible:outline-hidden focus-visible:shadow-focus disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:shadow-destructive aria-invalid:focus-visible:shadow-focus-destructive", {
|
|
8
9
|
variants: {
|
|
9
10
|
variant: {
|
|
10
11
|
default: "",
|
|
@@ -21,7 +22,9 @@ const textareaVariants = cva("flex min-h-15 w-full rounded bg-transparent px-3 p
|
|
|
21
22
|
});
|
|
22
23
|
/** A themed multi-line text box; `flat` and `ghost` drop the border. */
|
|
23
24
|
const Textarea = ({ ref, className, variant, text, truncate, ...props }) => {
|
|
25
|
+
const field = useFieldControl();
|
|
24
26
|
return /* @__PURE__ */ jsx("textarea", {
|
|
27
|
+
...field,
|
|
25
28
|
className: cn(textareaVariants({
|
|
26
29
|
variant,
|
|
27
30
|
text,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
/** The first field to type into under `root`, if it has one. */
|
|
3
|
+
export declare const findFirstField: (root: Element | null | undefined) => HTMLElement | null;
|
|
4
|
+
/**
|
|
5
|
+
* Puts the cursor in the first field under `ref` when the form opens. For a page or panel whose
|
|
6
|
+
* one job is that form; it doesn't scroll the field into view.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useFocusFirstField: (ref: RefObject<HTMLElement | null>) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
// src/hooks/use-focus-first-field.ts
|
|
3
|
+
const FIRST_FIELD = "input:not([type=hidden],[type=file],[type=checkbox],[type=radio],:disabled), textarea:not(:disabled)";
|
|
4
|
+
/** The first field to type into under `root`, if it has one. */
|
|
5
|
+
const findFirstField = (root) => root?.querySelector(FIRST_FIELD) ?? null;
|
|
6
|
+
/**
|
|
7
|
+
* Puts the cursor in the first field under `ref` when the form opens. For a page or panel whose
|
|
8
|
+
* one job is that form; it doesn't scroll the field into view.
|
|
9
|
+
*/
|
|
10
|
+
const useFocusFirstField = (ref) => {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
findFirstField(ref.current)?.focus({ preventScroll: true });
|
|
13
|
+
}, [ref]);
|
|
14
|
+
};
|
|
15
|
+
export { findFirstField, useFocusFirstField };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Keys } from "react-hotkeys-hook";
|
|
2
|
+
/** Whether a dialog, menu or list is shown, other than one that holds `inside`. */
|
|
3
|
+
export declare const isOverlayShown: (inside?: Element | null) => boolean;
|
|
2
4
|
/**
|
|
3
5
|
* A page shortcut, skipped while typing or while a dialog or menu is open.
|
|
4
6
|
* Examples: `c` adds, `f` filters, `/` focuses the description, `mod+shift+enter` expands the
|