@pixpilot/formily-shadcn 0.44.2 → 0.45.0
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/components/Checkbox.d.cts +2 -2
- package/dist/components/DatePicker.d.cts +3 -3
- package/dist/components/IconPicker.d.cts +3 -3
- package/dist/components/Input.d.cts +3 -3
- package/dist/components/Rating.d.cts +5 -5
- package/dist/components/Select.cjs +11 -8
- package/dist/components/Select.js +11 -8
- package/dist/components/Separator.d.cts +2 -2
- package/dist/components/Switch.d.cts +2 -2
- package/dist/components/Switch.d.ts +2 -2
- package/dist/components/TagsInputInline.d.cts +3 -3
- package/dist/components/TagsInputInline.d.ts +2 -2
- package/dist/components/Textarea.d.cts +2 -2
- package/dist/components/ToggleGroup.cjs +118 -0
- package/dist/components/ToggleGroup.d.cts +55 -0
- package/dist/components/ToggleGroup.d.ts +55 -0
- package/dist/components/ToggleGroup.js +113 -0
- package/dist/components/array-base/components/Addition.cjs +11 -3
- package/dist/components/array-base/components/Addition.js +11 -3
- package/dist/components/array-cards/ArrayCards.cjs +3 -2
- package/dist/components/array-cards/ArrayCards.js +3 -2
- package/dist/components/array-cards/Item.cjs +3 -2
- package/dist/components/array-cards/Item.js +3 -2
- package/dist/components/array-collapse/ArrayCollapse.cjs +3 -2
- package/dist/components/array-collapse/ArrayCollapse.d.cts +1 -0
- package/dist/components/array-collapse/ArrayCollapse.d.ts +1 -0
- package/dist/components/array-collapse/ArrayCollapse.js +3 -2
- package/dist/components/array-collapse/Item.cjs +2 -1
- package/dist/components/array-collapse/Item.js +2 -1
- package/dist/components/array-dialog/ArrayDialog.cjs +2 -1
- package/dist/components/array-dialog/ArrayDialog.d.cts +4 -1
- package/dist/components/array-dialog/ArrayDialog.d.ts +4 -1
- package/dist/components/array-dialog/ArrayDialog.js +2 -1
- package/dist/components/array-dialog/EditDialog.cjs +2 -1
- package/dist/components/array-dialog/EditDialog.js +2 -1
- package/dist/components/array-popover/ArrayPopover.cjs +3 -1
- package/dist/components/array-popover/ArrayPopover.d.cts +3 -1
- package/dist/components/array-popover/ArrayPopover.d.ts +3 -1
- package/dist/components/array-popover/ArrayPopover.js +3 -1
- package/dist/components/array-popover/Popover.cjs +12 -10
- package/dist/components/array-popover/Popover.js +12 -10
- package/dist/components/array-tags/ArrayTags.cjs +14 -11
- package/dist/components/array-tags/ArrayTags.d.cts +3 -1
- package/dist/components/array-tags/ArrayTags.d.ts +3 -1
- package/dist/components/array-tags/ArrayTags.js +15 -12
- package/dist/components/array-toggle-group/ArrayToggleGroup.cjs +123 -0
- package/dist/components/array-toggle-group/ArrayToggleGroup.d.cts +65 -0
- package/dist/components/array-toggle-group/ArrayToggleGroup.d.ts +65 -0
- package/dist/components/array-toggle-group/ArrayToggleGroup.js +118 -0
- package/dist/components/array-toggle-group/index.cjs +1 -0
- package/dist/components/array-toggle-group/index.d.cts +1 -0
- package/dist/components/array-toggle-group/index.d.ts +1 -0
- package/dist/components/array-toggle-group/index.js +1 -0
- package/dist/components/file-upload/FileUpload.d.cts +8 -8
- package/dist/components/file-upload/FileUpload.d.ts +8 -8
- package/dist/components/file-upload/FileUploadInline.d.cts +8 -8
- package/dist/components/file-upload/FileUploadInline.d.ts +8 -8
- package/dist/components/form-item/ConnectedFormItem.d.cts +4 -4
- package/dist/components/form-item/ConnectedFormItem.d.ts +4 -4
- package/dist/components/schema-field/schema-field-basics.cjs +11 -0
- package/dist/components/schema-field/schema-field-basics.d.cts +351 -265
- package/dist/components/schema-field/schema-field-basics.d.ts +356 -270
- package/dist/components/schema-field/schema-field-basics.js +11 -0
- package/dist/components/schema-field/schema-field-extended.d.cts +685 -599
- package/dist/components/schema-field/schema-field-extended.d.ts +686 -600
- package/dist/components/schema-field/schema-field.d.cts +465 -379
- package/dist/components/schema-field/schema-field.d.ts +465 -379
- package/dist/components/slider/Slider.d.cts +3 -3
- package/dist/components/slider/Slider.d.ts +2 -2
- package/dist/components/slider/SliderInput.d.cts +3 -3
- package/dist/components/slider/SliderInput.d.ts +2 -2
- package/dist/components/slider/SliderSelect.d.cts +2 -2
- package/dist/components/slider/SliderSelect.d.ts +3 -3
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/utils/index.cjs +1 -0
- package/dist/utils/index.d.cts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/resolve-field-options.cjs +70 -0
- package/dist/utils/resolve-field-options.d.cts +1 -0
- package/dist/utils/resolve-field-options.d.ts +1 -0
- package/dist/utils/resolve-field-options.js +69 -0
- package/dist/utils/transform-schema.cjs +28 -27
- package/dist/utils/transform-schema.js +28 -27
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react0 from "react";
|
|
2
2
|
import * as _radix_ui_react_checkbox0 from "@radix-ui/react-checkbox";
|
|
3
3
|
|
|
4
4
|
//#region src/components/Checkbox.d.ts
|
|
@@ -6,6 +6,6 @@ import * as _radix_ui_react_checkbox0 from "@radix-ui/react-checkbox";
|
|
|
6
6
|
* Formily-connected Checkbox component
|
|
7
7
|
* Maps Formily field checked state to shadcn Checkbox
|
|
8
8
|
*/
|
|
9
|
-
declare const Checkbox:
|
|
9
|
+
declare const Checkbox: react0.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_checkbox0.CheckboxProps & react0.RefAttributes<HTMLButtonElement>>, "ref"> & react0.RefAttributes<unknown>>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { Checkbox };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react2 from "react";
|
|
2
2
|
import { DatePickerProps } from "@pixpilot/shadcn-ui";
|
|
3
3
|
|
|
4
4
|
//#region src/components/DatePicker.d.ts
|
|
5
|
-
declare const DatePicker:
|
|
5
|
+
declare const DatePicker: react2.ForwardRefExoticComponent<Partial<{
|
|
6
6
|
value?: Date;
|
|
7
7
|
onChange?: (date: Date | undefined) => void;
|
|
8
8
|
placeholder?: string;
|
|
9
|
-
} & Omit<DatePickerProps, "onSelect" | "selected" | "mode">> &
|
|
9
|
+
} & Omit<DatePickerProps, "onSelect" | "selected" | "mode">> & react2.RefAttributes<unknown>>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { DatePicker };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react7 from "react";
|
|
2
2
|
import { IconPickerProps, IconProviderProps } from "@pixpilot/shadcn-ui";
|
|
3
3
|
|
|
4
4
|
//#region src/components/IconPicker.d.ts
|
|
@@ -8,8 +8,8 @@ import { IconPickerProps, IconProviderProps } from "@pixpilot/shadcn-ui";
|
|
|
8
8
|
* Automatically connects to Formily field state
|
|
9
9
|
* Supports both static and async icon providers
|
|
10
10
|
*/
|
|
11
|
-
declare const IconPicker:
|
|
11
|
+
declare const IconPicker: react7.ForwardRefExoticComponent<Partial<Omit<IconPickerProps, "providers"> & {
|
|
12
12
|
providers?: IconProviderProps[];
|
|
13
|
-
}> &
|
|
13
|
+
}> & react7.RefAttributes<unknown>>;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { IconPicker };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react9 from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/components/Input.d.ts
|
|
4
4
|
|
|
@@ -6,12 +6,12 @@ import * as react7 from "react";
|
|
|
6
6
|
* Formily-connected Input component
|
|
7
7
|
* Automatically connects shadcn Input to Formily field state
|
|
8
8
|
*/
|
|
9
|
-
declare const Input:
|
|
9
|
+
declare const Input: react9.ForwardRefExoticComponent<Omit<Partial<react9.ClassAttributes<HTMLInputElement> & react9.InputHTMLAttributes<HTMLInputElement> & {
|
|
10
10
|
prefix?: React.ReactNode;
|
|
11
11
|
suffix?: React.ReactNode;
|
|
12
12
|
groupClassName?: string;
|
|
13
13
|
prefixClassName?: string;
|
|
14
14
|
suffixClassName?: string;
|
|
15
|
-
}>, "ref"> &
|
|
15
|
+
}>, "ref"> & react9.RefAttributes<unknown>>;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { Input };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as react13 from "react";
|
|
2
|
+
import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
|
|
3
3
|
|
|
4
4
|
//#region src/components/Rating.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Formily-connected Rating component
|
|
7
7
|
* Automatically connects shadcn-ui Rating to Formily field state
|
|
8
8
|
*/
|
|
9
|
-
declare const Rating:
|
|
10
|
-
children?:
|
|
11
|
-
}> &
|
|
9
|
+
declare const Rating: react13.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui0.RatingProps & {
|
|
10
|
+
children?: react13.ReactNode | undefined;
|
|
11
|
+
}> & react13.RefAttributes<unknown>>;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { Rating };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_resolve_field_options = require('../utils/resolve-field-options.cjs');
|
|
2
3
|
let __formily_react = require("@formily/react");
|
|
3
4
|
__formily_react = require_rolldown_runtime.__toESM(__formily_react);
|
|
4
5
|
let __pixpilot_shadcn_ui = require("@pixpilot/shadcn-ui");
|
|
@@ -7,15 +8,17 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
7
8
|
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
8
9
|
|
|
9
10
|
//#region src/components/Select.tsx
|
|
10
|
-
function isOptionArray(value) {
|
|
11
|
-
return Array.isArray(value) && value.every((item) => typeof item === "object" && item !== null && "value" in item && "label" in item);
|
|
12
|
-
}
|
|
13
11
|
const SelectComponent = ({ mapOption, options,...props }) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const transformedOptions = require_resolve_field_options.resolveFieldOptions({
|
|
13
|
+
field: (0, __formily_react.useField)(),
|
|
14
|
+
options
|
|
15
|
+
})?.map((option) => {
|
|
16
|
+
const normalizedOption = {
|
|
17
|
+
value: option.value,
|
|
18
|
+
label: typeof option.label === "string" ? option.label : String(option.value)
|
|
19
|
+
};
|
|
20
|
+
return mapOption ? mapOption(normalizedOption) : normalizedOption;
|
|
21
|
+
});
|
|
19
22
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn_ui.Select, {
|
|
20
23
|
...props,
|
|
21
24
|
options: transformedOptions
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { resolveFieldOptions } from "../utils/resolve-field-options.js";
|
|
1
2
|
import { connect, mapProps, useField } from "@formily/react";
|
|
2
3
|
import { Select } from "@pixpilot/shadcn-ui";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
4
5
|
|
|
5
6
|
//#region src/components/Select.tsx
|
|
6
|
-
function isOptionArray(value) {
|
|
7
|
-
return Array.isArray(value) && value.every((item) => typeof item === "object" && item !== null && "value" in item && "label" in item);
|
|
8
|
-
}
|
|
9
7
|
const SelectComponent = ({ mapOption, options,...props }) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const transformedOptions = resolveFieldOptions({
|
|
9
|
+
field: useField(),
|
|
10
|
+
options
|
|
11
|
+
})?.map((option) => {
|
|
12
|
+
const normalizedOption = {
|
|
13
|
+
value: option.value,
|
|
14
|
+
label: typeof option.label === "string" ? option.label : String(option.value)
|
|
15
|
+
};
|
|
16
|
+
return mapOption ? mapOption(normalizedOption) : normalizedOption;
|
|
17
|
+
});
|
|
15
18
|
return /* @__PURE__ */ jsx(Select, {
|
|
16
19
|
...props,
|
|
17
20
|
options: transformedOptions
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react16 from "react";
|
|
2
2
|
import * as _radix_ui_react_separator0 from "@radix-ui/react-separator";
|
|
3
3
|
|
|
4
4
|
//#region src/components/Separator.d.ts
|
|
@@ -6,6 +6,6 @@ import * as _radix_ui_react_separator0 from "@radix-ui/react-separator";
|
|
|
6
6
|
* Formily-connected Separator component
|
|
7
7
|
* A visual divider for content sections
|
|
8
8
|
*/
|
|
9
|
-
declare const Separator:
|
|
9
|
+
declare const Separator: react16.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_separator0.SeparatorProps & react16.RefAttributes<HTMLDivElement>>, "ref"> & react16.RefAttributes<unknown>>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { Separator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react19 from "react";
|
|
2
2
|
import * as _radix_ui_react_switch0 from "@radix-ui/react-switch";
|
|
3
3
|
|
|
4
4
|
//#region src/components/Switch.d.ts
|
|
@@ -6,6 +6,6 @@ import * as _radix_ui_react_switch0 from "@radix-ui/react-switch";
|
|
|
6
6
|
* Formily-connected Switch component
|
|
7
7
|
* Toggle switch for boolean values
|
|
8
8
|
*/
|
|
9
|
-
declare const Switch:
|
|
9
|
+
declare const Switch: react19.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_switch0.SwitchProps & react19.RefAttributes<HTMLButtonElement>>, "ref"> & react19.RefAttributes<unknown>>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { Switch };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react19 from "react";
|
|
2
2
|
import * as _radix_ui_react_switch0 from "@radix-ui/react-switch";
|
|
3
3
|
|
|
4
4
|
//#region src/components/Switch.d.ts
|
|
@@ -6,6 +6,6 @@ import * as _radix_ui_react_switch0 from "@radix-ui/react-switch";
|
|
|
6
6
|
* Formily-connected Switch component
|
|
7
7
|
* Toggle switch for boolean values
|
|
8
8
|
*/
|
|
9
|
-
declare const Switch:
|
|
9
|
+
declare const Switch: react19.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_switch0.SwitchProps & react19.RefAttributes<HTMLButtonElement>>, "ref"> & react19.RefAttributes<unknown>>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { Switch };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as react22 from "react";
|
|
2
|
+
import * as _pixpilot_shadcn_ui1 from "@pixpilot/shadcn-ui";
|
|
3
3
|
|
|
4
4
|
//#region src/components/TagsInputInline.d.ts
|
|
5
5
|
|
|
@@ -10,6 +10,6 @@ import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
|
|
|
10
10
|
* Based on DiceUI's tags-input for inline tag editing with keyboard navigation
|
|
11
11
|
* and validation support.
|
|
12
12
|
*/
|
|
13
|
-
declare const TagsInputInLine:
|
|
13
|
+
declare const TagsInputInLine: react22.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui1.TagsInputProps> & react22.RefAttributes<unknown>>;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { TagsInputInLine };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react22 from "react";
|
|
2
2
|
import * as _pixpilot_shadcn_ui1 from "@pixpilot/shadcn-ui";
|
|
3
3
|
|
|
4
4
|
//#region src/components/TagsInputInline.d.ts
|
|
@@ -10,6 +10,6 @@ import * as _pixpilot_shadcn_ui1 from "@pixpilot/shadcn-ui";
|
|
|
10
10
|
* Based on DiceUI's tags-input for inline tag editing with keyboard navigation
|
|
11
11
|
* and validation support.
|
|
12
12
|
*/
|
|
13
|
-
declare const TagsInputInLine:
|
|
13
|
+
declare const TagsInputInLine: react22.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui1.TagsInputProps> & react22.RefAttributes<unknown>>;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { TagsInputInLine };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react24 from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/components/Textarea.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Formily-connected Textarea component
|
|
6
6
|
*/
|
|
7
|
-
declare const Textarea:
|
|
7
|
+
declare const Textarea: react24.ForwardRefExoticComponent<Omit<Partial<react24.ClassAttributes<HTMLTextAreaElement> & react24.TextareaHTMLAttributes<HTMLTextAreaElement>>, "ref"> & react24.RefAttributes<unknown>>;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { Textarea };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_resolve_field_options = require('../utils/resolve-field-options.cjs');
|
|
3
|
+
let __formily_react = require("@formily/react");
|
|
4
|
+
__formily_react = require_rolldown_runtime.__toESM(__formily_react);
|
|
5
|
+
let react = require("react");
|
|
6
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
7
|
+
let __pixpilot_shadcn_ui = require("@pixpilot/shadcn-ui");
|
|
8
|
+
__pixpilot_shadcn_ui = require_rolldown_runtime.__toESM(__pixpilot_shadcn_ui);
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
11
|
+
|
|
12
|
+
//#region src/components/ToggleGroup.tsx
|
|
13
|
+
function toVariant(input) {
|
|
14
|
+
return input === "outline" || input === "default" ? input : void 0;
|
|
15
|
+
}
|
|
16
|
+
function toSize(input) {
|
|
17
|
+
return input === "sm" || input === "lg" || input === "default" ? input : void 0;
|
|
18
|
+
}
|
|
19
|
+
function isToggleGroupValue(value) {
|
|
20
|
+
return typeof value === "string" || typeof value === "number";
|
|
21
|
+
}
|
|
22
|
+
function coerceOptions(options) {
|
|
23
|
+
if (!Array.isArray(options)) return [];
|
|
24
|
+
return options.map((option) => {
|
|
25
|
+
const { value, label, disabled } = option;
|
|
26
|
+
if (!isToggleGroupValue(value)) return null;
|
|
27
|
+
return {
|
|
28
|
+
value,
|
|
29
|
+
label,
|
|
30
|
+
disabled: Boolean(disabled)
|
|
31
|
+
};
|
|
32
|
+
}).filter((v) => v !== null);
|
|
33
|
+
}
|
|
34
|
+
function ToggleGroupBase({ options, value, defaultValue, onValueChange, allowEmptySelection = false, variant = "outline", size, buttonClassName, ref,...props }) {
|
|
35
|
+
const valueString = value === void 0 ? void 0 : String(value);
|
|
36
|
+
const defaultValueString = defaultValue === void 0 ? void 0 : String(defaultValue);
|
|
37
|
+
const valueByString = react.useMemo(() => {
|
|
38
|
+
const map = /* @__PURE__ */ new Map();
|
|
39
|
+
for (const option of options) map.set(String(option.value), option.value);
|
|
40
|
+
return map;
|
|
41
|
+
}, [options]);
|
|
42
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn_ui.ToggleGroup, {
|
|
43
|
+
...props,
|
|
44
|
+
ref,
|
|
45
|
+
type: "single",
|
|
46
|
+
value: valueString,
|
|
47
|
+
defaultValue: defaultValueString,
|
|
48
|
+
variant: toVariant(variant),
|
|
49
|
+
size: toSize(size),
|
|
50
|
+
onValueChange: (nextValue) => {
|
|
51
|
+
if (nextValue === "") {
|
|
52
|
+
if (allowEmptySelection !== true) return;
|
|
53
|
+
onValueChange?.(void 0);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
onValueChange?.(valueByString.get(nextValue) ?? nextValue);
|
|
57
|
+
},
|
|
58
|
+
children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn_ui.ToggleGroupItem, {
|
|
59
|
+
value: String(option.value),
|
|
60
|
+
"aria-label": String(option.value),
|
|
61
|
+
disabled: option.disabled,
|
|
62
|
+
className: buttonClassName,
|
|
63
|
+
children: option.label
|
|
64
|
+
}, String(option.value)))
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* ToggleGroup component for single selection from a set of options.
|
|
69
|
+
*
|
|
70
|
+
* For multiple selection (array fields), use ArrayToggleGroup instead.
|
|
71
|
+
*
|
|
72
|
+
* Example usage:
|
|
73
|
+
* ```tsx
|
|
74
|
+
* const schema = {
|
|
75
|
+
* type: 'object',
|
|
76
|
+
* properties: {
|
|
77
|
+
* period: {
|
|
78
|
+
* type: 'string',
|
|
79
|
+
* title: 'Select period',
|
|
80
|
+
* enum: [
|
|
81
|
+
* { label: 'Day', value: 'day' },
|
|
82
|
+
* { label: 'Week', value: 'week' },
|
|
83
|
+
* { label: 'Month', value: 'month' },
|
|
84
|
+
* ],
|
|
85
|
+
* 'x-decorator': 'FormItem',
|
|
86
|
+
* 'x-component': 'ToggleGroup',
|
|
87
|
+
* 'x-component-props': {
|
|
88
|
+
* allowEmptySelection: false,
|
|
89
|
+
* },
|
|
90
|
+
* },
|
|
91
|
+
* },
|
|
92
|
+
* };
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
const ToggleGroup = (0, __formily_react.connect)(ToggleGroupBase, (0, __formily_react.mapProps)({
|
|
96
|
+
value: true,
|
|
97
|
+
onInput: "onValueChange",
|
|
98
|
+
dataSource: "options"
|
|
99
|
+
}, (props, field) => {
|
|
100
|
+
const toggleGroupProps = props;
|
|
101
|
+
const fieldValue = field.value;
|
|
102
|
+
const resolvedOptions = coerceOptions(require_resolve_field_options.resolveFieldOptions({
|
|
103
|
+
field,
|
|
104
|
+
options: props.options
|
|
105
|
+
}));
|
|
106
|
+
const value = isToggleGroupValue(fieldValue) ? fieldValue : void 0;
|
|
107
|
+
return {
|
|
108
|
+
...toggleGroupProps,
|
|
109
|
+
options: resolvedOptions,
|
|
110
|
+
value,
|
|
111
|
+
onValueChange: (nextValue) => {
|
|
112
|
+
field.onInput(nextValue).catch(() => {});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
exports.ToggleGroup = ToggleGroup;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React$1 from "react";
|
|
2
|
+
import { ToggleGroupProps } from "@pixpilot/shadcn-ui";
|
|
3
|
+
import "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/components/ToggleGroup.d.ts
|
|
6
|
+
type ToggleGroupValue = string | number;
|
|
7
|
+
type ToggleGroupVariant = 'default' | 'outline';
|
|
8
|
+
type ToggleGroupSize = 'default' | 'sm' | 'lg';
|
|
9
|
+
interface ToggleGroupOption {
|
|
10
|
+
label: React$1.ReactNode;
|
|
11
|
+
value: ToggleGroupValue;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface ToggleGroupBaseProps extends Omit<ToggleGroupProps, 'type' | 'value' | 'defaultValue' | 'onValueChange' | 'children' | 'variant' | 'size'> {
|
|
15
|
+
options: readonly ToggleGroupOption[];
|
|
16
|
+
value?: ToggleGroupValue;
|
|
17
|
+
defaultValue?: ToggleGroupValue;
|
|
18
|
+
onValueChange?: (value: ToggleGroupValue | undefined) => void;
|
|
19
|
+
allowEmptySelection?: boolean;
|
|
20
|
+
variant?: ToggleGroupVariant;
|
|
21
|
+
size?: ToggleGroupSize;
|
|
22
|
+
buttonClassName?: string;
|
|
23
|
+
ref?: React$1.Ref<HTMLDivElement>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* ToggleGroup component for single selection from a set of options.
|
|
27
|
+
*
|
|
28
|
+
* For multiple selection (array fields), use ArrayToggleGroup instead.
|
|
29
|
+
*
|
|
30
|
+
* Example usage:
|
|
31
|
+
* ```tsx
|
|
32
|
+
* const schema = {
|
|
33
|
+
* type: 'object',
|
|
34
|
+
* properties: {
|
|
35
|
+
* period: {
|
|
36
|
+
* type: 'string',
|
|
37
|
+
* title: 'Select period',
|
|
38
|
+
* enum: [
|
|
39
|
+
* { label: 'Day', value: 'day' },
|
|
40
|
+
* { label: 'Week', value: 'week' },
|
|
41
|
+
* { label: 'Month', value: 'month' },
|
|
42
|
+
* ],
|
|
43
|
+
* 'x-decorator': 'FormItem',
|
|
44
|
+
* 'x-component': 'ToggleGroup',
|
|
45
|
+
* 'x-component-props': {
|
|
46
|
+
* allowEmptySelection: false,
|
|
47
|
+
* },
|
|
48
|
+
* },
|
|
49
|
+
* },
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare const ToggleGroup: React$1.ForwardRefExoticComponent<Omit<Partial<ToggleGroupBaseProps>, "ref"> & React$1.RefAttributes<unknown>>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { ToggleGroup, ToggleGroupBaseProps };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React$1 from "react";
|
|
2
|
+
import { ToggleGroupProps } from "@pixpilot/shadcn-ui";
|
|
3
|
+
import "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/components/ToggleGroup.d.ts
|
|
6
|
+
type ToggleGroupValue = string | number;
|
|
7
|
+
type ToggleGroupVariant = 'default' | 'outline';
|
|
8
|
+
type ToggleGroupSize = 'default' | 'sm' | 'lg';
|
|
9
|
+
interface ToggleGroupOption {
|
|
10
|
+
label: React$1.ReactNode;
|
|
11
|
+
value: ToggleGroupValue;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface ToggleGroupBaseProps extends Omit<ToggleGroupProps, 'type' | 'value' | 'defaultValue' | 'onValueChange' | 'children' | 'variant' | 'size'> {
|
|
15
|
+
options: readonly ToggleGroupOption[];
|
|
16
|
+
value?: ToggleGroupValue;
|
|
17
|
+
defaultValue?: ToggleGroupValue;
|
|
18
|
+
onValueChange?: (value: ToggleGroupValue | undefined) => void;
|
|
19
|
+
allowEmptySelection?: boolean;
|
|
20
|
+
variant?: ToggleGroupVariant;
|
|
21
|
+
size?: ToggleGroupSize;
|
|
22
|
+
buttonClassName?: string;
|
|
23
|
+
ref?: React$1.Ref<HTMLDivElement>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* ToggleGroup component for single selection from a set of options.
|
|
27
|
+
*
|
|
28
|
+
* For multiple selection (array fields), use ArrayToggleGroup instead.
|
|
29
|
+
*
|
|
30
|
+
* Example usage:
|
|
31
|
+
* ```tsx
|
|
32
|
+
* const schema = {
|
|
33
|
+
* type: 'object',
|
|
34
|
+
* properties: {
|
|
35
|
+
* period: {
|
|
36
|
+
* type: 'string',
|
|
37
|
+
* title: 'Select period',
|
|
38
|
+
* enum: [
|
|
39
|
+
* { label: 'Day', value: 'day' },
|
|
40
|
+
* { label: 'Week', value: 'week' },
|
|
41
|
+
* { label: 'Month', value: 'month' },
|
|
42
|
+
* ],
|
|
43
|
+
* 'x-decorator': 'FormItem',
|
|
44
|
+
* 'x-component': 'ToggleGroup',
|
|
45
|
+
* 'x-component-props': {
|
|
46
|
+
* allowEmptySelection: false,
|
|
47
|
+
* },
|
|
48
|
+
* },
|
|
49
|
+
* },
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare const ToggleGroup$1: React$1.ForwardRefExoticComponent<Omit<Partial<ToggleGroupBaseProps>, "ref"> & React$1.RefAttributes<unknown>>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { ToggleGroup$1 as ToggleGroup, ToggleGroupBaseProps };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { resolveFieldOptions } from "../utils/resolve-field-options.js";
|
|
2
|
+
import { connect, mapProps } from "@formily/react";
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
import { ToggleGroup, ToggleGroupItem } from "@pixpilot/shadcn-ui";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/components/ToggleGroup.tsx
|
|
8
|
+
function toVariant(input) {
|
|
9
|
+
return input === "outline" || input === "default" ? input : void 0;
|
|
10
|
+
}
|
|
11
|
+
function toSize(input) {
|
|
12
|
+
return input === "sm" || input === "lg" || input === "default" ? input : void 0;
|
|
13
|
+
}
|
|
14
|
+
function isToggleGroupValue(value) {
|
|
15
|
+
return typeof value === "string" || typeof value === "number";
|
|
16
|
+
}
|
|
17
|
+
function coerceOptions(options) {
|
|
18
|
+
if (!Array.isArray(options)) return [];
|
|
19
|
+
return options.map((option) => {
|
|
20
|
+
const { value, label, disabled } = option;
|
|
21
|
+
if (!isToggleGroupValue(value)) return null;
|
|
22
|
+
return {
|
|
23
|
+
value,
|
|
24
|
+
label,
|
|
25
|
+
disabled: Boolean(disabled)
|
|
26
|
+
};
|
|
27
|
+
}).filter((v) => v !== null);
|
|
28
|
+
}
|
|
29
|
+
function ToggleGroupBase({ options, value, defaultValue, onValueChange, allowEmptySelection = false, variant = "outline", size, buttonClassName, ref,...props }) {
|
|
30
|
+
const valueString = value === void 0 ? void 0 : String(value);
|
|
31
|
+
const defaultValueString = defaultValue === void 0 ? void 0 : String(defaultValue);
|
|
32
|
+
const valueByString = React$1.useMemo(() => {
|
|
33
|
+
const map = /* @__PURE__ */ new Map();
|
|
34
|
+
for (const option of options) map.set(String(option.value), option.value);
|
|
35
|
+
return map;
|
|
36
|
+
}, [options]);
|
|
37
|
+
return /* @__PURE__ */ jsx(ToggleGroup, {
|
|
38
|
+
...props,
|
|
39
|
+
ref,
|
|
40
|
+
type: "single",
|
|
41
|
+
value: valueString,
|
|
42
|
+
defaultValue: defaultValueString,
|
|
43
|
+
variant: toVariant(variant),
|
|
44
|
+
size: toSize(size),
|
|
45
|
+
onValueChange: (nextValue) => {
|
|
46
|
+
if (nextValue === "") {
|
|
47
|
+
if (allowEmptySelection !== true) return;
|
|
48
|
+
onValueChange?.(void 0);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
onValueChange?.(valueByString.get(nextValue) ?? nextValue);
|
|
52
|
+
},
|
|
53
|
+
children: options.map((option) => /* @__PURE__ */ jsx(ToggleGroupItem, {
|
|
54
|
+
value: String(option.value),
|
|
55
|
+
"aria-label": String(option.value),
|
|
56
|
+
disabled: option.disabled,
|
|
57
|
+
className: buttonClassName,
|
|
58
|
+
children: option.label
|
|
59
|
+
}, String(option.value)))
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* ToggleGroup component for single selection from a set of options.
|
|
64
|
+
*
|
|
65
|
+
* For multiple selection (array fields), use ArrayToggleGroup instead.
|
|
66
|
+
*
|
|
67
|
+
* Example usage:
|
|
68
|
+
* ```tsx
|
|
69
|
+
* const schema = {
|
|
70
|
+
* type: 'object',
|
|
71
|
+
* properties: {
|
|
72
|
+
* period: {
|
|
73
|
+
* type: 'string',
|
|
74
|
+
* title: 'Select period',
|
|
75
|
+
* enum: [
|
|
76
|
+
* { label: 'Day', value: 'day' },
|
|
77
|
+
* { label: 'Week', value: 'week' },
|
|
78
|
+
* { label: 'Month', value: 'month' },
|
|
79
|
+
* ],
|
|
80
|
+
* 'x-decorator': 'FormItem',
|
|
81
|
+
* 'x-component': 'ToggleGroup',
|
|
82
|
+
* 'x-component-props': {
|
|
83
|
+
* allowEmptySelection: false,
|
|
84
|
+
* },
|
|
85
|
+
* },
|
|
86
|
+
* },
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
const ToggleGroup$1 = connect(ToggleGroupBase, mapProps({
|
|
91
|
+
value: true,
|
|
92
|
+
onInput: "onValueChange",
|
|
93
|
+
dataSource: "options"
|
|
94
|
+
}, (props, field) => {
|
|
95
|
+
const toggleGroupProps = props;
|
|
96
|
+
const fieldValue = field.value;
|
|
97
|
+
const resolvedOptions = coerceOptions(resolveFieldOptions({
|
|
98
|
+
field,
|
|
99
|
+
options: props.options
|
|
100
|
+
}));
|
|
101
|
+
const value = isToggleGroupValue(fieldValue) ? fieldValue : void 0;
|
|
102
|
+
return {
|
|
103
|
+
...toggleGroupProps,
|
|
104
|
+
options: resolvedOptions,
|
|
105
|
+
value,
|
|
106
|
+
onValueChange: (nextValue) => {
|
|
107
|
+
field.onInput(nextValue).catch(() => {});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { ToggleGroup$1 as ToggleGroup };
|
|
@@ -18,17 +18,25 @@ function ArrayAddition({ ref,...props }) {
|
|
|
18
18
|
const { fullWidth = true } = props;
|
|
19
19
|
const self = (0, __formily_react.useField)();
|
|
20
20
|
const array = require_array_context.useArray();
|
|
21
|
+
const currentLength = Array.isArray(array?.field?.value) ? array.field.value.length : 0;
|
|
22
|
+
const maxItems = array?.schema?.maxItems;
|
|
23
|
+
const isAtMax = typeof maxItems === "number" && currentLength >= maxItems;
|
|
24
|
+
const isDisabled = Boolean(self?.disabled || array?.props?.disabled || isAtMax);
|
|
25
|
+
const tooltip = isAtMax ? `Maximum of ${maxItems} items reached` : props.tooltip;
|
|
21
26
|
if (!array) return null;
|
|
22
27
|
if (array.field?.pattern !== "editable" && array.field?.pattern !== "disabled") return null;
|
|
28
|
+
const defaultLabel = props.title ?? self.title ?? props.children ?? "Add Item";
|
|
29
|
+
const buttonLabel = isAtMax ? `Limit Reached (${currentLength}/${maxItems})` : defaultLabel;
|
|
23
30
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn_ui.Button, {
|
|
24
31
|
type: "button",
|
|
25
32
|
variant: fullWidth ? "ghost" : "outline",
|
|
26
33
|
...props,
|
|
27
|
-
|
|
34
|
+
disabledTooltip: tooltip,
|
|
35
|
+
disabled: isDisabled,
|
|
28
36
|
className: (0, __pixpilot_shadcn_ui.cn)(props.className, { "w-full border border-dashed border-muted": fullWidth }),
|
|
29
37
|
ref,
|
|
30
38
|
onClick: (e) => {
|
|
31
|
-
if (array.props?.disabled) return;
|
|
39
|
+
if (array.props?.disabled || isAtMax) return;
|
|
32
40
|
if (props.onClick) {
|
|
33
41
|
props.onClick(e);
|
|
34
42
|
if (e.defaultPrevented) return;
|
|
@@ -42,7 +50,7 @@ function ArrayAddition({ ref,...props }) {
|
|
|
42
50
|
array.props?.onAdd?.((array?.field?.value?.length ?? 1) - 1);
|
|
43
51
|
}
|
|
44
52
|
},
|
|
45
|
-
children: [props.icon !== void 0 ? props.icon : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.PlusIcon, { className: "mr-2 size-4" }),
|
|
53
|
+
children: [!isAtMax && (props.icon !== void 0 ? props.icon : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.PlusIcon, { className: "mr-2 size-4" })), buttonLabel]
|
|
46
54
|
});
|
|
47
55
|
}
|
|
48
56
|
ArrayAddition.displayName = "ArrayAddition";
|
|
@@ -12,17 +12,25 @@ function ArrayAddition({ ref,...props }) {
|
|
|
12
12
|
const { fullWidth = true } = props;
|
|
13
13
|
const self = useField();
|
|
14
14
|
const array = useArray();
|
|
15
|
+
const currentLength = Array.isArray(array?.field?.value) ? array.field.value.length : 0;
|
|
16
|
+
const maxItems = array?.schema?.maxItems;
|
|
17
|
+
const isAtMax = typeof maxItems === "number" && currentLength >= maxItems;
|
|
18
|
+
const isDisabled = Boolean(self?.disabled || array?.props?.disabled || isAtMax);
|
|
19
|
+
const tooltip = isAtMax ? `Maximum of ${maxItems} items reached` : props.tooltip;
|
|
15
20
|
if (!array) return null;
|
|
16
21
|
if (array.field?.pattern !== "editable" && array.field?.pattern !== "disabled") return null;
|
|
22
|
+
const defaultLabel = props.title ?? self.title ?? props.children ?? "Add Item";
|
|
23
|
+
const buttonLabel = isAtMax ? `Limit Reached (${currentLength}/${maxItems})` : defaultLabel;
|
|
17
24
|
return /* @__PURE__ */ jsxs(Button, {
|
|
18
25
|
type: "button",
|
|
19
26
|
variant: fullWidth ? "ghost" : "outline",
|
|
20
27
|
...props,
|
|
21
|
-
|
|
28
|
+
disabledTooltip: tooltip,
|
|
29
|
+
disabled: isDisabled,
|
|
22
30
|
className: cn(props.className, { "w-full border border-dashed border-muted": fullWidth }),
|
|
23
31
|
ref,
|
|
24
32
|
onClick: (e) => {
|
|
25
|
-
if (array.props?.disabled) return;
|
|
33
|
+
if (array.props?.disabled || isAtMax) return;
|
|
26
34
|
if (props.onClick) {
|
|
27
35
|
props.onClick(e);
|
|
28
36
|
if (e.defaultPrevented) return;
|
|
@@ -36,7 +44,7 @@ function ArrayAddition({ ref,...props }) {
|
|
|
36
44
|
array.props?.onAdd?.((array?.field?.value?.length ?? 1) - 1);
|
|
37
45
|
}
|
|
38
46
|
},
|
|
39
|
-
children: [props.icon !== void 0 ? props.icon : /* @__PURE__ */ jsx(PlusIcon, { className: "mr-2 size-4" }),
|
|
47
|
+
children: [!isAtMax && (props.icon !== void 0 ? props.icon : /* @__PURE__ */ jsx(PlusIcon, { className: "mr-2 size-4" })), buttonLabel]
|
|
40
48
|
});
|
|
41
49
|
}
|
|
42
50
|
ArrayAddition.displayName = "ArrayAddition";
|