types#DropdownProps TypeScript Examples

The following examples show how to use types#DropdownProps. 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: Select.tsx    From contracts-ui with GNU General Public License v3.0 6 votes vote down vote up
function Select({
  isDisabled,
  onChange,
  options,
  placeholder = 'Select Address...',
  className,
  value,
}: DropdownProps<string>) {
  return (
    <Dropdown
      className={classes('account-select', className)}
      isDisabled={isDisabled}
      formatOptionLabel={Option}
      onChange={onChange}
      options={options}
      placeholder={placeholder}
      isSearchable
      value={value}
    />
  );
}
Example #2
Source File: Dropdown.tsx    From contracts-ui with GNU General Public License v3.0 5 votes vote down vote up
export function Dropdown<T>({
  className = '',
  components = {},
  formatOptionLabel,
  isDisabled = false,
  isSearchable = false,
  onChange: _onChange,
  options = [],
  placeholder,
  value: _value,
}: DropdownProps<T>) {
  const onChange = useCallback(
    (option: DropdownOption<T> | null): void => {
      option && _onChange(option.value);
    },
    [_onChange]
  );

  const value = useMemo(() => {
    if (isGroupedOptions(options)) {
      return options
        .reduce((result: DropdownOption<T>[], { options }) => [...result, ...options], [])
        .find(({ value }) => value === _value);
    }

    return (options as DropdownOption<T>[]).find(({ value }) => value === _value);
  }, [options, _value]);

  return (
    <Select
      className={classes('dropdown', className)}
      classNamePrefix="dropdown"
      components={{ Control, DropdownIndicator, Input, Option, ...components }}
      formatOptionLabel={formatOptionLabel}
      isDisabled={isDisabled}
      isSearchable={isSearchable}
      onChange={onChange}
      options={options}
      placeholder={placeholder}
      styles={{
        dropdownIndicator: provided => ({ ...provided, padding: '0.25rem' }),
        input: provided => ({ ...provided, color: 'unset' }),
        option: () => ({}),
      }}
      value={value}
    />
  );
}