All Projects → nelonoel → postcss-theme-ui

nelonoel / postcss-theme-ui

Licence: CC0-1.0 license
PostCSS plugin for accessing Theme UI variables

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to postcss-theme-ui

parsers
Specify is a central platform for companies who want to unify their brand identity, by connecting their design system tools.
Stars: ✭ 50 (+127.27%)
Mutual labels:  design-tokens, theme-ui
lovelace-light-soft-ui-theme
🎨 Home Assistant soft UI light theme, with help from @JuanMTech, @thomasloven, and @N-l1.
Stars: ✭ 59 (+168.18%)
Mutual labels:  theme-ui
postcss-clearfix
PostCSS plugin that adds a 'fix' argument to the 'clear' property
Stars: ✭ 47 (+113.64%)
Mutual labels:  postcss-plugin
theme-starter
🐤 A sample Next.js project for getting started with MDX, Theme UI, & Hack Club Theme.
Stars: ✭ 71 (+222.73%)
Mutual labels:  theme-ui
postcss-center
PostCSS plugin to center elements.
Stars: ✭ 44 (+100%)
Mutual labels:  postcss-plugin
postcss-styl
PostCSS parser plugin for converting Stylus syntax to PostCSS AST.
Stars: ✭ 15 (-31.82%)
Mutual labels:  postcss-plugin
TwoDark
Atom's OneDark inspired theme for Sublime Text
Stars: ✭ 19 (-13.64%)
Mutual labels:  theme-ui
gunfunded
Analyzing the gun lobby’s funding of Congress.
Stars: ✭ 32 (+45.45%)
Mutual labels:  theme-ui
postcss-rename
Replace class names based on a customizable renaming scheme.
Stars: ✭ 77 (+250%)
Mutual labels:  postcss-plugin
firefly-theme
Firefly Glows to attract Mates, Firefly Pro Glows to attract Developers. A Pure Colourful Dark Theme for VsCode that Glows in Night, inspired by Fireflies.
Stars: ✭ 29 (+31.82%)
Mutual labels:  theme-ui
postcss-import-url
PostCSS plugin inlines remote files.
Stars: ✭ 47 (+113.64%)
Mutual labels:  postcss-plugin
theme-ui-native
Build consistent, themeable React Native apps based on constraint-based design principles
Stars: ✭ 67 (+204.55%)
Mutual labels:  design-tokens
postcss-critical-css
PostCSS plugin to define and output critical CSS using custom atRules, and/or custom CSS properties. Critical CSS may be output to one or more files, as defined within the plugin options or within the CSS.
Stars: ✭ 84 (+281.82%)
Mutual labels:  postcss-plugin
postcss-input-style
PostCSS plugin that adds new pseudo-elements for easily styling the inner elements of inputs
Stars: ✭ 16 (-27.27%)
Mutual labels:  postcss-plugin
postcss
No description or website provided.
Stars: ✭ 59 (+168.18%)
Mutual labels:  postcss-plugin
postcss-trash-killer
It is a postcss plugin which wil be remove all unused css
Stars: ✭ 20 (-9.09%)
Mutual labels:  postcss-plugin
gatsby-minimal-portfolio
👔 JAMstack (Gatsby JS) content-focused portfolio blog starter. Features include dark-mode, installable PWA, SEO, code highlighting, form, CI/CD.
Stars: ✭ 36 (+63.64%)
Mutual labels:  theme-ui
postcss-inline-media
Media queries shortcut, built on PostCSS, example: font-size: 20px @1200 18px @480 16px;
Stars: ✭ 47 (+113.64%)
Mutual labels:  postcss-plugin
postcss-prefixwrap
A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.
Stars: ✭ 54 (+145.45%)
Mutual labels:  postcss-plugin
postcss-purgecss
PostCSS plugin for purgecss
Stars: ✭ 92 (+318.18%)
Mutual labels:  postcss-plugin

Build Status Support Chat

PostCSS Theme UI lets you access Theme UI variables in your CSS.

Table of Contents

Introduction

This package is still experimental, but mostly functional with some caveats outlined below. Developer ergonomics may still change based on community feedback. Feel free to file a PR!

Setup

Add PostCSS Theme UI to your project:

npm install postcss-theme-ui --save-dev

