Skip to content

Sketch plugin to generate text styles for Text workflow

License

Notifications You must be signed in to change notification settings

rickcecil/text-to-styles

 
 

Repository files navigation

logo

Text to Styles

demo of exporting text layers to text styles

What?

Generate all the Sketch text styles you have based on a config set up in your artboards. No more making and maintaining multiple variations!

Why?

If your text style system requires the use of different alignments or colour variations you are faced with either detaching styles, risking updates overwrite the tweaks you make or you manually have to create every style.

This plugin aims to solve the generation and maintenance of Sketch text styles where you need colour and alignment variations of your text styles.

Installation

Install Text to Styles with Sketchpacks

Either install via Sketchpacks, Sketch Runner or...

  1. Download from the releases page
  2. Unzip
  3. Double Click on text-to-styles.sketchplugin

Text Style naming convention

This is an opinioated plugin on how Text Styles should be named. The naming convention is:

Style Name/Colour/Alignment/Breakpoint Varation

The breakpoint variation is optional.

Your Page setup

There is a sample project under sample/text-styles-sample.sketch to base your text and colour tokens off

You will need to set your Page structure and naming like this:

  • Styles
  • Colours or Colors
  • Alignments

Please note that this is case sensitive!

Styles

Add your base text styles here. This plugin will pick up on:

  • Font Family
  • Font Size
  • Font Weight
  • Font Style
  • Line Height
  • Letter Spacing
  • Text Transform (uppercase,lowercase)
  • Paragraph Spacing

Breakpoint adjustments

If you wish to add breakpoint adjustment for styles use the following naming syntax for the layer

Style Name/Breakpoint Variation

e.g.

Heading 1/BP1

The plugin will then split the name and add the breakpoint to the end of the text style name

Colours

Add shapes here with the colour value you want to render. The name of the layer defines the name in the Text Style palette. Order is done alphabetically.

Alignments

Add your alignments here by setting each text layer to your preffered alignment. Order is set Left, Center, Right.

Commands

There are several commands available Run Document Setup, Create Text Styles, Render Style Sheet and Export JSON Tokens

Run Document Setup

Sets up the Sketch document Page names with sample Styles, Alignments and Colors. You can then remove or modify them as you see fit.

Create Text Styles

Converts the contents of Styles, Alignments and Colors into text styles.

Render Style Sheet

This will reate a Page called "Rendered Styles" and create every combination within your text styles. Please make sure you have run the Create Text Styles command before.

Performance

This command can take a long time to run. The more combinations the longer it will take.

Export JSON Tokens

demo of exporting text layers to json

This will export out the text styles and colour palettes as a JSON file to use in other applications. Perhaps your production code base or documentation.

You will be presented with two options for formatting the text style json. Either an Array or an Object. Depending on your needs you may want the Object.

Array formatting

{
    "name": "Style 1",
    "styles": {
        "fontFamily": "SFProDisplay-Semibold",
        "fontSize": "28px",
        "lineHeight": "34px",
        "fontWeight": 8,
        "paragraphSpacing": 25,
        "letterSpacing": "0.02em",
        "textTransform": "none"
    },
    "alignments": [
        "left",
        "right",
        "center"
    ],
    "adjustments": [
        {
            "name": "BP3",
            "styles": {
                "fontSize": "42px",
                "lineHeight": "48px",
                "paragraphSpacing": 100,
                "letterSpacing": "0.03em"
            }
        }
    ]
}

Object formatting

"Style 1": {
    "name": "Style 1",
    "styles": {
        "fontFamily": "SFProDisplay-Semibold",
        "fontSize": "28px",
        "lineHeight": "34px",
        "fontWeight": 8,
        "paragraphSpacing": 25,
        "letterSpacing": "0.02em",
        "textTransform": "none"
    },
    "alignments": [
        "left",
        "right",
        "center"
    ],
    "adjustments": [
        {
            "name": "BP3",
            "styles": {
                "fontSize": "42px",
                "lineHeight": "48px",
                "paragraphSpacing": 100,
                "letterSpacing": "0.03em"
            }
        }
    ]
}

@tbrasington | tbrasington.com

About

Sketch plugin to generate text styles for Text workflow

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%