FilterPanel

FilterPanel

HkFilterPanel is the condition-row list inside the filter affordance, and the one place the library defines the filter-condition model. A condition is { key, op, value } — which field, which operator, which text — and a field is { key, label, kind, options?, operators?, placeholder? }. The panel shows one row per condition ([field label | operator toggles | value control | remove]) and one growth verb, "Add condition", which opens a chooser of the declared fields.

  • This is the paired half of FilterBar's popover and FilterTrigger's header button: those components own the surface, this one owns the conditions. Placing it in a bar's fields slot or behind the trigger is the whole composition.
  • A single facet whose alternatives are known up front (a provider list, a status set) does not need rows at all — that is FilterChip. A keyword is SearchTrigger.
  • The semantics are also exported as pure functions (hkFieldMatches, hkConditionMatches, sanitizeNumberInput): a page can filter its own rows with exactly the rule the panel describes, and a server can be held to the same rule instead of re-inventing it.

Import

tsx
1
2
3
4
5
6
7
import {
  HkFilterPanel,
  hkConditionMatches,
  hkFieldMatches,
  sanitizeNumberInput,
} from "@celestia-island/hikari";
import type { HkFilterCondition, HkFilterFieldDef, HkFilterOperator, HkFilterState } from "@celestia-island/hikari";
rust
1
2
3
use hikari_components::*;          // FilterPanel, FilterFieldDef, FilterFieldKind, FilterOperator,
                                   // FilterCondition, FilterState, FilterOption, AddMenuState
use hikari_components::prelude::*; // FilterPanelProps, rsx!, VNode, EventHandler

The Rust form is FilterPanel(FilterPanelProps { … }); the state type is FilterState = Vec<FilterCondition> on both sides. Inside rsx! only fields and model_value matter — disabled, label, the three controlled-state props and the three handlers all default to "closed / none".

The condition model: operators per kind, and how they combine

Each field kind offers a fixed operator set: text → approx / napprox (contains / does not contain), number → lt / lte / eq / gte / gt, select → eq / ne, date → gte / lte. operators on the field overrides the set — and an override of [] stays empty (?? only falls through on undefined), so a field may offer none.

The same field may carry many conditions: the state is an ordered array, not a map. They combine in two classes — the match class (approx; plus eq for select) OR-combines, so ≈banana and ≈apple match rows containing either; every other condition must hold individually (AND), so ≥10 and ≤50 form a band and ≉draft excludes. Empty values are skipped entirely; an empty list matches everything.

Name
Name
Amount
Amount

Apple juice matches text: true

24 matches amount: true

Both cards show the same four rows; the TSX card additionally prints field_matches for one sample row of each field ("Apple juice" hits the text class, "24" sits inside the band). Editing a value in the TSX card is live — the controls are real — while the Rust rows paint the given state.

Pinned rows, the chooser and undeclared keys

The panel carries two condition classes. A field declared with pinned renders as a permanent row at the top: one row per field, always visible, never removable — its value control's own "All" entry is the clear. Pinned fields never appear in the chooser. Every other field stays on demand behind "Add condition", whose menu lists the addable fields; re-picking a field the panel already holds with an identical empty condition adds nothing.

A state entry whose key no longer matches a declared field (a page renamed a field under live state) still renders — a bare row naming the raw key, removable but not editable — so a legacy state never silently disappears.

Rust gap. FilterFieldDef has no pinned field and the Rust panel renders every state entry as an ordinary removable row. A pinned band is a Vue-only shape; on the Rust side, express a standing field the same way its "All" entry does — a select condition with an empty value, which filters nothing until picked.

Scope
Name

The TSX card shows the pinned band above two on-demand rows; the Rust card reproduces the same two condition rows with the scope as an ordinary row whose empty value renders as the localized "All" entry. The visible difference is the pinned row's missing remove verb and its fixed position — a Vue-only shape.

Controlled state: what Vue keeps in refs, Rust takes as props

