Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: MultiComboBoxのStoryで定義しているdefaultItemsを関数の中に移動 #5201

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,61 @@ export default {
},
}

const defaultItems = [
{
label: 'option 1',
value: 'value-1',
data: {
name: 'test',
age: 23,
},
},
{
label: 'option 2',
value: 'value-2',
data: {
name: 'test 2',
age: 34,
},
},
{
label: 'option 3',
value: 'value-3',
disabled: true,
},
{
label: 'option 4',
value: 'value-4',
},
{
label: 'option 5',
value: 'value-5',
},
{
label: 'アイテムのラベルが長い場合(ダミーテキストダミーテキストダミーテキストダミーテキスト)',
value: 'value-6',
},
{
label: (
<Stack as="span" gap={0.25}>
<span>アイテムのラベルがReactNodeの場合</span>
<span>(ダミーテキストダミーテキストダミーテキストダミーテキスト)</span>
</Stack>
),
value: 'value-7',
},
]

const manyItems = Array.from({ length: 2000 }).map((_, i) => ({
label: `option ${i}`,
value: `option ${i}`,
}))

type Item = { label: ReactNode; value: string; disabled?: boolean; data?: any }

export const MultiCombobox: StoryFn = () => {
const [items, setItems] = useState<Item[]>(defaultItems)
const MultiComboboxComponent = () => {
const defaultItems = [
{
label: 'option 1',
value: 'value-1',
data: {
name: 'test',
age: 23,
},
},
{
label: 'option 2',
value: 'value-2',
data: {
name: 'test 2',
age: 34,
},
},
{
label: 'option 3',
value: 'value-3',
disabled: true,
},
{
label: 'option 4',
value: 'value-4',
},
{
label: 'option 5',
value: 'value-5',
},
{
label:
'アイテムのラベルが長い場合(ダミーテキストダミーテキストダミーテキストダミーテキスト)',
value: 'value-6',
},
{
label: (
<Stack as="span" gap={0.25}>
<span>アイテムのラベルがReactNodeの場合</span>
<span>(ダミーテキストダミーテキストダミーテキストダミーテキスト)</span>
</Stack>
),
value: 'value-7',
},
]
const [addedItems, setAddedItems] = useState<Item[]>([])
const items = [...defaultItems, ...addedItems]
const [selectedItems, setSelectedItems] = useState<Item[]>([])
const [seq, setSeq] = useState(0)
const [controlledInputValue, setControlledInputValue] = useState<string>('')
Expand All @@ -96,11 +97,11 @@ export const MultiCombobox: StoryFn = () => {
label,
value: label,
}
setItems([...items, newItem])
setAddedItems([...addedItems, newItem])
setSelectedItems([...selectedItems, newItem])
setSeq(seq + 1)
},
[items, selectedItems, seq],
[addedItems, selectedItems, seq],
)

return (
Expand Down Expand Up @@ -293,3 +294,5 @@ export const MultiCombobox: StoryFn = () => {
</Stack>
)
}

export const MultiCombobox: StoryFn = () => <MultiComboboxComponent />
Loading