All Projects → kripod → Glaze

kripod / Glaze

Licence: mit
CSS-in-JS microlibrary for making design systems approachable with React

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Glaze

Scale
The Scale library offers a set of customizable web components written with Stencil.js & TypeScript. The default theme of the library can be easily replaced so that a corresponding corporate identity of a dedicated brand can be represented.
Stars: ✭ 87 (-78.78%)
Mutual labels:  design-system, css-in-js
Design System
Priceline.com Design System
Stars: ✭ 604 (+47.32%)
Mutual labels:  design-system, css-in-js
visage
Visage design system
Stars: ✭ 12 (-97.07%)
Mutual labels:  css-in-js, design-system
Flame
Component library for building Lightspeed products
Stars: ✭ 65 (-84.15%)
Mutual labels:  design-system, css-in-js
Framework
🎨 Aesthetic is an end-to-end multi-platform styling framework that offers a strict design system, robust atomic CSS-in-JS engine, a structural style sheet specification (SSS), a low-runtime solution, and much more!
Stars: ✭ 176 (-57.07%)
Mutual labels:  design-system, css-in-js
morfeo
Morfeo is a tool to build design systems based on a theme. It helps you to follow a design language and write consistent UIs, whatever it is the framework of your choice. It's easy to use and, with the browser extension, your theme and your components are automatically documented.
Stars: ✭ 30 (-92.68%)
Mutual labels:  css-in-js, design-system
stitchwind
A bridge between Tailwind and Stitches
Stars: ✭ 33 (-91.95%)
Mutual labels:  css-in-js, design-system
Uiengine
Workbench for UI-driven development
Stars: ✭ 349 (-14.88%)
Mutual labels:  design-system
Color2k
a color parsing and manipulation lib served in roughly 2kB
Stars: ✭ 370 (-9.76%)
Mutual labels:  css-in-js
Community Platform
A series of tools for the Precious Plastic community to collaborate around the world and tackle plastic waste.
Stars: ✭ 343 (-16.34%)
Mutual labels:  design-system
Awesome Design Tokens
A list of resources on all things to do with Design Tokens
Stars: ✭ 338 (-17.56%)
Mutual labels:  design-system
React Awesome Reveal
React components to add reveal animations using the Intersection Observer API and CSS Animations.
Stars: ✭ 346 (-15.61%)
Mutual labels:  css-in-js
Alva
Create living prototypes with code components.
Stars: ✭ 3,734 (+810.73%)
Mutual labels:  design-system
Lab
React UI component design tool
Stars: ✭ 349 (-14.88%)
Mutual labels:  design-system
Cljss
Clojure Style Sheets — CSS-in-JS for ClojureScript
Stars: ✭ 382 (-6.83%)
Mutual labels:  css-in-js
Reshadow
Markup and styles that feel right
Stars: ✭ 343 (-16.34%)
Mutual labels:  css-in-js
Daisyui
⭐️ ⭐️ ⭐️ ⭐️ ⭐️  Tailwind Components
Stars: ✭ 382 (-6.83%)
Mutual labels:  design-system
React Native Web
React Native Components and APIs for the Web
Stars: ✭ 19,563 (+4671.46%)
Mutual labels:  css-in-js
Sancho
Responsive and accessible React UI components built with Typescript
Stars: ✭ 365 (-10.98%)
Mutual labels:  design-system
Shards Dashboard Vue
A free Vue admin dashboard template pack featuring a modern design system and lots of custom templates and components.
Stars: ✭ 363 (-11.46%)
Mutual labels:  design-system

glaze

CSS-in-JS microlibrary for making design systems approachable with React

npm Language grade: JavaScript Travis (.com) Open Collective backers and sponsors

💡 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

  1. Install the package and its peer dependencies:

    npm install glaze treat
    
  2. 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, shorthands and aliases) are embedded into production JavaScript bundles. Other values can only be accessed exclusively for styling, as shown later.

  3. 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>;
    }
    
  4. Style elements with the sx function:

    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>
      );
    }
    
  5. 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 globalStyle in *.treat.js files. They have to be applied as a side effect, e.g. from a top-level layout component:

      import './globalStyles.treat.js';
      
  6. Configure server-side rendering for dynamically created styles.

🤔 How it works

  • The sx function 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

  1. Transform each alias to its corresponding CSS property name or custom shorthand
  2. 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:

  1. { px: 4 }
  2. { paddingX: 4 }, after transforming aliases
  3. { paddingLeft: 4, paddingRight: 4 }, after unfolding custom shorthands
  4. { paddingLeft: '1rem', paddingRight: '1rem' }, after applying matchers

✨ Contributors

Thanks goes to these wonderful people (emoji key):


Kristóf Poduszló

🚧 💻 📖 💡 🤔 🚇

Jess Telford

📖

Corentin Leruth

📖 💻 ⚠️

Evan Hennessy

💻

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.

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