BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/agent-elements/question-tool

question-tool

agent-elements/question-tool
FreeComponent

agent-elements publishes no description for this item.

Live preview

live · rendered by the registry
Rendered by agent-elements on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://agent-elements.21st.dev/r/question-tool.json

Source

registry/agent-elements/components/question/question-tool.tsxagent-elements.21st.dev/r/question-tool.json · first 6 KB
1import { useEffect, useMemo, useState } from "react";
2import {
3 IconChevronDown,
4 IconChevronUp,
5 IconMessageCircleQuestion,
6} from "@tabler/icons-react";
7import { QuestionPrompt } from "./question-prompt";
8import type { QuestionAnswer, QuestionConfig } from "./question-prompt";
9
10export type QuestionToolPart = {
11 type: string;
12 toolCallId?: string;
13 state?: string;
14 input?: {
15 questions: QuestionConfig[];
16 questionIndex?: number;
17 totalQuestions?: number;
18 onPreviousQuestion?: () => void;
19 onNextQuestion?: () => void;
20 submitLabel?: string;
21 nextLabel?: string;
22 skipLabel?: string;
23 allowSkip?: boolean;
24 onSubmitAnswer?: (answer: QuestionAnswer) => void;
25 };
26 output?: {
27 answer?: QuestionAnswer;
28 };
29};
30
31export type QuestionToolProps = {
32 part: QuestionToolPart;
33 chatStatus?: string;
34};
35
36function formatAnswer(answer: QuestionAnswer) {
37 if (answer.kind === "skip") return "Skipped";
38 if (answer.kind === "text") return answer.text || "Answered";
39 const ids = answer.selectedIds?.length ? answer.selectedIds.join(", ") : "";
40 if (answer.text) return ids ? `${ids} (${answer.text})` : answer.text;
41 return ids || "Answered";
42}
43
44export function QuestionTool({ part }: QuestionToolProps) {
45 const [localIndex, setLocalIndex] = useState(part.input?.questionIndex ?? 1);
46 const questions: QuestionConfig[] = part.input?.questions ?? [];
47 const totalQuestions = part.input?.totalQuestions ?? questions.length;
48 const isControlled = typeof part.input?.questionIndex === "number";
49 const questionIndex = isControlled
50 ? (part.input?.questionIndex ?? 1)
51 : questions.length > 0
52 ? localIndex
53 : (part.input?.questionIndex ?? 1);
54 const clampedIndex = Math.max(1, Math.min(questionIndex, totalQuestions));
55 const question = questions[clampedIndex - 1];
56 const [localAnswers, setLocalAnswers] = useState<
57 Record<number, QuestionAnswer>
58 >({});
59
60 useEffect(() => {
61 if (typeof part.input?.questionIndex === "number") {
62 setLocalIndex(part.input.questionIndex);
63 }
64 }, [part.input?.questionIndex]);
65
66 useEffect(() => {
67 setLocalAnswers({});
68 setLocalIndex(part.input?.questionIndex ?? 1);
69 }, [part.toolCallId]);
70
71 if (!question) return null;
72
73 const outputAnswer = part.output?.answer;
74 const answeredCount = Object.keys(localAnswers).length;
75 const isComplete =
76 totalQuestions === 1
77 ? !!outputAnswer || answeredCount >= 1
78 : totalQuestions > 0 && answeredCount >= totalQuestions;
79// … truncated

Facts

Registry
agent-elements
Type
registry:ui
Access
Free
Files written
0
Licence
the repository states none
First indexed
2026-08-04
Last confirmed
today

Go to the source

Docs on agent-elements agent-elements.21st.dev Raw registry item This item as JSON

More from agent-elements

All 25 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
agent-chatagent-chatagent-elementsComponentsFreeno deps
attachment-buttonattachment-buttonagent-elementsComponentsFreeno deps
bash-toolbash-toolagent-elementsComponentsFreeno deps
edit-tooledit-toolagent-elementsComponentsFreeno deps
error-messageerror-messageagent-elementsComponentsFreeno deps
file-attachmentfile-attachmentagent-elementsComponentsFreeno deps
generic-toolgeneric-toolagent-elementsComponentsFreeno deps
input-barinput-baragent-elementsComponentsFreeno deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex