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 (
); }; export const PreventClearInput = () => { const [value, setValue] = useState(['facebook']); return (
); }; export const Disabled = () => { const [value, setValue] = useState(['facebook']); return (
); }; export const DefaultValue = () => { const [value, setValue] = useState(['facebook', 'twitter']); return (
); }; export const CustomLabels = () => { const [value, setValue] = useState(['facebook']); return (
); }; export const CustomCheckIcon = () => { const [value, setValue] = useState(['facebook']); return (
); }; export const Createable = () => { const [value, setValue] = useState([]); const [animals, setAnimals] = useState(['chicken', 'cow', 'mouse']); return (
); }; export const LongInputNames = () => { const [value, setValue] = useState(['dod']); return (
); }; export const MultipleValuesOverflow = () => { const [value, setValue] = useState(['dod', 'dhs', 'soc']); return (
); }; export const MultipleValuesFixed = () => { const [value, setValue] = useState(['dod', 'dhs', 'soc']); return (
); }; export const FluidWidth = () => { const [value, setValue] = useState(['dod']); return (
); }; export const Unfilterable = () => { const [value, setValue] = useState(['dod']); return (
); }; export const Error = () => (
setValue(v)} placeholder="Pick a tool..." menu={} />} > facebook twitter twitch
); }; export const CreateableNoOptions = () => { const [value, setValue] = useState([]); const [animals, setAnimals] = useState([]); return (
); }; export const CreateableDuplicateRejected = () => { const [value, setValue] = useState([]); const [options, setOptions] = useState([]); const [lastDuplicate, setLastDuplicate] = useState(null); return (
{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 (
); };