Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/flourish-ui/src/components/Typeahead/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import {
ComboBox,
Input,
Label,
ListBox,
ListBoxItem,
Popover
} from 'react-aria-components'

interface TypeaheadProps {
label: string
options: string[]
}

export const Typeahead = ({ label, options }: TypeaheadProps) => {
return (
<ComboBox>
<Label>{label}</Label>
<Input />
<Popover>
<ListBox>
{options.map((option) => (
<ListBoxItem key={option}>{option}</ListBoxItem>
))}
</ListBox>
</Popover>
</ComboBox>
)
}
36 changes: 36 additions & 0 deletions packages/flourish-ui/src/stories/Typeahead.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Typeahead } from '../components/Typeahead'


// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta = {
title: 'Example/Typeahead',
component: Typeahead,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout
layout: 'centered'
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {
label: { control: 'text' },
options: {
control: {
type: 'array',
of: { type: 'text'}
}
}
}
} satisfies Meta<typeof Typeahead>

export default meta
type Story = StoryObj<typeof meta>

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const primary: Story = {
args: {
label: 'Select an animal',
options: ['Aardvark', 'Cat', 'Dog', 'Kangaroo', 'Panda', 'Snake']
}
}