Vue holds three transients in local refs: the chooser (addMenuOpen, addHighlight), and each row's own popup control (open). The Rust mirror takes all three as props — add_menu_open, add_highlight: i32 (-1 = none), open_row: Option<u32> — with on_add_menu_change, on_open_row_change and on_value_change out. One host wiring drives the whole panel, and the mirror stores nothing. Vue's watch(fields) reconciliation becomes the pure add_menu_reconciled (closes the chooser on an empty menu, clamps an out-of-range highlight); the keyboard model is add_menu_key (arrows move the highlight with wrap, Enter/Space confirm, Escape closes one layer and stops the bubble).

A snapshot cannot run the popover layer. The Rust chooser renders as an absolutely positioned sibling of the panel — Vue teleports its own, and neither executes in a static preview — so the example below passes add_menu_open: true and add_highlight: 1 to paint the open chooser statically. On the TSX side the chooser is a real popover: press "Add condition" to see the same frame.

The Rust card paints the empty panel with its chooser open and the second field highlighted; the TSX card starts empty with the chooser closed, and opens it on click. A second Rust-only state is one row popup at a time: open_row: Some(0) opens the first row's value control, where Vue lets each row hold its own ref.

API

Vue

Props

NameTypeDefaultRequired
fieldsArray as PropType<HkFilterFieldDef[]>—✓
modelValueArray as PropType<HkFilterState>() => []—
disabledBooleanfalse—
labelStringundefined—

Emits

EventPayload
update:modelValueHkFilterState

Rust

Props — FilterPanel

PropTypeDefaultDescription
fieldsVec<FilterFieldDef>[]The page's declared fields (Vue: fields, required).
model_valueFilterStateDefault::default()The visible row list — the single source of truth (Vue: modelValue).
disabledboolfalse—
labelOption<String>NonePanel aria-label (Vue: label, defaulting to the localized "Filters").
add_menu_openboolfalseThe add-condition chooser's visibility (Vue: the local addMenuOpen).
add_highlighti32-1The chooser's highlighted row (Vue: the local addHighlight).
open_rowOption<u32>NoneThe row whose popup control is open (Vue: each row control's local open; the mirror carries one index — see the header delta).
on_value_changeOption<EventHandler<FilterState>>NoneFires with the next state (Vue: update:modelValue).
on_add_menu_changeOption<EventHandler<AddMenuState>>NoneFires with the next chooser state (Vue: the addMenuOpen / addHighlight ref writes).
on_open_row_changeOption<EventHandler<Option<u32>>>NoneFires with the row whose popup should open (None = close them all).

Accessibility

  • The panel root is named by label (aria-label) — "Ledger filters" — and carries data-active / data-empty markers the sheet reads; neither is announced.
  • Each row's operator column is a role="group" named "<field label> — <panel label>", so the operator glyphs are read with their field. Each operator is a real button carrying aria-pressed for the chosen one, an aria-label and a matching title; the label is the real operation ("contains", "at least"), never a glyph name.
  • [D] On the Rust side a select field's exact pair is drawn and named as equals / not equals (= / ≠), where Vue swaps in the fuzzy pair's glyphs and words (≈ "fuzzy match"). The tairitsu form is the one that agrees with condition_matches; treat the Vue wording as the deviation, not the reference.
  • The remove verb is a button with aria-label / title "Remove condition"; add the field name to the row context if you render several conditions on the same field ("Remove condition: Name, contains banana") — the default label does not distinguish siblings.
  • The growth verb is aria-haspopup="menu" with a live aria-expanded and data-state; its chooser is a role="menu" of role="menuitem" buttons named "Choose a field to add". Focus stays on the trigger and arrows move a highlight — a roving pattern the host must mirror if it renders its own chooser.
  • Pinned rows carry no remove verb, so a user cannot drop that field; the row's value control is the only verb. Say so in the label or hint if the state is not obvious.
  • Undeclared-key rows are inert: their operator buttons and controls are disabled, because there is nothing declared to edit against. They stay removable.

Related components

  • FilterBar — the strip that hosts this panel inline or in its popover.
  • FilterTrigger — the header button that hosts it as a dialog.
  • FilterChip — the facet alternative, for one known option set.
  • SearchTrigger — the keyword twin that sits beside the filter button.