Calm motion: animations on this site only fade, with no movement
Filter bar
Filters as chips in a row
A short row of filters above a list or a table, for example "Status is Live". Each filter is a chip that a person can change or remove. All the filters must match. For "any" rules and groups of rules, use the query builder, which has the same data for a rule.
Basic
- Status
- Plays
Add filter
[{"field":"status","op":"eq","value":"live"},{"field":"plays","op":"gt","value":"1000"}]
vue
<template>
<div>
<BlessFilterBar v-model="rules" :fields />
<BlessText as="p" size="xs" style="margin-top: 12px; font-family: var(--bless-font-mono)">{{
json
}}</BlessText>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from "vue";
import { BlessFilterBar, BlessText, type BlessQueryField, type BlessQueryRule } from "blessing-ui";
const fields: BlessQueryField[] = [
{ name: "title", label: "Title" },
{
name: "status",
label: "Status",
type: "select",
options: [
{ value: "live", label: "Live" },
{ value: "draft", label: "Draft" },
{ value: "scheduled", label: "Scheduled" },
],
},
{ name: "plays", label: "Plays", type: "number" },
{ name: "published", label: "Published", type: "date" },
];
const rules = ref<BlessQueryRule[]>([
{ field: "status", op: "eq", value: "live" },
{ field: "plays", op: "gt", value: "1000" },
]);
const json = computed(() => JSON.stringify(rules.value));
</script>fieldsis a list of{ name, label, type, options }, as for the query builder. The type (text,number,date, orselect) sets the operators and the value control.v-modelis a list of rules{ field, op, value }. All the rules must match. The value is the text of the control, so turn it into your query, for example on the server.- Each chip says its rule in words, for example "Status is Live". A select field shows the label of its option, and a date field says "is before" and "is after".
- "Add filter" opens a list of the fields. The new filter opens its editor at once, so the person sets the value next. A click on a chip opens the editor again. Enter in the value closes it.
- The × on a chip removes the filter, and focus goes to "Add filter". "Clear all" removes all of them.
- Change the words with
labelsor a label pack:label,add,clear,done,remove,op,value, and the words of each operator.
Usage
ts
import { BlessFilterBar, type BlessQueryField, type BlessQueryRule } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
fields* | BlessQueryField[] | — | what people can filter by |
disabled | boolean | — | |
labels | Partial<{ label: string; add: string; clear: string; done: string; remove: string; op: string; value: string; eq: string; neq: string; contains: string; starts: string; lt: string; lte: string; gt: string; gte: string; empty: string; notEmpty: string; before: string; onOrBefore: string; after: string; onOrAfter: string; }> | — | |
modelValue | BlessQueryRule[] | [] | the filters, all of which must match; the same rules as `BlessQueryBuilder` |
Events
| Name | Payload | Description |
|---|---|---|
update:modelValue | [value: BlessQueryRule[]] |