⚛️ A React renderer for Figma

Overview

React Figma

React Figma logo by Lera Lesik

npm version CircleCI

A React renderer for Figma. Use React components as a source for your designs.

Example of code:

import * as React from 'react';
import { Page, View, Text } from 'react-figma';

export const App = () => {
    return (
        <Page name="New page" isCurrent>
            <View>
                <View style={{ width: 200, height: 100, backgroundColor: '#dd55aa' }} />
                <Text style={{ color: '#ffffff' }}>text</Text>
            </View>
        </Page>
    );
};

Installation

Using boilerplate

You can use react-figma-boilerplate for creating own projects.

From scratch

Install it with yarn:

yarn add react react-figma

Or with npm:

npm i react react-figma --save

Usage

Configure main thread

import { setupMainThread } from 'react-figma/rpc';

figma.showUI(__html__, { visible: false });

setupMainThread();

Configure ui thread

import * as React from 'react';
import { App } from './App';

import 'react-figma/rpc';
import { render } from 'react-figma';

render(<App />);

Import components

import * as React from 'react';
import { Page, Rectangle, Text } from 'react-figma';

export const App = () => {
    return (
        <Page name="New page">
            <Rectangle style={{ width: 200, height: 100, backgroundColor: '#dd55aa' }} />
            <Text characters="text" style={{ color: '#ffffff' }} />
        </Page>
    );
};

Docs

Examples

Sponsoring

Become a backer and get your logo on our Readme on GitHub with a link to your site.

Become a sponsor and get your logo on our README on Github with a link to your site.

Contributing

Everyone is welcome to contribute. Whether you're helping us implement features, fix bugs or improve the docs, we'd love to have you as part of the community!

How to Contribute

Check out our Contributing Guide for ideas on contributing and setup steps for getting repository up and running on your local machine.

Acknowledgements

React Figma team wishes to thank the following invaluable contributions:

Tested with browserstack

Tested with browserstack

Contributors

Thanks goes to these wonderful people (emoji key):


Ilya Lesik

💻

Losev Yaroslav

💻

Vishnu Singh

💻

corrina

💻

Zachary Witt

💻

Abdelrahman Ashraf

💻

sprashad

📖

Vivian Lee

💻

macintoshhelper

💻

Pierre Grimaud

📖

Greg Westneat

💻

Marius Reimer

💻

