Skip to content

Latest commit

 

History

History
598 lines (301 loc) · 15.4 KB

TextStyle.md

File metadata and controls

598 lines (301 loc) · 15.4 KB

TextStyle

Interface: TextStyle

Defined in: figmaPluginTypes.ts:10077

See

https://www.figma.com/plugin-docs/api/node-properties

Extends

Properties

boundVariables?

optional boundVariables: object

Defined in: figmaPluginTypes.ts:10133

The variables bound to a particular field on this text style.

fontFamily?

optional fontFamily: VariableAlias

fontSize?

optional fontSize: VariableAlias

fontStyle?

optional fontStyle: VariableAlias

fontWeight?

optional fontWeight: VariableAlias

letterSpacing?

optional letterSpacing: VariableAlias

lineHeight?

optional lineHeight: VariableAlias

paragraphIndent?

optional paragraphIndent: VariableAlias

paragraphSpacing?

optional paragraphSpacing: VariableAlias


consumers

readonly consumers: StyleConsumers[]

Defined in: figmaPluginTypes.ts:10051

The consumers of this style. The fields in StyleConsumers refers to the field where the style is applied (e.g. a PaintStyle can be applied in setFillStyleIdAsync or setStrokeStyleIdAsync).

Deprecated

Use getStyleConsumersAsync instead. Accessing this property will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Inherited from

BaseStyleMixin.consumers


description

description: string

Defined in: figmaPluginTypes.ts:7052

The plain-text annotation entered by the user for this style/component.

Remarks

To set a rich-text description using markdown, see PublishableMixin.descriptionMarkdown

Caution: ⚠️ There is a currently a bug in Figma where the description field will appear to be missing or not up to date. Until this is fixed, the workaround is to re-publish nodes for which the description is missing.

Inherited from

BaseStyleMixin.description


descriptionMarkdown

descriptionMarkdown: string

Defined in: figmaPluginTypes.ts:7061

The rich-text annotation entered by the user for this style/component.

Remarks

Caution: ⚠️ There is a currently a bug in Figma where the description field will appear to be missing or not up to date. Until this is fixed, the workaround is to re-publish nodes for which the description is missing.

Inherited from

BaseStyleMixin.descriptionMarkdown


documentationLinks

documentationLinks: readonly DocumentationLink[]

Defined in: figmaPluginTypes.ts:7078

The documentation links for this style/component.

Remarks

This API currently only supports setting a single documentation link. To clear the documentation links, set to the empty list [].

Example:

node.documentationLinks = [{ uri: "https://www.figma.com" }];

// clear documentation links
node.documentationLinks = [];

Inherited from

BaseStyleMixin.documentationLinks


fontName

fontName: FontName

Defined in: figmaPluginTypes.ts:10093

Value to replace the text BaseNonResizableTextMixin.fontName with.


fontSize

fontSize: number

Defined in: figmaPluginTypes.ts:10085

Value to replace the text BaseNonResizableTextMixin.fontSize with.


hangingList

hangingList: boolean

Defined in: figmaPluginTypes.ts:10125

Value to replace the text NonResizableTextMixin.hangingList with.


hangingPunctuation

hangingPunctuation: boolean

Defined in: figmaPluginTypes.ts:10121

Value to replace the text NonResizableTextMixin.hangingPunctuation with.


id

readonly id: string

Defined in: figmaPluginTypes.ts:10040

The unique identifier of the style in the document the plugin is executing from. You can assign this value via setFillStyleIdAsync, setStrokeStyleIdAsync, setTextStyleIdAsync, etc. to make the node properties reflect that of the style node.

Inherited from

BaseStyleMixin.id


key

readonly key: string

Defined in: figmaPluginTypes.ts:7086

The key to use with PluginAPI.importComponentByKeyAsync, PluginAPI.importComponentSetByKeyAsync and PluginAPI.importStyleByKeyAsync. Note that while this key is present on local and published components, you can only import components that are already published.

Inherited from

BaseStyleMixin.key


leadingTrim

leadingTrim: LeadingTrim

Defined in: figmaPluginTypes.ts:10105

Value to replace the text NonResizableTextMixin.leadingTrim with.


letterSpacing

letterSpacing: LetterSpacing

Defined in: figmaPluginTypes.ts:10097

Value to replace the text BaseNonResizableTextMixin.letterSpacing with.


lineHeight

lineHeight: LineHeight

Defined in: figmaPluginTypes.ts:10101

Value to replace the text NonResizableTextMixin.lineHeight with.


listSpacing

listSpacing: number

Defined in: figmaPluginTypes.ts:10117

Value to replace the text NonResizableTextMixin.listSpacing with.


name

name: string

Defined in: figmaPluginTypes.ts:10055

The name of the style node. Note that setting this also sets "autoRename" to false on TextNode.

Inherited from

BaseStyleMixin.name


paragraphIndent

paragraphIndent: number

Defined in: figmaPluginTypes.ts:10109

Value to replace the text NonResizableTextMixin.paragraphIndent with.


paragraphSpacing

paragraphSpacing: number

Defined in: figmaPluginTypes.ts:10113

Value to replace the text NonResizableTextMixin.paragraphSpacing with.


remote

readonly remote: boolean

Defined in: figmaPluginTypes.ts:7082

Whether this style/component is a remote style/component that doesn't live in the file (i.e. is from the team library). Remote components are read-only: attempts to change their properties will throw.

Inherited from

BaseStyleMixin.remote


textCase

textCase: TextCase

Defined in: figmaPluginTypes.ts:10129

Value to replace the text BaseNonResizableTextMixin.textCase with.


textDecoration

textDecoration: TextDecoration

Defined in: figmaPluginTypes.ts:10089

Value to replace the text NonResizableTextMixin.textDecoration with.


