Prepared Docs

Prepared Docs

⌘K

    Loading navigation…

User

  1. Blocks
  2. Filters
  3. API and Development

Filters

API and Development

View Source
Submit Issue

Import sort/group and filter surfaces from @prepared911/ui-filters. Props below are documented with manual tables — this package uses flat/src/sort layouts that are outside the docs component-api registry / DocgenPropsTable discovery.

SortControl Props

SortControl is a discriminated union on variant.

Multiple (variant omitted or SortVariant.Multiple)

NameTypeDefaultDescription
variantSortVariant.MultipleMultipleCriterion menu.
criteriaSortCriterion<T>[]requiredSort options. Prefer module-stable or useMemo'd arrays.
valueSortValue—Controlled sort value. Empty criterionId means no active sort.
defaultValueSortValuefirst criterion ascendingUncontrolled initial sort.
onChange(value: SortValue) => void—Sort change handler (including clear → criterionId: "").
groupingGroupCriterion<T>[]—When set, renders group menu in a ButtonGroup before sort.
groupValuestring | null—Controlled group criterion id; null = ungrouped.
defaultGroupValuestring | nullnullUncontrolled initial group.
onGroupChange(groupId: string | null) => void—Group change handler.
labelstringlocalized "Sort By"Sort menu / Simple title override.
groupLabelstringlocalized "Group By"Group menu label override.
aria-labelstringlocalized "Sort and group"ButtonGroup accessible name when grouping is set.
sizeIconButtonSize—Icon button size for triggers.
classNamestring—Root class.

Simple (variant={SortVariant.Simple})

NameTypeDefaultDescription
variantSortVariant.SimplerequiredDirection toggle for one criterion.
criterionSortControlSimpleCriterion<T>requiredExactly one toggleable criterion (fixedDirection is not part of this type). Shared value/label/grouping props match Multiple.

SortControl embeds useSortState. Sort is controlled when value !== undefined; group is controlled when groupValue !== undefined — axes may differ.

SortCriterion

NameTypeDescription
idstringStable id (persistable).
labelstringMenu / title label.
iconSVGAssetOptional; not rendered in the Multiple sort menu (labels only).
fieldkeyof T & stringShorthand field compare.
compare(a, b) => numberAscending comparator; wins over field.
fixedDirectionSortDirectionPins direction and hides the trailing direction control while selected.
disabledbooleanDisables the criterion option.

GroupCriterion

NameTypeDescription
idstringStable id (persistable).
labelstringGroup menu label.
iconSVGAssetDecorative leading icon.
getKey(item) => string | string[] | null | undefinedMulti-key allowed; nullish → ungrouped.
getLabel(key, items) => stringOptional bucket label.
compareGroups(a, b) => numberOptional group ordering.
disabledbooleanDisables the option.

Group rows are toggleable menuitemcheckbox options with a bare checkmark indicator. Public ungrouped state is groupValue === null (no sentinel export). useSortState.toggleGroup enforces single-select: activating the checked id clears to null.

Hooks

useSortState

Controlled/uncontrolled sort + group selection (like useFilterState). Exposes toggleCriterion, setGroup, and toggleGroup.

toggleCriterion

(criterionId: string) => void — if criterionId matches the active criterion, clears to criterionId: ""; otherwise selects that id (honoring fixedDirection).

toggleGroup

(groupId: string) => void — if groupId matches the active group, clears to null; otherwise selects that id.

useSortedData

Embeds useSortState and returns memoised sortedData (like useFilteredData). Sorting is non-mutating (toSorted).

useGroupedData

Transform-only: { data, grouping, groupId } → { groups, ungrouped }. Pass groupId from state / SortControl.

Filter

Filter (search, categories, quick filters, segmented control, column visibility) lives in this package. Full prop tables currently remain under Data Table API with a cross-link pointing back here as the package home. Prefer:

debounceSearchMs: omit or 0 for immediate updates (not 300).

Previous

Filters / Usage

Next

Filters / Accessibility

On this page

SortControl Props
Multiple (variant omitted or SortVariant.Multiple)
Simple (variant={SortVariant.Simple})
SortCriterion
GroupCriterion
Hooks
useSortState
toggleCriterion
toggleGroup
useSortedData
useGroupedData
Filter