tailwind-js-in-css-pattern-example uses Tailwind’s design tokens without Tailwind’s CSS. Its theme file holds Tailwind 0.7’s default color palette, text sizes and margin scale, copied value for value. Emotion’s ThemeProvider hands the theme to components, and styled-system turns props like color="red-light" and fontSize="5xl" into styles, the way Tailwind’s text-red-light and text-5xl classes would.
It’s a Create React App project from January 2019 with two commits: the generated app, and the pattern on top of it. The package is named pattern-library, but it has a single component, a Box that renders the word “test”. It hasn’t changed since, and the README is the Create React App default.
The theme
src/theme/index.js has three scales. colors holds all 73 entries of Tailwind 0.7’s palette, from black and the grey scale to the pink scale. fontSizes runs from xs (0.75rem) to 5xl (3rem), and spaces holds auto, px and the steps 0 to 32 (8rem). All of them match the default config that shipped with tailwindcss 0.7.3.


What it renders
The app renders one Box with m="4", color="red-light" and fontSize="5xl". Emotion turns it into a single class: margin: 32px; font-size: 3rem; color: rgb(239, 87, 83). The color is Tailwind’s red-light (#ef5753) and the size is its 5xl, both from the theme. The margin isn’t Tailwind’s m-4 (1rem): styled-system 3 looks for a scale named space, and this theme calls it spaces, so m="4" falls back to styled-system’s default scale, where step 4 is 32px.
How it’s built
It uses react-scripts 2.1.3 with React 16.7, Emotion 10 (@emotion/core, @emotion/styled through its Babel macro, and emotion-theming) and styled-system 3.2. Tailwind itself isn’t a dependency: only its default values are.
It still installs from its lockfile and starts with Node 10: yarn install, then yarn start.
The creation date shown here is the GitHub repository’s UTC creation date. The screenshot was captured by running the project locally from its source with Node 10, and the code cards show real source files from the repository.