@pixpilot/formily-shadcn 0.44.2 → 0.44.3

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.
Files changed (57) hide show
  1. package/dist/components/Checkbox.d.cts +2 -2
  2. package/dist/components/DatePicker.d.cts +3 -3
  3. package/dist/components/IconPicker.d.cts +3 -3
  4. package/dist/components/IconToggle.d.cts +2 -2
  5. package/dist/components/Input.d.cts +3 -3
  6. package/dist/components/Rating.d.cts +5 -5
  7. package/dist/components/Select.cjs +11 -8
  8. package/dist/components/Select.js +11 -8
  9. package/dist/components/Separator.d.cts +2 -2
  10. package/dist/components/Switch.d.cts +2 -2
  11. package/dist/components/Switch.d.ts +2 -2
  12. package/dist/components/TagsInputInline.d.cts +3 -3
  13. package/dist/components/TagsInputInline.d.ts +2 -2
  14. package/dist/components/Textarea.d.cts +2 -2
  15. package/dist/components/ToggleGroup.cjs +118 -0
  16. package/dist/components/ToggleGroup.d.cts +55 -0
  17. package/dist/components/ToggleGroup.d.ts +55 -0
  18. package/dist/components/ToggleGroup.js +113 -0
  19. package/dist/components/array-toggle-group/ArrayToggleGroup.cjs +123 -0
  20. package/dist/components/array-toggle-group/ArrayToggleGroup.d.cts +65 -0
  21. package/dist/components/array-toggle-group/ArrayToggleGroup.d.ts +65 -0
  22. package/dist/components/array-toggle-group/ArrayToggleGroup.js +118 -0
  23. package/dist/components/array-toggle-group/index.cjs +1 -0
  24. package/dist/components/array-toggle-group/index.d.cts +1 -0
  25. package/dist/components/array-toggle-group/index.d.ts +1 -0
  26. package/dist/components/array-toggle-group/index.js +1 -0
  27. package/dist/components/file-upload/FileUpload.d.ts +8 -8
  28. package/dist/components/file-upload/FileUploadInline.d.ts +8 -8
  29. package/dist/components/form-item/ConnectedFormItem.d.cts +4 -4
  30. package/dist/components/form-item/ConnectedFormItem.d.ts +4 -4
  31. package/dist/components/schema-field/schema-field-basics.cjs +11 -0
  32. package/dist/components/schema-field/schema-field-basics.d.cts +296 -265
  33. package/dist/components/schema-field/schema-field-basics.d.ts +301 -270
  34. package/dist/components/schema-field/schema-field-basics.js +11 -0
  35. package/dist/components/schema-field/schema-field-extended.d.cts +53 -22
  36. package/dist/components/schema-field/schema-field-extended.d.ts +631 -600
  37. package/dist/components/schema-field/schema-field.d.cts +406 -375
  38. package/dist/components/schema-field/schema-field.d.ts +407 -376
  39. package/dist/components/slider/Slider.d.cts +3 -3
  40. package/dist/components/slider/Slider.d.ts +2 -2
  41. package/dist/components/slider/SliderInput.d.cts +3 -3
  42. package/dist/components/slider/SliderInput.d.ts +2 -2
  43. package/dist/components/slider/SliderSelect.d.cts +2 -2
  44. package/dist/components/slider/SliderSelect.d.ts +3 -3
  45. package/dist/index.cjs +5 -0
  46. package/dist/index.d.cts +4 -1
  47. package/dist/index.d.ts +4 -1
  48. package/dist/index.js +4 -1
  49. package/dist/utils/index.cjs +1 -0
  50. package/dist/utils/index.d.cts +1 -0
  51. package/dist/utils/index.d.ts +1 -0
  52. package/dist/utils/index.js +1 -0
  53. package/dist/utils/resolve-field-options.cjs +70 -0
  54. package/dist/utils/resolve-field-options.d.cts +1 -0
  55. package/dist/utils/resolve-field-options.d.ts +1 -0
  56. package/dist/utils/resolve-field-options.js +69 -0
  57. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- import * as react1 from "react";
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: react1.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_checkbox0.CheckboxProps & react1.RefAttributes<HTMLButtonElement>>, "ref"> & react1.RefAttributes<unknown>>;
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 react0 from "react";
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: react0.ForwardRefExoticComponent<Partial<{
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">> & react0.RefAttributes<unknown>>;
9
+ } & Omit<DatePickerProps, "onSelect" | "selected" | "mode">> & react2.RefAttributes<unknown>>;
10
10
  //#endregion
