Skip to content

useVariableModes ​

useVariableModes() provides headless state and actions for a variable mode control, such as a frame's theme: the collections a mode can be set for on the selection, or on the current page when nothing is selected, and the mode each one shows.

Usage ​

ts
import { useVariableModes } from '@open-pencil/vue/controls/variable-modes'

const { choices, applied, setMode } = useVariableModes()
  • choices lists every collection with more than one mode for pages and layers that hold others (frames, groups, sections, components, and instances), so a theme can be chosen before anything inside binds its variables; for other layers, only those whose variables they use, through their own bindings or variables those alias. Each has its modes, its value (the mode set on every target, MIXED when they differ, or null for Auto), and the inherited mode the targets show without one of their own.
  • applied is the part of choices with a mode set on at least one target.
  • setMode(collectionId, modeId) sets the mode on every target in one undo step; null clears it, so the targets inherit their parent's mode again.

variableModeChoices(editor, nodes) and setVariableMode(editor, nodes, collectionId, modeId) do the same for any layers, outside a component.