Skip to content
Calm motion: animations on this site only fade, with no movement

Rule builder ​

An automation rule: when something happens, if a condition holds, then do an action

Makes a rule for a smart home or a workflow tool. For a filter with many fields and operators, use the query builder.

Basic
When
Only if
Then

The rule: When the studio door opens, if the on air sign is on, then send me a notice.

  • triggers, conditions, and actions are the lists to pick from. Each option has an id and a label. Write each label so that it reads well in a sentence, such as "the studio door opens".
  • v-model is the rule: when is one trigger id, if is a list of condition ids, and then is a list of action ids. All the conditions must hold.
  • Each part is a fieldset of native menus. "Add a condition" and "Add an action" add a row. The ✕ button removes a row, and its name says what it removes. A rule keeps at least one action row.
  • A line under the form reads the rule as one sentence. The demo shows an example.
  • "Save the rule" emits save with the rule, without empty rows. It is off until the rule has a trigger and an action.
  • Without conditions, the "Only if" part does not show.
  • Change the words with labels or a label pack: when, if, then, pick, addIf, addThen, save, preview, and, and the functions remove and sentence.

Usage ​

ts
import { BlessRuleBuilder } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
triggers*BlessRuleOption[]—
conditionsBlessRuleOption[]—
actions*BlessRuleOption[]—
labelsPartial<{ when: string; if: string; then: string; pick: string; addIf: string; addThen: string; remove: (what: string) => string; save: string; preview: string; sentence: (when: string, ifs: string, thens: string) => string; and: string; }>—
modelValueBlessRule{ when: "", if: [], then: [""] }

Events

NamePayloadDescription
update:modelValue[value: BlessRule]
save[rule: BlessRule]

Released under the MIT License. Character names and artwork belong to their owners.