szeko

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Comments
  • Structuring design system with react-figma

    Structuring design system with react-figma

    Hi 👋

    I'm currently a figma and react/react-native user. The little startup my friends and I are working on have several UI primitives that we use and compose together to create more complex UI. Currently we're in a situation where

    1. Our figma designs of our components get updated in figma and we have to go and update both our webapp and react-native app with the updates to those components.
    2. Our components are updated in the webapp/react-native app and we have to go update the figma board to keep them in sync.

    This wasn't much of an issue at first when we had 10 -30 components. But as our primitives got larger so did our "molecules" that are composed from primitives and updating all of them in figma and code is starting to become a full on task that is pretty tedious.

    How can we leverage react-figma to mitigate this issue? We're not design or design-system experts by any means but this has been a pain point for us and really would prefer to create a component-library that we would import into our application and have things "just work".

    We also use emotion for styling our webapp and react-native app so we're not quite sure how much of a barrier that is.

    Would love any insight into this 🙏

    opened by kennetpostigo 8
  • Create styled-components primitives example

    Create styled-components primitives example

    Create styled-components examples using the react-primitives package for cross-platform components.

    ~(probably worth waiting for my react-primitives PR to be merged first, to avoid needing to use a fork).~

    ~(prettier fails on CI, but is passing locally, strange)~

    ~And please don't merge before the webpack-config PR is merged.~

    Ready to merge now.

    Related issues

    #194

    opened by macintoshhelper 7
  • Implementing borders style props support

    Implementing borders style props support

    https://react-figma.now.sh/docs/styling.html

    Props:

    • borderColor

    • borderTopColor

    • borderRightColor

    • borderBottomColor

    • borderLeftColor

    • borderWidth

    • borderTopWidth

    • borderRightWidth

    • borderBottomWidth

    • borderLeftWidth

    react-figma already has transformBorderStyleProperties function.

    Can be used Figma API (GeometryMixin):

    strokes: ReadonlyArray<Paint>
    

    and Yoga Layout:

    setBorder(edge: YogaEdge, borderWidth: number): void;
    
    type: feature or enhancement help wanted priority: medium topic: yoga topic: components complexity: medium topic: primitives support 
    opened by ilyalesik 7
  • Aligning with React Native API - proposal

    Aligning with React Native API - proposal

    Hi, just discovered this repo and am excited to see this be developed!

    I was wondering whether it would be possible to tend towards using a React Native style API for the project? e.g. <View> as a generic core component API instead of <Rectangle> or <Circle>, etc. I've found with react-sketchapp that the Svg API acts as a really nice escape hatch for using shape-specific components if you need a <Circle> instead of <View style={{ borderRadius: '50%' }}> for some reason.

    e.g.

    src/svg.js

    const Svg = {
      rect: RectangleRenderer,
      path: PathRenderer,
    };
    

    src/index.js

    export { View, Text, Image };
    
    export { Svg };
    

    Also, regarding components like #20 , I feel that these should live in another library, and that react-figma can provide "internal hooks" to Figma specific components intended for library use.

    e.g.

    npm: react-primitives-shapes

    const { View } from 'react-primitives';
    const { Svg, Path } = require('react-primitives-svg');
    const { shapes } = require('react-figma');
    
    const Rectangle = (props) => <View style={{ display: 'flex' }} {...props} />;
    
    const Star = Platform.OS === 'figma'
      ? shapes.Star 
      : (
        <Svg>
         <Path data="starhere..." />
        </Svg>
      );
    
    module.exports = { Rectangle, Star };
    

    This would help a lot with react-primitives support and with standardising React cross-platform usage to center around a core, shared API, with platform-specific as opt-in components. For me, a lot of the value of this project would be in using existing React Native or React Sketch.app codebases to render design systems/UI libraries to Figma.

    type: feature or enhancement topic: components type: idea topic: primitives support 
    opened by macintoshhelper 6
  • Examples package.json doesn't have dependencies or DevDependencies

    Examples package.json doesn't have dependencies or DevDependencies

    This is the basic example in your examples it has no dependencies nor dev dependencies so whenever i try to yarn install i get nothing plus if i do it manually i get a lot of errors . please add the dependencies.

    opened by oSethoum 5
  • Add missing but necessary step in setup guide

    Add missing but necessary step in setup guide

    Hi, I noticed that there's a missing step in your 'running' guide. Without starting webpack, Figma won't load the plugin.

    Apologies if I've misunderstood. At least for me, I had to run this script before Figma would allow me to open the plugin via Plugins > Development > react-figma-boilerplate.

    opened by yoniholmes 5
  • Support fillStyleId for Frames

    Support fillStyleId for Frames

    Context

    For my use case, we're extending off of this PR which allowed Components to take in a style prop.

    We want to leverage the new useXStyle hooks in order to:

    • Create a new Color Style
    • Apply the new Color style to a given component

    This works fine for Views, but I noticed that this didn't work for Components.

    Debugging

    When digging deeper, I found out that this mixin is the problem. This mixin carries over the background prop from the component. Since it comes after geometryMixin (which is where the fillStyleId is initially carried over), I believe this background is taking precedence and fillStyleId is being ignored.

    The fix(es)

    As a fix, I'm just adding fillStyleId to also be carried over.

    Another alternative could be to just change the order of the mixins, but that feels a bit fragile.

    Testing

    I rendered a Component that took in useFillPaintStyle, and saw that its fill color was linked to the Color Styles on the file:

    Screen Shot 2021-12-16 at 3 54 45 PM

    opened by kahyoung 4
  • Using useTextStyle cause font load issues

    Using useTextStyle cause font load issues

    Hello,

    Thanks for the great job done on that project.

    I'm actually experiencing a strange issue when using useTextStyle hook. For the same style the one that do not use the local style stored on Figma with the hook work as expected (using the correct font weight). The one with the hook fail with the following error in the console:

    rpc.js:136 Uncaught (in promise) Error: in set_fontName: Cannot use unloaded font "SF Pro Display SemiBold". Please call figma.loadFontAsync({ family: "SF Pro Display", style: "SemiBold" }) and await the returned promise first.
        at callback (<anonymous>:859:25)
        at handleRpc (<anonymous>:800:7)
        at handleRaw (<anonymous>:774:5)
        at onmessage (<anonymous>:733:24)
    

    Here the minimal example:

    import React from 'react';
    import { Frame, Page, StyleSheet, Text, useTextStyle } from 'react-figma';
    import { FRAME_PRESETS } from 'react-figma/components/frame/Frame';
    
    const style = StyleSheet.create({
      text: {
        fontFamily: 'SF Pro Display',
        fontSize: 20,
        fontWeight: '600',
      },
    });
    
    export default function FigmaApp() {
      const textStyle = useTextStyle(style.text, { name: 'header/h1' });
    
      return (
        <Page isCurrent name="Styleguide" style={{ flexDirection: 'row' }}>
          <Frame
            name="Typography"
            preset={FRAME_PRESETS.a4}
            style={{
              backgroundColor: 'white',
              marginRight: 48,
            }}
          >
            <Text style={style.text}>
              SF Pro Display without using local styles (and textStyleId)
            </Text>
            <Text style={textStyle}>
              SF Pro Display using local styles (and textStyleId)
            </Text>
          </Frame>
        </Page>
      );
    }
    
    
    Capture d’écran 2021-07-19 à 21 37 09

    When I remove the generated textStyleId key things works again ;-/ FYI all works as expected with Roboto. And I'm on Mac and have SF Pro Display and all his variants correctly installed.

    Thanks for the help, 🙏

    Edit 1: fontWeight: 700 (Bold) works well in both cases, it seems related to font variant naming Semibold on Figma, trying and failing to load SemiBold on the console

    type: bug priority: medium 
    opened by momsse 4
  • Is react-figma suitable for web only cases?

    Is react-figma suitable for web only cases?

    I can't find anything in the docs about using react-figma with simple HTML tags. Is there any way to use it without <View>, <Text>, e.g.? It would be really nice to use it with component libraries like react-bootstrap which are built upon <div>s, <span>s, etc.

    question 
    opened by Wyctus 4
  • Remove constraints from group

    Remove constraints from group

    Rendering a Group (regardless of its props) would throw an error:

    Cannot add property constraints, object is not extensible
    

    Looks like constraints aren't supported on GroupNode so this removes the constraintsMixin from the group renderer and constraints from the Group props type.

    opened by szeko 4
  • fix: site dark mode images

    fix: site dark mode images

    This changes the navbar logo and three feature images to white when dark mode is toggled. Also fixed img-alt not being displayed correctly and bumped deps.

    Closes #258.

    opened by reime005 4
  • 📦 NEW: Add strict variables in tsconfig

    📦 NEW: Add strict variables in tsconfig

    Hello, this PR is solving Issue #128. In this PR, I added different strict mode variables like: ✅ noImplicitAny ✅ noImplicitThis ✅ strictNullChecks ✅ strictPropertyInitialization ✅ alwaysStrict

    opened by meerhamzadev 4
  • What's the purpose of this project?

    What's the purpose of this project?

    It's really impressive what this project can do but what's the initial problem it solves? I'd want to use the project but I don't really see any use cases for it.

    It would be useful to mention that on the website and in the project description in the first paragraph.

    There's a "getting started" page but no page "why would you get started at all?".

    opened by ulitiy 7
  • Is it possible and how to work with instances of component sets?

    Is it possible and how to work with instances of component sets?

    The documentation describes how to work with component instances, but it seems that it does not account for components with variants (aka. component sets).

    Is there a way to get an instance of a component set?

    type: feature or enhancement 
    opened by ervasive 1
  • Add examples with a plugin UI

    Add examples with a plugin UI

    I want to control the state of my Figma canvas via the plugin UI, but can't figure out how. Now all the examples appear to be "headless", even the interactive example:

    figma.showUI(__html__, { visible: false });

    type: feature or enhancement topic: examples Hacktoberfest 
    opened by gengwang 1
