@stenajs-webui/filter

中文文档
25.3.3发布于 2026/11/02MITTypeScriptESM + CJS

This package contains components and functionality that makes it easy to create custom filters in a drawer, and an overview row containing chips.

原始使用文档
文档目录4 节
  1. DateRangeCalendarSection
  2. ChipMultiSelectSection
  3. Chips
  4. Manual chips

stenajs-webui/filter

This package contains components and functionality that makes it easy to create custom filters in a drawer, and an overview row containing chips.

This package is alpha. API:s will most likely change, and more features added. If you use it, be ready for breaking changes.

The section

A section is one expandable part of the filter. The filter can consist of many sections. Each section can how none, one or many chips.

The context

The filter components access state, dispatch and actions. These are fetched from context, so any filter components must be wrapped with

<SearchFilterContext actions={actions} state={state} dispatch={dispatch}>
  <SearchFilterButton/>
  <SearchFilterChips>
    <SectionChips {...stuff} />
  </SearchFilterChips>
  <SearchFilterDrawer>
    ... sections
  </SearchFilterDrawer>

If you are only using local state (no Redux, persistence, etc), you can use SearchFilterLocalStateContext. It will automatically setup actions, state and dispatch.

<SearchFilterLocalStateContext<FormModel>
  initialFormModel={{ startDate: undefined, endDate: undefined }}
>
  ... same as above
</SearchFilterLocalStateContext>

If you use SearchFilterLocalStateContext, you can use this to access filter state.

const state = useSearchFilterState();

Custom sections

You can create custom sections easily.

const MySection = (...props) => (
  <SearchFilterSection sectionId={sectionId} loading={loading} error={error}>
    <ChipMultiSelect
      options={filteredOptions}
      value={listValue}
      onValueChange={onValueChangeInternal}
      inputValue={text}
      onInputChange={setText}
    />
  </SearchFilterSection>
);

See source code for examples.

Ready-to-use sections

There are sections available ready to use.

More will be made available as the filter package matures.

DateRangeCalendarSection

Add the section to the drawer.

<DateRangeCalendarSection
  sectionId={"comparisonDate"}
  {...createDateRangeSectionProps(state.formModel, "startDate", "endDate")}
/>

And add the chips.

<SectionChips
  sectionId={"comparisonDate"}
  emptyChipLabel={"No dates"}
  {...createChipsPropsForDateRange(state.formModel, "startDate", "endDate")}
/>

ChipMultiSelectSection

Add the section to the drawer. This section does not have a helper method for creating props.

They must be specified manually. This might change.

<ChipMultiSelectSection
  sectionId={"divisions"}
  loading={false}
  options={divisionOptions}
  value={state.formModel.divisions}
  onValueChange={(divisions) =>
    dispatch(actions.setFormModelFields({ divisions }))
  }
/>

And add the chips.

<SectionChips
  sectionId={"divisions"}
  emptyChipLabel={"All division"}
  {...createChipsPropsForBooleanRecord(
    state.formModel,
    "divisions",
    divisionOptions
  )}
/>

In this example, state.formModel.divisions must be a BooleanRecord.

Another section for BooleanRecord is SimpleCheckboxListSection. They are API compatible and are interchangeable.

<SimpleCheckboxListSection
  sectionId={"divisions"}
  loading={false}
  options={divisionOptions}
  value={state.formModel.divisions}
  onValueChange={(divisions) =>
    dispatch(actions.setFormModelFields({ divisions }))
  }
/>

Chips

You can add all chips for a section using the SectionChips component.

<SectionChips
  sectionId={"divisions"}
  emptyChipLabel={"All division"}
  {...createChipsPropsForBooleanRecord(
    state.formModel,
    "divisions",
    divisionOptions
  )}
/>

Manual chips

If you need more manual control over each chip, you can add them individually.

{
  myList.map(({ value, label }) => (
    <SearchFilterChip
      key={value}
      label={label ?? sectionId}
      sectionId={sectionId}
      onClickRemove={onClickRemoveOnChip}
      value={value}
    />
  ));
}

If you need a chip to indicate no selection, you can use EmptyChip.

<EmptyChip sectionId={sectionId} label={emptyChipLabel} />

版本与发布记录

@stenajs-webui/filter 共发布 506 个版本,首次发布于 2021/11/18;过去 12 个月发布了 86 个版本。

版本发布日期距今
25.3.3latest2026/11/02今天
25.3.22026/10/303 天前
25.3.12026/10/285 天前
25.3.02026/10/277 天前
25.2.02026/10/277 天前
25.1.72026/10/2311 天前

其他发布通道:next → 19.0.0-next.76。

关于 @stenajs-webui/filter 的常见问题

@stenajs-webui/filter 是什么?

这个包包含组件和功能,可以轻松地在抽屉中创建自定义过滤器,以及包含芯片的概述行。

如何安装 @stenajs-webui/filter?

在项目目录运行 npm install @stenajs-webui/filter,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=19.0.0)、redux(>=5.0.1)、react-dom(>=19.0.0)、prop-types(>=15.5.4)、@emotion/react(>=11.14.0)、@emotion/styled(>=11.14.0)、@types/lodash-es(>=4.17.12)、@fortawesome/fontawesome-svg-core(>=6.7.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@stenajs-webui/filter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@stenajs-webui/filter 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@stenajs-webui/filter 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@stenajs-webui/filter 可以商用吗?

@stenajs-webui/filter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@stenajs-webui/filter 还在维护吗?

最新版本 25.3.3 发布于 2026/11/02(今天);至今共发布 506 个版本,其中过去 12 个月发布了 86 个;首次发布于 2021/11/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。