Files
supabase/packages/ui-patterns/AssistantChat/AssistantChatForm.stories.tsx
Jonathan Summers-MuirandAlaister Young 33df85e910 feat: AssistantChatForm ui-pattern and AssistantCommandsPopover ui-pattern (#19296)
* proto

* chore: added pattern for input

* migrated whole form over

* Added basics

* add commands

* Update index.tsx

* remove old code

* add Input

* add chat into studio

* init stories

* revert

* Update AIPolicyChat.tsx

* revert

* udpate

* Update AssistantCommandsPopover.tsx

* Update packages/ui-patterns/AssistantChat/AssistantChatForm.tsx

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>

* Update AssistantCommandsPopover.tsx

* Update AssistantCommandsPopover.tsx

---------

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
2024-03-29 15:27:05 +08:00

67 lines
1.9 KiB
TypeScript

import { StoryObj } from '@storybook/react'
import { AssistantChatForm } from './AssistantChatForm'
import { Box, User } from 'lucide-react'
import { createRef, useRef, useState } from 'react'
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
export default {
title: 'AI/Assistant Chat',
component: AssistantChatForm,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
decorators: [
(Story: any) => {
return (
<div className="w-80">
<Story />
</div>
)
},
],
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
// argTypes: {},
}
// export default meta
type Story = StoryObj<typeof AssistantChatForm>
export const Primary: Story = {
render: function Render(args) {
const textAreaRef = createRef<HTMLTextAreaElement>()
const [value, setValueState] = useState('')
const [loading, setLoading] = useState(false)
function handleSubmit(event: React.FormEvent) {
// set loading for 3 seconds and then reset
setLoading(true)
setTimeout(() => {
setLoading(false)
}, 1500)
}
return (
<AssistantChatForm
{...args}
textAreaRef={textAreaRef}
icon={<Box strokeWidth={1.5} size={24} className="text-foreground-muted" />}
value={value}
loading={loading}
disabled={loading}
onValueChange={(e) => setValueState(e.target.value)}
onSubmit={async (event) => {
event.preventDefault()
handleSubmit(event)
}}
/>
)
},
args: {
// placeholder: 'Ask AI a question...',
},
}