@deftui/addons 0.3.0 → 0.3.2

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/form.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { RHFField } from "./react-hook-form/field.mjs";
2
2
  import { RHFForm } from "./react-hook-form/form.mjs";
3
+ import { RHFCascader } from "./react-hook-form/widgets/cascader.mjs";
3
4
  import { RHFCombobox } from "./react-hook-form/widgets/combobox.mjs";
4
5
  import { RHFSelect } from "./react-hook-form/widgets/select.mjs";
5
6
  export declare const RHF: {
@@ -11,4 +12,6 @@ export declare const RHF: {
11
12
  Select: typeof RHFSelect;
12
13
  /** One-liner component for Combobox, used under {@link RHF.Field}. */
13
14
  Combobox: typeof RHFCombobox;
15
+ /** One-liner drill-mode component for Cascader, used under {@link RHF.Field}. */
16
+ Cascader: typeof RHFCascader;
14
17
  };
package/dist/form.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { RHFField } from "./react-hook-form/field.mjs";
2
2
  import { RHFForm } from "./react-hook-form/form.mjs";
3
+ import { RHFCascader } from "./react-hook-form/widgets/cascader.mjs";
3
4
  import { RHFCombobox } from "./react-hook-form/widgets/combobox.mjs";
4
5
  import { RHFSelect } from "./react-hook-form/widgets/select.mjs";
5
6
  // src/react-hook-form/index.ts
@@ -11,6 +12,8 @@ const RHF = {
11
12
  /** One-liner component for Select, used under {@link RHF.Field}. */
12
13
  Select: RHFSelect,
13
14
  /** One-liner component for Combobox, used under {@link RHF.Field}. */
14
- Combobox: RHFCombobox
15
+ Combobox: RHFCombobox,
16
+ /** One-liner drill-mode component for Cascader, used under {@link RHF.Field}. */
17
+ Cascader: RHFCascader
15
18
  };
16
19
  export { RHF };
@@ -1,10 +1,6 @@
1
+ import { InputControlProps } from "./widgets/types.mjs";
1
2
  import React from "react";
2
3
  import { FieldPath, FieldValues, UseControllerProps, UseControllerReturn } from "react-hook-form";
3
- interface ControlProps {
4
- "id": string;
5
- "aria-invalid": boolean;
6
- "aria-describedby": string | undefined;
7
- }
8
4
  interface RHFFieldProps<Values extends FieldValues, Name extends FieldPath<Values> = FieldPath<Values>, Output = Values> extends UseControllerProps<Values, Name, Output> {
9
5
  /** Label associated with the control's ID. */
10
6
  label?: React.ReactNode;
@@ -25,7 +21,8 @@ interface RHFFieldProps<Values extends FieldValues, Name extends FieldPath<Value
25
21
  */
26
22
  injectControlProps?: boolean;
27
23
  /** Callback with `useController` states and `controllerProps` for rendering JSX. */
28
- children: (state: UseControllerReturn<Values, Name>, controlProps: ControlProps) => React.ReactNode;
24
+ children: (state: UseControllerReturn<Values, Name>, controlProps: InputControlProps) => React.ReactNode;
25
+ className?: string;
29
26
  }
30
27
  export declare function RHFField<T extends FieldValues, Name extends FieldPath<T>, Output = T>(props: RHFFieldProps<T, Name, Output>): React.JSX.Element;
31
28
  export {};
@@ -4,7 +4,7 @@ import { useController } from "react-hook-form";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  // src/react-hook-form/field.tsx
6
6
  function RHFField(props) {
7
- const { label, associateLabel = false, description, injectControlProps = true, children, ...controllerProps } = props;
7
+ const { label, description, associateLabel = false, injectControlProps = true, className, children, ...controllerProps } = props;
8
8
  const id = useId();
9
9
  const controller = useController(controllerProps);
10
10
  const hasError = Boolean(controller.fieldState.error?.message);
@@ -21,6 +21,7 @@ function RHFField(props) {
21
21
  return /* @__PURE__ */ jsxs(Field, {
22
22
  "data-invalid": controller.fieldState.invalid,
23
23
  "data-disabled": controller.field.disabled,
24
+ className,
24
25
  children: [
25
26
  label != null && /* @__PURE__ */ jsx(Field.Label, {
26
27
  htmlFor: associateLabel ? controlId : void 0,
@@ -0,0 +1,15 @@
1
+ import { InputControlProps, OnValueChange } from "./types.mjs";
2
+ import { Cascader, CascaderProps, CascaderSingleProps } from "@deftui/react";
3
+ import { ComponentProps } from "react";
4
+ /** `Omit` on the whole union collapses the `multiple` discriminant; omit per branch. */
5
+ type OmitCascader<T, K extends string | number | symbol> = CascaderProps<T> extends (infer P) ? (P extends CascaderSingleProps<T> ? Omit<P, K> : never) : never;
6
+ type Props<T> = InputControlProps & OmitCascader<T, "invalid" | "children" | "onValueChange"> & Pick<ComponentProps<typeof Cascader.Input>, "placeholder"> & {
7
+ onChange?: OnValueChange;
8
+ /** Class on the trigger surface, e.g. its width. */
9
+ className?: ComponentProps<typeof Cascader.Trigger>["className"];
10
+ /** Class on the panel surface. The panel is wider than the trigger by design. */
11
+ popupClassName?: ComponentProps<typeof Cascader.Popup>["className"];
12
+ };
13
+ /** One-liner drill-mode Cascader: trigger + searchable panel with breadcrumb, rendered rows and status. */
14
+ export declare function RHFCascader<T>(props: Props<T>): import("react").JSX.Element;
15
+ export {};
@@ -0,0 +1,26 @@
1
+ import { Cascader } from "@deftui/react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ // src/react-hook-form/widgets/cascader.tsx
4
+ /** One-liner drill-mode Cascader: trigger + searchable panel with breadcrumb, rendered rows and status. */
5
+ function RHFCascader(props) {
6
+ const { placeholder, className, popupClassName, ...rootProps } = props;
7
+ return /* @__PURE__ */ jsxs(Cascader, {
8
+ ...rootProps,
9
+ onValueChange: rootProps.onChange,
10
+ invalid: Boolean(rootProps["aria-invalid"]),
11
+ children: [/* @__PURE__ */ jsx(Cascader.Trigger, {
12
+ className,
13
+ children: /* @__PURE__ */ jsx(Cascader.Value, { placeholder })
14
+ }), /* @__PURE__ */ jsx(Cascader.Popup, {
15
+ className: popupClassName,
16
+ children: /* @__PURE__ */ jsxs(Cascader.Panel, { children: [
17
+ /* @__PURE__ */ jsx(Cascader.Nav, { children: /* @__PURE__ */ jsx(Cascader.Input, { placeholder }) }),
18
+ /* @__PURE__ */ jsx(Cascader.Breadcrumb, {}),
19
+ /* @__PURE__ */ jsx(Cascader.Empty, {}),
20
+ /* @__PURE__ */ jsx(Cascader.List, { children: /* @__PURE__ */ jsx(Cascader.VirtualItems, {}) }),
21
+ /* @__PURE__ */ jsx(Cascader.Status, {})
22
+ ] })
23
+ })]
24
+ });
25
+ }
26
+ export { RHFCascader };
@@ -1,8 +1,7 @@
1
- import { OnValueChange, Options } from "./types.mjs";
1
+ import { InputControlProps, OnValueChange, Options } from "./types.mjs";
2
2
  import { Combobox } from "@deftui/react";
3
3
  import { ComponentProps } from "react";
4
- type Props<V extends string> // oxfmt-ignore
5
- = Omit<ComponentProps<typeof Combobox>, "items" | "children"> & Pick<ComponentProps<typeof Combobox.Input>, "size" | "placeholder" | "showClear" | "className"> & {
4
+ type Props<V extends string> = InputControlProps & Omit<ComponentProps<typeof Combobox>, "items" | "children" | "onValueChange"> & Pick<ComponentProps<typeof Combobox.Input>, "size" | "placeholder" | "showClear" | "className"> & {
6
5
  options: Options<V>;
7
6
  emptyLabel?: string;
8
7
  onChange?: OnValueChange;
@@ -9,8 +9,10 @@ function RHFCombobox(props) {
9
9
  items: options,
10
10
  children: [/* @__PURE__ */ jsx(Combobox.Input, {
11
11
  size,
12
- placeholder,
13
12
  showClear,
13
+ placeholder,
14
+ "aria-invalid": rootProps["aria-invalid"],
15
+ "aria-describedby": rootProps["aria-describedby"],
14
16
  className
15
17
  }), /* @__PURE__ */ jsxs(Combobox.Content, { children: [/* @__PURE__ */ jsx(Combobox.Empty, { children: emptyLabel }), /* @__PURE__ */ jsx(Combobox.List, { children: options.map((option) => /* @__PURE__ */ jsx(Combobox.Item, {
16
18
  value: option.value,
@@ -1,8 +1,7 @@
1
- import { OnValueChange, Options } from "./types.mjs";
1
+ import { InputControlProps, OnValueChange, Options } from "./types.mjs";
2
2
  import { Select } from "@deftui/react";
3
3
  import { ComponentProps } from "react";
4
- type Props<V extends string> // oxfmt-ignore
5
- = Omit<ComponentProps<typeof Select>, "items" | "children"> & Pick<ComponentProps<typeof Select.Trigger>, "size" | "className"> & Pick<ComponentProps<typeof Select.Value>, "placeholder" | "className"> & {
4
+ type Props<V extends string> = InputControlProps & Omit<ComponentProps<typeof Select>, "items" | "children" | "onValueChange"> & Pick<ComponentProps<typeof Select.Trigger>, "size" | "className"> & Pick<ComponentProps<typeof Select.Value>, "placeholder"> & {
6
5
  options: Options<V>;
7
6
  onChange?: OnValueChange;
8
7
  };
@@ -10,6 +10,8 @@ function RHFSelect(props) {
10
10
  children: [/* @__PURE__ */ jsx(Select.Trigger, {
11
11
  size,
12
12
  className,
13
+ "aria-invalid": rootProps["aria-invalid"],
14
+ "aria-describedby": rootProps["aria-describedby"],
13
15
  children: /* @__PURE__ */ jsx(Select.Value, { placeholder })
14
16
  }), /* @__PURE__ */ jsx(Select.Content, { children: options.map((option) => /* @__PURE__ */ jsx(Select.Item, {
15
17
  value: option.value,
@@ -1,6 +1,8 @@
1
+ import { ComponentProps } from "react";
1
2
  export type Options<V extends string> = readonly {
2
3
  label: string;
3
4
  value: V;
4
5
  disabled?: boolean;
5
6
  }[];
6
- export type OnValueChange = ((value: unknown, eventDetails: unknown) => void) | undefined;
7
+ export type OnValueChange = ((value: unknown, eventDetails: unknown) => void) | undefined;
8
+ export type InputControlProps = Pick<ComponentProps<"input">, "id" | "aria-invalid" | "aria-describedby">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deftui/addons",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/KiriRainCat/deftui.git",
@@ -40,7 +40,7 @@
40
40
  "fix": "vp check --fix"
41
41
  },
42
42
  "devDependencies": {
43
- "@deftui/react": "^0.3.0",
43
+ "@deftui/react": "^0.3.2",
44
44
  "@tanstack/react-router": "^1.170.46",
45
45
  "@types/react": "^19.3.0",
46
46
  "@types/react-dom": "^19.3.0",
@@ -49,7 +49,7 @@
49
49
  "vite-plus": "catalog:"
50
50
  },
51
51
  "peerDependencies": {
52
- "@deftui/react": "^0.3.0",
52
+ "@deftui/react": "^0.3.2",
53
53
  "@tanstack/react-router": "^1.170.0",
54
54
  "react": "^19.0.0",
55
55
  "react-dom": "^19.0.0",