@mostra/kit 0.0.0-placeholder → 0.19.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/README.md +42 -1
- package/css/kit.css +59 -0
- package/css/shadcn.css +638 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +60 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +112 -0
- package/dist/layout.js.map +1 -0
- package/dist/questionnaire.d.ts +100 -0
- package/dist/questionnaire.d.ts.map +1 -0
- package/dist/questionnaire.js +632 -0
- package/dist/questionnaire.js.map +1 -0
- package/package.json +120 -4
- package/registry/LICENSE.md +21 -0
- package/registry/base/accordion.json +19 -0
- package/registry/base/alert-dialog.json +21 -0
- package/registry/base/alert.json +18 -0
- package/registry/base/aspect-ratio.json +17 -0
- package/registry/base/attachment.json +22 -0
- package/registry/base/avatar.json +18 -0
- package/registry/base/badge.json +19 -0
- package/registry/base/breadcrumb.json +19 -0
- package/registry/base/bubble.json +19 -0
- package/registry/base/button-group.json +22 -0
- package/registry/base/button.json +19 -0
- package/registry/base/calendar.json +22 -0
- package/registry/base/card.json +17 -0
- package/registry/base/carousel.json +22 -0
- package/registry/base/chart.json +21 -0
- package/registry/base/checkbox.json +19 -0
- package/registry/base/code-block.json +23 -0
- package/registry/base/collapsible.json +17 -0
- package/registry/base/combobox.json +23 -0
- package/registry/base/command.json +23 -0
- package/registry/base/components/mostra/layout.tsx +221 -0
- package/registry/base/components/mostra/questionnaire.tsx +1005 -0
- package/registry/base/components/ui/accordion.tsx +71 -0
- package/registry/base/components/ui/alert-dialog.tsx +187 -0
- package/registry/base/components/ui/alert.tsx +75 -0
- package/registry/base/components/ui/aspect-ratio.tsx +22 -0
- package/registry/base/components/ui/attachment.tsx +207 -0
- package/registry/base/components/ui/avatar.tsx +108 -0
- package/registry/base/components/ui/badge.tsx +54 -0
- package/registry/base/components/ui/breadcrumb.tsx +124 -0
- package/registry/base/components/ui/bubble.tsx +127 -0
- package/registry/base/components/ui/button-group.tsx +87 -0
- package/registry/base/components/ui/button.tsx +57 -0
- package/registry/base/components/ui/calendar.tsx +221 -0
- package/registry/base/components/ui/card.tsx +102 -0
- package/registry/base/components/ui/carousel.tsx +242 -0
- package/registry/base/components/ui/chart.tsx +372 -0
- package/registry/base/components/ui/checkbox.tsx +28 -0
- package/registry/base/components/ui/code-block.tsx +249 -0
- package/registry/base/components/ui/collapsible.tsx +21 -0
- package/registry/base/components/ui/combobox.tsx +297 -0
- package/registry/base/components/ui/command.tsx +196 -0
- package/registry/base/components/ui/context-menu.tsx +270 -0
- package/registry/base/components/ui/dialog.tsx +160 -0
- package/registry/base/components/ui/direction.tsx +6 -0
- package/registry/base/components/ui/drawer.tsx +227 -0
- package/registry/base/components/ui/dropdown-menu.tsx +267 -0
- package/registry/base/components/ui/empty.tsx +103 -0
- package/registry/base/components/ui/field.tsx +238 -0
- package/registry/base/components/ui/hover-card.tsx +50 -0
- package/registry/base/components/ui/input-group.tsx +158 -0
- package/registry/base/components/ui/input-otp.tsx +86 -0
- package/registry/base/components/ui/input.tsx +19 -0
- package/registry/base/components/ui/item.tsx +201 -0
- package/registry/base/components/ui/kbd.tsx +26 -0
- package/registry/base/components/ui/label.tsx +19 -0
- package/registry/base/components/ui/marker.tsx +70 -0
- package/registry/base/components/ui/menubar.tsx +280 -0
- package/registry/base/components/ui/message-scroller.tsx +131 -0
- package/registry/base/components/ui/message.tsx +91 -0
- package/registry/base/components/ui/native-select.tsx +60 -0
- package/registry/base/components/ui/navigation-menu.tsx +167 -0
- package/registry/base/components/ui/pagination.tsx +130 -0
- package/registry/base/components/ui/popover.tsx +89 -0
- package/registry/base/components/ui/progress.tsx +82 -0
- package/registry/base/components/ui/questionnaire.tsx +324 -0
- package/registry/base/components/ui/radio-group.tsx +37 -0
- package/registry/base/components/ui/resizable.tsx +49 -0
- package/registry/base/components/ui/scroll-area.tsx +53 -0
- package/registry/base/components/ui/select.tsx +200 -0
- package/registry/base/components/ui/separator.tsx +24 -0
- package/registry/base/components/ui/sheet.tsx +138 -0
- package/registry/base/components/ui/sidebar.tsx +723 -0
- package/registry/base/components/ui/skeleton.tsx +13 -0
- package/registry/base/components/ui/slider.tsx +51 -0
- package/registry/base/components/ui/sonner.tsx +65 -0
- package/registry/base/components/ui/spinner.tsx +10 -0
- package/registry/base/components/ui/switch.tsx +31 -0
- package/registry/base/components/ui/table.tsx +116 -0
- package/registry/base/components/ui/tabs.tsx +85 -0
- package/registry/base/components/ui/textarea.tsx +17 -0
- package/registry/base/components/ui/toast.tsx +234 -0
- package/registry/base/components/ui/toggle-group.tsx +89 -0
- package/registry/base/components/ui/toggle.tsx +44 -0
- package/registry/base/components/ui/tooltip.tsx +65 -0
- package/registry/base/components/ui/trace.tsx +162 -0
- package/registry/base/context-menu.json +19 -0
- package/registry/base/dialog.json +22 -0
- package/registry/base/direction.json +17 -0
- package/registry/base/drawer.json +18 -0
- package/registry/base/dropdown-menu.json +19 -0
- package/registry/base/empty.json +18 -0
- package/registry/base/field.json +22 -0
- package/registry/base/hooks/use-highlighted-code.ts +75 -0
- package/registry/base/hooks/use-mobile.ts +19 -0
- package/registry/base/hover-card.json +18 -0
- package/registry/base/input-group.json +23 -0
- package/registry/base/input-otp.json +19 -0
- package/registry/base/input.json +18 -0
- package/registry/base/item.json +22 -0
- package/registry/base/kbd.json +17 -0
- package/registry/base/label.json +17 -0
- package/registry/base/lib/highlighter.tsx +124 -0
- package/registry/base/lib/utils.ts +1 -0
- package/registry/base/marker.json +19 -0
- package/registry/base/menubar.json +22 -0
- package/registry/base/message-scroller.json +22 -0
- package/registry/base/message.json +17 -0
- package/registry/base/mostra-layout.json +20 -0
- package/registry/base/mostra-questionnaire.json +22 -0
- package/registry/base/native-select.json +18 -0
- package/registry/base/navigation-menu.json +20 -0
- package/registry/base/pagination.json +21 -0
- package/registry/base/popover.json +18 -0
- package/registry/base/progress.json +18 -0
- package/registry/base/questionnaire.json +22 -0
- package/registry/base/radio-group.json +18 -0
- package/registry/base/registry.json +287 -0
- package/registry/base/resizable.json +18 -0
- package/registry/base/scroll-area.json +18 -0
- package/registry/base/select.json +19 -0
- package/registry/base/separator.json +18 -0
- package/registry/base/sheet.json +22 -0
- package/registry/base/sidebar.json +29 -0
- package/registry/base/skeleton.json +17 -0
- package/registry/base/slider.json +18 -0
- package/registry/base/sonner.json +18 -0
- package/registry/base/spinner.json +18 -0
- package/registry/base/switch.json +18 -0
- package/registry/base/table.json +17 -0
- package/registry/base/tabs.json +19 -0
- package/registry/base/textarea.json +17 -0
- package/registry/base/toast.json +22 -0
- package/registry/base/toggle-group.json +22 -0
- package/registry/base/toggle.json +19 -0
- package/registry/base/tooltip.json +18 -0
- package/registry/base/trace.json +21 -0
- package/registry/base/use-highlighted-code.json +21 -0
- package/registry/base/use-mobile.json +14 -0
- package/registry/base/utils.json +17 -0
- package/registry/radix/accordion.json +19 -0
- package/registry/radix/alert-dialog.json +21 -0
- package/registry/radix/alert.json +18 -0
- package/registry/radix/aspect-ratio.json +17 -0
- package/registry/radix/attachment.json +22 -0
- package/registry/radix/avatar.json +18 -0
- package/registry/radix/badge.json +19 -0
- package/registry/radix/breadcrumb.json +19 -0
- package/registry/radix/bubble.json +19 -0
- package/registry/radix/button-group.json +22 -0
- package/registry/radix/button.json +19 -0
- package/registry/radix/calendar.json +22 -0
- package/registry/radix/card.json +17 -0
- package/registry/radix/carousel.json +22 -0
- package/registry/radix/chart.json +18 -0
- package/registry/radix/checkbox.json +19 -0
- package/registry/radix/code-block.json +23 -0
- package/registry/radix/collapsible.json +17 -0
- package/registry/radix/combobox.json +23 -0
- package/registry/radix/command.json +23 -0
- package/registry/radix/components/mostra/layout.tsx +221 -0
- package/registry/radix/components/mostra/questionnaire.tsx +1005 -0
- package/registry/radix/components/ui/accordion.tsx +80 -0
- package/registry/radix/components/ui/alert-dialog.tsx +199 -0
- package/registry/radix/components/ui/alert.tsx +75 -0
- package/registry/radix/components/ui/aspect-ratio.tsx +11 -0
- package/registry/radix/components/ui/attachment.tsx +204 -0
- package/registry/radix/components/ui/avatar.tsx +111 -0
- package/registry/radix/components/ui/badge.tsx +51 -0
- package/registry/radix/components/ui/breadcrumb.tsx +121 -0
- package/registry/radix/components/ui/bubble.tsx +124 -0
- package/registry/radix/components/ui/button-group.tsx +83 -0
- package/registry/radix/components/ui/button.tsx +66 -0
- package/registry/radix/components/ui/calendar.tsx +222 -0
- package/registry/radix/components/ui/card.tsx +102 -0
- package/registry/radix/components/ui/carousel.tsx +242 -0
- package/registry/radix/components/ui/chart.tsx +372 -0
- package/registry/radix/components/ui/checkbox.tsx +32 -0
- package/registry/radix/components/ui/code-block.tsx +249 -0
- package/registry/radix/components/ui/collapsible.tsx +33 -0
- package/registry/radix/components/ui/combobox.tsx +299 -0
- package/registry/radix/components/ui/command.tsx +195 -0
- package/registry/radix/components/ui/context-menu.tsx +262 -0
- package/registry/radix/components/ui/dialog.tsx +168 -0
- package/registry/radix/components/ui/direction.tsx +22 -0
- package/registry/radix/components/ui/drawer.tsx +133 -0
- package/registry/radix/components/ui/dropdown-menu.tsx +268 -0
- package/registry/radix/components/ui/empty.tsx +103 -0
- package/registry/radix/components/ui/field.tsx +238 -0
- package/registry/radix/components/ui/hover-card.tsx +43 -0
- package/registry/radix/components/ui/input-group.tsx +156 -0
- package/registry/radix/components/ui/input-otp.tsx +86 -0
- package/registry/radix/components/ui/input.tsx +18 -0
- package/registry/radix/components/ui/item.tsx +196 -0
- package/registry/radix/components/ui/kbd.tsx +26 -0
- package/registry/radix/components/ui/label.tsx +23 -0
- package/registry/radix/components/ui/marker.tsx +68 -0
- package/registry/radix/components/ui/menubar.tsx +279 -0
- package/registry/radix/components/ui/message-scroller.tsx +131 -0
- package/registry/radix/components/ui/message.tsx +91 -0
- package/registry/radix/components/ui/native-select.tsx +60 -0
- package/registry/radix/components/ui/navigation-menu.tsx +163 -0
- package/registry/radix/components/ui/pagination.tsx +129 -0
- package/registry/radix/components/ui/popover.tsx +88 -0
- package/registry/radix/components/ui/progress.tsx +30 -0
- package/registry/radix/components/ui/questionnaire.tsx +324 -0
- package/registry/radix/components/ui/radio-group.tsx +43 -0
- package/registry/radix/components/ui/resizable.tsx +49 -0
- package/registry/radix/components/ui/scroll-area.tsx +54 -0
- package/registry/radix/components/ui/select.tsx +191 -0
- package/registry/radix/components/ui/separator.tsx +27 -0
- package/registry/radix/components/ui/sheet.tsx +147 -0
- package/registry/radix/components/ui/sidebar.tsx +702 -0
- package/registry/radix/components/ui/skeleton.tsx +13 -0
- package/registry/radix/components/ui/slider.tsx +62 -0
- package/registry/radix/components/ui/sonner.tsx +65 -0
- package/registry/radix/components/ui/spinner.tsx +10 -0
- package/registry/radix/components/ui/switch.tsx +32 -0
- package/registry/radix/components/ui/table.tsx +116 -0
- package/registry/radix/components/ui/tabs.tsx +129 -0
- package/registry/radix/components/ui/textarea.tsx +17 -0
- package/registry/radix/components/ui/toggle-group.tsx +89 -0
- package/registry/radix/components/ui/toggle.tsx +46 -0
- package/registry/radix/components/ui/tooltip.tsx +56 -0
- package/registry/radix/components/ui/trace.tsx +162 -0
- package/registry/radix/context-menu.json +19 -0
- package/registry/radix/dialog.json +22 -0
- package/registry/radix/direction.json +17 -0
- package/registry/radix/drawer.json +18 -0
- package/registry/radix/dropdown-menu.json +19 -0
- package/registry/radix/empty.json +18 -0
- package/registry/radix/field.json +22 -0
- package/registry/radix/hooks/use-highlighted-code.ts +75 -0
- package/registry/radix/hooks/use-mobile.ts +19 -0
- package/registry/radix/hover-card.json +18 -0
- package/registry/radix/input-group.json +23 -0
- package/registry/radix/input-otp.json +19 -0
- package/registry/radix/input.json +17 -0
- package/registry/radix/item.json +22 -0
- package/registry/radix/kbd.json +17 -0
- package/registry/radix/label.json +18 -0
- package/registry/radix/lib/highlighter.tsx +124 -0
- package/registry/radix/lib/utils.ts +1 -0
- package/registry/radix/marker.json +19 -0
- package/registry/radix/menubar.json +19 -0
- package/registry/radix/message-scroller.json +22 -0
- package/registry/radix/message.json +17 -0
- package/registry/radix/mostra-layout.json +20 -0
- package/registry/radix/mostra-questionnaire.json +22 -0
- package/registry/radix/native-select.json +18 -0
- package/registry/radix/navigation-menu.json +20 -0
- package/registry/radix/pagination.json +21 -0
- package/registry/radix/popover.json +18 -0
- package/registry/radix/progress.json +18 -0
- package/registry/radix/questionnaire.json +22 -0
- package/registry/radix/radio-group.json +18 -0
- package/registry/radix/registry.json +283 -0
- package/registry/radix/resizable.json +18 -0
- package/registry/radix/scroll-area.json +18 -0
- package/registry/radix/select.json +19 -0
- package/registry/radix/separator.json +18 -0
- package/registry/radix/sheet.json +22 -0
- package/registry/radix/sidebar.json +29 -0
- package/registry/radix/skeleton.json +17 -0
- package/registry/radix/slider.json +18 -0
- package/registry/radix/sonner.json +18 -0
- package/registry/radix/spinner.json +18 -0
- package/registry/radix/switch.json +18 -0
- package/registry/radix/table.json +17 -0
- package/registry/radix/tabs.json +19 -0
- package/registry/radix/textarea.json +17 -0
- package/registry/radix/toggle-group.json +22 -0
- package/registry/radix/toggle.json +19 -0
- package/registry/radix/tooltip.json +18 -0
- package/registry/radix/trace.json +21 -0
- package/registry/radix/use-highlighted-code.json +21 -0
- package/registry/radix/use-mobile.json +14 -0
- package/registry/radix/utils.json +17 -0
- package/src/index.ts +15 -0
- package/src/layout.tsx +221 -0
- package/src/questionnaire.tsx +1005 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useField } from "@mostra/react";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { ArrowDown, ArrowUp, Check, X } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/questionnaire.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The questionnaire (ROUND-3 §1.4, KT-05): questions people answer, each answer a field
|
|
10
|
+
* (`<questionnaire>.<question>`, D52) saved as they go, labelled in results with the options the
|
|
11
|
+
* person saw and whether they took the one recommended. Choices (one or several, with an answer of
|
|
12
|
+
* their own), scales, rankings and text; a comment on any question; required questions, which the
|
|
13
|
+
* trusted Submit waits for; sections; progress; on one page or a step at a time.
|
|
14
|
+
*
|
|
15
|
+
* Ordinary React on native inputs, so it works in either base and anywhere React runs; every part
|
|
16
|
+
* reads the theme's tokens and takes `className`, and `mostra add mostra-questionnaire` copies it
|
|
17
|
+
* into the artifact for editing, where the copy then wins (D68, KT-10).
|
|
18
|
+
*/
|
|
19
|
+
const QuestionnaireContext = React.createContext(null);
|
|
20
|
+
function useQuestionnaire(part) {
|
|
21
|
+
const context = React.useContext(QuestionnaireContext);
|
|
22
|
+
if (context === null) throw new Error(`<${part}> belongs inside a <Questionnaire>.`);
|
|
23
|
+
return context;
|
|
24
|
+
}
|
|
25
|
+
/** The `id`s of the questions under `children`, in reading order, through sections and fragments. */
|
|
26
|
+
function questionIds(children) {
|
|
27
|
+
const ids = [];
|
|
28
|
+
React.Children.forEach(children, (child) => {
|
|
29
|
+
if (!React.isValidElement(child)) return;
|
|
30
|
+
const props = child.props;
|
|
31
|
+
if (child.type === Question && typeof props.id === "string") ids.push(props.id);
|
|
32
|
+
else if (child.type === Section || child.type === React.Fragment) ids.push(...questionIds(props.children));
|
|
33
|
+
});
|
|
34
|
+
return ids;
|
|
35
|
+
}
|
|
36
|
+
function Questionnaire({ id, title, description, mode = "page", progress = true, className, children, ...props }) {
|
|
37
|
+
const ids = questionIds(children);
|
|
38
|
+
const numbers = new Map(ids.map((question, index) => [question, index + 1]));
|
|
39
|
+
const [answered, setAnswered] = React.useState(/* @__PURE__ */ new Set());
|
|
40
|
+
const context = {
|
|
41
|
+
id,
|
|
42
|
+
numbers,
|
|
43
|
+
report: React.useCallback((question, isAnswered) => {
|
|
44
|
+
setAnswered((current) => {
|
|
45
|
+
if (current.has(question) === isAnswered) return current;
|
|
46
|
+
const next = new Set(current);
|
|
47
|
+
if (isAnswered) next.add(question);
|
|
48
|
+
else next.delete(question);
|
|
49
|
+
return next;
|
|
50
|
+
});
|
|
51
|
+
}, [])
|
|
52
|
+
};
|
|
53
|
+
const numbered = numberSections(children);
|
|
54
|
+
const steps = React.Children.toArray(numbered).filter(React.isValidElement);
|
|
55
|
+
const [step, setStep] = React.useState(0);
|
|
56
|
+
const current = Math.min(step, Math.max(steps.length - 1, 0));
|
|
57
|
+
const count = ids.filter((question) => answered.has(question)).length;
|
|
58
|
+
return /* @__PURE__ */ jsx(QuestionnaireContext.Provider, {
|
|
59
|
+
value: context,
|
|
60
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
61
|
+
"data-slot": "questionnaire",
|
|
62
|
+
"data-mode": mode,
|
|
63
|
+
className: cn("flex flex-col gap-(--stack-gap)", className),
|
|
64
|
+
...props,
|
|
65
|
+
children: [
|
|
66
|
+
(title !== void 0 || description !== void 0 || progress) && /* @__PURE__ */ jsxs("header", {
|
|
67
|
+
"data-slot": "questionnaire-header",
|
|
68
|
+
className: "flex flex-col gap-3",
|
|
69
|
+
children: [
|
|
70
|
+
title !== void 0 && /* @__PURE__ */ jsx("h1", { children: title }),
|
|
71
|
+
description !== void 0 && /* @__PURE__ */ jsx("p", {
|
|
72
|
+
className: "max-w-prose text-pretty text-muted-foreground",
|
|
73
|
+
children: description
|
|
74
|
+
}),
|
|
75
|
+
progress && ids.length > 0 && /* @__PURE__ */ jsx(AnswerProgress, {
|
|
76
|
+
answered: count,
|
|
77
|
+
total: ids.length
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
}),
|
|
81
|
+
mode === "page" ? numbered : steps.map((child, index) => /* @__PURE__ */ jsx("div", {
|
|
82
|
+
"data-slot": "questionnaire-step",
|
|
83
|
+
hidden: index !== current,
|
|
84
|
+
children: child
|
|
85
|
+
}, child.key ?? index)),
|
|
86
|
+
mode === "steps" && steps.length > 1 && /* @__PURE__ */ jsxs("nav", {
|
|
87
|
+
"data-slot": "questionnaire-steps",
|
|
88
|
+
"aria-label": "Steps",
|
|
89
|
+
className: "flex items-center justify-between gap-4 border-t border-border pt-5",
|
|
90
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
91
|
+
className: "text-sm text-muted-foreground tabular-nums",
|
|
92
|
+
children: [
|
|
93
|
+
"Step ",
|
|
94
|
+
current + 1,
|
|
95
|
+
" of ",
|
|
96
|
+
steps.length
|
|
97
|
+
]
|
|
98
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
99
|
+
className: "flex gap-2",
|
|
100
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
101
|
+
type: "button",
|
|
102
|
+
disabled: current === 0,
|
|
103
|
+
onClick: () => setStep(current - 1),
|
|
104
|
+
className: stepButton("secondary"),
|
|
105
|
+
children: "Previous"
|
|
106
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
107
|
+
type: "button",
|
|
108
|
+
disabled: current === steps.length - 1,
|
|
109
|
+
onClick: () => setStep(current + 1),
|
|
110
|
+
className: stepButton("primary"),
|
|
111
|
+
children: "Next"
|
|
112
|
+
})]
|
|
113
|
+
})]
|
|
114
|
+
})
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function stepButton(kind) {
|
|
120
|
+
return cn("press inline-flex h-(--control-h-sm) items-center rounded-button px-4 text-sm font-medium outline-none focus-visible:ring-3 focus-visible:ring-ring/40 disabled:pointer-events-none disabled:opacity-40", kind === "primary" ? "bg-primary text-primary-foreground shadow-button hover:bg-[color-mix(in_oklab,var(--primary),var(--foreground)_14%)]" : "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklab,var(--secondary),var(--foreground)_6%)]");
|
|
121
|
+
}
|
|
122
|
+
function Section({ title, description, index, className, children, ...props }) {
|
|
123
|
+
const headingId = React.useId();
|
|
124
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
125
|
+
"data-slot": "questionnaire-section",
|
|
126
|
+
"aria-labelledby": headingId,
|
|
127
|
+
className: cn("flex flex-col gap-8 rounded-(--section-radius) bg-(--section-bg) p-(--section-pad) shadow-(--section-shadow) [border-top:var(--section-rule)]", className),
|
|
128
|
+
...props,
|
|
129
|
+
children: [/* @__PURE__ */ jsxs("header", {
|
|
130
|
+
className: "flex flex-col gap-1.5",
|
|
131
|
+
children: [/* @__PURE__ */ jsxs("h2", {
|
|
132
|
+
id: headingId,
|
|
133
|
+
className: "flex items-center gap-[0.6em]",
|
|
134
|
+
children: [index !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
135
|
+
"data-slot": "section-index",
|
|
136
|
+
"aria-hidden": true,
|
|
137
|
+
className: "grid size-(--section-index-size) shrink-0 place-items-center rounded-full bg-(--section-index-bg) text-[0.8em] text-(--section-index-color) tabular-nums",
|
|
138
|
+
children: index
|
|
139
|
+
}), /* @__PURE__ */ jsx("span", { children: title })]
|
|
140
|
+
}), description !== void 0 && /* @__PURE__ */ jsx("p", {
|
|
141
|
+
className: "max-w-prose text-pretty text-muted-foreground",
|
|
142
|
+
children: description
|
|
143
|
+
})]
|
|
144
|
+
}), children]
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** The questionnaire's sections, numbered in order: those it holds directly or in fragments. */
|
|
148
|
+
function numberSections(children, next = { value: 1 }) {
|
|
149
|
+
return React.Children.map(children, (child) => {
|
|
150
|
+
if (!React.isValidElement(child)) return child;
|
|
151
|
+
if (child.type === Section) return child.props.index !== void 0 ? child : React.cloneElement(child, { index: next.value++ });
|
|
152
|
+
if (child.type === React.Fragment) {
|
|
153
|
+
const props = child.props;
|
|
154
|
+
return /* @__PURE__ */ jsx(React.Fragment, { children: numberSections(props.children, next) }, child.key);
|
|
155
|
+
}
|
|
156
|
+
return child;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const QuestionContext = React.createContext(null);
|
|
160
|
+
function useQuestion(part) {
|
|
161
|
+
const context = React.useContext(QuestionContext);
|
|
162
|
+
if (context === null) throw new Error(`<${part}> belongs inside a <Question>.`);
|
|
163
|
+
return context;
|
|
164
|
+
}
|
|
165
|
+
/** The text of a title, for results' labels, when it is text. */
|
|
166
|
+
function textOf(node) {
|
|
167
|
+
if (typeof node === "string") return node;
|
|
168
|
+
if (typeof node === "number") return String(node);
|
|
169
|
+
}
|
|
170
|
+
function Question({ id, title, label, description, required = false, multiple = false, comments = false, className, children, ...props }) {
|
|
171
|
+
const questionnaire = useQuestionnaire("Question");
|
|
172
|
+
const field = `${questionnaire.id}.${id}`;
|
|
173
|
+
const titleId = React.useId();
|
|
174
|
+
const descriptionId = React.useId();
|
|
175
|
+
const reportTo = questionnaire.report;
|
|
176
|
+
const report = React.useCallback((answered) => reportTo(id, answered), [reportTo, id]);
|
|
177
|
+
const context = React.useMemo(() => ({
|
|
178
|
+
field,
|
|
179
|
+
label: label ?? textOf(title),
|
|
180
|
+
required,
|
|
181
|
+
multiple,
|
|
182
|
+
titleId,
|
|
183
|
+
descriptionId: description === void 0 ? void 0 : descriptionId,
|
|
184
|
+
report
|
|
185
|
+
}), [
|
|
186
|
+
field,
|
|
187
|
+
label,
|
|
188
|
+
title,
|
|
189
|
+
required,
|
|
190
|
+
multiple,
|
|
191
|
+
titleId,
|
|
192
|
+
description,
|
|
193
|
+
descriptionId,
|
|
194
|
+
report
|
|
195
|
+
]);
|
|
196
|
+
const choices = React.Children.toArray(children).some((child) => React.isValidElement(child) && (child.type === Choice || child.type === Other));
|
|
197
|
+
const number = questionnaire.numbers.get(id);
|
|
198
|
+
return /* @__PURE__ */ jsx(QuestionContext.Provider, {
|
|
199
|
+
value: context,
|
|
200
|
+
children: /* @__PURE__ */ jsxs("fieldset", {
|
|
201
|
+
"data-slot": "question",
|
|
202
|
+
"aria-describedby": description === void 0 ? void 0 : descriptionId,
|
|
203
|
+
className: cn("m-0 flex min-w-0 flex-col gap-4 border-0 p-0", className),
|
|
204
|
+
...props,
|
|
205
|
+
children: [
|
|
206
|
+
/* @__PURE__ */ jsx("legend", {
|
|
207
|
+
id: titleId,
|
|
208
|
+
className: "contents",
|
|
209
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
210
|
+
className: "flex items-baseline gap-3 font-heading text-[1.0625rem] leading-snug font-(--heading-weight) tracking-(--heading-tracking) text-balance",
|
|
211
|
+
children: [number !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
212
|
+
"data-slot": "question-number",
|
|
213
|
+
"aria-hidden": true,
|
|
214
|
+
className: "font-sans text-sm font-semibold text-(--question-number-color) tabular-nums",
|
|
215
|
+
children: number
|
|
216
|
+
}), /* @__PURE__ */ jsxs("span", { children: [title, required ? /* @__PURE__ */ jsx("span", {
|
|
217
|
+
className: "ml-2 align-middle font-sans text-xs font-medium text-muted-foreground",
|
|
218
|
+
children: "Required"
|
|
219
|
+
}) : null] })]
|
|
220
|
+
})
|
|
221
|
+
}),
|
|
222
|
+
description !== void 0 && /* @__PURE__ */ jsx("p", {
|
|
223
|
+
id: descriptionId,
|
|
224
|
+
className: "-mt-2 text-sm text-pretty text-muted-foreground",
|
|
225
|
+
children: description
|
|
226
|
+
}),
|
|
227
|
+
choices ? /* @__PURE__ */ jsx(ChoiceAnswer, { children }) : children,
|
|
228
|
+
comments && /* @__PURE__ */ jsx(Comment, {})
|
|
229
|
+
]
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/** Reports to the questionnaire whether the question is answered. */
|
|
234
|
+
function useAnswered(report, answered) {
|
|
235
|
+
React.useEffect(() => report(answered), [report, answered]);
|
|
236
|
+
React.useEffect(() => () => report(false), [report]);
|
|
237
|
+
}
|
|
238
|
+
/** A choice of a question: rendered by its question, which owns the answer. */
|
|
239
|
+
function Choice(_props) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
/** The value an answer of the person's own holds; the text is `<question>.other`. */
|
|
243
|
+
const OTHER = "other";
|
|
244
|
+
/** An answer of the person's own: chosen, then written. */
|
|
245
|
+
function Other(_props) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
function ChoiceAnswer({ children }) {
|
|
249
|
+
const question = useQuestion("Choice");
|
|
250
|
+
const items = React.Children.toArray(children).filter(React.isValidElement);
|
|
251
|
+
const choices = items.filter((item) => item.type === Choice);
|
|
252
|
+
const other = items.find((item) => item.type === Other);
|
|
253
|
+
const otherLabel = textOf(other?.props.children) ?? "Something else";
|
|
254
|
+
const options = [...choices.map((choice) => ({
|
|
255
|
+
value: choice.props.value,
|
|
256
|
+
...(choice.props.label ?? textOf(choice.props.children)) !== void 0 ? { label: choice.props.label ?? textOf(choice.props.children) } : {},
|
|
257
|
+
...choice.props.recommended ? { recommended: true } : {}
|
|
258
|
+
})), ...other ? [{
|
|
259
|
+
value: OTHER,
|
|
260
|
+
label: otherLabel
|
|
261
|
+
}] : []];
|
|
262
|
+
const fieldOptions = {
|
|
263
|
+
...question.label !== void 0 ? { label: question.label } : {},
|
|
264
|
+
required: question.required,
|
|
265
|
+
options
|
|
266
|
+
};
|
|
267
|
+
return question.multiple ? /* @__PURE__ */ jsx(ManyChoices, {
|
|
268
|
+
choices,
|
|
269
|
+
other,
|
|
270
|
+
otherLabel,
|
|
271
|
+
options: fieldOptions
|
|
272
|
+
}) : /* @__PURE__ */ jsx(OneChoice, {
|
|
273
|
+
choices,
|
|
274
|
+
other,
|
|
275
|
+
otherLabel,
|
|
276
|
+
options: fieldOptions
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function OneChoice({ choices, other, otherLabel, options }) {
|
|
280
|
+
const question = useQuestion("Choice");
|
|
281
|
+
const [value, setValue] = useField(question.field, "", options);
|
|
282
|
+
useAnswered(question.report, value !== "");
|
|
283
|
+
const media = choices.some((choice) => choice.props.media !== void 0);
|
|
284
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
285
|
+
className: "flex flex-col gap-3",
|
|
286
|
+
children: [
|
|
287
|
+
/* @__PURE__ */ jsxs("div", {
|
|
288
|
+
role: "radiogroup",
|
|
289
|
+
"aria-labelledby": question.titleId,
|
|
290
|
+
"aria-required": question.required || void 0,
|
|
291
|
+
className: cn("grid gap-2.5", media && "sm:grid-cols-2"),
|
|
292
|
+
children: [choices.map((choice) => /* @__PURE__ */ jsx(ChoiceCard, {
|
|
293
|
+
type: "radio",
|
|
294
|
+
name: question.field,
|
|
295
|
+
checked: value === choice.props.value,
|
|
296
|
+
onChange: () => setValue(choice.props.value),
|
|
297
|
+
...choice.props
|
|
298
|
+
}, choice.props.value)), other && /* @__PURE__ */ jsx(ChoiceCard, {
|
|
299
|
+
type: "radio",
|
|
300
|
+
name: question.field,
|
|
301
|
+
value: OTHER,
|
|
302
|
+
checked: value === OTHER,
|
|
303
|
+
onChange: () => setValue(OTHER),
|
|
304
|
+
className: other.props.className,
|
|
305
|
+
children: otherLabel
|
|
306
|
+
})]
|
|
307
|
+
}),
|
|
308
|
+
other && value === OTHER && /* @__PURE__ */ jsx(OtherText, {
|
|
309
|
+
placeholder: other.props.placeholder,
|
|
310
|
+
label: otherLabel
|
|
311
|
+
}),
|
|
312
|
+
!question.required && value !== "" && /* @__PURE__ */ jsxs("button", {
|
|
313
|
+
type: "button",
|
|
314
|
+
onClick: () => setValue(""),
|
|
315
|
+
"aria-label": question.label ? `Clear my answer to “${question.label}”` : "Clear my answer",
|
|
316
|
+
className: "press inline-flex w-fit items-center gap-1.5 rounded-button px-2 py-1 text-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/40",
|
|
317
|
+
children: [/* @__PURE__ */ jsx(X, {
|
|
318
|
+
"aria-hidden": true,
|
|
319
|
+
className: "size-3.5"
|
|
320
|
+
}), "Clear my answer"]
|
|
321
|
+
})
|
|
322
|
+
]
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function ManyChoices({ choices, other, otherLabel, options }) {
|
|
326
|
+
const question = useQuestion("Choice");
|
|
327
|
+
const [value, setValue] = useField(question.field, [], options);
|
|
328
|
+
useAnswered(question.report, value.length > 0);
|
|
329
|
+
const toggle = (choice, on) => setValue((current) => on ? [...current.filter((v) => v !== choice), choice] : current.filter((v) => v !== choice));
|
|
330
|
+
const media = choices.some((choice) => choice.props.media !== void 0);
|
|
331
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
332
|
+
className: "flex flex-col gap-3",
|
|
333
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
334
|
+
className: cn("grid gap-2.5", media && "sm:grid-cols-2"),
|
|
335
|
+
children: [choices.map((choice) => /* @__PURE__ */ jsx(ChoiceCard, {
|
|
336
|
+
type: "checkbox",
|
|
337
|
+
name: question.field,
|
|
338
|
+
checked: value.includes(choice.props.value),
|
|
339
|
+
onChange: (event) => toggle(choice.props.value, event.currentTarget.checked),
|
|
340
|
+
...choice.props
|
|
341
|
+
}, choice.props.value)), other && /* @__PURE__ */ jsx(ChoiceCard, {
|
|
342
|
+
type: "checkbox",
|
|
343
|
+
name: question.field,
|
|
344
|
+
value: OTHER,
|
|
345
|
+
checked: value.includes(OTHER),
|
|
346
|
+
onChange: (event) => toggle(OTHER, event.currentTarget.checked),
|
|
347
|
+
className: other.props.className,
|
|
348
|
+
children: otherLabel
|
|
349
|
+
})]
|
|
350
|
+
}), other && value.includes(OTHER) && /* @__PURE__ */ jsx(OtherText, {
|
|
351
|
+
placeholder: other.props.placeholder,
|
|
352
|
+
label: otherLabel
|
|
353
|
+
})]
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
function OtherText({ placeholder, label }) {
|
|
357
|
+
const question = useQuestion("Other");
|
|
358
|
+
const [text, setText] = useField(`${question.field}.other`, "", { label: question.label !== void 0 ? `${question.label}: ${label}` : label });
|
|
359
|
+
return /* @__PURE__ */ jsx("input", {
|
|
360
|
+
type: "text",
|
|
361
|
+
"data-slot": "question-other",
|
|
362
|
+
"aria-label": label,
|
|
363
|
+
value: text,
|
|
364
|
+
placeholder: placeholder ?? "Say what you'd choose",
|
|
365
|
+
onChange: (event) => setText(event.currentTarget.value),
|
|
366
|
+
className: fieldClasses
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function ChoiceCard({ type, name, value, checked, onChange, children, description, recommended, meta, media, className }) {
|
|
370
|
+
const descriptionId = React.useId();
|
|
371
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
372
|
+
/* @__PURE__ */ jsx(AnswerMark, { shape: type === "radio" ? "circle" : "square" }),
|
|
373
|
+
/* @__PURE__ */ jsxs("span", {
|
|
374
|
+
className: "flex min-w-0 flex-1 flex-col gap-1",
|
|
375
|
+
children: [
|
|
376
|
+
/* @__PURE__ */ jsxs("span", {
|
|
377
|
+
className: "flex flex-wrap items-center gap-x-2.5 gap-y-1",
|
|
378
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
379
|
+
className: "font-medium",
|
|
380
|
+
children
|
|
381
|
+
}), recommended ? /* @__PURE__ */ jsxs("span", {
|
|
382
|
+
"data-slot": "recommended",
|
|
383
|
+
className: "inline-flex items-center gap-1.5 text-xs font-semibold text-highlight group-data-[checked=true]/choice:text-(--choice-selected-fg)",
|
|
384
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
385
|
+
"aria-hidden": true,
|
|
386
|
+
className: "size-1.5 rounded-full bg-highlight group-data-[checked=true]/choice:bg-answer"
|
|
387
|
+
}), typeof recommended === "string" ? recommended : "Recommended"]
|
|
388
|
+
}) : null]
|
|
389
|
+
}),
|
|
390
|
+
description !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
391
|
+
id: descriptionId,
|
|
392
|
+
className: "text-sm text-muted-foreground group-data-[checked=true]/choice:text-(--choice-selected-muted)",
|
|
393
|
+
children: description
|
|
394
|
+
}),
|
|
395
|
+
media !== void 0 && meta !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
396
|
+
className: "pt-1 text-sm font-medium tabular-nums",
|
|
397
|
+
children: meta
|
|
398
|
+
})
|
|
399
|
+
]
|
|
400
|
+
}),
|
|
401
|
+
media === void 0 && meta !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
402
|
+
className: "shrink-0 text-sm text-muted-foreground tabular-nums group-data-[checked=true]/choice:text-(--choice-selected-muted)",
|
|
403
|
+
children: meta
|
|
404
|
+
})
|
|
405
|
+
] });
|
|
406
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
407
|
+
"data-slot": "choice",
|
|
408
|
+
"data-checked": checked,
|
|
409
|
+
className: cn("group/choice press relative flex w-full cursor-pointer rounded-choice bg-(--choice-bg) p-4 text-left shadow-choice transition-[background-color,box-shadow,color] duration-(--state-ms)", media !== void 0 ? "flex-col gap-4" : "items-start gap-3.5", "hover:bg-(--choice-hover-bg) has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/40", "data-[checked=true]:bg-(--choice-selected-bg) data-[checked=true]:text-(--choice-selected-fg) data-[checked=true]:shadow-(--choice-selected-shadow) data-[checked=true]:hover:bg-(--choice-selected-hover-bg)", className),
|
|
410
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
411
|
+
type,
|
|
412
|
+
name,
|
|
413
|
+
value,
|
|
414
|
+
checked,
|
|
415
|
+
onChange,
|
|
416
|
+
"aria-describedby": description !== void 0 ? descriptionId : void 0,
|
|
417
|
+
className: "absolute inset-0 z-10 m-0 size-full cursor-pointer appearance-none rounded-[inherit] opacity-0"
|
|
418
|
+
}), media !== void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
419
|
+
"data-slot": "choice-media",
|
|
420
|
+
className: "block w-full",
|
|
421
|
+
children: media
|
|
422
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
423
|
+
className: "flex items-start gap-3.5",
|
|
424
|
+
children: body
|
|
425
|
+
})] }) : body]
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/** The mark of an answer: a giallo dot that drops in, the theme's signature move (D181 item 1). */
|
|
429
|
+
function AnswerMark({ shape = "circle" }) {
|
|
430
|
+
return /* @__PURE__ */ jsx("span", {
|
|
431
|
+
"data-slot": "answer-mark",
|
|
432
|
+
"aria-hidden": true,
|
|
433
|
+
className: cn("relative mt-px grid size-5 shrink-0 place-items-center border-[1.5px] border-input bg-card transition-colors duration-(--state-ms)", "group-data-[checked=true]/choice:border-foreground group-data-[checked=true]/choice:bg-answer", shape === "circle" ? "rounded-full" : "rounded-[5px]"),
|
|
434
|
+
children: shape === "circle" ? /* @__PURE__ */ jsx("span", { className: "animate-answer hidden size-2 rounded-full bg-foreground group-data-[checked=true]/choice:block" }) : /* @__PURE__ */ jsx(Check, {
|
|
435
|
+
strokeWidth: 3,
|
|
436
|
+
className: "animate-answer hidden size-3.5 text-foreground group-data-[checked=true]/choice:block"
|
|
437
|
+
})
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
function Scale({ min = 1, max = 5, labels, className }) {
|
|
441
|
+
const question = useQuestion("Scale");
|
|
442
|
+
const steps = Array.from({ length: Math.max(0, max - min + 1) }, (_, index) => min + index);
|
|
443
|
+
const [value, setValue] = useField(question.field, null, {
|
|
444
|
+
...question.label !== void 0 ? { label: question.label } : {},
|
|
445
|
+
required: question.required,
|
|
446
|
+
options: steps.map((step, index) => ({
|
|
447
|
+
value: step,
|
|
448
|
+
label: labels !== void 0 && index === 0 ? `${step} (${labels[0]})` : labels !== void 0 && index === steps.length - 1 ? `${step} (${labels[1]})` : String(step)
|
|
449
|
+
}))
|
|
450
|
+
});
|
|
451
|
+
useAnswered(question.report, value !== null);
|
|
452
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
453
|
+
"data-slot": "scale",
|
|
454
|
+
className: cn("flex flex-col gap-2.5", className),
|
|
455
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
456
|
+
role: "radiogroup",
|
|
457
|
+
"aria-labelledby": question.titleId,
|
|
458
|
+
className: "grid gap-1.5",
|
|
459
|
+
style: { gridTemplateColumns: `repeat(${steps.length}, minmax(0, 1fr))` },
|
|
460
|
+
children: steps.map((step, index) => /* @__PURE__ */ jsxs("label", {
|
|
461
|
+
"data-slot": "scale-step",
|
|
462
|
+
"data-checked": value === step,
|
|
463
|
+
className: cn("press relative grid h-12 cursor-pointer place-items-center rounded-control bg-(--choice-bg) text-[0.9375rem] font-medium tabular-nums shadow-choice transition-[background-color,box-shadow] duration-(--state-ms)", "hover:bg-(--choice-hover-bg) has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/40", "data-[checked=true]:bg-(--scale-selected-bg) data-[checked=true]:text-(--scale-selected-fg) data-[checked=true]:shadow-(--scale-selected-shadow)"),
|
|
464
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
465
|
+
type: "radio",
|
|
466
|
+
name: question.field,
|
|
467
|
+
value: step,
|
|
468
|
+
checked: value === step,
|
|
469
|
+
onChange: () => setValue(step),
|
|
470
|
+
"aria-label": labels !== void 0 && index === 0 ? `${step}, ${labels[0]}` : labels !== void 0 && index === steps.length - 1 ? `${step}, ${labels[1]}` : String(step),
|
|
471
|
+
className: "absolute inset-0 z-10 m-0 size-full cursor-pointer appearance-none rounded-[inherit] opacity-0"
|
|
472
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
473
|
+
"aria-hidden": true,
|
|
474
|
+
children: step
|
|
475
|
+
})]
|
|
476
|
+
}, step))
|
|
477
|
+
}), labels !== void 0 && /* @__PURE__ */ jsxs("div", {
|
|
478
|
+
"aria-hidden": true,
|
|
479
|
+
className: "flex justify-between text-sm text-muted-foreground",
|
|
480
|
+
children: [/* @__PURE__ */ jsx("span", { children: labels[0] }), /* @__PURE__ */ jsx("span", { children: labels[1] })]
|
|
481
|
+
})]
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function Rank({ items, className }) {
|
|
485
|
+
const question = useQuestion("Rank");
|
|
486
|
+
const all = items.map((item) => typeof item === "string" ? {
|
|
487
|
+
value: item,
|
|
488
|
+
label: item
|
|
489
|
+
} : item);
|
|
490
|
+
const [order, setOrder] = useField(question.field, null, {
|
|
491
|
+
...question.label !== void 0 ? { label: question.label } : {},
|
|
492
|
+
required: question.required,
|
|
493
|
+
options: all.map((item) => ({
|
|
494
|
+
value: item.value,
|
|
495
|
+
label: item.label
|
|
496
|
+
}))
|
|
497
|
+
});
|
|
498
|
+
useAnswered(question.report, order !== null);
|
|
499
|
+
const shown = order === null ? all : [...order.flatMap((value) => all.filter((item) => item.value === value)), ...all.filter((item) => !order.includes(item.value))];
|
|
500
|
+
const move = (from, to) => {
|
|
501
|
+
if (to < 0 || to >= shown.length) return;
|
|
502
|
+
const next = shown.map((item) => item.value);
|
|
503
|
+
const [moved] = next.splice(from, 1);
|
|
504
|
+
next.splice(to, 0, moved);
|
|
505
|
+
setOrder(next);
|
|
506
|
+
};
|
|
507
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
508
|
+
"data-slot": "rank",
|
|
509
|
+
className: cn("flex flex-col gap-3", className),
|
|
510
|
+
children: [/* @__PURE__ */ jsx("ol", {
|
|
511
|
+
"aria-labelledby": question.titleId,
|
|
512
|
+
className: "flex flex-col gap-2",
|
|
513
|
+
children: shown.map((item, index) => /* @__PURE__ */ jsxs("li", {
|
|
514
|
+
"data-slot": "rank-item",
|
|
515
|
+
className: "flex items-center gap-3 rounded-choice bg-(--choice-bg) py-2 pr-2 pl-4 shadow-choice",
|
|
516
|
+
children: [
|
|
517
|
+
/* @__PURE__ */ jsx("span", {
|
|
518
|
+
className: "w-5 text-sm font-semibold text-muted-foreground tabular-nums",
|
|
519
|
+
children: index + 1
|
|
520
|
+
}),
|
|
521
|
+
/* @__PURE__ */ jsx("span", {
|
|
522
|
+
className: "flex-1 font-medium",
|
|
523
|
+
children: item.label
|
|
524
|
+
}),
|
|
525
|
+
/* @__PURE__ */ jsxs("span", {
|
|
526
|
+
className: "flex gap-1",
|
|
527
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
528
|
+
type: "button",
|
|
529
|
+
"aria-label": `Move ${item.label} up`,
|
|
530
|
+
disabled: index === 0,
|
|
531
|
+
onClick: () => move(index, index - 1),
|
|
532
|
+
className: "press grid size-9 place-items-center rounded-button text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/40 disabled:opacity-30",
|
|
533
|
+
children: /* @__PURE__ */ jsx(ArrowUp, {
|
|
534
|
+
"aria-hidden": true,
|
|
535
|
+
className: "size-4"
|
|
536
|
+
})
|
|
537
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
538
|
+
type: "button",
|
|
539
|
+
"aria-label": `Move ${item.label} down`,
|
|
540
|
+
disabled: index === shown.length - 1,
|
|
541
|
+
onClick: () => move(index, index + 1),
|
|
542
|
+
className: "press grid size-9 place-items-center rounded-button text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/40 disabled:opacity-30",
|
|
543
|
+
children: /* @__PURE__ */ jsx(ArrowDown, {
|
|
544
|
+
"aria-hidden": true,
|
|
545
|
+
className: "size-4"
|
|
546
|
+
})
|
|
547
|
+
})]
|
|
548
|
+
})
|
|
549
|
+
]
|
|
550
|
+
}, item.value))
|
|
551
|
+
}), order === null && /* @__PURE__ */ jsx("button", {
|
|
552
|
+
type: "button",
|
|
553
|
+
onClick: () => setOrder(shown.map((item) => item.value)),
|
|
554
|
+
className: cn(stepButton("secondary"), "w-fit"),
|
|
555
|
+
children: "Keep this order"
|
|
556
|
+
})]
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
const fieldClasses = "w-full min-w-0 rounded-control border border-input bg-(--field) px-3.5 text-base shadow-control outline-none transition-[border-color,box-shadow] duration-(--state-ms) placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 h-(--control-h)";
|
|
560
|
+
function TextAnswer({ multiline = true, type = "text", placeholder, className }) {
|
|
561
|
+
const question = useQuestion("TextAnswer");
|
|
562
|
+
const [text, setText] = useField(question.field, "", {
|
|
563
|
+
...question.label !== void 0 ? { label: question.label } : {},
|
|
564
|
+
required: question.required
|
|
565
|
+
});
|
|
566
|
+
useAnswered(question.report, text.trim() !== "");
|
|
567
|
+
const shared = {
|
|
568
|
+
"aria-labelledby": question.titleId,
|
|
569
|
+
"aria-describedby": question.descriptionId,
|
|
570
|
+
"aria-required": question.required || void 0,
|
|
571
|
+
value: text,
|
|
572
|
+
placeholder
|
|
573
|
+
};
|
|
574
|
+
return multiline ? /* @__PURE__ */ jsx("textarea", {
|
|
575
|
+
"data-slot": "text-answer",
|
|
576
|
+
...shared,
|
|
577
|
+
onChange: (event) => setText(event.currentTarget.value),
|
|
578
|
+
className: cn(fieldClasses, "h-auto min-h-28 py-3 leading-relaxed field-sizing-content", className)
|
|
579
|
+
}) : /* @__PURE__ */ jsx("input", {
|
|
580
|
+
"data-slot": "text-answer",
|
|
581
|
+
type,
|
|
582
|
+
...shared,
|
|
583
|
+
onChange: (event) => setText(event.currentTarget.value),
|
|
584
|
+
className: cn(fieldClasses, className)
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
function Comment() {
|
|
588
|
+
const question = useQuestion("Question");
|
|
589
|
+
const [comment, setComment] = useField(`${question.field}.comment`, "", { label: question.label !== void 0 ? `${question.label}: comment` : "Comment" });
|
|
590
|
+
const [open, setOpen] = React.useState(false);
|
|
591
|
+
if (!open && comment === "") return /* @__PURE__ */ jsx("button", {
|
|
592
|
+
type: "button",
|
|
593
|
+
onClick: () => setOpen(true),
|
|
594
|
+
className: "press inline-flex w-fit items-center rounded-button px-2 py-1 text-sm text-muted-foreground underline-offset-4 outline-none hover:text-foreground hover:underline focus-visible:ring-3 focus-visible:ring-ring/40",
|
|
595
|
+
children: "Add a comment"
|
|
596
|
+
});
|
|
597
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
598
|
+
"data-slot": "question-comment",
|
|
599
|
+
"aria-label": question.label !== void 0 ? `Comment on “${question.label}”` : "Comment",
|
|
600
|
+
value: comment,
|
|
601
|
+
placeholder: "Anything to add?",
|
|
602
|
+
autoFocus: open && comment === "",
|
|
603
|
+
onChange: (event) => setComment(event.currentTarget.value),
|
|
604
|
+
className: cn(fieldClasses, "h-auto min-h-20 py-2.5 text-[0.9375rem] leading-relaxed field-sizing-content")
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
/** How many questions are answered: a dot for each, giallo once answered. */
|
|
608
|
+
function AnswerProgress({ answered, total, className, ...props }) {
|
|
609
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
610
|
+
"data-slot": "answer-progress",
|
|
611
|
+
className: cn("flex items-center gap-3 text-sm text-muted-foreground", className),
|
|
612
|
+
...props,
|
|
613
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
614
|
+
"aria-hidden": true,
|
|
615
|
+
className: "flex flex-wrap gap-1.5",
|
|
616
|
+
children: Array.from({ length: total }, (_, index) => /* @__PURE__ */ jsx("span", { className: cn("size-2.5 rounded-full border-[1.5px] border-input transition-colors duration-(--state-ms)", index < answered && "animate-answer border-foreground bg-answer") }, index))
|
|
617
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
618
|
+
"aria-live": "polite",
|
|
619
|
+
className: "tabular-nums",
|
|
620
|
+
children: [
|
|
621
|
+
answered,
|
|
622
|
+
" of ",
|
|
623
|
+
total,
|
|
624
|
+
" answered"
|
|
625
|
+
]
|
|
626
|
+
})]
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
//#endregion
|
|
630
|
+
export { AnswerMark, AnswerProgress, Choice, Other, Question, Questionnaire, Rank, Scale, Section, TextAnswer };
|
|
631
|
+
|
|
632
|
+
//# sourceMappingURL=questionnaire.js.map
|