Glaze
CSS-in-JS microlibrary for making design systems approachable with React
Install / Use
/learn @kripod/GlazeREADME
💡 Motivation
This project was born to combine the best of its predecessors into a single solution:
- Utility-first CSS, as implemented by Tailwind CSS
- Fully static, but customizable upfront
- Embraces reusability with no duplicated rules
- Constraint-based layouts, popularized by Theme UI
- Highly dynamic, thankfully to Emotion
- One-off styles can be defined naturally
- Near-zero runtime, made possible by treat
- Theming support with legacy browsers in mind
- Static style extraction while retaining type safety
📚 Usage
-
Install the package and its peer dependencies:
npm install glaze treat -
Define a theme, preferably by overriding the default tokens:
/* theme.treat.js */ import { createTheme, defaultTokens } from 'glaze'; export default createTheme({ ...defaultTokens, // Customization scales: { ...defaultTokens.scales, color: { red: '#f8485e', }, }, });Keeping the runtime as small as possible, only a few tokens (
breakpoints,shorthandsandaliases) are embedded into production JavaScript bundles. Other values can only be accessed exclusively for styling, as shown later. -
Apply the theme through
ThemeProvider:📝 The Gatsby plugin for glaze does this unobtrusively.
import { ThemeProvider } from 'glaze'; import theme from './theme.treat'; export default function Layout({ children }) { return <ThemeProvider theme={theme}>{children}</ThemeProvider>; } -
Style elements with the
sxfunction:import { useStyling } from 'glaze'; export default function Component() { const sx = useStyling(); return ( <p className={sx({ px: 4, // Sets padding-left and padding-right to 1rem color: 'white', bg: 'red', // Sets background to #f8485e })} > Hello, world! </p> ); } -
Set up static style extraction with the help of treat.
📝 The Gatsby plugin for treat does this unobtrusively.
-
Afterwards, selector-based CSS rules may be created with
globalStylein*.treat.jsfiles. They have to be applied as a side effect, e.g. from a top-level layout component:import './globalStyles.treat.js';
-
-
Configure server-side rendering for dynamically created styles.
🤔 How it works
- The
sxfunction maps themed values to statically generated class names- If that fails, the style gets injected dynamically through the CSSOM
- Dynamic styles which are not in use by any component get removed
Rule handling
- Transform each alias to its corresponding CSS property name or custom shorthand
- Resolve values from the scales available
- CSS properties associated with a custom shorthand are resolved one by one
Example
Given the theme below:
import { createTheme } from 'glaze';
export default createTheme({
scales: {
spacing: { 4: '1rem' },
},
shorthands: {
paddingX: ['paddingLeft', 'paddingRight'],
},
aliases: {
px: 'paddingX',
},
matchers: {
paddingLeft: 'spacing',
paddingRight: 'spacing',
},
});
An sx parameter is matched to CSS rules as follows:
{ px: 4 }{ paddingX: 4 }, after transforming aliases{ paddingLeft: 4, paddingRight: 4 }, after unfolding custom shorthands{ paddingLeft: '1rem', paddingRight: '1rem' }, after applying matchers
✨ Contributors
Thanks goes to these wonderful people (emoji key):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <td align="center"><a href="https://github.com/kripod"><img src="https://avatars3.githubusercontent.com/u/14854048?v=4" width="100px;" alt=""/><br /><sub><b>Kristóf Poduszló</b></sub></a><br /><a href="#maintenance-kripod" title="Maintenance">🚧</a> <a href="https://github.com/kripod/glaze/commits?author=kripod" title="Code">💻</a> <a href="https://github.com/kripod/glaze/commits?author=kripod" title="Documentation">📖</a> <a href="#example-kripod" title="Examples">💡</a> <a href="#ideas-kripod" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-kripod" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> <td align="center"><a href="http://jes.st/about"><img src="https://avatars1.githubusercontent.com/u/612020?v=4" width="100px;" alt=""/><br /><sub><b>Jess Telford</b></sub></a><br /><a href="https://github.com/kripod/glaze/commits?author=jesstelford" title="Documentation">📖</a></td> <td align="center"><a href="https://github.com/tatchi"><img src="https://avatars2.githubusercontent.com/u/5595092?v=4" width="100px;" alt=""/><br /><sub><b>Corentin Leruth</b></sub></a><br /><a href="https://github.com/kripod/glaze/commits?author=tatchi" title="Documentation">📖</a> <a href="https://github.com/kripod/glaze/commits?author=tatchi" title="Code">💻</a> <a href="https://github.com/kripod/glaze/commits?author=tatchi" title="Tests">⚠️</a></td> <td align="center"><a href="http://hennessyevan.com"><img src="https://avatars1.githubusercontent.com/u/16711653?v=4" width="100px;" alt=""/><br /><sub><b>Evan Hennessy</b></sub></a><br /><a href="https://github.com/kripod/glaze/commits?author=hennessyevan" title="Code">💻</a></td> </tr> </table> <!-- markdownlint-enable --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->This project follows the all-contributors specification. Contributions of any kind welcome!
Acknowledgements
Without its predecessors, glaze wouldn't exist. Thanks for all the wonderful people who have contributed towards the project, even indirectly.
The logo's donut emoji is courtesy of Twemoji.
Related Skills
bluebubbles
351.4kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
slack
351.4kUse when you need to control Slack from OpenClaw via the slack tool, including reacting to messages or pinning/unpinning items in Slack channels or DMs.
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
110.7kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