type

type: "TEXT"

Defined in: figmaPluginTypes.ts:10081

The string literal "TEXT" representing the style type. Always check the type before reading other properties.

Overrides

BaseStyleMixin.type

Methods

getPluginData()

getPluginData(key): string

Defined in: figmaPluginTypes.ts:5031

Retrieves custom information that was stored on this node or style using PluginDataMixin.setPluginData. If there is no data stored for the provided key, an empty string is returned.

Parameters

key

string

Returns

string

Inherited from

BaseStyleMixin.getPluginData


getPluginDataKeys()

getPluginDataKeys(): string[]

Defined in: figmaPluginTypes.ts:5053

Retrieves a list of all keys stored on this node or style using using PluginDataMixin.setPluginData. This enables iterating through all data stored privately on a node or style by your plugin.

Returns

string[]

Inherited from

BaseStyleMixin.getPluginDataKeys


getPublishStatusAsync()

getPublishStatusAsync(): Promise<PublishStatus>

Defined in: figmaPluginTypes.ts:7090

Gets the status of this style/component in the team library.

Returns

Promise<PublishStatus>

Inherited from

BaseStyleMixin.getPublishStatusAsync


getSharedPluginData()

getSharedPluginData(namespace, key): string

Defined in: figmaPluginTypes.ts:5057

Retrieves custom information that was stored on this node or style using PluginDataMixin.setSharedPluginData. If there is no data stored for the provided namespace and key, an empty string is returned.

Parameters

namespace

string

key

string

Returns

string

Inherited from

BaseStyleMixin.getSharedPluginData


getSharedPluginDataKeys()

getSharedPluginDataKeys(namespace): string[]

Defined in: figmaPluginTypes.ts:5079

Retrieves a list of all keys stored on this node or style using PluginDataMixin.setSharedPluginData. This enables iterating through all data stored in a given namespace.

Parameters

namespace

string

Returns

string[]

Inherited from

BaseStyleMixin.getSharedPluginDataKeys


getStyleConsumersAsync()

getStyleConsumersAsync(): Promise<StyleConsumers[]>

Defined in: figmaPluginTypes.ts:10045

The consumers of this style. The fields in StyleConsumers refers to the field where the style is applied (e.g. a PaintStyle can be applied in setFillStyleIdAsync or setStrokeStyleIdAsync).

Returns

Promise<StyleConsumers[]>

Inherited from

BaseStyleMixin.getStyleConsumersAsync


remove()

remove(): void

Defined in: figmaPluginTypes.ts:10059

Deletes a local style.

Returns

void

Inherited from

BaseStyleMixin.remove


setBoundVariable()

setBoundVariable(field, variable): void

Defined in: figmaPluginTypes.ts:10144

Binds the provided field on this node to the given variable. Please see the Working with Variables guide for how to get and set variable bindings.

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

Parameters

field

VariableBindableTextField

The field to bind the variable to.

variable

The variable to bind to the field. If null is provided, the field will be unbound from any variables. Make sure to pass a Variable object or null; passing a variable ID is not supported.

null | Variable

Returns

void


setPluginData()

setPluginData(key, value): void

Defined in: figmaPluginTypes.ts:5049

Lets you store custom information on any node or style, private to your plugin. The total size of your entry (pluginId, key, value) cannot exceed 100 kB.

Parameters

key

string

The key under which to store the data. This is similar to writing to a plain object via obj[key] = value.

value

string

The data you want to store. If you want to store a value type other than a string, encode it as a JSON string first via JSON.stringify and JSON.parse. If you set the value to the empty string (""), the key/value pair is removed.

Returns

void

Remarks

The data is specific to your plugin ID. Plugins with other IDs won't be able to read this data. You can retrieve it later by calling getPluginData with the same key. To find all data stored on a node or style by your plugin use getPluginDataKeys.

Caution: ⚠ The data is stored privately for stability, not security. It prevents other plugins from accessing with your data. It does not, however, prevent users from seeing the data given sufficient effort. For example, they could export the document as a .fig file and try to decode it.

Caution: ⚠ Data will become inaccessible if your plugin ID changes.

Caution: ⚠ Total entry size cannot exceed 100 kB.

Inherited from

BaseStyleMixin.setPluginData


setSharedPluginData()

setSharedPluginData(namespace, key, value): void

Defined in: figmaPluginTypes.ts:5075

Lets you store custom information on any node or style, public to all plugins. The total size of your entry (namespace, key, value) cannot exceed 100 kB.

Parameters

namespace

string

A unique string to identify your plugin and avoid key collisions with other plugins. The namespace must be at least 3 alphanumeric characters.

key

string

The key under which to store the data. This is similar to writing to a plain object via obj[key] = value.

value

string

The data you want to store. If you want to store a value type other than a string, encode it as a JSON string first via JSON.stringify and JSON.parse. If you set the value to the empty string (""), the key/value pair is removed.

Returns

void

Remarks

This lets you store custom information on any node or style. You can retrieve it later by calling PluginDataMixin.getSharedPluginData with the same namespace and key. To find all data stored on a node or style in a particular namespace, use PluginDataMixin.getSharedPluginDataKeys.

Any data you write using this API will be readable by any plugin. The intent is to allow plugins to interoperate with each other. Use PluginDataMixin.setPluginData instead if you don't want other plugins to be able to read your data.

You must also provide a namespace argument to avoid key collisions with other plugins. This argument is mandatory to prevent multiple plugins from using generic key names like data and overwriting one another. We recommend passing a value that identifies your plugin. This namespace can be given to authors of other plugins so that they can read data from your plugin.

Caution: ⚠ Total entry size cannot exceed 100 kB.

Inherited from

BaseStyleMixin.setSharedPluginData