Releases(v0.24.0)
  • v0.24.0(Mar 9, 2022)

    An example:

    <Page name="New page" style={{ backgroundColor: '#ff0000' }}>
        <View>
            <View style={{ width: 200, height: 100, backgroundColor: '#ffffff' }} />
        </View>
    </Page>
    
    Source code(tar.gz)
    Source code(zip)
  • v0.23.0(Mar 9, 2022)

    Add useStyleByKey hook which allows one to pass in specific textStyleId, fillStyleId, etc.

            const ViewComponent = () => {
                const fillStyle = useStyleByKey('testStyleId');
                return (
                    <View
                        style={{
                            fillStyleId: fillStyle && fillStyle.id
                        }}
                    />
                );
            };
            const TextComponent = () => {
                const textStyle = useStyleByKey('testStyleId');
                return (
                    <Text
                        style={{
                            textStyleId: textStyle && textStyle.id
                        }}
                    />
                );
            };
    
    Source code(tar.gz)
    Source code(zip)
  • v0.22.0(Feb 19, 2022)

    Added useEffectStyle new props

    | Args | Type | Default | Note | | ---------- | -------- | ------- | ------------------------------------------------- | | style.blurType | LAYER_BLUR or BACKGROUND_BLUR | LAYER_BLUR | Type of blur effect | | style.blurRadius | number | 0 | Blur radius. Must be >= 0 |

    Source code(tar.gz)
    Source code(zip)
  • v0.21.0(Feb 17, 2022)

    The useEffectStyle hook creates (or updates) EffectStyle and returns an object that contains effectStyleId and can be consumed in style prop.

    | Args | Type | Default | Note | | ---------- | -------- | ------- | ------------------------------------------------- | | style | Style Object | | The style will applied to a local style | | style.shadowType | DROP_SHADOW or INNER_SHADOW | DROP_SHADOW | Type of shadow effect | | style.shadowSpread | number | 0 | Shadow expansion distance | | params | Object | | | | params.id | String | | A style id | | params.name | String | | A style name | | params.description | String | | A style description |

    Source code(tar.gz)
    Source code(zip)
  • v0.17.0(Jul 11, 2021)

    • Text component got hyperlink prop supporting.
    • All components over Figma Nodes go onNodeId callback supporting. onNodeId returns Figma Node ID.

    An example:

    <View>                                                                                 
        <Text                                                                              
            style={{ color: '#308eff', marginBottom: 50 }}                                 
            hyperlink={{                                                                   
                type: 'URL',                                                               
                value: 'https://react-figma.dev/'                                          
            }}>                                                                            
            React Figma website                                                            
        </Text>                                                                            
        {nodeId && (                                                                       
            <Text                                                                          
                style={{ color: '#308eff', marginBottom: 50 }}                             
                hyperlink={{                                                               
                    type: 'NODE',                                                          
                    value: nodeId                                                          
                }}>                                                                        
                Rectangle link                                                             
            </Text>                                                                        
        )}                                                                                 
        <View onNodeId={setNodeId}>                                                        
            <View style={{ width: 200, height: 100, backgroundColor: '#dd55aa' }} />       
        </View>                                                                            
    </View>                                                                                
    
    Source code(tar.gz)
    Source code(zip)
  • v0.16.0(May 29, 2021)

    Example:

    
    <View
      style={{
        shadows: [{
          shadowColor: 'rgba(0, 0, 0, 0.2)', shadowRadius: 1
        }, {
          shadowColor: 'rgba(0, 0, 0, 0.3)', shadowRadius: 2 
        }]
      }}
    />
    
    Source code(tar.gz)
    Source code(zip)
  • v0.15.0(May 28, 2021)

  • v0.14.0(May 17, 2021)

    Component and ComponentSet got publishable props supporting:

    | Prop | Type | Default | Note | | ---------- | -------- | ------- | ------------------------------------------------- | | description | String | '' | The annotation entered by the user for this component | | documentationLinks | ReadonlyArray<DocumentationLink> | [] | The documentation links for this component |

    Introduced in the Figma API Version 1, Update 23

    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Mar 13, 2021)

  • v0.10.0(Mar 7, 2021)

  • v0.8.0(Mar 1, 2021)

  • v0.7.0(Feb 23, 2021)

  • v0.6.0(Feb 16, 2021)

    Demo:

    Code example:

    import * as React from 'react';
    import { Page, View, Text, StyleSheet, useFillPaintStyle, useStrokePaintStyle, useTextStyle } from 'react-figma';
    
    const styles = StyleSheet.create({
        root: {
            backgroundColor: '#76ff1c',
            borderColor: '#ffffff',
            borderWidth: 5
        },
        heading: {
            fontFamily: 'Roboto',
            fontWeight: 'bold',
            fontSize: 24,
            color: '#000000'
        }
    });
    
    export const App = () => {
        const rootFillStyle = useFillPaintStyle(styles.root, {
            name: 'root/background'
        });
    
        const rootStrokeStyle = useStrokePaintStyle(styles.root, {
            name: 'root/border'
        });
    
        const headingTextStyle = useTextStyle(styles.heading, {
            name: 'heading'
        });
    
        return (
            <Page name="New page" isCurrent>
                <View>
                    <View style={{ width: 200, height: 100, ...styles.root, ...rootFillStyle, ...rootStrokeStyle }} />
                    <Text style={{ ...headingTextStyle }}>Local styles</Text>
                </View>
            </Page>
        );
    };                                                                                    
    
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Jan 7, 2021)

  • v0.4.0(Jan 6, 2021)

    The doc

    It's possible to enable a CSS-like inheritance.

    Available under the flag process.env.REACT_FIGMA_STYLE_INHERITANCE_ENABLED.

    An example:

    <View style={{ fontSize: 50, fontWeight: 'bold', fontFamily: 'Roboto' }}>
        <View style={{ fontSize: 48 }}>
            <View style={{ width: 200, height: 100, backgroundColor: '#dd55aa' }} />
            <Text style={{ color: '#ffffff' }}>text</Text>
        </View>
    </View>
    

    The text got a combined style:

    ({fontWeight: 'bold', fontFamily: 'Roboto', fontSize: 48, color: '#ffffff' })
    
    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Jan 5, 2021)

  • v0.3.1(Dec 21, 2020)

  • v0.3.0(Dec 20, 2020)

  • v0.2.0(Dec 10, 2020)

  • v0.1.16(Oct 29, 2020)

    Added a new component: ComponentSet. It allows defining component variants.

    Example of usage:

    <ComponentSet name="Button">
        <Component name="variant=Primary">
            <PrimaryButton text="Primary" />
        </Component>
        <Component name="variant=Dangerous">
            <DangerousButton text="Dangerous" />
        </Component>
        <Component name="variant=Secondary">
            <SecondaryButton text="Secondary" />
        </Component>
    </ComponentSet>
    
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(May 20, 2020)

    Architecture has changed: react-reconciler works on Figma UI thread right now.

    Launching API also changed corresponding to architectural change:

    main thread entry point:

    import { setupMainThread } from 'react-figma/rpc';
    
    figma.showUI(__html__, { visible: false });
    
    setupMainThread();
    

    ui thread entry point:

    import * as React from 'react';
    import { App } from './App';
    
    import 'react-figma/rpc';
    import { render } from 'react-figma';
    
    render(<App />);
    

    It's was needed for many reasons:

    • Impossibility of HMR implementing.
    • fetch function supporting.
    • Yoga Layout and image loading perfomance.
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1-alpha.4(Sep 10, 2019)

    Changes:

    • Renderer rewritten with react-reconciler.
    • Hydration support was implemented. Renderer tries to update existing nodes after restarting.
    • Component component was added. Example
    <Component name="SizingXSmall" {...componentStyles}>
      <Rectangle style={{ width: 8, height: 8, ...sizingStyles }} />
    </Component>
    
    • CurrentPage component was removed.
    • renderer function was renamed to render.
    Source code(tar.gz)
    Source code(zip)
