Giter Site home page Giter Site logo

mwa22 / figma-styles-to-ts Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 801 KB

Generate typescript files with colors, fonts and shadows from figma styles. Generate icons and images from figma file.

License: MIT License

TypeScript 96.37% JavaScript 3.63%
figma icons svg generator generate shadows images fonts colors styles

figma-styles-to-ts's Introduction

Welcome to figma-styles-to-ts ๐Ÿ‘‹

Version Documentation Maintenance License: MIT

Generate typescript files with colors, fonts and shadows from figma styles. Generate icons and images from figma file.

๐Ÿ  Homepage

Install

npm install -D figma-styles-to-ts

Usage

First of all, you need to give your personal figma token (you can do this once, the token will be registered). It will save your personal token in /node_modules and generate the styles.

figma-styles-to-ts --token="your_token"

Next time you just have to use this:

figma-styles-to-ts

To reset your token:

figma-styles-reset && figma-styles-to-ts --token="your_new_token"

Configuration

Create a figma.config.json file at the root of your project.

{
	"fileKey": "your_file_key",
	"color": {
		"enable": false,
		"outDir": "color_out_dir",
		"template": "default",
		"base": ""
	},
	"font": {
		"enable": false,
		"outDir": "font_out_dir",
		"template": "default",
		"base": ""
	},
	"shadow": {
		"enable": false,
		"outDir": "shadow_out_dir",
		"template": "default",
		"base": ""
	},
	"icon": {
		"enable": false,
		"outDir": "icon_out_dir",
		"template": "default",
		"storybook": false,
		"page": "the_page",
		"container": "the_icons_container"
	},
	"image": {
		"enable": false,
		"outDir": "image_out_dir",
		"page": "the_page",
		"container": "the_images_container"
	}
}

Required

Config Summary
fileKey The file key of your figma file. ex: https://www.figma.com/file/<file_key_here>/Name?node-id=11:09

Color

โš ๏ธ To generate Colors, you need to publish your styles in figma. โš ๏ธ

โš ๏ธ Only colors that have one value with a normal blend mode will be generated.

Config Summary
enable (default: false) Enable Color generator (true or false).
outDir The directory to store the code generated (a colors.ts file will be generated in this folder).
template (default: default) Use default template or palette template (see Templates) ('default' or 'palette').
base (default: all colors) Generate all colors from base path. ex: All my colors are as CompanyName/Black/100. Use base: "CompanyName" to get all colors of CompanyName.

Templates

The default template will generate a COLORS constant with all colors recursively. Example:

const COLORS = {
  CompanyName: {
    Black: {
      dark: { value: "#000000" }
      light: { value: "#131231" }
    },
    White: {
      value: "#FFFFFF"
    }
  },
  CustomColor: {
    value: "#452398"
  }
}

The palette template will generate a COLORS constant with colors that matches the palette format. You must name your colors as Color/100, Color/200, ..., Color/700 (only colors from 100 to 700 will be generated). Example:

const COLORS = {
	Black: {
		T100: "#000001",
		T200: "#000002",
		T300: "#000003",
		T400: "#000004",
		T500: "#000005",
		T600: "#000006",
		T700: "#000007",
	},
};

Font

โš ๏ธ To generate Fonts, you need to publish your styles in figma. โš ๏ธ

Config Summary
enable (default: false) Enable Font generator (true or false).
outDir The directory to store the code generated (a fonts.ts file will be generated in this folder).
template (default: default) Use default, react or chakra template (see Templates) ('default', 'reat' or 'chakra').
base (default: all fonts) Generate all fonts from base path. ex: All my fonts are as CompanyName/P1/Bold. Use base: "CompanyName" to get all fonts of CompanyName.

Templates

The default template will generate a FONTS constant with all fonts recursively. Example:

const FONTS: Fonts = {
	Bold: {
		value: {
			fontFamily: "Ubuntu",
			fontWeight: 700,
			fontSize: 12,
			letterSpacing: 0,
			lineHeight: "14.0625px",
		},
	},
	Medium: {
		value: {
			fontFamily: "Ubuntu",
			fontWeight: 500,
			fontSize: 12,
			letterSpacing: 0,
			lineHeight: "14.0625px",
		},
	},
};

The react template will generate the fonts.ts file from default template and will generate a Text component. Example:

