Skip to main content

Custom Token

sacss/
โ”œโ”€โ”€ less/ # The folder where the LESS Mixin is stored
โ”‚ โ”œโ”€โ”€ SACSS.less # Helps create a secondary LESS Mixin for sacss
โ”‚ โ”œโ”€โ”€ WidthPrefix.less # Add custom prefixes to the core code
โ”‚ โ””โ”€โ”€ Helpers.less # Common helper mixin independent of sacss
โ”œโ”€โ”€ sass/ # Folder where LESS Mixin is stored
โ”‚ โ”œโ”€โ”€ SACSS.scss # Helper SASS Mixin to help create sacss
โ”‚ โ”œโ”€โ”€ WidthPrefix.scss # Add custom prefixes to the core code
โ”‚ โ””โ”€โ”€ Helpers.scss # Common helper mixin independent of sacss
โ””โ”€โ”€ index.css # Core code that is basically the same for all projects (only customization is recommended, named prefixes);

less and sass have the exact same documentation and API, just syntax different implementations.

The core code sacss/index.css basically holds layout related code. There are only two colors, pure black and pure white, and even the common font-size related code is not included.

The reason for this is that different designers have different design specifications for different projects, and we recommend combining them with the project for customization.

SACSS API#

nameexplanationexample
prefixclass name prefix'_'
attribute namefull Style attribute'font-size'
property abbreviationsnaming rule-based property abbreviations'fs'
List of valuesList of values to be output consecutively8,16,24
unitsAll values will be multiplied with units (null means no units are needed)1px
@import 'sacss/less/SACSS';
@prefix: ''; // class name prefix
@unit: 1px; // unit conversion expression
#SACSS('attribute name'; '@{prefix} attribute abbreviation'; 'list of values'; @unit);

For naming rules for abbreviations, please click here.

@import 'sacss/less/SACSS';
@prefix: '';
@prefix_: '_';
@unit_px: 1px;
@unit_rem: (1/16*1rem); // Parentheses are required here in less
#SACSS('margin-top'; '@{prefix}mt'; 8, 16, 24; @unit_px);
#SACSS('margin-right'; '@{prefix}mr'; 8, 16, 14; @unit_px);
#SACSS('margin-bottom'; '@{prefix_}mb'; 8, 16, 24; @unit_rem);
#SACSS('margin-left'; '@{prefix_}ml'; 8, 16, 24; @unit_rem);

This is the same method as SACSS, just to make it simpler and intuitive to create the CSS code in output.

If you feel comfortable writing this part of the CSS by hand, you can also write it yourself.

Unit Conversions#

@import 'sacss/less/SACSS';
// px
#SACSS('margin-top'; 'mt'; 8, 16; 1px);
// rem
#SACSS('margin-bottom'; 'mb'; 8, 16; (1/16*1rem));
// Empty
#SACSS('font-weight'; 'fw'; 100,200,300,400;);

If a rem-based conversion of units is required, fill in 1/16*1rem.

The SACSS method is only available for use with values of numeric type.

For example, font-weight:bold; cannot be created using SACSS, but font-weight:400; ok.

Project examples#

  • A project design specification: all spacing, font size must be a multiple of 4 and the primary color is red.
  • B project design specification: all spacing, font size must be a multiple of 5, and the primary color is blue;
/* All spacing, font size must be a multiple of 4; */
@import 'sacss/less/SACSS';
// This prefix is added to all ClassName (but not recommended)
@prefix: '';
// Unit conversion expressions
@unit: 1px;
// margin
#SACSS('margin-top'; '@{prefix}mt'; 8, 16; @unit);
#SACSS('margin-right'; '@{prefix}mr'; 8, 16; @unit);
#SACSS('margin-bottom'; '@{prefix}mb'; 8, 16; @unit);
#SACSS('margin-left'; '@{prefix}ml'; 8, 16; @unit);
// padding
#SACSS('padding-top'; '@{prefix}pt'; 8, 16; @unit);
#SACSS('padding-right'; '@{prefix}pr'; 8, 16; @unit);
#SACSS('padding-bottom'; '@{prefix}pb'; 8, 16; @unit);
#SACSS('padding-left'; '@{prefix}pl'; 8, 16; @unit);
// font
#SACSS('font-size'; '@{prefix}fs'; 12, 16; @unit);
#SACSS('line-height'; '@{prefix}lh'; 16, 24; @unit);
// Color
.c_primary{ color: red; }
.bc_primary{ background-color: red; }
/* Other custom codes */

What to customize#

  • margin: abbreviation m
  • padding: abbreviation p
  • font-size: abbreviation fs
  • line-height: abbreviation lh
  • color: abbreviation c_
  • background-color: abbreviation bc_
  • The Token you communicate with the designer (the agreement between you and the designer)