Owner
React Figma
A React renderer for Figma
React Figma
React JSX Renderer is a React Component for rendering JSX to React nodes.

React JSX Renderer A React Component for Rendering JSX. Description React JSX Renderer is a React Component for rendering JSX to React nodes.

Sho Kusano 43 Nov 28, 2022
🇨🇭 A React renderer for Three.js (web and react-native)

react-three-fiber react-three-fiber is a React renderer for threejs on the web and react-native. npm install three react-three-fiber These demos are r

Poimandres 20.9k Jan 8, 2023
🇨🇭 A React renderer for Three.js (web and react-native)

react-three-fiber react-three-fiber is a React renderer for threejs on the web and react-native. npm install three react-three-fiber These demos are r

Poimandres 20.9k Jan 8, 2023
[ Unmaintained due to raphamorim/react-ape ] React Renderer for low memory applications

React-TV · react-tv: React Renderer for low memory applications. react-tv-cli: React Packager for TVs. Currently under development. import React from

Raphael Amorim 2k Jan 6, 2023
⃝ A react null renderer

Nothing to see here ... Quite so. This package allows you to bring Reacts high-level component abstraction to Node, or wherever you need it. Why not m

Poimandres 653 Dec 23, 2022
A React renderer for Hardware.

React Hardware React Hardware enables you to build firmata-based hardware applications using a consistent developer experience based on JavaScript and

