Latest

Filter

Purpose

The Filter component contains all of the complexity for configuring and rendering the supported @appbaseio/reactivesearch filter components.

Usage

Most implementations will pass the filter object directly from the Filters component as seen in the example below however you could replace that with the useFilter hook for this.

If a render method is not provided a built-in component for that filter will be rendered.

import React from "react";
import { Filters } from "@usereactify/search";

import { ExampleFilterList } from "./ExampleFilterList";
import { ExampleFilterRange } from "./ExampleFilterRange";
import { ExampleFilterSlider } from "./ExampleFilterSlider";

export const Component: React.FC = () => {
  return (
    <Filters
      render={(filters) => filters.map((filter) => (
        <Filter
          filter={filter}
          renderFilterList={ExampleFilterList}
          renderFilterRange={ExampleFilterRange}
          renderFilterSlider={ExampleFilterSlider}
        />
      )}
    />
  );
};

Props

type FilterProps = {
  /** The filter option being rendered */
  filter: ConfigFilterOption;
  /** Render method for List filters */
  renderFilterList?: React.FC<{
    filter: ConfigFilterOption;
    filterListProps: ReturnType<typeof useFilterListProps>;
  }>;
  /** Render method for Range filters */
  renderFilterRange?: React.FC<{
    filter: ConfigFilterOption;
    filterRangeProps: ReturnType<typeof useFilterRangeProps>;
  }>;
  /** Render method for Slider filters */
  renderFilterSlider?: React.FC<{
    filter: ConfigFilterOption;
    filterSliderProps: ReturnType<typeof useFilterSliderProps>;
    // reactSliderProps: ReturnType<typeof useReactSliderProps>;
  }>;
  /** Show filters even when no options are available */
  showEmptyFilters?: boolean;
};

Last updated