import React, { FC, Fragment, useEffect, useState } from 'react'; import { Select } from 'reablocks'; import { SelectOption } from 'reablocks'; import { SelectMenu } from 'reablocks'; import { SelectInput, SelectInputChip } from 'reablocks'; const CheckIcon: FC<{ className?: string }> = ({ className }) => ( ); export default { title: 'Components/Form/Select/Multi', component: Select, subcomponents: { SelectOption, SelectMenu, SelectInput, SelectInputChip } }; const options = [ { value: 'facebook', label: 'Facebook' }, { value: 'twitter', label: 'Twitter' }, { value: 'github', label: 'GitHub' }, { value: 'google', label: 'Google' }, { value: 'azure', label: 'Azure' } ]; export const Basic = () => { const [value, setValue] = useState(null); return ( { setValue(v); console.log('onChange', v); }} > facebook twitter twitch ); }; export const PreventClearInput = () => { const [value, setValue] = useState(['facebook']); return ( setValue(v)} > facebook twitter twitch ); }; export const Disabled = () => { const [value, setValue] = useState(['facebook']); return ( { setValue(v); console.log('onChange', v); }} > facebook twitter twitch ); }; export const DefaultValue = () => { const [value, setValue] = useState(['facebook', 'twitter']); return ( { setValue(v); console.log('onChange', v); }} > facebook twitter twitch ); }; export const CustomLabels = () => { const [value, setValue] = useState(['facebook']); return ( setValue(v)} > 🔑 facebook} menuLabel={🔑 facebook} > 🔑 facebook 🔐 twitter} menuLabel={🔐 twitter} > 🔐 twitter 🔥 twitch} menuLabel={🔥 twitch} > 🔥 twitch ); }; export const CustomCheckIcon = () => { const [value, setValue] = useState(['facebook']); return ( setValue(v)} placeholder="Pick a tool..." menu={} />} > facebook twitter twitch ); }; export const Createable = () => { const [value, setValue] = useState([]); const [animals, setAnimals] = useState(['chicken', 'cow', 'mouse']); return ( setValue(v)} onOptionsChange={opts => setAnimals(opts.map(o => o.value))} > {animals.map(o => ( {o} ))} ); }; export const LongInputNames = () => { const [value, setValue] = useState(['dod']); return ( setValue(v)} > Department of Defense Logistic and Infrastucture Agency Department of Homeland Security Operations Center Security Operations Center for Central Intel Agency ); }; export const MultipleValuesOverflow = () => { const [value, setValue] = useState(['dod', 'dhs', 'soc']); return ( setValue(v)} > Department of Defense Logistic and Infrastucture Agency Department of Homeland Security Operations Center Security Operations Center for Central Intel Agency ); }; export const MultipleValuesFixed = () => { const [value, setValue] = useState(['dod', 'dhs', 'soc']); return ( setValue(v)} > Department of Defense Logistic and Infrastucture Agency Department of Homeland Security Operations Center Security Operations Center for Central Intel Agency ); }; export const FluidWidth = () => { const [value, setValue] = useState(['dod']); return ( setValue(v)} > Department of Defense Logistic and Infrastucture Agency Department of Homeland Security Operations Center Security Operations Center for Central Intel Agency ); }; export const Unfilterable = () => { const [value, setValue] = useState(['dod']); return ( setValue(v)} > facebook twitter twitch ); }; export const Error = () => ( ); export const InvalidValues = () => { const [value, setValue] = useState(['gop']); return ( setValue(v)} placeholder="Pick a tool..." menu={} />} > facebook twitter twitch ); }; export const CreateableNoOptions = () => { const [value, setValue] = useState([]); const [animals, setAnimals] = useState([]); return ( setAnimals(opts.map(o => o.value))} onChange={v => { setValue(v); console.log('onChange', v); }} > {animals.map(animal => ( {animal} ))} ); }; export const CreateableDuplicateRejected = () => { const [value, setValue] = useState([]); const [options, setOptions] = useState([]); const [lastDuplicate, setLastDuplicate] = useState(null); return ( setOptions(opts.map(o => o.value))} onChange={v => setValue(v)} onDuplicate={dupe => setLastDuplicate(dupe)} > {options.map(opt => ( {opt} ))} {lastDuplicate && ( "{lastDuplicate}" already exists )} ); }; export const Async = () => { const [value, setValue] = useState('github'); const [loading, setLoading] = useState(false); const [refreshable, setRefreshable] = useState(false); const [opts, setOpts] = useState<{ value: string; label: string }[] | null>( null ); useEffect(() => { let timeout; async function getOptions() { const next = await new Promise(resolve => { timeout = setTimeout(() => { resolve(options); }, 1500); }); setOpts(next); setLoading(false); setRefreshable(true); } if (opts === null) { setLoading(true); setRefreshable(false); getOptions(); } return () => { clearTimeout(timeout); }; }, [opts]); return ( setValue(v)} onRefresh={() => setOpts(null)} > {opts?.map(o => ( {o.label} ))} ); };
"{lastDuplicate}"