Giter Club home page Giter Club logo

react-figma's Introduction

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

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
Ilya Lesik

💻
Losev Yaroslav
Losev Yaroslav

💻
Vishnu Singh
Vishnu Singh

💻
corrina
corrina

💻
Zachary Witt
Zachary Witt

💻
Abdelrahman Ashraf
Abdelrahman Ashraf

💻
sprashad
sprashad

📖
Vivian Lee
Vivian Lee

💻
macintoshhelper
macintoshhelper

💻
Pierre Grimaud
Pierre Grimaud

📖
Greg Westneat
Greg Westneat

💻
Marius Reimer
Marius Reimer

💻
szeko
szeko

💻
Jonathan Holmes
Jonathan Holmes

📖
不吃猫的鱼
不吃猫的鱼

💻
Darío Hereñú
Darío Hereñú

📖
Konstantin Popov
Konstantin Popov

📖
Utkarsh Singh
Utkarsh Singh

📖
mrkenneh
mrkenneh

💻
Anna Do
Anna Do

💻
Steven Petryk
Steven Petryk

💻
Thierry Charbonnel
Thierry Charbonnel

📖
Jack Oliver
Jack Oliver

📖
Marc Abramowitz
Marc Abramowitz

📖
fishtriangle
fishtriangle

💻
Carlos
Carlos

📖

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

react-figma's People

Contributors

allcontributors[bot] avatar annuhdo avatar carlostpg avatar corrinachow avatar dependabot[bot] avatar fishtriangle avatar headwindz avatar hvish avatar ilyalesik avatar jackoliver avatar kahyoung-zz avatar kant avatar konsthardy avatar leggomuhgreggo avatar losyear avatar macintoshhelper avatar msabramo avatar pgrimaud avatar reime005 avatar stevenpetryk avatar szeko avatar theashraf avatar thierryc avatar utkarsh299-tech avatar wyvl avatar yoniholmes avatar zqwitt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-figma's Issues

Documenting compatibility with Figma API

Table with compatibility information needed. Example:

Feature react-figma Figma API
Creating Rectangle ✅Rectangle component ✅createRectangle function
Rectangle radius support 🚫  ✅Rectangle node attributes: topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius

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.

Adopt yoga-layout for using from main-thread

Now yoga-layout worked at ui-thread, because trying to use yoga-layout at main-thread throws realm error. Main-thread and ui-thread communicate through async messages. It complicates the code.

Code behaving weirdly

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

// import { data } from './Helper/data';

const frameProps = {
    style: { paddingTop: 10, paddingBottom: 10, paddingLeft: 10, paddingRight: 10 }
};

const RenderData = () => {
    return (
        <Frame name="Column" {...frameProps}>
            <Text characters={'Space'} fontSize={14} />
        </Frame>
    );
};

export const App = () => {
    return (
        <Page name="New page">
            <RenderData />
        </Page>
    );
};

OutPut

Screenshot 2019-10-09 at 10 25 55 AM

I add fontSize 14 but its not showing 14 as you can font is too big,
And what's this error, is my code wrong here.

Documenting style propeties

Groups:

  • Geometry styles (background etc.)
  • layout style properties
    • child properties (margin, width, etc.)
    • parent properties (padding, flexDirection, etc.)
  • text style properties (color, etc.)

Implementing rectangle radius support

Figma API:

  topLeftRadius: number
  topRightRadius: number
  bottomLeftRadius: number
  bottomRightRadius: number

Also, style support needed:

borderRadius: number
borderBottomLeftRadius: number
borderBottomRightRadius: number
borderTopLeftRadius: number
borderTopRightRadius: number

Text children

Hi, it would be great to be able to use <Text> with children instead of having the characters prop.

I've implemented a basic form of this using react-reconciler in my react-xd project, maybe the code there may be of help:

https://github.com/macintoshhelper/react-xd/blob/master/src/renderer.js#L55

I think the main parts are:

  shouldSetTextContent: (type, props) => {
    return (
      typeof props.children === 'string' ||
      typeof props.children === 'number'
    );
  },

and

  createTextInstance: (
    text,
    rootContainerInstance,
    hostContext,
    internalInstanceHandle
  ) => {
    return createInstance(
      { type: 'text', props: { children: text } },
      rootContainerInstance
    );
    // return document.createTextNode(text);
  },

