56

React Figma - a custom React renderer to Figma

 4 years ago
source link: https://github.com/react-figma/react-figma
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

React Figma

jAJnEfn.png!web

Render React components to Figma.

eAJ7v2a.gif

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>
    );
};

:warning: Warning!️ Project is not production ready and currently at alpha version. API can be changed.

Installation

Using boilerplate

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

From scratch

Install it with yarn:

yarn add react react-figma yoga-layout-prebuilt

Or with npm:

npm i react react-figma yoga-layout-prebuilt --save

Usage

Configure main thread

import * as React from 'react';
import { render, subscribeOnMessages } from 'react-figma';
import { App } from './App';

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

figma.ui.onmessage = message => {
    subscribeOnMessages(message);
};

render(<App />, figma.root);

Configure ui thread

import * as yoga from 'yoga-layout-prebuilt';
import { uiWorker } from 'react-figma';

onmessage = event => {
    uiWorker({ yoga })(event);
};

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

Become a Contributor

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:

Contributors :sparkles:

Thanks goes to these wonderful people ( emoji key ):

JRJ77zU.jpg!webIlya Lesik
:computer: ZjmMvqM.png!webLosev Yaroslav
:computer: beem63J.png!webVishnu Singh
:computer: FJrm22Y.png!webcorrina
:computer: eANBzae.png!webZachary Witt
:computer: yi6fAfz.jpg!webAbdelrahman Ashraf
:computer: IBRRZ3y.png!websprashad
:book:

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK