@alexgorbatchev/shadcn 0.0.107 → 0.0.108
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/{chunk-j7fvvgyp.js → chunk-h1b1mqnc.js} +5 -2
- package/dist/components/json-render/JsonForm.d.ts +18 -3
- package/dist/components/json-render/JsonSlider.d.ts +4 -0
- package/dist/components/json-render/JsonSwitch.d.ts +4 -0
- package/dist/components/json-render/JsonToggleGroup.d.ts +4 -0
- package/dist/components/json-render/catalog.d.ts +7 -0
- package/dist/components/json-render/catalog.js +1 -1
- package/dist/components/json-render/index.js +149 -49
- package/dist/prototype.js +1 -1
- package/llms/components/data-display/JsonRenderForm.md +53 -0
- package/package.json +1 -1
|
@@ -6021,10 +6021,13 @@ var componentDefinitions2 = {
|
|
|
6021
6021
|
value: string2()
|
|
6022
6022
|
})),
|
|
6023
6023
|
type: _enum(["single", "multiple"]).nullable(),
|
|
6024
|
-
value: string2().nullable()
|
|
6024
|
+
value: string2().nullable(),
|
|
6025
|
+
label: string2().nullish().describe("The question the group answers, shown above the options and naming the group. Set it whenever value is bound to an answer."),
|
|
6026
|
+
description: string2().nullish().describe("Help text shown under the label, or null."),
|
|
6027
|
+
checks: validationCheckSchema.optional()
|
|
6025
6028
|
}),
|
|
6026
6029
|
events: ["change"],
|
|
6027
|
-
description: "Group of toggle buttons. Type 'single' (default) or 'multiple'. Use { $bindState } on value."
|
|
6030
|
+
description: "Group of toggle buttons. Type 'single' (default) or 'multiple'. Use { $bindState } on value. Bound to an answer it is a question: label names it above the options, pressed options show a check, and checks validate it."
|
|
6028
6031
|
},
|
|
6029
6032
|
ButtonGroup: {
|
|
6030
6033
|
props: object({
|
|
@@ -11,6 +11,7 @@ export type JsonFormMode = "edit" | "locked" | "values";
|
|
|
11
11
|
interface IJsonFormContext {
|
|
12
12
|
mode: JsonFormMode;
|
|
13
13
|
errors: Readonly<Record<string, string>>;
|
|
14
|
+
defaults: readonly string[];
|
|
14
15
|
}
|
|
15
16
|
export interface IJsonFormProviderProps {
|
|
16
17
|
mode?: JsonFormMode;
|
|
@@ -20,10 +21,16 @@ export interface IJsonFormProviderProps {
|
|
|
20
21
|
* messages, so no message appears before the consumer decides to show it.
|
|
21
22
|
*/
|
|
22
23
|
errors?: Readonly<Record<string, string>>;
|
|
24
|
+
/**
|
|
25
|
+
* Binding paths whose value is still the one the author set, such as `["/answers/oncall"]`. Each of those controls
|
|
26
|
+
* shows a "Default" tag beside its label until its value changes, so a person can tell a value they chose from one
|
|
27
|
+
* they never touched.
|
|
28
|
+
*/
|
|
29
|
+
defaults?: readonly string[];
|
|
23
30
|
children?: ReactNode;
|
|
24
31
|
}
|
|
25
|
-
/** Sets the mode
|
|
26
|
-
export declare function JsonFormProvider({ mode, errors, children }: IJsonFormProviderProps): ReactElement;
|
|
32
|
+
/** Sets the mode, the field messages and the default-valued fields of the bound controls rendered inside it. */
|
|
33
|
+
export declare function JsonFormProvider({ mode, errors, defaults, children, }: IJsonFormProviderProps): ReactElement;
|
|
27
34
|
/** The nearest `JsonFormProvider`'s mode and messages, or `undefined` outside one. */
|
|
28
35
|
export declare function useJsonForm(): IJsonFormContext | undefined;
|
|
29
36
|
type Reveal = () => void;
|
|
@@ -55,6 +62,8 @@ export interface IJsonField {
|
|
|
55
62
|
/** The label without a trailing "*": the "Required" tag replaces it. */
|
|
56
63
|
label: string;
|
|
57
64
|
isRequired: boolean;
|
|
65
|
+
/** The value is still the author's default (`JsonFormProvider`'s `defaults`); the label shows a "Default" tag. */
|
|
66
|
+
isDefault: boolean;
|
|
58
67
|
error?: string;
|
|
59
68
|
mode: JsonFormMode;
|
|
60
69
|
messageId: string;
|
|
@@ -74,8 +83,14 @@ export interface IJsonFieldLabelProps {
|
|
|
74
83
|
id?: string;
|
|
75
84
|
htmlFor?: string;
|
|
76
85
|
}
|
|
77
|
-
/** The field's
|
|
86
|
+
/** The field's "Required" and "Default" tags, in that order; nothing when neither applies. */
|
|
87
|
+
export declare function JsonFieldTags({ field }: {
|
|
88
|
+
field: IJsonField;
|
|
89
|
+
}): ReactElement | null;
|
|
90
|
+
/** The field's label followed by its "Required" and "Default" tags. */
|
|
78
91
|
export declare function JsonFieldLabel({ field, id, htmlFor }: IJsonFieldLabelProps): ReactElement | null;
|
|
92
|
+
/** What an answer control the author left empty shows instead of a value it would not send. */
|
|
93
|
+
export declare const NOT_SET_TEXT = "Not set";
|
|
79
94
|
/** The field's message, referenced by the control's `aria-describedby`. */
|
|
80
95
|
export declare function JsonFieldMessage({ field }: {
|
|
81
96
|
field: IJsonField;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type BaseComponentProps } from "@json-render/react";
|
|
2
2
|
import { type JsonProps } from "./catalog.js";
|
|
3
|
+
/**
|
|
4
|
+
* A range slider. Bound to a value the author left `null`, it reads "Not set" instead of its minimum until the person
|
|
5
|
+
* moves it, so it never shows a value it would not send.
|
|
6
|
+
*/
|
|
3
7
|
export declare const JsonSlider: ({ props, bindings, emit }: BaseComponentProps<JsonProps<"Slider">>) => import("react").JSX.Element;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type BaseComponentProps } from "@json-render/react";
|
|
2
2
|
import { type JsonProps } from "./catalog.js";
|
|
3
|
+
/**
|
|
4
|
+
* A toggle switch. Bound to a value the author left `null`, it reads "Not set" beside an off switch until the person
|
|
5
|
+
* turns it on or off, so it never shows "off" as an answer it would not send.
|
|
6
|
+
*/
|
|
3
7
|
export declare const JsonSwitch: ({ props, bindings, emit }: BaseComponentProps<JsonProps<"Switch">>) => import("react").JSX.Element;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type BaseComponentProps } from "@json-render/react";
|
|
2
2
|
import { type JsonProps } from "./catalog.js";
|
|
3
|
+
/**
|
|
4
|
+
* A group of toggle buttons. Bound to an answer it is a question: its label sits above the options and names the group,
|
|
5
|
+
* pressed options show a check, and its checks validate it. Unbound it switches a view and keeps working in every mode.
|
|
6
|
+
*/
|
|
3
7
|
export declare const JsonToggleGroup: ({ props, bindings, emit }: BaseComponentProps<JsonProps<"ToggleGroup">>) => import("react").JSX.Element;
|
|
@@ -500,6 +500,13 @@ export declare const componentDefinitions: {
|
|
|
500
500
|
single: "single";
|
|
501
501
|
}>>;
|
|
502
502
|
value: z.ZodNullable<z.ZodString>;
|
|
503
|
+
label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
504
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
505
|
+
checks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
506
|
+
type: z.ZodString;
|
|
507
|
+
message: z.ZodString;
|
|
508
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
509
|
+
}, z.core.$strip>>>>;
|
|
503
510
|
}, z.core.$strip>;
|
|
504
511
|
events: string[];
|
|
505
512
|
description: string;
|
|
@@ -169,7 +169,7 @@ import {
|
|
|
169
169
|
} from "../../chunk-2jsgsjas.js";
|
|
170
170
|
import {
|
|
171
171
|
componentDefinitions2
|
|
172
|
-
} from "../../chunk-
|
|
172
|
+
} from "../../chunk-h1b1mqnc.js";
|
|
173
173
|
import"../../chunk-5mydsjp3.js";
|
|
174
174
|
|
|
175
175
|
// src/components/json-render/JsonCard.tsx
|
|
@@ -272,11 +272,17 @@ import { useBoundProp } from "@json-render/react";
|
|
|
272
272
|
|
|
273
273
|
// src/components/json-render/JsonForm.tsx
|
|
274
274
|
import { createContext, use, useCallback, useId, useMemo } from "react";
|
|
275
|
-
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
275
|
+
import { jsx as jsx5, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
|
|
276
276
|
var JsonFormContext = createContext(undefined);
|
|
277
277
|
var noErrors = {};
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
var noDefaults = [];
|
|
279
|
+
function JsonFormProvider({
|
|
280
|
+
mode = "edit",
|
|
281
|
+
errors = noErrors,
|
|
282
|
+
defaults = noDefaults,
|
|
283
|
+
children
|
|
284
|
+
}) {
|
|
285
|
+
const value = useMemo(() => ({ mode, errors, defaults }), [mode, errors, defaults]);
|
|
280
286
|
return /* @__PURE__ */ jsx5(JsonFormContext, {
|
|
281
287
|
value,
|
|
282
288
|
children
|
|
@@ -311,6 +317,7 @@ function useJsonField({ path, label, checks, ownErrors = [] }) {
|
|
|
311
317
|
return {
|
|
312
318
|
label: stripRequiredMark(label ?? ""),
|
|
313
319
|
isRequired,
|
|
320
|
+
isDefault: !!path && !!form?.defaults.includes(path),
|
|
314
321
|
error,
|
|
315
322
|
mode: form?.mode ?? "edit",
|
|
316
323
|
messageId,
|
|
@@ -321,8 +328,25 @@ function useJsonField({ path, label, checks, ownErrors = [] }) {
|
|
|
321
328
|
}
|
|
322
329
|
};
|
|
323
330
|
}
|
|
331
|
+
function JsonFieldTags({ field }) {
|
|
332
|
+
if (!field.isRequired && !field.isDefault)
|
|
333
|
+
return null;
|
|
334
|
+
return /* @__PURE__ */ jsxs2(Fragment, {
|
|
335
|
+
children: [
|
|
336
|
+
field.isRequired && /* @__PURE__ */ jsx5(Badge2, {
|
|
337
|
+
variant: "outline",
|
|
338
|
+
children: "Required"
|
|
339
|
+
}),
|
|
340
|
+
field.isDefault && /* @__PURE__ */ jsx5(Badge2, {
|
|
341
|
+
variant: "outline",
|
|
342
|
+
"data-slot": "json-field-default",
|
|
343
|
+
children: "Default"
|
|
344
|
+
})
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
}
|
|
324
348
|
function JsonFieldLabel({ field, id, htmlFor }) {
|
|
325
|
-
if (!field.label && !field.isRequired)
|
|
349
|
+
if (!field.label && !field.isRequired && !field.isDefault)
|
|
326
350
|
return null;
|
|
327
351
|
return /* @__PURE__ */ jsxs2("div", {
|
|
328
352
|
"data-slot": "json-field-label",
|
|
@@ -333,13 +357,13 @@ function JsonFieldLabel({ field, id, htmlFor }) {
|
|
|
333
357
|
htmlFor,
|
|
334
358
|
children: field.label
|
|
335
359
|
}),
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
children: "Required"
|
|
360
|
+
/* @__PURE__ */ jsx5(JsonFieldTags, {
|
|
361
|
+
field
|
|
339
362
|
})
|
|
340
363
|
]
|
|
341
364
|
});
|
|
342
365
|
}
|
|
366
|
+
var NOT_SET_TEXT = "Not set";
|
|
343
367
|
function JsonFieldMessage({ field }) {
|
|
344
368
|
if (!field.error)
|
|
345
369
|
return null;
|
|
@@ -1011,13 +1035,17 @@ var JsonCheckbox = ({ props, bindings, emit }) => {
|
|
|
1011
1035
|
emit("change");
|
|
1012
1036
|
}
|
|
1013
1037
|
}),
|
|
1014
|
-
/* @__PURE__ */
|
|
1015
|
-
|
|
1016
|
-
children:
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1038
|
+
/* @__PURE__ */ jsxs18("div", {
|
|
1039
|
+
className: "flex flex-auto flex-wrap items-center gap-2",
|
|
1040
|
+
children: [
|
|
1041
|
+
/* @__PURE__ */ jsx27(FieldLabel2, {
|
|
1042
|
+
htmlFor: id,
|
|
1043
|
+
children: field.label
|
|
1044
|
+
}),
|
|
1045
|
+
/* @__PURE__ */ jsx27(JsonFieldTags, {
|
|
1046
|
+
field
|
|
1047
|
+
})
|
|
1048
|
+
]
|
|
1021
1049
|
})
|
|
1022
1050
|
]
|
|
1023
1051
|
}),
|
|
@@ -1099,11 +1127,13 @@ import { useFieldValidation as useFieldValidation6 } from "@json-render/react";
|
|
|
1099
1127
|
import { jsx as jsx29, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
1100
1128
|
var JsonSwitch = ({ props, bindings, emit }) => {
|
|
1101
1129
|
const id = useId7();
|
|
1130
|
+
const notSetId = useId7();
|
|
1102
1131
|
const form = useJsonForm();
|
|
1103
1132
|
const [boundChecked, setBoundChecked] = useBoundProp7(props.checked ?? undefined, bindings?.checked);
|
|
1104
1133
|
const [localChecked, setLocalChecked] = useState8(!!props.checked);
|
|
1105
1134
|
const isBound = !!bindings?.checked;
|
|
1106
1135
|
const checked = isBound ? boundChecked ?? false : localChecked;
|
|
1136
|
+
const isNotSet = isBound && (boundChecked === null || boundChecked === undefined);
|
|
1107
1137
|
const setChecked = isBound ? setBoundChecked : setLocalChecked;
|
|
1108
1138
|
const validateOn = props.validateOn ?? "change";
|
|
1109
1139
|
const hasValidation = !!(bindings?.checked && props.checks?.length) && !form;
|
|
@@ -1112,27 +1142,39 @@ var JsonSwitch = ({ props, bindings, emit }) => {
|
|
|
1112
1142
|
if (field.mode === "values")
|
|
1113
1143
|
return /* @__PURE__ */ jsx29(JsonFieldValue, {
|
|
1114
1144
|
field,
|
|
1115
|
-
text: checked ? "On" : "Off"
|
|
1145
|
+
text: isNotSet ? NOT_SET_TEXT : checked ? "On" : "Off"
|
|
1116
1146
|
});
|
|
1147
|
+
const describedBy = [field.controlProps["aria-describedby"], isNotSet ? notSetId : undefined].filter(Boolean).join(" ") || undefined;
|
|
1117
1148
|
return /* @__PURE__ */ jsxs20("div", {
|
|
1118
1149
|
className: "space-y-1",
|
|
1119
1150
|
children: [
|
|
1120
1151
|
/* @__PURE__ */ jsxs20(Field2, {
|
|
1121
1152
|
orientation: "horizontal",
|
|
1122
1153
|
children: [
|
|
1123
|
-
/* @__PURE__ */
|
|
1124
|
-
|
|
1125
|
-
children:
|
|
1154
|
+
/* @__PURE__ */ jsxs20("div", {
|
|
1155
|
+
className: "flex flex-auto flex-wrap items-center gap-2",
|
|
1156
|
+
children: [
|
|
1157
|
+
/* @__PURE__ */ jsx29(FieldLabel2, {
|
|
1158
|
+
htmlFor: id,
|
|
1159
|
+
children: field.label
|
|
1160
|
+
}),
|
|
1161
|
+
/* @__PURE__ */ jsx29(JsonFieldTags, {
|
|
1162
|
+
field
|
|
1163
|
+
})
|
|
1164
|
+
]
|
|
1126
1165
|
}),
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1166
|
+
isNotSet && /* @__PURE__ */ jsx29("span", {
|
|
1167
|
+
id: notSetId,
|
|
1168
|
+
"data-slot": "json-field-not-set",
|
|
1169
|
+
className: "shrink-0 text-sm whitespace-nowrap text-muted-foreground",
|
|
1170
|
+
children: NOT_SET_TEXT
|
|
1130
1171
|
}),
|
|
1131
1172
|
/* @__PURE__ */ jsx29(Switch2, {
|
|
1132
1173
|
id,
|
|
1133
1174
|
checked,
|
|
1134
1175
|
disabled: field.mode === "locked",
|
|
1135
1176
|
...field.controlProps,
|
|
1177
|
+
"aria-describedby": describedBy,
|
|
1136
1178
|
onCheckedChange: (c) => {
|
|
1137
1179
|
setChecked(c);
|
|
1138
1180
|
if (hasValidation && validateOn === "change")
|
|
@@ -1158,33 +1200,45 @@ var JsonSlider = ({ props, bindings, emit }) => {
|
|
|
1158
1200
|
const [boundValue, setBoundValue] = useBoundProp8(props.value ?? undefined, bindings?.value);
|
|
1159
1201
|
const [localValue, setLocalValue] = useState9(props.value ?? props.min ?? 0);
|
|
1160
1202
|
const isBound = !!bindings?.value;
|
|
1203
|
+
const isNotSet = isBound && (boundValue === null || boundValue === undefined);
|
|
1161
1204
|
const value = isBound ? boundValue ?? props.min ?? 0 : localValue;
|
|
1162
1205
|
const setValue = isBound ? setBoundValue : setLocalValue;
|
|
1163
1206
|
const field = useJsonField({ path: bindings?.value, label: props.label });
|
|
1207
|
+
const valueText = isNotSet ? NOT_SET_TEXT : String(value);
|
|
1164
1208
|
if (field.mode === "values")
|
|
1165
1209
|
return /* @__PURE__ */ jsx30(JsonFieldValue, {
|
|
1166
1210
|
field,
|
|
1167
|
-
text:
|
|
1211
|
+
text: valueText
|
|
1168
1212
|
});
|
|
1169
1213
|
return /* @__PURE__ */ jsxs21("div", {
|
|
1170
1214
|
className: "space-y-2",
|
|
1171
1215
|
children: [
|
|
1172
|
-
field.label && /* @__PURE__ */ jsxs21("div", {
|
|
1173
|
-
className: "flex justify-between",
|
|
1216
|
+
(field.label || isNotSet) && /* @__PURE__ */ jsxs21("div", {
|
|
1217
|
+
className: "flex items-center justify-between gap-2",
|
|
1174
1218
|
children: [
|
|
1175
|
-
/* @__PURE__ */
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1219
|
+
/* @__PURE__ */ jsxs21("div", {
|
|
1220
|
+
className: "flex flex-wrap items-center gap-2",
|
|
1221
|
+
children: [
|
|
1222
|
+
field.label && /* @__PURE__ */ jsx30(Label2, {
|
|
1223
|
+
id,
|
|
1224
|
+
className: "text-sm",
|
|
1225
|
+
children: field.label
|
|
1226
|
+
}),
|
|
1227
|
+
/* @__PURE__ */ jsx30(JsonFieldTags, {
|
|
1228
|
+
field
|
|
1229
|
+
})
|
|
1230
|
+
]
|
|
1179
1231
|
}),
|
|
1180
1232
|
/* @__PURE__ */ jsx30("span", {
|
|
1233
|
+
"data-slot": isNotSet ? "json-field-not-set" : undefined,
|
|
1181
1234
|
className: "text-sm text-muted-foreground",
|
|
1182
|
-
children:
|
|
1235
|
+
children: valueText
|
|
1183
1236
|
})
|
|
1184
1237
|
]
|
|
1185
1238
|
}),
|
|
1186
1239
|
/* @__PURE__ */ jsx30(Slider2, {
|
|
1187
1240
|
getAriaLabel: () => field.label || "Value",
|
|
1241
|
+
getAriaValueText: isNotSet ? () => NOT_SET_TEXT : undefined,
|
|
1188
1242
|
value: [value],
|
|
1189
1243
|
min: props.min ?? 0,
|
|
1190
1244
|
max: props.max ?? 100,
|
|
@@ -1306,7 +1360,7 @@ var JsonDropdownMenu = ({ props, bindings, emit }) => {
|
|
|
1306
1360
|
// src/components/json-render/JsonToggle.tsx
|
|
1307
1361
|
import { useState as useState10 } from "react";
|
|
1308
1362
|
import { useBoundProp as useBoundProp10 } from "@json-render/react";
|
|
1309
|
-
import { jsx as jsx34 } from "react/jsx-runtime";
|
|
1363
|
+
import { jsx as jsx34, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
1310
1364
|
var JsonToggle = ({ props, bindings, emit }) => {
|
|
1311
1365
|
const [boundPressed, setBoundPressed] = useBoundProp10(props.pressed ?? undefined, bindings?.pressed);
|
|
1312
1366
|
const [localPressed, setLocalPressed] = useState10(props.pressed ?? false);
|
|
@@ -1320,7 +1374,7 @@ var JsonToggle = ({ props, bindings, emit }) => {
|
|
|
1320
1374
|
field,
|
|
1321
1375
|
text: pressed ? "On" : "Off"
|
|
1322
1376
|
});
|
|
1323
|
-
|
|
1377
|
+
const toggle = /* @__PURE__ */ jsx34(Toggle2, {
|
|
1324
1378
|
variant: props.variant ?? "default",
|
|
1325
1379
|
pressed,
|
|
1326
1380
|
disabled: mode === "locked",
|
|
@@ -1330,13 +1384,27 @@ var JsonToggle = ({ props, bindings, emit }) => {
|
|
|
1330
1384
|
},
|
|
1331
1385
|
children: props.label
|
|
1332
1386
|
});
|
|
1387
|
+
return isBound && (field.isRequired || field.isDefault) ? /* @__PURE__ */ jsxs23("div", {
|
|
1388
|
+
className: "flex flex-wrap items-center gap-2",
|
|
1389
|
+
children: [
|
|
1390
|
+
toggle,
|
|
1391
|
+
/* @__PURE__ */ jsx34(JsonFieldTags, {
|
|
1392
|
+
field
|
|
1393
|
+
})
|
|
1394
|
+
]
|
|
1395
|
+
}) : toggle;
|
|
1333
1396
|
};
|
|
1334
1397
|
|
|
1335
1398
|
// src/components/json-render/JsonToggleGroup.tsx
|
|
1336
|
-
import { useState as useState11 } from "react";
|
|
1399
|
+
import { useId as useId10, useState as useState11 } from "react";
|
|
1400
|
+
import { CheckIcon } from "lucide-react";
|
|
1337
1401
|
import { useBoundProp as useBoundProp11 } from "@json-render/react";
|
|
1338
|
-
import {
|
|
1402
|
+
import { useFieldValidation as useFieldValidation7 } from "@json-render/react";
|
|
1403
|
+
import { jsx as jsx35, jsxs as jsxs24 } from "react/jsx-runtime";
|
|
1339
1404
|
var JsonToggleGroup = ({ props, bindings, emit }) => {
|
|
1405
|
+
const labelId = useId10();
|
|
1406
|
+
const descriptionId = useId10();
|
|
1407
|
+
const form = useJsonForm();
|
|
1340
1408
|
const type = props.type ?? "single";
|
|
1341
1409
|
const items = props.items ?? [];
|
|
1342
1410
|
const [boundValue, setBoundValue] = useBoundProp11(props.value ?? undefined, bindings?.value);
|
|
@@ -1344,7 +1412,9 @@ var JsonToggleGroup = ({ props, bindings, emit }) => {
|
|
|
1344
1412
|
const isBound = !!bindings?.value;
|
|
1345
1413
|
const value = isBound ? boundValue ?? "" : localValue;
|
|
1346
1414
|
const setValue = isBound ? setBoundValue : setLocalValue;
|
|
1347
|
-
const
|
|
1415
|
+
const hasValidation = isBound && !!props.checks?.length && !form;
|
|
1416
|
+
const { errors, validate } = useFieldValidation7(bindings?.value ?? "", hasValidation ? { checks: props.checks ?? [], validateOn: "change" } : undefined);
|
|
1417
|
+
const field = useJsonField({ path: bindings?.value, label: props.label, checks: props.checks, ownErrors: errors });
|
|
1348
1418
|
const mode = isBound ? field.mode : "edit";
|
|
1349
1419
|
const selected = value ? value.split(",") : [];
|
|
1350
1420
|
if (mode === "values")
|
|
@@ -1352,18 +1422,48 @@ var JsonToggleGroup = ({ props, bindings, emit }) => {
|
|
|
1352
1422
|
field,
|
|
1353
1423
|
text: items.filter((item) => selected.includes(item.value)).map((item) => item.label).join(", ")
|
|
1354
1424
|
});
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1425
|
+
const describedBy = [props.description ? descriptionId : undefined, field.controlProps["aria-describedby"]].filter(Boolean).join(" ") || undefined;
|
|
1426
|
+
return /* @__PURE__ */ jsxs24("div", {
|
|
1427
|
+
className: "space-y-2",
|
|
1428
|
+
children: [
|
|
1429
|
+
/* @__PURE__ */ jsx35(JsonFieldLabel, {
|
|
1430
|
+
field,
|
|
1431
|
+
id: labelId
|
|
1432
|
+
}),
|
|
1433
|
+
props.description && /* @__PURE__ */ jsx35("p", {
|
|
1434
|
+
id: descriptionId,
|
|
1435
|
+
className: "text-sm text-muted-foreground",
|
|
1436
|
+
children: props.description
|
|
1437
|
+
}),
|
|
1438
|
+
/* @__PURE__ */ jsx35(ToggleGroup2, {
|
|
1439
|
+
multiple: type === "multiple",
|
|
1440
|
+
disabled: mode === "locked",
|
|
1441
|
+
value: selected,
|
|
1442
|
+
"aria-labelledby": field.label ? labelId : undefined,
|
|
1443
|
+
"aria-required": field.controlProps["aria-required"],
|
|
1444
|
+
"aria-invalid": field.controlProps["aria-invalid"],
|
|
1445
|
+
"aria-describedby": describedBy,
|
|
1446
|
+
onValueChange: (values) => {
|
|
1447
|
+
setValue(values.join(","));
|
|
1448
|
+
if (hasValidation)
|
|
1449
|
+
validate();
|
|
1450
|
+
emit("change");
|
|
1451
|
+
},
|
|
1452
|
+
children: items.map((item) => /* @__PURE__ */ jsxs24(ToggleGroupItem2, {
|
|
1453
|
+
value: item.value,
|
|
1454
|
+
children: [
|
|
1455
|
+
selected.includes(item.value) && /* @__PURE__ */ jsx35(CheckIcon, {
|
|
1456
|
+
"aria-hidden": "true",
|
|
1457
|
+
"data-slot": "toggle-group-item-check"
|
|
1458
|
+
}),
|
|
1459
|
+
item.label
|
|
1460
|
+
]
|
|
1461
|
+
}, item.value))
|
|
1462
|
+
}),
|
|
1463
|
+
/* @__PURE__ */ jsx35(JsonFieldMessage, {
|
|
1464
|
+
field
|
|
1465
|
+
})
|
|
1466
|
+
]
|
|
1367
1467
|
});
|
|
1368
1468
|
};
|
|
1369
1469
|
|
|
@@ -1428,7 +1528,7 @@ function getPaginationRange(current, total) {
|
|
|
1428
1528
|
}
|
|
1429
1529
|
|
|
1430
1530
|
// src/components/json-render/JsonPagination.tsx
|
|
1431
|
-
import { jsx as jsx37, jsxs as
|
|
1531
|
+
import { jsx as jsx37, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
1432
1532
|
var JsonPagination = ({ props, bindings, emit }) => {
|
|
1433
1533
|
const [boundPage, setBoundPage] = useBoundProp13(props.page ?? undefined, bindings?.page);
|
|
1434
1534
|
const [localPage, setLocalPage] = useState13(props.page ?? 1);
|
|
@@ -1437,7 +1537,7 @@ var JsonPagination = ({ props, bindings, emit }) => {
|
|
|
1437
1537
|
const totalPages = props.totalPages ?? 1;
|
|
1438
1538
|
const pages = getPaginationRange(currentPage, totalPages);
|
|
1439
1539
|
return /* @__PURE__ */ jsx37(Pagination2, {
|
|
1440
|
-
children: /* @__PURE__ */
|
|
1540
|
+
children: /* @__PURE__ */ jsxs25(PaginationContent2, {
|
|
1441
1541
|
children: [
|
|
1442
1542
|
/* @__PURE__ */ jsx37(PaginationItem2, {
|
|
1443
1543
|
children: /* @__PURE__ */ jsx37(PaginationPrevious2, {
|
package/dist/prototype.js
CHANGED
|
@@ -2051,7 +2051,7 @@ var program = new Command;
|
|
|
2051
2051
|
// package.json
|
|
2052
2052
|
var package_default = {
|
|
2053
2053
|
name: "@alexgorbatchev/shadcn",
|
|
2054
|
-
version: "0.0.
|
|
2054
|
+
version: "0.0.108",
|
|
2055
2055
|
description: "Sharp, monospace React components with compact and comfortable densities.",
|
|
2056
2056
|
license: "MIT",
|
|
2057
2057
|
repository: {
|
|
@@ -97,3 +97,56 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
```
|
|
100
|
+
|
|
101
|
+
### DefaultTagsAndNotSet
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
{
|
|
105
|
+
args: {
|
|
106
|
+
spec: settingsSpec,
|
|
107
|
+
state: { answers: { oncall: false, notify: null, budget: 5, risk: null, pilot: false, agree: false } },
|
|
108
|
+
defaults: ["/answers/oncall", "/answers/budget", "/answers/pilot", "/answers/agree"],
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### NotSetReadOnly
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
{
|
|
117
|
+
args: {
|
|
118
|
+
spec: settingsSpec,
|
|
119
|
+
state: { answers: { oncall: true, notify: null, budget: 5, risk: null, pilot: false, agree: false } },
|
|
120
|
+
mode: "values",
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### ToggleGroupQuestion
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
{
|
|
129
|
+
args: { spec: channelsSpec, state: { answers: { channels: "email" }, ui: { view: "list" } } }
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### ToggleGroupQuestionValues
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
{
|
|
137
|
+
args: { spec: channelsSpec, state: { answers: { channels: "email,phone" }, ui: { view: "list" } }, mode: "values" }
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### ToggleGroupOwnValidation
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
{
|
|
145
|
+
render: () => {
|
|
146
|
+
const [store] = useState(() => createStateStore({ answers: { channels: "email" } }));
|
|
147
|
+
return (<JSONUIProvider registry={registry} store={store}>
|
|
148
|
+
<Renderer spec={channelsSpec} registry={registry}/>
|
|
149
|
+
</JSONUIProvider>);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|