• Stars
    star
    1,152
  • Rank 38,945 (Top 0.8 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🍬 Themeable, statically extracted CSS‑in‑JS with near‑zero runtime.
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.

More Repositories

1

vanilla-extract

Zero-runtime Stylesheets-in-TypeScript
TypeScript
5,738
star
2

playroom

Design with JSX, powered by your own component library.
TypeScript
4,321
star
3

braid-design-system

Themeable design system for the SEEK Group
TypeScript
1,465
star
4

capsize

Flipping how we define typography in CSS.
TypeScript
1,356
star
5

html-sketchapp-cli

Quickly generate Sketch libraries from HTML documents and living style guides, powered by html-sketchapp
JavaScript
633
star
6

sku

Front-end development toolkit
JavaScript
472
star
7

seek-style-guide

Living style guide for SEEK, powered by React, webpack, CSS Modules and Less.
JavaScript
309
star
8

serverless-haskell

Deploying Haskell applications to AWS Lambda with Serverless
Haskell
213
star
9

css-modules-typescript-loader

Webpack loader to create TypeScript declarations for CSS Modules
JavaScript
193
star
10

vocab

Vocab is a strongly typed internationalization framework for React
TypeScript
122
star
11

csp-server

CSP (Content Security Policy) reports server which forwards reports to Elasticsearch.
JavaScript
56
star
12

docker-ecr-cache-buildkite-plugin

Zero config plugin for caching Docker images in Amazon ECR or Google Container Registry
Shell
51
star
13

skuba

🤿 SEEK development toolkit for backend applications and packages
TypeScript
48
star
14

aws-sm-buildkite-plugin

Buildkite plugin for working with AWS Secrets Manager
Shell
42
star
15

listo

Listo. Use questionnaires and checklists to make it easy to do the right thing, regarding the software you build.
TypeScript
26
star
16

github-merged-pr-buildkite-plugin

BuildKite plugin to work with GitHub PRs
Shell
25
star
17

crackle

A build tool for apps and packages, static and server-rendered sites
TypeScript
20
star
18

changesets-snapshot

A GitHub Action for publishing snapshot releases when using changesets
TypeScript
18
star
19

fsharp-workshop

Exercises for an F# workshop.
F#
15
star
20

lightgbm4j

A JVM interface 🌯 for LightGBM, written in Scala, for inference in production.
Scala
14
star
21

is-pwned

is-pwned — Utility to safely check the HaveIBeenPwned "Pwned Passwords" database in the browser.
TypeScript
12
star
22

docker-ecr-publish-buildkite-plugin

Build, tag, and push Docker images to Amazon ECR
Shell
11
star
23

seek-style-guide-webpack

Webpack decorators for integrating with the SEEK Style Guide.
JavaScript
11
star
24

react-scrollmonitor

React wrapper for scrollMonitor
JavaScript
11
star
25

gradle-aws-plugin

AWS Plugin for Gradle
Scala
10
star
26

evaporate

Evaporate is a convention-based, simple CloudFormation Stack deployment tool.
Haskell
9
star
27

browserslist-config-seek

Shareable Browserslist config for SEEK
JavaScript
9
star
28

seek.automation.phantom

A Pact based service simulator.
C#
9
star
29

toolbox

Standard build tools
Shell
8
star
30

aec

AWS EC2 CLI - easily work with ec2 instances via the cli 🐶
Python
8
star
31

create-ecr-buildkite-plugin

Create and manage an Amazon ECR repository
Shell
7
star
32

seek.automation.stub

A Pact based stubbing library for .NET.
C#
7
star
33

dynamotools

Tools to manage DynamoDB tables.
Go
7
star
34

snyk-buildkite-plugin

Buildkite plugin for running Snyk scans
Python
7
star
35

renovate-config-seek

Shareable Renovate config for SEEK
JavaScript
7
star
36

eslint-config-seek

Shareable ESLint configuration used by SEEK
JavaScript
7
star
37

private-npm-buildkite-plugin

A Buildkite plugin to simplify the use of an NPM token to install private modules
Shell
6
star
38

datadog-event-buildkite-plugin

BuildKite plugin to send a deployment event to datadog
Shell
5
star
39

seek-stackable

iOS framework for laying out nested views vertically and horizontally.
Swift
5
star
40

ensure-gitignore

Ensure the presence of patterns within a project's gitignore
JavaScript
5
star
41

aws-lambda-scala

Example of an AWS Lambda function written in Scala with deployment tools
Scala
4
star
42

https-proxy-server

HTTP proxy server in Node.js allowing modification of user responses.
JavaScript
4
star
43

style-guide-resources-for-sketch

A template containing SEEK UI components, for designers using Sketch.
4
star
44

ssm-buildkite-plugin

Secure Store Parameters for Buildkite
Shell
4
star
45

scoobie

🧶 Component library for SEEK documentation sites
TypeScript
4
star
46

wingman

🛩 Reference implementation of a SEEK-integrated recruitment system
TypeScript
4
star
47

koala

🐨 Koa add-ons for SEEK-standard tracing, logging and metrics
TypeScript
4
star
48

nodejs-consumer-pact-interceptor

A Node.js consumer Pact tool.
JavaScript
3
star
49

rynovate

🦏 dangerouslySetRenovatePreset
3
star
50

commitlint-config-seek

Shareable commitlint config for SEEK
JavaScript
3
star
51

kpt-functions

A library of Kpt functions for extending Kpt's functionality
Go
3
star
52

ad-posting-api-client

SEEK's Job Ad Posting API .NET client and sample consumer code.
C#
2
star
53

serverless-plugin-inspect

Serverless plugin - Get AWS stack info in JSON.
JavaScript
2
star
54

IdentityServer4.Contrib.DynamoDB

A persistence layer using DynamoDB for operational data for Identity Server 4
C#
2
star
55

datadog-custom-metrics

🐶 Common interface for sending Datadog custom metrics from Node.js runtime environments
TypeScript
1
star
56

text1

A NonEmpty version of Data.Text
Haskell
1
star
57

skuba-dive

🌊 Minimal runtime for skuba
TypeScript
1
star
58

action-project-manager

A github action which labels and adds isses and PRs to github projects
JavaScript
1
star
59

fake-hr

Node.js package of HR data sets for mocking and testing
TypeScript
1
star
60

logger

TypeScript
1
star
61

tslint-config-seek

TSLint configuration used by SEEK
JavaScript
1
star
62

babel-plugin-seek-style-guide

Optimise your bundle by automatically rewriting import statements from seek-style-guide
JavaScript
1
star
63

splunk-logger

Generates Splunk consumable logs in Node JS 4.3.2 AWS Lambda functions.
JavaScript
1
star
64

redux-batched-subscribe

FORK: https://github.com/tappleby/redux-batched-subscribe
JavaScript
1
star
65

spark-dist

Spark with hadoop-aws 3.1 for modern S3 access
Makefile
1
star