const Text = ({ children, font, color, ...rest }: TextProps) => {
	return (
		<p
			style={{
				color: color,
				fontSize: font?.fontSize,
				fontFamily: font?.fontFamily,
				fontWeight: font?.fontWeight,
				lineHeight: font?.lineHeight,
				letterSpacing: font?.letterSpacing,
			}}
			{...rest}
		>
			{children}
		</p>
	);
};

The chakra template will generate the fonts.ts file from default template and will generate a Paragraph component. Example:

const Paragraph = ({ children, font, color, ...rest }: ParagraphProps) => {
	return (
		<Text
			color={color}
			fontFamily={font?.fontFamily}
			fontSize={font?.fontSize}
			fontWeight={font?.fontWeight}
			lineHeight={font?.lineHeight}
			letterSpacing={font?.letterSpacing}
			{...rest}
		>
			{children}
		</Text>
	);
};

Shadow

โš ๏ธ To generate Shadows, you need to publish your styles in figma. โš ๏ธ

โš ๏ธ Only drop shadows with a normal blend mode will be generated.

Config Summary
enable (default: false) Enable Shadow generator (true or false).
outDir The directory to store the code generated (a shadows.ts file will be generated in this folder).
template (default: default) Use default template or palette template (see Templates) ('default' or 'palette').
base (default: all shadows) Generate all shadows from base path. ex: All my shadows are as CompanyName/Bottom/100. Use base: "CompanyName" to get all shadows of CompanyName.

Templates

The default template will generate a SHADOWS constant with all shadows recursively. Example:

const SHADOWS = {
  CompanyName: {
    Bottom: {
      dark: { value: "0px 0.5px 2px rgba(96, 97, 112, 0.16)" }
      light: { value: "0px 2px 4px rgba(40, 41, 61, 0.04)" }
    },
    Top: {
      value: "0px 2px 4px rgba(96, 97, 112, 0.16), 0px 0px 1px rgba(40, 41, 61, 0.04)"
    }
  },
  CustomShadow: {
    value: "0px 26px 34px rgba(96, 97, 112, 0.06)"
  }
}

The palette template will generate a SHADOWS constant with shadows that matches the palette format. You must name your shadows as Shadow/100, Shadow/200, ..., Color/500 (only shadows from 100 to 500 will be generated). Example:

const SHADOWS = {
	Bottom: {
		T100: "0px 0.5px 2px rgba(96, 97, 112, 0.16)",
		T200: "0px 2px 4px rgba(96, 97, 112, 0.16)",
		T300: "0px 2px 4px rgba(96, 97, 112, 0.16)",
		T400: "0px 8px 16px rgba(96, 97, 112, 0.16)",
		T500: "0px 26px 34px rgba(96, 97, 112, 0.06)",
	},
};

Icon

Config Summary
enable (default: false) Enable Icon generator (true or false).
outDir The directory to store the code generated.
template (default: default) Use default template or react template (see Templates) ('default' or 'react').
storybook (default: false) Generate a index.stories.tsx file (โš ๏ธ only with react template) (trueor false)
page (default: the first page) The page name of your icons.
container (default: all components in the page) The container name in the page of your icons (โš ๏ธ all your icons must have a unique name and must be a component).

Templates

The default template will generate svg files. Example:

<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path d="M11 1L1 11M1 1L11 11" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

The react template will generate tsx files with React Component. Example:

const Cross = (props: React.SVGProps<SVGSVGElement>) => {
	return (
		<svg
			viewBox="0 0 12 12"
			fill="none"
			xmlns="http://www.w3.org/2000/svg"
			width={props.width}
			height={props.height}
		>
			<path
				d="M11.2174 0.782609L0.782609 11.2174M0.782609 0.782609L11.2174 11.2174"
				stroke={props.fill}
				strokeWidth="1.5"
				strokeLinecap="round"
				strokeLinejoin="round"
			/>
		</svg>
	);
};
export default Cross;

Use: <Cross height={20} width={20} fill="#000000" />;

Image

โš ๏ธ Only images with a fill scale mode, with a normal blend mode and with export settings will be generated.

โš ๏ธ PDF format is not supported.

Config Summary
enable (default: false) Enable Image generator (true or false).
outDir The directory to store the images generated.
page (default: the first page) The page name of your images.
container (default: all images in the page) The container name in the page of your images (โš ๏ธ all your images must have a unique name).

Author

๐Ÿ‘ค Thomas Michel

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a โญ๏ธ if this project helped you!

๐Ÿ“ License

Copyright ยฉ 2021 Thomas Michel.
This project is MIT licensed.

figma-styles-to-ts's People

Contributors

mwa22 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

stuartapp

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.