All Projects → seek-oss → Treat

seek-oss / Treat

Licence: mit
🍬 Themeable, statically extracted CSS‑in‑JS with near‑zero runtime.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Treat

Snackui
SnackUI 🍑 - the final React style library. With an *optimizing compiler* that lets you write views naturally, with easier DX, working on native and web at once, all while being faster than hand-rolling your own CSS.
Stars: ✭ 55 (-94.8%)
Mutual labels:  webpack-plugin, css-in-js
Dotenv Webpack
A secure webpack plugin that supports dotenv and other environment variables and only exposes what you choose and use.
Stars: ✭ 1,022 (-3.4%)
Mutual labels:  webpack-plugin
Polished
A lightweight toolset for writing styles in JavaScript ✨
Stars: ✭ 7,074 (+568.62%)
Mutual labels:  css-in-js
Mpx Webpack Plugin
原生小程序开发定制 webpack 插件套装
Stars: ✭ 34 (-96.79%)
Mutual labels:  webpack-plugin
Webpack Common Shake
CommonJS Tree Shaker plugin for WebPack
Stars: ✭ 875 (-17.3%)
Mutual labels:  webpack-plugin
Webpack Aliyun Oss
一个webpack(version >= 4)插件,上传资源到阿里云oss。可以作为webpack插件使用,也可独立使用
Stars: ✭ 36 (-96.6%)
Mutual labels:  webpack-plugin
Cloudflare Workers Webpack Plugin
Launch Cloudflare Workers to the Edge from the comfort of your build step 🚀
Stars: ✭ 18 (-98.3%)
Mutual labels:  webpack-plugin
Shadow
collection of useful CLJS code
Stars: ✭ 47 (-95.56%)
Mutual labels:  css-in-js
Postjss
Use the power of PostCSS in compiling with JSS
Stars: ✭ 40 (-96.22%)
Mutual labels:  css-in-js
Beamwind
a collection of packages to compile Tailwind CSS like shorthand syntax into CSS at runtime
Stars: ✭ 32 (-96.98%)
Mutual labels:  css-in-js
Tinypng Webpack Plugin
a tinyPNG plugin for webpack
Stars: ✭ 31 (-97.07%)
Mutual labels:  webpack-plugin
Linaria
Zero-runtime CSS in JS library
Stars: ✭ 8,443 (+698.02%)
Mutual labels:  css-in-js
Cattous
CSS in JSX for lazy developers, built using styled-components and styled-system
Stars: ✭ 38 (-96.41%)
Mutual labels:  css-in-js
React Postcss
Simple style tag for React
Stars: ✭ 9 (-99.15%)
Mutual labels:  css-in-js
Emotion Module
💖 Emotion module for Nuxt.js
Stars: ✭ 47 (-95.56%)
Mutual labels:  css-in-js
Ui Box
Blazing Fast React UI Primitive
Stars: ✭ 847 (-19.94%)
Mutual labels:  css-in-js
Event Hooks Webpack Plugin
Event hooks plugin for webpack
Stars: ✭ 30 (-97.16%)
Mutual labels:  webpack-plugin
Webpack Alioss Plugin
阿里 oss-webpack 自动上传插件
Stars: ✭ 35 (-96.69%)
Mutual labels:  webpack-plugin
Html Inline Css Webpack Plugin
☄️ A webpack plugin for convert external stylesheet to the embedded stylesheet
Stars: ✭ 48 (-95.46%)
Mutual labels:  webpack-plugin
Webpack Webextension Plugin
Webpack plugin that compiles WebExtension manifest.json files and adds smart auto reload
Stars: ✭ 47 (-95.56%)
Mutual labels:  webpack-plugin
treat

Themeable, statically extracted CSS‑in‑JS with near‑zero runtime.

Build Status treat Spectrum Community



Write your styles in JavaScript/TypeScript within treat files (e.g. Button.treat.js) that get executed at build time.

All CSS rules are created ahead of time, so the runtime is very lightweight—only needing to swap out pre-existing classes. In fact, if your application doesn’t use theming, you don’t even need the runtime at all.

All CSS logic, including its dependencies, will not be included in your final bundle.

Because theming is achieved by generating multiple classes, legacy browsers are supported.


Documentation

See the documentation at seek-oss.github.io/treat for more information about using treat.


Requirements

Your project must be using webpack with the supplied webpack plugin, but that’s it.

First-class support is provided for React and TypeScript, but those layers are entirely optional. The core runtime API can be integrated into other frameworks, if needed.

The runtime makes use of Map, so you may need a polyfill for pre-ES2015 browsers.

Basic usage

First, install the core libary.

$ yarn add treat

Then, add the webpack plugin to your project. In this case, we’re using mini-css-extract-plugin to generate a static CSS file.

const { TreatPlugin } = require('treat/webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  plugins: [
    new TreatPlugin({
      outputLoaders: [MiniCssExtractPlugin.loader]
    }),
    new MiniCssExtractPlugin()
  ]
};

Next, define and export styles from a treat file.

// Button.treat.js
// ** THIS CODE WON'T END UP IN YOUR BUNDLE! **
import { style } from 'treat';

export const button = style({
  backgroundColor: 'blue',
  height: 48
});

Finally, import the styles.

// Button.js
import * as styles from './Button.treat.js';

export const Button = ({ text }) => `
  <button class="${styles.button}">${text}</button>
`;

Themed usage

This themed usage example makes use of react-treat to keep things simple. React is not required to use treat.

First, install react-treat.

$ yarn add react-treat

Assuming you’ve already set up the webpack plugin, start by creating and exporting a theme from a treat file. Normally, you’d define multiple themes, but let’s keep it short.

// theme.treat.js
// ** THIS CODE WON'T END UP IN YOUR BUNDLE! **
import { createTheme } from 'treat';

export default createTheme({
  brandColor: 'blue',
  grid: 4
});

Then, import the desired theme and pass it to TreatProvider at the root of your application.

// App.js
import React from 'react';
import { TreatProvider } from 'react-treat';

import theme from './theme.treat.js';

export const App = () => (
  <TreatProvider theme={theme}>...</TreatProvider>
);

Now that you’ve configured the theming system, define and export themed styles from a treat file.

// Button.treat.js
// ** THIS CODE WON'T END UP IN YOUR BUNDLE EITHER! **
import { style } from 'treat';

export const button = style((theme) => ({
  backgroundColor: theme.brandColor,
  height: theme.grid * 11
}));

Themed styles have higher precedence than non-themed styles, regardless of document order. For more information, read the theming guide.

Then import and resolve themed styles via the useStyles Hook.

// Button.js
import React from 'react';
import { useStyles } from 'react-treat';
import * as styleRefs from './Button.treat.js';

export const Button = (props) => {
  const styles = useStyles(styleRefs);

  return <button {...props} className={styles.button} />;
};

Documentation

See the documentation at seek-oss.github.io/treat for more information about using treat.

License

MIT.

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].