Skip to content

Improvements to external styles #46

Open
@blairwilcox

Description

@blairwilcox

It would be helpful if we had a better way to simulate the workflow for "importing external styles"

const externalStyle = await figma.importByKeyAsync(key);
node.fillStyleId = externalStyle.id

I think to do this, we'd need to support:

  1. styles to have a "key" property
  2. an implementation for figma.importantByKeyAsync, which uses that key to import a style
  3. Maybe some way of initializing the mock API with "external" libraries

Not sure what the best way of representing "external" libraries. Maybe there could be some internal field like _orig in nodes? something like:

const externalStyle1 = figma.createPaintStyle();
// setup externalStyle1 with keys, paints, etc...

const externalStyle2 = figma.createTextStyle();
// setup externalStyle2 with keys, fontFamilies, etc...

figma._externalStyles = [
  externalStyle1,
  externalStyle2
];

// definition for importByKeyAsync

figma.importByKeyAsync = async function(key: string) {
  const style = this._externalStyles.find(style => style.key === key);
  return style;
}

Another option might be to have some sort of configuration?

createFigma({
  externalStyles: {
    key1: { /* externalStyle1 info */ },
    key2: { /* externalStyle2 info */ }
  }
});

this might be difficult though, since the creation functions wouldn't have been initialized yet

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