semantic-ui-react#Flag TypeScript Examples
The following examples show how to use
semantic-ui-react#Flag.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From frontegg-react with MIT License | 5 votes |
Select = (props: SelectProps) => {
const [open, setOpen] = useState(false);
const p = mapper(props);
const { t } = useT();
const { multiple, options, label, loading, getOptionLabel, renderOption } = p;
const {
noOptionsText,
loadingText,
onOpen,
open: openProps,
onClose,
fullWidth,
onBlur,
value,
onChange,
options: propsOptions,
} = props;
const handleOnChange = useCallback(
(e, data) => {
onChange && onChange(e, data);
},
[onChange]
);
const optionsMessage = useMemo(
() => (loading ? loadingText ?? `${t('common.loading')}...` : noOptionsText ?? t('common.empty-items')),
[loading, loadingText, noOptionsText]
);
const renderLabel = useCallback((option, state) => {
const { flag, image, text } = option;
const content = renderOption ? (
<>{renderOption({ label: option.text, value: option.value }, state)}</>
) : (
<>
{(Flag as any).create(flag)}
{(Image as any).create(image)}
{text}
</>
);
return { content };
}, []);
const preparedValue = useMemo(() => {
return Array.isArray(value) ? value?.map((v) => v.value) : value?.value;
}, [value]);
const onHandleChange = useCallback(
(e, newValue) => {
const data = propsOptions?.filter((o) => newValue.includes(o.value)) || [];
onChange?.(e, data);
},
[propsOptions]
);
return (
<Dropdown
{...p}
search
selection
value={preparedValue}
fluid={fullWidth ?? true}
open={openProps ?? open}
onBlur={(e, data) => onBlur?.({ ...e, target: { ...e.target, name: data.name } } as any)}
options={options}
loading={loading}
onOpen={() => (onOpen ? onOpen() : setOpen(true))}
onClose={() => (onClose ? onClose() : setOpen(false))}
multiple={multiple ?? false}
placeholder={value ? '' : label}
onChange={(e, data) => onHandleChange(e, data.value)}
renderLabel={(option, _index, state) => renderLabel(option, state)}
noResultsMessage={optionsMessage}
getoptionlabel={getOptionLabel}
/>
);
}