Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Official Figma skill for writing directly to the Figma canvas through the MCP server and Plugin API.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
effect-style-patterns.md
1# Effect Style API Patterns23> Part of the [use_figma skill](../SKILL.md). How to create, apply, and inspect effect styles using the Plugin API.4>5> For design system context (effect types, variable bindings on effects, gotchas), see [wwds-effect-styles](working-with-design-systems/wwds-effect-styles.md).67## Contents89- Listing Effect Styles10- Creating a Drop Shadow Style11- Importing Library Effect Styles12- Applying Effect Styles to Nodes1314## Listing Effect Styles1516```javascript17/**18* Lists all local effect styles.19*20* @returns {Promise<Array<{id: string, name: string, key: string, effectCount: number}>>}21*/22async function listEffectStyles() {23const styles = await figma.getLocalEffectStylesAsync();24return styles.map(s => ({25id: s.id,26name: s.name,27key: s.key,28effectCount: s.effects.length29}));30}31```3233Full runnable script:3435```javascript36const results = await listEffectStyles();37return results;38```3940## Creating a Drop Shadow Style4142Colors are **RGBA 0–1 range**. `effects` is a read-only array — always reassign, never mutate in place.4344```javascript45/**46* Creates a drop shadow effect style.47*48* @param {string} name - e.g. "Elevation/200"49* @param {{ r: number, g: number, b: number, a: number }} color - RGBA, 0-1 range50* @param {{ x: number, y: number }} offset51* @param {number} radius - blur radius52* @param {number} [spread=0]53* @returns {EffectStyle}54*/55function createDropShadowStyle(name, color, offset, radius, spread) {56const style = figma.createEffectStyle();57style.name = name;58style.effects = [{59type: "DROP_SHADOW",60color,61offset,62radius,63spread: spread || 0,64visible: true,65blendMode: "NORMAL"66}];67return style;68}69```7071Full runnable script:7273```javascript74const style = createDropShadowStyle(75"Elevation/200",76{ r: 0, g: 0, b: 0, a: 0.15 },77{ x: 0, y: 4 },7812,79080);81return { id: style.id, name: style.name };82```8384## Importing Library Effect Styles8586For effect styles from **team libraries**, use `importStyleByKeyAsync`:8788```javascript89// Import a library effect style by key90const shadowStyle = await figma.importStyleByKeyAsync("EFFECT_STYLE_KEY");91// Apply to a node92node.effectStyleId = shadowStyle.id;93```9495`search_design_system` with `includeStyles: true` returns style keys you can import this way. Prefer importing library styles over creating new ones.9697## Applying Effect Styles to Nodes9899```javascript100/**101* Applies an effect style to all nodes on the current page that match a given name pattern.102*103* @param {string} styleId - The ID of an EffectStyle.104* @param {string} nodeNamePattern - Substring match against node names.105* @returns {number} - Number of nodes the style was applied to.106*/107function applyEffectStyleToMatchingNodes(styleId, nodeNamePattern) {108const nodes = figma.currentPage.findAll(n => n.name.includes(nodeNamePattern));109let applied = 0;110for (const node of nodes) {111if ('effectStyleId' in node) {112node.effectStyleId = styleId;113applied++;114}115}116return applied;117}118```119120Full runnable script:121122```javascript123const applied = applyEffectStyleToMatchingNodes('STYLE_ID', 'Card');124return { applied };125```126