Dustan Kasten 794 Dec 26, 2022
A react renderer for browser's dev console

Konsul is an abstraction of the browser's console that comes with a React renderer. It offers text styling, images, style inheritance, buttons with cl

Mohamad Mohebifar 614 Dec 13, 2022
React custom renderer for Appcelerator® Titanium™ SDK

⚠️ Maintainer wanted! Create an issue if you want to maintain it! react-titanium A React custom renderer for Appcelerator® Titanium™ SDK. This rendere

Pier Paolo Ramon 107 Nov 21, 2022
React renderer for NativeScript

React NativeScript is A React renderer for NativeScript, allowing you to write a NativeScript app using the familiar React style. I'm always hanging o

Jamie Birch 266 Dec 17, 2022
A react renderer for blessed.

react-blessed A React custom renderer for the blessed library. This renderer should currently be considered as experimental, is subject to change and

Guillaume Plique 4.3k Jan 1, 2023
a react renderer for the command line

This repository is now archived This project was originally created as an alternative to the Ink library, as a separate renderer for a real React comp

Mike Grip 46 Jul 15, 2022
🦍• [Work in Progress] React Renderer to build UI interfaces using canvas/WebGL

React Ape React Ape is a react renderer to build UI interfaces using canvas/WebGL. React Ape was built to be an optional React-TV renderer. It's mainl

