Skip to content

Latest commit

 

History

History
446 lines (225 loc) · 9.27 KB

File metadata and controls

446 lines (225 loc) · 9.27 KB

VariablesAPI

Interface: VariablesAPI

Defined in: figmaPluginTypes.ts:1876

See

https://www.figma.com/plugin-docs/api/figma-variables

Methods

createVariable()

Call Signature

createVariable(name, collectionId, resolvedType): Variable

Defined in: figmaPluginTypes.ts:1935

Creates a variable with a given name and resolved type inside a collection.

Parameters
name

string

the name of the newly created variable

collectionId

string

the ID of a collection object

resolvedType

VariableResolvedDataType

the resolved type of this variable

Returns

Variable

Deprecated

Use createVariable(string, VariableCollection, VariableResolvedDataType) instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Call Signature

createVariable(name, collection, resolvedType): Variable

Defined in: figmaPluginTypes.ts:1947

Creates a variable with a given name and resolved type inside a collection.

Parameters
name

string

the name of the newly created variable

collection

VariableCollection

A variable collection. Make sure to pass a collection object here; passing a collection ID is deprecated.

resolvedType

VariableResolvedDataType

the resolved type of this variable

Returns

Variable


createVariableAlias()

createVariableAlias(variable): VariableAlias

Defined in: figmaPluginTypes.ts:1963

Helper function to create a variable alias.

This should be used with functions such as node.setProperties() to assign component properties to variables.

Parameters

variable

Variable

Returns

VariableAlias


createVariableAliasByIdAsync()

createVariableAliasByIdAsync(variableId): Promise<VariableAlias>

Defined in: figmaPluginTypes.ts:1970

Helper function to create a variable alias.

This should be used with functions such as node.setProperties() to assign component properties to variables.

Parameters

variableId

string

Returns

Promise<VariableAlias>


createVariableCollection()

createVariableCollection(name): VariableCollection

Defined in: figmaPluginTypes.ts:1956

Creates a new variable collection with the given name.

Parameters

name

string

the name of the newly created variable collection.

Returns

VariableCollection


getLocalVariableCollections()

getLocalVariableCollections(): VariableCollection[]

Defined in: figmaPluginTypes.ts:1925

Returns all local variable collections in the current file.

Returns

VariableCollection[]

Deprecated

Use VariablesAPI.getLocalVariableCollectionsAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".


getLocalVariableCollectionsAsync()

getLocalVariableCollectionsAsync(): Promise<VariableCollection[]>

Defined in: figmaPluginTypes.ts:1919

Returns all local variable collections in the current file.

Returns

Promise<VariableCollection[]>


getLocalVariables()

getLocalVariables(type?): Variable[]

Defined in: figmaPluginTypes.ts:1915

Returns all local variables in the current file, optionally filtering by resolved type.

Parameters

type?

VariableResolvedDataType

Filters the returned variables to only be of the given resolved type.

Returns

Variable[]

Deprecated

Use VariablesAPI.getLocalVariablesAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".


getLocalVariablesAsync()

getLocalVariablesAsync(type?): Promise<Variable[]>

Defined in: figmaPluginTypes.ts:1908

Returns all local variables in the current file, optionally filtering by resolved type.

Parameters

type?

VariableResolvedDataType

Filters the returned variables to only be of the given resolved type.

Returns

Promise<Variable[]>


getVariableById()

getVariableById(id): null | Variable

Defined in: figmaPluginTypes.ts:1889

Finds a variable by ID. If not found or the provided ID is invalid, returns null.

Parameters

id

string

The variable ID to search for, which represents a unique identifier for the variable.

Returns

null | Variable

Deprecated

Use VariablesAPI.getVariableByIdAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".


getVariableByIdAsync()

getVariableByIdAsync(id): Promise<null | Variable>

Defined in: figmaPluginTypes.ts:1882

Finds a variable by ID. If not found or the provided ID is invalid, returns a promise containing null.

Parameters

id

string

The variable ID to search for, which represents a unique identifier for the variable.

Returns

Promise<null | Variable>


getVariableCollectionById()

getVariableCollectionById(id): null | VariableCollection

Defined in: figmaPluginTypes.ts:1902

Finds a variable collection by ID. If not found or the provided ID is invalid, returns null.

Parameters

id

string

The variable collection ID to search for, which represents a unique identifier for the variable collection.

Returns

null | VariableCollection

Deprecated

Use VariablesAPI.getVariableCollectionByIdAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".


getVariableCollectionByIdAsync()

getVariableCollectionByIdAsync(id): Promise<null | VariableCollection>

Defined in: figmaPluginTypes.ts:1895

Finds a variable collection by ID. If not found or the provided ID is invalid, returns a promise containing null.

Parameters

id

string

The variable collection ID to search for, which represents a unique identifier for the variable collection.

Returns

Promise<null | VariableCollection>


importVariableByKeyAsync()

importVariableByKeyAsync(key): Promise<Variable>

Defined in: figmaPluginTypes.ts:2013

Loads a variable from the team library. Promise is rejected if there is no published variable with that key or if the request fails.

Parameters

key

string

the key of the variable to import.

Returns

Promise<Variable>


setBoundVariableForEffect()

setBoundVariableForEffect(effect, field, variable): Effect

Defined in: figmaPluginTypes.ts:1990

Helper function to bind a variable to an Effect.

If null is provided as the variable, the given field will be unbound from any variables.

Parameters

effect

Effect

field

VariableBindableEffectField

variable

null | Variable

Returns

Effect

a copy of the effect which is now bound to the provided variable.


setBoundVariableForLayoutGrid()

setBoundVariableForLayoutGrid(layoutGrid, field, variable): LayoutGrid

Defined in: figmaPluginTypes.ts:2002

Helper function to bind a variable to a LayoutGrid.

If null is provided as the variable, the given field will be unbound from any variables.

Parameters

layoutGrid

LayoutGrid

field

VariableBindableLayoutGridField

variable

null | Variable

Returns

LayoutGrid

a copy of the layout grid which is now bound to the provided variable.


setBoundVariableForPaint()

setBoundVariableForPaint(paint, field, variable): SolidPaint

Defined in: figmaPluginTypes.ts:1978

Helper function to bind a variable to a SolidPaint.

If null is provided as the variable, the given field will be unbound from any variables.

Parameters

paint

SolidPaint

field

"color"

variable

null | Variable

Returns

SolidPaint

a copy of the paint which is now bound to the provided variable.