Skip to main content

condition

function

Define a rule that gates whether something is enabled and visible. Declare it once, list it in `defineMod`'s `conditions` slot, and reference the same value from every `when` that needs it. Reach for this instead of checking state inside a handler when the user should see the command greyed out rather than have it fail on click.

function condition<TId extends string>(input: ConditionInput<TId>): Condition<TId>

Import

import { condition } from '@modular/sdk';

Notes

example
```ts const hasSelection = condition({ id: 'my-mod.hasSelection', when: ctx => { const selection = ctx.state('editor.selection').value; return selection !== null && selection.charCount > 0; }, }); command({ id: 'my-mod.shout', title: 'Shout', when: hasSelection, run }); ```
category
State