Raphael Amorim 1.5k Dec 18, 2022
📟 A React Renderer for SSD1306 OLED chip on Raspberry Pi.

React SSD1306 A React Renderer for SSD1306 OLED chip on Raspberry Pi For those who doesn't have the device, a canvas-based web emulator is also includ

Yifeng Wang 341 Jan 3, 2023
React renderer with X11 as a target

react-x11 React custom rendering where side effects are communication with X11 server. The goal is to create a simple library where you would apply yo

Andrey Sidorov 231 Nov 12, 2022
A custom Slack renderer for React! 3

react-slack-renderer Render Slack messages in a cool (React) way. const message = SlackRenderer.render( <SlackMessage> <SlackText> Heyo

Andrey 31 Aug 11, 2022
React renderer for building user interfaces in Unity UI

React Unity React Unity is a way to build interactive UI in Unity3D using React. It can be used together with packages like Typescript, redux, i18next

React Unity 493 Dec 30, 2022
🦴 A barebones react renderer for ogl.

react-ogl Declaratively create scenes with re-usable OGL components that have their own state and effects and can tap into React's infinite ecosystem.

Poimandres 116 Dec 1, 2022
React Fiber Reconciler Renderer for Regl WebGL

react-regl This library enables Regl shader WebGL draw commands to be rendered directly as React components. Demos View demos in the Storybook There i

kev zettler 191 Dec 20, 2022
Connect, discover, be free to choose between WebGL / Canvas (PIXI) / DOM or any other UI renderer

React Liberty Be free to choose between WebGL / Canvas / DOM / Native or any other UI renderer This is a React library designed to abstract renderer b

LibertyGlobal 35 Oct 7, 2022