Skip to content

Composed color variable values can be read but not written; VariableScope missing COLOR_OPACITY and TRANSFORM #375

Description

@six7

The Sept 3 "Control opacity at scale" release added color variables that alias another color variable with an opacity override. valuesByMode returns them, but setValueForMode rejects them, and the typings have no shape for them.

Reading works. Variables created in the UI come back as:

// color aliased to {red} at 50% opacity
{ type: 'VARIABLE_EXPRESSION',
  expressionFunction: 'COMPOSE_COLOR',
  expressionArguments: [{ type: 'VARIABLE_ALIAS', id: 'VariableID:76:8' }, 50] }

// same, with opacity driven by a FLOAT variable
{ type: 'VARIABLE_EXPRESSION',
  expressionFunction: 'COMPOSE_COLOR',
  expressionArguments: [{ type: 'VARIABLE_ALIAS', id: '…' }, { type: 'VARIABLE_ALIAS', id: '…' }] }

resolveForConsumer() resolves them correctly too ({ r: 1, g: 0, b: 0, a: 0.5 }).

But writing back the exact object just read fails:

const modeId = Object.keys(v.valuesByMode)[0]
v.setValueForMode(modeId, v.valuesByMode[modeId])
// ✗ in setValueForMode: Composed color variable values are not supported

So a plugin can read these variables but can't create them, round-trip them, or migrate them between files. For design-token tools this means dynamic references still have to be flattened to a static hex on write, even though the product now models it natively.

VariableScope is also missing two values the runtime accepts — COLOR_OPACITY (the scope this feature uses) and TRANSFORM:

runtime:  … 'OPACITY' | … | 'TRANSFORM' | 'COLOR_OPACITY' | 'STROKE_COLOR' | 'FONT_WEIGHT'
typings:  22 values, both absent

variable.scopes = ['COLOR_OPACITY'] works at runtime today, it just doesn't typecheck.

Request

  1. Allow setValueForMode to accept composed color values at runtime.
  2. Add the composed shape to VariableValue, and 'COMPOSE_COLOR' to ExpressionFunction.
  3. Add 'COLOR_OPACITY' and 'TRANSFORM' to VariableScope.

Figma Desktop 126.8.18, @figma/plugin-typings@1.138.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions