An open source design system that's fully customizable and agent ready
TypeScript
feat(storybook): add FollowUpQuestion story to ChatComposer (#1832)
Ernestb2957cbb07f7
diff --git a/apps/storybook/stories/ChatComposer.stories.tsx b/apps/storybook/stories/ChatComposer.stories.tsxindex 18b2ead986..a45bd13a77 100644--- a/apps/storybook/stories/ChatComposer.stories.tsx+++ b/apps/storybook/stories/ChatComposer.stories.tsx@@ -7,6 +7,9 @@ import {import {XDSToken} from '@xds/core/Token';import {XDSButton} from '@xds/core/Button';import {XDSProgressBar} from '@xds/core/ProgressBar';+import {XDSList, XDSListItem} from '@xds/core/List';+import {XDSText} from '@xds/core/Text';+import {XDSBadge} from '@xds/core/Badge';import {useState} from 'react';// Inline icons for story demos (not in the default icon registry)@@ -53,6 +56,33 @@ const MicIcon = (</svg>);+const ChevronLeftIcon = (+ <svg+ width="1em"+ height="1em"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="1.5"+ strokeLinecap="round"+ strokeLinejoin="round">+ <path d="m15 18-6-6 6-6" />+ </svg>+);+const ChevronRightIcon = (+ <svg+ width="1em"+ height="1em"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="1.5"+ strokeLinecap="round"+ strokeLinejoin="round">+ <path d="m9 18 6-6-6-6" />+ </svg>+);+const meta: Meta<typeof XDSChatComposer> = {title: 'Core/Chat/Composer',component: XDSChatComposer,@@ -330,3 +360,120 @@ export const SendStopToggle: Story = {);},};++/** Drawer with follow-up questions, selectable options, and prev/next navigation */+export const FollowUpQuestion: Story = {+ render: () => {+ const questions = [+ {+ question: 'Which environment should this deploy to?',+ options: [+ {key: 'A', label: 'Production (requires approval)'},+ {key: 'B', label: 'Staging'},+ {key: 'C', label: 'Local development only'},+ ],+ },+ {+ question:+ 'This will modify 12 files. How should I handle breaking changes?',+ options: [+ {key: 'A', label: 'Add a migration and keep backward compatibility'},+ {+ key: 'B',+ label: 'Breaking change is fine \u2014 bump the major version',+ },+ ],+ },+ {+ question:+ 'I found 3 existing implementations. Which one should I extend?',+ options: [+ {key: 'A', label: 'UserService in src/services/ (most recent)'},+ {+ key: 'B',+ label: 'UserManager in src/legacy/ (has more test coverage)',+ },+ {key: 'C', label: 'Neither \u2014 start fresh'},+ ],+ },+ ];++ const [currentQ, setCurrentQ] = useState(0);+ const [answers, setAnswers] = useState<Record<number, string>>({});+ const q = questions[currentQ];+ const selected = answers[currentQ] ?? null;++ return (+ <XDSChatComposer+ onSubmit={value => {+ console.log('Submit:', value, '| Answers:', answers);+ alert(+ `Sent: "${value}"\nAnswers: ${JSON.stringify(answers, null, 2)}`,+ );+ }}+ placeholder="Or describe what you need in your own words\u2026"+ drawer={+ <XDSChatComposerDrawer count={questions.length} label="Questions">+ <div style={{width: '100%'}}>+ <div+ style={{+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'space-between',+ marginBlockEnd: 4,+ }}>+ <XDSButton+ label="Previous question"+ variant="ghost"+ size="sm"+ icon={ChevronLeftIcon}+ isIconOnly+ isDisabled={currentQ === 0}+ onClick={() => setCurrentQ(i => i - 1)}+ />+ <XDSText color="secondary">+ {currentQ + 1} of {questions.length}+ </XDSText>+ <XDSButton+ label="Next question"+ variant="ghost"+ size="sm"+ icon={ChevronRightIcon}+ isIconOnly+ isDisabled={currentQ === questions.length - 1}+ onClick={() => setCurrentQ(i => i + 1)}+ />+ </div>+ <XDSList>+ <XDSListItem+ label={+ <XDSText weight="bold">+ {currentQ + 1}. {q.question}+ </XDSText>+ }+ />+ {q.options.map(opt => (+ <XDSListItem+ key={opt.key}+ label={opt.label}+ startContent={+ <XDSBadge+ variant={selected === opt.key ? 'info' : 'neutral'}+ label={opt.key}+ />+ }+ isSelected={selected === opt.key}+ onClick={() =>+ setAnswers(prev => ({...prev, [currentQ]: opt.key}))+ }+ />+ ))}+ </XDSList>+ </div>+ </XDSChatComposerDrawer>+ }+ footerActions={<XDSButton label="Skip all" variant="ghost" size="md" />}+ />+ );+ },+};diff --git a/packages/cli/templates/blocks/components/ChatComposer/ChatComposerFollowUpQuestions.doc.mjs b/packages/cli/templates/blocks/components/ChatComposer/ChatComposerFollowUpQuestions.doc.mjsnew file mode 100644index 0000000000..76432c032d--- /dev/null+++ b/packages/cli/templates/blocks/components/ChatComposer/ChatComposerFollowUpQuestions.doc.mjs@@ -0,0 +1,10 @@+/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */+export const doc = {+ type: 'block',+ name: 'ChatComposer — Follow-Up Questions',+ description:+ 'Chat composer with a collapsible drawer containing navigable follow-up questions and selectable lettered options.',+ isReady: true,+ aspectRatio: 4 / 3,+ componentsUsed: ['ChatComposer', 'List', 'Badge', 'Text', 'Button'],+};diff --git a/packages/cli/templates/blocks/components/ChatComposer/ChatComposerFollowUpQuestions.tsx b/packages/cli/templates/blocks/components/ChatComposer/ChatComposerFollowUpQuestions.tsxnew file mode 100644index 0000000000..159019113e--- /dev/null+++ b/packages/cli/templates/blocks/components/ChatComposer/ChatComposerFollowUpQuestions.tsx@@ -0,0 +1,142 @@+'use client';++import {useState} from 'react';+import {XDSChatComposer, XDSChatComposerDrawer} from '@xds/core/Chat';+import {XDSButton} from '@xds/core/Button';+import {XDSList, XDSListItem} from '@xds/core/List';+import {XDSText} from '@xds/core/Text';+import {XDSBadge} from '@xds/core/Badge';++const ChevronLeftIcon = (+ <svg+ width="1em"+ height="1em"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="1.5"+ strokeLinecap="round"+ strokeLinejoin="round">+ <path d="m15 18-6-6 6-6" />+ </svg>+);+const ChevronRightIcon = (+ <svg+ width="1em"+ height="1em"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="1.5"+ strokeLinecap="round"+ strokeLinejoin="round">+ <path d="m9 18 6-6-6-6" />+ </svg>+);++const questions = [+ {+ question: 'Which environment should this deploy to?',+ options: [+ {key: 'A', label: 'Production (requires approval)'},+ {key: 'B', label: 'Staging'},+ {key: 'C', label: 'Local development only'},+ ],+ },+ {+ question:+ 'This will modify 12 files. How should I handle breaking changes?',+ options: [+ {key: 'A', label: 'Add a migration and keep backward compatibility'},+ {+ key: 'B',+ label: 'Breaking change is fine \u2014 bump the major version',+ },+ ],+ },+ {+ question: 'I found 3 existing implementations. Which one should I extend?',+ options: [+ {key: 'A', label: 'UserService in src/services/ (most recent)'},+ {key: 'B', label: 'UserManager in src/legacy/ (has more test coverage)'},+ {key: 'C', label: 'Neither \u2014 start fresh'},+ ],+ },+];++export default function ChatComposerFollowUpQuestions() {+ const [currentQ, setCurrentQ] = useState(0);+ const [answers, setAnswers] = useState<Record<number, string>>({});+ const q = questions[currentQ];+ const selected = answers[currentQ] ?? null;++ return (+ <XDSChatComposer+ onSubmit={value => {+ console.log('Submit:', value, '| Answers:', answers);+ }}+ placeholder="Or describe what you need in your own words\u2026"+ drawer={+ <XDSChatComposerDrawer count={questions.length} label="Questions">+ <div style={{width: '100%'}}>+ <div+ style={{+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'space-between',+ marginBlockEnd: 4,+ }}>+ <XDSButton+ label="Previous question"+ variant="ghost"+ size="sm"+ icon={ChevronLeftIcon}+ isIconOnly+ isDisabled={currentQ === 0}+ onClick={() => setCurrentQ(i => i - 1)}+ />+ <XDSText color="secondary">+ {currentQ + 1} of {questions.length}+ </XDSText>+ <XDSButton+ label="Next question"+ variant="ghost"+ size="sm"+ icon={ChevronRightIcon}+ isIconOnly+ isDisabled={currentQ === questions.length - 1}+ onClick={() => setCurrentQ(i => i + 1)}+ />+ </div>+ <XDSList>+ <XDSListItem+ label={+ <XDSText weight="bold">+ {currentQ + 1}. {q.question}+ </XDSText>+ }+ />+ {q.options.map(opt => (+ <XDSListItem+ key={opt.key}+ label={opt.label}+ startContent={+ <XDSBadge+ variant={selected === opt.key ? 'info' : 'neutral'}+ label={opt.key}+ />+ }+ isSelected={selected === opt.key}+ onClick={() =>+ setAnswers(prev => ({...prev, [currentQ]: opt.key}))+ }+ />+ ))}+ </XDSList>+ </div>+ </XDSChatComposerDrawer>+ }+ footerActions={<XDSButton label="Skip all" variant="ghost" size="md" />}+ />+ );+}