11
11
  export { DatePicker };
@@ -1,4 +1,4 @@
1
- import * as react11 from "react";
1
+ import * as react4 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: react11.ForwardRefExoticComponent<Partial<Omit<IconPickerProps, "providers"> & {
11
+ declare const IconPicker: react4.ForwardRefExoticComponent<Partial<Omit<IconPickerProps, "providers"> & {
12
12
  providers?: IconProviderProps[];
13
- }> & react11.RefAttributes<unknown>>;
13
+ }> & react4.RefAttributes<unknown>>;
14
14
  //#endregion
15
15
  export { IconPicker };
@@ -1,4 +1,4 @@
1
- import * as react4 from "react";
1
+ import * as react10 from "react";
2
2
  import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
3
3
 
4
4
  //#region src/components/IconToggle.d.ts
@@ -6,6 +6,6 @@ import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
6
6
  * Formily-connected IconToggle component
7
7
  * Toggle button with customizable icons for boolean values
8
8
  */
9
- declare const IconToggle: react4.ForwardRefExoticComponent<Omit<Partial<Omit<_pixpilot_shadcn_ui0.IconToggleProps, "ref"> & react4.RefAttributes<HTMLButtonElement>>, "ref"> & react4.RefAttributes<unknown>>;
9
+ declare const IconToggle: react10.ForwardRefExoticComponent<Omit<Partial<Omit<_pixpilot_shadcn_ui0.IconToggleProps, "ref"> & react10.RefAttributes<HTMLButtonElement>>, "ref"> & react10.RefAttributes<unknown>>;
10
10
  //#endregion
11
11
  export { IconToggle };
@@ -1,4 +1,4 @@
1
- import * as react7 from "react";
1
+ import * as react6 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: react7.ForwardRefExoticComponent<Omit<Partial<react7.ClassAttributes<HTMLInputElement> & react7.InputHTMLAttributes<HTMLInputElement> & {
9
+ declare const Input: react6.ForwardRefExoticComponent<Omit<Partial<react6.ClassAttributes<HTMLInputElement> & react6.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"> & react7.RefAttributes<unknown>>;
15
+ }>, "ref"> & react6.RefAttributes<unknown>>;
16
16
  //#endregion
17
17
  export { Input };
@@ -1,13 +1,13 @@
1
- import * as react25 from "react";
2
- import * as _pixpilot_shadcn_ui1 from "@pixpilot/shadcn-ui";
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: react25.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui1.RatingProps & {
10
- children?: react25.ReactNode | undefined;
11
- }> & react25.RefAttributes<unknown>>;
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 field = (0, __formily_react.useField)();
15
- let selectOptions;
16
- if (isOptionArray(field?.componentProps?.options)) selectOptions = field.componentProps.options;
17
- else if (isOptionArray(options)) selectOptions = options;
18
- const transformedOptions = selectOptions?.map((option) => mapOption ? mapOption(option) : option);
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 field = useField();
11
- let selectOptions;
12
- if (isOptionArray(field?.componentProps?.options)) selectOptions = field.componentProps.options;
13
- else if (isOptionArray(options)) selectOptions = options;
14
- const transformedOptions = selectOptions?.map((option) => mapOption ? mapOption(option) : option);
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 react13 from "react";
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: react13.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_separator0.SeparatorProps & react13.RefAttributes<HTMLDivElement>>, "ref"> & react13.RefAttributes<unknown>>;
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 react16 from "react";
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: react16.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_switch0.SwitchProps & react16.RefAttributes<HTMLButtonElement>>, "ref"> & react16.RefAttributes<unknown>>;
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 react21 from "react";
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: react21.ForwardRefExoticComponent<Omit<Partial<_radix_ui_react_switch0.SwitchProps & react21.RefAttributes<HTMLButtonElement>>, "ref"> & react21.RefAttributes<unknown>>;
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 react19 from "react";
2
- import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
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: react19.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui0.TagsInputProps> & react19.RefAttributes<unknown>>;
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 react19 from "react";
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: react19.ForwardRefExoticComponent<Partial<_pixpilot_shadcn_ui1.TagsInputProps> & react19.RefAttributes<unknown>>;
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 react21 from "react";
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: react21.ForwardRefExoticComponent<Omit<Partial<react21.ClassAttributes<HTMLTextAreaElement> & react21.TextareaHTMLAttributes<HTMLTextAreaElement>>, "ref"> & react21.RefAttributes<unknown>>;
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 };