import React, { Fragment, useEffect, useState } from 'react'; import { Select } from 'reablocks'; import { SelectOption } from 'reablocks'; import { SelectMenu } from 'reablocks'; import { SelectInput, SelectInputChip } from 'reablocks'; import { ListItem } from 'reablocks'; export default { title: 'Components/Form/Select/Single', 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 Sizes = () => { const [value, setValue] = useState(null); return (
); }; export const Fonts = () => { const [value, setValue] = useState(null); return (
); }; export const NoOptions = () => (
{ setValue(v); console.log('onChange', v); }} > {options.map(o => ( {`Option ${o}`} ))}
); }; export const DefaultValue = () => { const [value, setValue] = useState('facebook'); return (
); }; export const InvalidValues = () => { const [value, setValue] = useState('gop'); return (
); }; export const OptionsArray = () => { const [value, setValue] = useState('github'); return (
); }; export const Autofocus = () => { const [value, setValue] = useState('facebook'); return (
); }; export const LongInputNames = () => { const [value, setValue] = useState('dod'); return (
); }; export const FluidWidth = () => { const [value, setValue] = useState('dod'); return (
); }; export const Groups = () => { const [value, setValue] = useState('twitch'); return (
); }; export const LongGroupNames = () => { const [value, setValue] = useState('twitch'); return (
); }; export const MixedGroups = () => { const [value, setValue] = useState('twitch'); return (
); }; export const LoadingIcon = () => (
); export const RefreshIcon = () => (
setValue(v)} onRefresh={() => setOpts(null)} > {opts?.map(o => ( {o.label} ))}
); }; export const AsyncDefaultValue = () => { 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 (
); }; export const AsyncFiltering = () => { const [inputValue, setInputValue] = useState(null); const [value, setValue] = useState(null); const [loading, setLoading] = 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); }, 300); }); const filtered = next.filter(n => n.label.toLowerCase().startsWith(inputValue.toLowerCase()) ); setOpts(filtered); setLoading(false); } if (inputValue) { getOptions(); } else { setOpts(null); setLoading(false); } return () => { clearTimeout(timeout); }; }, [inputValue]); return (
); }; export const CustomLabels = () => { const [value, setValue] = useState('facebook'); return (
); }; export const CustomLongLabels = () => { const [value, setValue] = useState('facebook'); return (
); }; export const Disabled = () => (
); export const DisabledOption = () => { const [value, setValue] = useState(null); return (
); }; export const Unfilterable = () => { const [value, setValue] = useState('facebook'); return (
); }; export const Createable = () => { const [value, setValue] = useState(null); const [animals, setAnimals] = useState(['chicken', 'cow', 'mouse']); return (
); }; export const CustomCreatableOption = () => { const [value, setValue] = useState(null); const [animals, setAnimals] = useState(['chicken', 'cow', 'mouse']); return (
); }; export const TabToSelect = () => { const [value, setValue] = useState(null); return (
); }; export const WithStartEnd = () => { const [value, setValue] = useState(null); return (
); }; export const DefaultFilter = () => { const [value, setValue] = useState(null); return (
); };