A script to quickly create multiple variants of a text style.
The script is provided as a single file so that it may be run from inside Sketch's script editor.
- Edit the variable sections defined below
- Copy and paste the script into the Sketch script editor
- Use your new type styles
The intent is for global variables to be specified first (fonts, colors, alignments), then the specification of individual styles.
The script file is organized into 5 sections. The first 3 are definition of the global variables. The 4th is style definition. And 5th are the executables.
An array of color objects to for your text styles to be generated in. By default all styles will use all colors. A color object should have a name and a hexValue, both provided as strings.
The order they are provided in will dictate the order they appear within the style tree.
var colors =
[
{
name: 'Text',
hexValue: '#424242',
},
...
]
An array of the alignment you want to support for your styles. By default Left, Center, and Right are used. To disable an alignment from being generated, set display
to false, don't delete the alignment.
var align =
[
{
type: 'Left',
display: true,
value: NSTextAlignmentLeft,
},
...
]
Current support is provided for a single font family, with multi-support planned. Because of that, font support should be provided as a global variable. (Even if using a serif font, replace the string value after sans
)
An array of objects created which allows you to formulate the common elements of the style which you are wanting to generate. Keep all fields, but set new values for the ones your styles need.
var styleList = [
{
name: 'h1',
fontWeight: ['Light'],
fontSize: 44,
lineHeight: 50,
characterSpacing: -.4,
fontFamily: fontFamilies,
color: colors,
alignment: align,
textTransform: null,
},
...
]
The part to make it run, you don't need to edit anything from the executables.