More work may be required to support nesting with text ranges (#32) though, React Native's reconciler may have some context on that.

Creating Group component

Figma API:

group(nodes: ReadonlyArray<BaseNode>, parent: BaseNode & ChildrenMixin, index?: number): FrameNode

Implementing ranges for text

Figma API:

  getRangeFontSize(start: number, end: number): number | symbol
  setRangeFontSize(start: number, end: number, value: number): void
  getRangeFontName(start: number, end: number): FontName | symbol
  setRangeFontName(start: number, end: number, value: FontName): void
  getRangeTextCase(start: number, end: number): TextCase | symbol
  setRangeTextCase(start: number, end: number, value: TextCase): void
  getRangeTextDecoration(start: number, end: number): TextDecoration | symbol
  setRangeTextDecoration(start: number, end: number, value: TextDecoration): void
  getRangeLetterSpacing(start: number, end: number): LetterSpacing | symbol
  setRangeLetterSpacing(start: number, end: number, value: LetterSpacing): void
  getRangeLineHeight(start: number, end: number): LineHeight | symbol
  setRangeLineHeight(start: number, end: number, value: LineHeight): void
  getRangeFills(start: number, end: number): Paint[] | symbol
  setRangeFills(start: number, end: number, value: Paint[]): void
  getRangeTextStyleId(start: number, end: number): string | symbol
  setRangeTextStyleId(start: number, end: number, value: string): void
  getRangeFillStyleId(start: number, end: number): string | symbol
  setRangeFillStyleId(start: number, end: number, value: string): void

Implementing all yoga-layout properties

Yoga properties:

  setAlignContent(alignContent: Yoga$Align): void,
  setAlignItems(alignItems: Yoga$Align): void,
  setAlignSelf(alignSelf: Yoga$Align): void,
  setAspectRatio(aspectRatio: number): void,
  setBorder(edge: Yoga$Edge, borderWidth: number): void,
  setDisplay(display: Yoga$Display): void,
  setFlex(flex: number): void,
  setFlexBasis(flexBasis: number | string): void,
  setFlexBasisPercent(flexBasis: number): void,
  setFlexDirection(flexDirection: Yoga$FlexDirection): void,
  setFlexGrow(flexGrow: number): void,
  setFlexShrink(flexShrink: number): void,
  setFlexWrap(flexWrap: Yoga$FlexWrap): void,
  setHeight(height: number | string): void,
  setHeightAuto(): void,
  setHeightPercent(height: number): void,
  setJustifyContent(justifyContent: Yoga$JustifyContent): void,
  setMargin(edge: Yoga$Edge, margin: number): void,
  setMarginAuto(edge: Yoga$Edge): void,
  setMarginPercent(edge: Yoga$Edge, margin: number): void,
  setMaxHeight(maxHeight: number | string): void,
  setMaxHeightPercent(maxHeight: number): void,
  setMaxWidth(maxWidth: number | string): void,
  setMaxWidthPercent(maxWidth: number): void,
  setMeasureFunc(measureFunc: ?Function): void,
  setMinHeight(minHeight: number | string): void,
  setMinHeightPercent(minHeight: number): void,
  setMinWidth(minWidth: number | string): void,
  setMinWidthPercent(minWidth: number): void,
  setOverflow(overflow: Yoga$Overflow): void,
  setPadding(edge: Yoga$Edge, padding: number | string): void,
  setPaddingPercent(edge: Yoga$Edge, padding: number): void,
  setPosition(edge: Yoga$Edge, position: number | string): void,
  setPositionPercent(edge: Yoga$Edge, position: number): void,
  setPositionType(positionType: Yoga$PositionType): void,
  setWidth(width: number | string): void,
  setWidthAuto(): void,
  setWidthPercent(width: number): void,

Clarify yoga layout api

After last updates YogaContextProvider used at design system example.

Two ways:

  1. Make YogaContextProvider part of public api.
  2. Hide YogaContextProvider inside renderer.

Plugin stuck in figma

I just clone this repo, and load the plugin in figma, but its not rendering anything, it stuck at Running react-figma-bilerplate toast message
Screenshot 2019-10-06 at 5 03 36 PM

Implementing blendMixin

Figma API:

interface BlendMixin {
  opacity: number
  blendMode: BlendMode
  isMask: boolean
  effects: ReadonlyArray<Effect>
  effectStyleId: string
}

Also

style={{opacity: ...}}

support needed

Implementing presets for Frame component

Preset should set default width, height, and name.

As an example,

<Frame preset={FRAME_PRESETS.iPhoneX} />

equal to

<Frame name="iPhone X" width={375} height={812} />

The package should export FRAME_PRESETS variable, that contains all of presets available at Figma. It is proposed to use CamelCase for FRAME_PRESETS keys naming.

List of presets available at Figma:

Phone

  • iPhone X 375x812
  • iPhone 8 Plus 414x736
  • iPhone 8 375x667
  • iPhone SE 320x568
  • Google Pixel 2 411x731
  • Google Pixel 2 XL 411x823
  • Android 360x640

Tablet

  • iPad Mini / 9.7 768x974
  • iPad Pro 10.5 834x1112
  • iPad Pro 12.9 1024x1366
  • Surface Pro 3 1440x990
  • Surface Pro 4 1368x912

Desktop

  • Desktop 1440 x 1024
  • Macbook 1152x700
  • Macbook Pro 1440x900
  • Surface Book 1500x1000
  • iMac 1280x720

Watch

  • Apple Watch 42mm 156x195
  • Apple Watch 38mm 136x170

Paper

  • A4 595x842
  • A5 420x595
  • A6 297x420
  • Letter 612x792
  • Tabloid 792x1224

Social Media

  • Twitter Post 1012 x 506
  • Twitter Header 1500 x 500
  • Facebook Post 1200x630
  • Facebook Cover 820x312
  • Instagram Post 1080x1080
  • Instagram Story 1080x1920
  • Dribbble Shot 400x300
  • Dribbble Shot HD 800x600
  • LinkedIn Cover 1584x396

Implementing exportMixin

Figma API:

interface ExportMixin {
  exportSettings: ExportSettings[]
  exportAsync(settings?: ExportSettings): Promise<Uint8Array> // Defaults to PNG format
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.