Skip to content

Latest commit

 

History

History
77 lines (48 loc) · 2.44 KB

File metadata and controls

77 lines (48 loc) · 2.44 KB

TeamLibraryAPI

Interface: TeamLibraryAPI

Defined in: figmaPluginTypes.ts:2058

See

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

Methods

getAvailableLibraryVariableCollectionsAsync()

getAvailableLibraryVariableCollectionsAsync(): Promise<LibraryVariableCollection[]>

Defined in: figmaPluginTypes.ts:2070

Returns a descriptor of all VariableCollections that exist in the enabled libraries of the current file. Rejects if the request fails.

Note: This requires that users enable libraries that contain variables via the UI. Currently it is not possible to enable libraries via the Plugin API.

Returns

Promise<LibraryVariableCollection[]>

A list of LibraryVariableCollections that are available for this file

Remarks

This is intended to be used in conjunction with TeamLibraryAPI.getVariablesInLibraryCollectionAsync


getVariablesInLibraryCollectionAsync()

getVariablesInLibraryCollectionAsync(libraryCollectionKey): Promise<LibraryVariable[]>

Defined in: figmaPluginTypes.ts:2095

Returns a descriptor of all Variables that exist in a given LibraryVariableCollection. Rejects if the given variable collection does not exist, or if the current user does not have access to that variable collection's library, or if the request fails.

Parameters

libraryCollectionKey

string

the key of the library variable collection that contains the returned library variables.

Example usage

// Query all published collections from libraries enabled for this file
const libraryCollections =
  await figma.teamLibrary.getAvailableLibraryVariableCollectionsAsync();
// Select a library variable collection to import into this file
const variablesInFirstLibrary =
  await figma.teamLibrary.getVariablesInLibraryCollectionAsync(
    libraryCollections[0].key
  );
// Import the first number variable we find in that collection
const variableToImport = variablesInFirstLibrary.find(
  (libVar) => libVar.resolvedType === "FLOAT"
);
const importedVariable = await figma.variables.importVariableByKeyAsync(
  variableToImport.key
);

Returns

Promise<LibraryVariable[]>