18.4.7 • Published 2 years ago

figma-paperclip v18.4.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

figma-paperclip allows you to import Figma designs in React code.

Resources

Getting started

To get started, you'll need to install the CLI tool - go ahead and run:

npm install figmark -g

cd to your project directory, then run:

figmark init

This will prompt you for a few things, starting with your Figma personal access key. Here's how you generate one:

alt figma design

Next you'll need to set your team ID. Herre's how you find that (it's in the URL):

alt figma design

Finally you can download your Figma designs:

figmark pull

☝🏻Run this command whenever you want to update your designs locally.

You'll also notice *.pc files which React files are compiled from. To learn more about how to use PC files, you can check out the Paperclip repository.

That's it! At this point you should have generated React files that you can import.

React example

Here's a quick demo of how designs are used in code. Starting off with a few button variations:

alt figma design

After pulling these designs using figmark pull, we can import them like so:

/*
  These are the designs imported from Figma. Each layer is exported as 
  an individual component that corresponds with the layer name. This 
  "slicing up" allows us to add responsive CSS styles to each individual layer.
*/

import {
  // This is the main button
  ButtonPrimary,

  // This is a child of ButtonPrimary -- we know that
  // because ButtonPrimary_ is the prefix.
  ButtonPrimary_Label3,

  // Another child of ButtonPrimary
  ButtonPrimary_Background3,

  // All classnames that correspond with each layer
  classNames,
} from "./design-generated/test/figmark-2";

import * as React from "react";
import * as cx from "classnames";
import styled from "styled-components";

// We can easily add responsiveness to our designs like so
const ResponsiveButton = styled(ButtonPrimary)`
  cursor: pointer;
  display: block;
  display: flex;
  .${classNames.buttonPrimary_background3} {
    padding: 8px 10px;
  }
  .${classNames.buttonPrimary_label3} {
    font-family: Helvetica;
  }
`;

type EnhancedButtonProps = {
  disabled?: boolean;
  primary?: boolean;
  secondary?: boolean;
  children?: React.ReactNode;
};

const EnhancedButton = ({
  disabled,
  secondary,
  children,
}: EnhancedButtonProps) => (
  <ResponsiveButton
    className={cx({
      [classNames.buttonDisabled]: disabled,
      [classNames.buttonSecondary]: secondary,
    })}
  >
    <ButtonPrimary_Background3>
      <ButtonPrimary_Label3>{children}</ButtonPrimary_Label3>
    </ButtonPrimary_Background3>
  </ResponsiveButton>
);

export const ButtonsPreview = () => {
  return (
    <>
      <EnhancedButton>Primary</EnhancedButton>
      <EnhancedButton secondary>Secondary</EnhancedButton>
      <EnhancedButton disabled>Disabled</EnhancedButton>
      <EnhancedButton disabled secondary>
        Disabled Secondary
      </EnhancedButton>
    </>
  );
};

Here's what the code above looks like when loaded in a browser:

alt figma design

For documentation on how to use these designs in Webpack, check out the Paperclip repository.

That's all there is to it! 🙌

Recommendations & Notes

  • You should GIT-ignore generated design files -- treat them like dependencies.
  • Unused layers are dropped from your application bundle if you're using tree-shaking.
  • *.pc file documentation can be found in the Paperclip repository
  • You can preview *.pc files directly using the VS Code extension
18.4.7

2 years ago

18.4.6

2 years ago

18.4.5

2 years ago

18.4.4

2 years ago

18.4.3

2 years ago

18.4.2

2 years ago

18.4.1

2 years ago

18.4.0

2 years ago

18.0.3

2 years ago

18.0.2

2 years ago

18.3.8

2 years ago

18.1.6

2 years ago

18.1.4

2 years ago

18.1.3

2 years ago

18.1.2

2 years ago

18.1.0

2 years ago

17.14.21

2 years ago

17.14.19

3 years ago

17.14.14

3 years ago

17.14.3

3 years ago

17.12.0

3 years ago

17.9.17

3 years ago

17.9.14

3 years ago

17.9.16

3 years ago

17.9.13

3 years ago

17.9.11

3 years ago

17.9.12

3 years ago

17.9.9

3 years ago

17.9.10

3 years ago

17.9.8

3 years ago

17.9.7

3 years ago

17.4.10

3 years ago

17.4.7

3 years ago

17.4.1

3 years ago

17.4.4

3 years ago

17.3.8

3 years ago

17.3.7

3 years ago

1.0.5

3 years ago

17.3.4

3 years ago

17.3.3

3 years ago

17.1.12

3 years ago

17.1.15

3 years ago

17.1.2

3 years ago

17.0.3

3 years ago

17.0.0

3 years ago

16.0.0

3 years ago

15.0.21

4 years ago

15.0.16

4 years ago

15.0.15

4 years ago

15.0.14

4 years ago

15.0.10

4 years ago

15.0.0

4 years ago

14.1.16

4 years ago

14.1.15

4 years ago

14.1.12

4 years ago

14.1.11

4 years ago

14.1.0

4 years ago

14.0.27

4 years ago

14.0.22

4 years ago

14.0.21

4 years ago

14.0.19

4 years ago

14.0.17

4 years ago

14.0.16

4 years ago

14.0.15

4 years ago

14.0.13

4 years ago

14.0.12

4 years ago

14.0.11

4 years ago

14.0.9

4 years ago

14.0.0

4 years ago

13.0.6

4 years ago

13.0.5

4 years ago

13.0.0

4 years ago

12.1.4

4 years ago

12.1.2

4 years ago

12.0.30

4 years ago

12.0.27

4 years ago

12.0.26

4 years ago

12.0.21

4 years ago

12.0.17

4 years ago

1.0.0

4 years ago