Use PostCSS Theme UI to process your CSS:

const postcssThemeUI = require("postcss-theme-ui");

postcssThemeUI.process(YOUR_CSS /*, processOptions, theme */);

Or use it as a PostCSS plugin:

const postcss = require("postcss");
const postcssThemeUI = require("postcss-theme-ui");
const theme = require("./theme");

postcss([postcssThemeUI(theme)]).process(YOUR_CSS /*, processOptions */);

PostCSS Theme UI runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Options

PostCSS Theme UI accepts an object formatted based on the System UI Theme Specification. See sample theme object.

Overview

Given the following theme config:

{
  breakpoints: ["40em", "52em", "64em"],
  colors: { text: '#111', primary: '#06c', error: '#c30' },
  fonts: {
    sans: '"IBM Plex Sans", sans-serif',
    serif: '"IBM Plex Serif", serif'
  },
  fontSizes: [12, 14, 16, 20, 24, 32, 48, 64, 72],
  sizes: ["initial", "48rem", "64rem"],
  space: [0, 4, 8, 16, 32, 64, 128, 256, 512]
}

PostCSS Theme UI maps CSS properties to the appropriate theme field. You can view the full prop mapping here. It supports negative values (for certain properties) and conversion of unitless integers to px.

.example {
  color: primary; /* colors.primary */
  font-size: 6; /* fontSizes[6] */
  margin: 0 auto -1; /* space[0] auto -space[1] */
  padding: 0 3 3px; /* space[0] space[3] 3px */
}

/* becomes */

.example {
  color: #06c;
  font-size: 48px;
  margin: 0 auto -4px;
  padding: 0 16px 3px;
}

Responsive Values

It also provides support for array values that map to your breakpoints for convenient responsive styling. You can call the theme function inside arrays, or use null to skip breakpoints. See Caveats for some limitations.

.card {
  border: th(colors.primary) [1, 2]; /* colors.primary [solid 1px, solid 2px] */
  color: primary; /* colors.primary */
  max-width: [0, null, 2]; /* [sizes], `null` is used to skip breakpoints */
  padding: [1, 2]; /* [space] */
}

/* becomes */

.card {
  border: #07c solid 1px;
  color: #07c;
  max-width: initial;
  padding: 4px;
}
@media screen and (min-width: 40em) {
  .card {
    border: #07c solid 2px;
    padding: 8px;
  }
}
@media screen and (min-width: 52em) {
  .card {
    max-width: 64rem;
  }
}

Custom Design Tokens

If you have design tokens currently not on the Theme UI spec, you can access them via the theme() or th() function.

Say, you want to add a gradients field to your tokens:

// theme config
{
  gradients: [
    "linear-gradient(to right, #DD2476, #FF512F)",
    "linear-gradient(to right, #FFF, #6DD5FA, #2980B9)"
  ];
}

Use them by calling the theme() or th() CSS functions.

.awesome-cta {
  background: th(gradients.0);
}

/* becomes */

.awesome-cta {
  background: linear-gradient(to right, #dd2476, #ff512f);
}

Note: Since we're using PostCSS, we can conveniently plug autoprefixer in our toolchain as well.

Caveats

  1. Short hand CSS properties such as font, background, and border will only map to one theme field as defined here. However, You can still access theme variables via the theme function.
.btn {
  border: theme(colors.primary) 1; /* colors.primary borders[1] */
  font: sans theme(fontSizes.1); /* fonts.sans fontSizes[1] */
}

/* becomes */

.btn {
  border: #07c solid 1px;
  font: "IBM Plex Sans", sans-serif 1rem;
}
  1. Responsive Values cannot be nested and can only be balanced when used more than once per property. For example, the following won't work at the moment. 😉
.unsupported {
  margin: [0, 1] [0, 1, 2];
  padding: [0, [1, 2]];
}

.fixed {
  margin: [0, 1, 1] [0, 1, 2];
  padding: 0 [1, 2];
}

.equivalent {
  margin-top: [0, 1];
  margin-right: [0, 1, 2];
  margin-bottom: [0, 1];
  margin-left: [0, 1, 2];
  padding: 0 [1, 2];
}
  1. Editor syntax highlighting is still a work in progress.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].