react-feather#Sliders TypeScript Examples

The following examples show how to use react-feather#Sliders. 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: Filters.tsx    From gear-js with GNU General Public License v3.0 5 votes vote down vote up
Filters = ({ values, setValues, isAnySelected }: Props) => {
  const [isOpen, setIsOpen] = useState(false);
  const filters = Object.keys(values);

  const handleChange = ({ target: { name, checked } }: ChangeEvent<HTMLInputElement>) => {
    setValues((prevValues) => {
      const newValues = { ...prevValues, [name]: checked };
      const stringifiedNewValues = JSON.stringify(newValues);

      localStorage.setItem(LOCAL_STORAGE.EVENT_FILTERS, stringifiedNewValues);
      return newValues;
    });
  };

  const getFilters = () =>
    filters.map((filter) => (
      <li key={filter}>
        <Checkbox
          label={filter}
          name={filter}
          className={styles.checkbox}
          checked={values[filter]}
          onChange={handleChange}
        />
      </li>
    ));

  const close = () => {
    setIsOpen(false);
  };

  const toggle = () => {
    setIsOpen((prevValue) => !prevValue);
  };

  const reset = () => {
    setValues(init.filterValues);
    localStorage.removeItem(LOCAL_STORAGE.EVENT_FILTERS);
    close();
  };

  const ref = useOutsideClick(close);
  const toggleButtonClassName = clsx(styles.button, styles.toggleButton);
  const resetButtonClassName = clsx(styles.button, styles.resetButton);

  return (
    <div className={styles.filters} ref={ref}>
      <button type="button" className={toggleButtonClassName} onClick={toggle}>
        <Sliders size={16} strokeWidth={3} />
      </button>
      {isOpen && (
        <div className={styles.body}>
          <ul className={styles.list}>{getFilters()}</ul>
          {isAnySelected && (
            <footer className={styles.footer}>
              <button type="button" className={resetButtonClassName} onClick={reset}>
                <X size={16} strokeWidth={3} className={styles.icon} />
                Clear filters
              </button>
            </footer>
          )}
        </div>
      )}
    </div>
  );
}