Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tailwind-friendly token resolver for semantic tokens

Given a set of global tokens, this package provides a function that resolves "semantic token" to their values - see below example.

// colors.js

import { Tokenizer } from '@hyraiq/tokenizer';

const globalTokens = {
  white: '#FFFFFF',
  grey: {
    25: '#F9F9FB',
    50: '#F0F1F5',
    75: '#E4E6EC',
    100: '#D9DBE3',
    200: '#C2C6D1',
    300: '#A0A7B6',
    400: '#838A9A',
    500: '#676E7E',
    600: '#515767',
    700: '#3F4655',
    800: '#2D3340',
    900: '#1D212B',
  },
  blue: {
    50: '#EBF3FE',
    75: '#D7E8FE',
    100: '#C2DEFF',
    200: '#99CAFF',
    300: '#6DA9FD',
    400: '#3D87FF',
    500: '#1F5EFF',
    600: '#002FFF',
    700: '#122EC4',
    800: '#142494',
    900: '#0E1662',
  },
};

const tokenizer = Tokenizer.with(globalTokens);

export const background = tokenizer.handle({
  'default': 'white',
  'secondary': 'grey-25',
  'hover': 'grey-50',
  'active': 'grey-100',
  'selected': 'grey-75',
  'brand': 'blue-600',
});

export { globalTokens };

This tokenizer.handle() method will resolve these references to blue-600 etc within the global tokens, which can then be used in your main tailwind.config.js:

// tailwind.config.js
import { globalTokens, background } from './colors';

export default {
  theme: {
    colors: globalTokens,
  },
  backgroundColor: theme => ({
    // Include the global tokens
    ...theme('theme.colors'),
    // And the semantic tokens just for background
    ...background,
  })
}

About

Tailwind tokenizer function for semantic token resolution

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages