Index of every page on this site: llms.txt
All skills
bergside avatar

/figma-plugin

@746501e
by bergsidebergside/design-md-figma160 stars
20
Run it yourself

Use when building Figma plugins, creating design automation tools, implementing sandbox/UI communication, or working with the Figma Plugin API for node manipulation, styles, and components.

Use this Skill: https://skilld.dev/gh/bergside/design-md-figma/figma-plugin

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesui-react-and-theming.md

≈1.4k tokens on demand. Your agent reads this file only when SKILL.md points to it.

React UI and Figma Theming

Using React for plugin UI and Figma's theme color system.

Using React

Setup with Create React App

# Using Figma plugin template
npx degit nicebook/figma-plugin-react-template my-plugin
cd my-plugin
npm install

Manual React Setup

// ui.tsx
import React, { useState, useEffect, useCallback } from 'react';
import { createRoot } from 'react-dom/client';
import './ui.css';

// Types
type Message =
  | { type: 'selection-changed'; count: number }
  | { type: 'node-data'; node: { name: string; type: string } };

function App() {
  const [count, setCount] = useState(0);
  const [name, setName] = useState('');
  const [size, setSize] = useState(100);

  // Listen for messages from main thread
  useEffect(() => {
    const handler = (event: MessageEvent) => {
      const msg = event.data.pluginMessage as Message;
      if (!msg) return;

      if (msg.type === 'selection-changed') {
        setCount(msg.count);
      }
    };

    window.addEventListener('message', handler);
    return () => window.removeEventListener('message', handler);
  }, []);

  // Send message to main thread
  const postMessage = useCallback((message: any) => {
    parent.postMessage({ pluginMessage: message }, '*');
  }, []);

  const handleCreate = () => {
    postMessage({ type: 'create', name, size });
  };

  const handleClose = () => {
    postMessage({ type: 'close' });
  };

  return (
    <div className="container">
      <p className="selection-info">
        {count} items selected
      </p>

      <div className="input-group">
        <label>Name</label>
        <input
          type="text"
          value={name}
          onChange={(e) => setName(e.target.value)}
        />
      </div>

      <div className="input-group">
        <label>Size</label>
        <input
          type="number"
          value={size}
          onChange={(e) => setSize(parseInt(e.target.value, 10))}
        />
      </div>

      <div className="btn-row">
        <button className="btn-secondary" onClick={handleClose}>
          Cancel
        </button>
        <button className="btn-primary" onClick={handleCreate}>
          Create
        </button>
      </div>
    </div>
  );
}

const root = createRoot(document.getElementById('root')!);
root.render(<App />);

Custom Hook for Figma Messages

// hooks/useFigmaMessage.ts
import { useEffect, useCallback } from 'react';

type MessageHandler<T> = (message: T) => void;

export function useFigmaMessage<T>(handler: MessageHandler<T>) {
  useEffect(() => {
    const listener = (event: MessageEvent) => {
      const msg = event.data.pluginMessage;
      if (msg) {
        handler(msg as T);
      }
    };

    window.addEventListener('message', listener);
    return () => window.removeEventListener('message', listener);
  }, [handler]);
}

export function usePostMessage() {
  return useCallback((message: any) => {
    parent.postMessage({ pluginMessage: message }, '*');
  }, []);
}

// Usage
function App() {
  const [data, setData] = useState(null);
  const postMessage = usePostMessage();

  useFigmaMessage((msg) => {
    if (msg.type === 'data') {
      setData(msg.data);
    }
  });

  return (
    <button onClick={() => postMessage({ type: 'fetch-data' })}>
      Fetch Data
    </button>
  );
}

Figma Theme Colors

When themeColors: true, Figma injects CSS variables:

/* Available CSS variables */
:root {
  /* Text */
  --figma-color-text: /* primary text */;
  --figma-color-text-secondary: /* secondary text */;
  --figma-color-text-tertiary: /* tertiary text */;
  --figma-color-text-disabled: /* disabled text */;
  --figma-color-text-onbrand: /* text on brand color */;
  --figma-color-text-onbrand-secondary: /* secondary text on brand */;
  --figma-color-text-danger: /* error text */;
  --figma-color-text-warning: /* warning text */;
  --figma-color-text-success: /* success text */;

  /* Backgrounds */
  --figma-color-bg: /* primary background */;
  --figma-color-bg-secondary: /* secondary background */;
  --figma-color-bg-tertiary: /* tertiary background */;
  --figma-color-bg-brand: /* brand background */;
  --figma-color-bg-brand-hover: /* brand hover */;
  --figma-color-bg-brand-pressed: /* brand pressed */;
  --figma-color-bg-danger: /* danger background */;
  --figma-color-bg-warning: /* warning background */;
  --figma-color-bg-success: /* success background */;
  --figma-color-bg-hover: /* hover state */;
  --figma-color-bg-pressed: /* pressed state */;
  --figma-color-bg-selected: /* selected state */;

  /* Borders */
  --figma-color-border: /* primary border */;
  --figma-color-border-strong: /* strong border */;
  --figma-color-border-brand: /* brand border */;
  --figma-color-border-danger: /* danger border */;

  /* Icons */
  --figma-color-icon: /* primary icon */;
  --figma-color-icon-secondary: /* secondary icon */;
  --figma-color-icon-tertiary: /* tertiary icon */;
  --figma-color-icon-brand: /* brand icon */;
  --figma-color-icon-danger: /* danger icon */;
}

Using Theme Colors

/* Automatically adapts to light/dark mode */
body {
  background: var(--figma-color-bg);
  color: var(--figma-color-text);
}

.card {
  background: var(--figma-color-bg-secondary);
  border: 1px solid var(--figma-color-border);
}

.btn-primary {
  background: var(--figma-color-bg-brand);
  color: var(--figma-color-text-onbrand);
}

.btn-primary:hover {
  background: var(--figma-color-bg-brand-hover);
}

.error {
  color: var(--figma-color-text-danger);
  background: var(--figma-color-bg-danger);
}

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts6mo3 checks · Risk SAFE
  • Gen Agent Trust Hub6mo

    This skill provides a comprehensive set of references and templates for developing Figma plugins. It covers architecture, API usage, UI development, and build processes. No malicious patterns or security risks were identified.

  • Socket6mo

    No alerts

  • Snyk6mo

    Risk: LOW · No issues

Signed by skilld at 746501e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 9 months ago

README badge

README badge for bergside/design-md-figma