npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

glaze

v0.5.1

Published

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

Downloads

4,340

Readme

💡 Motivation

When styling HTML elements, quite a few approaches may come to mind, including:

  • Utility-first/Atomic CSS, as implemented by Tailwind CSS, StyleSheet and CSS-Zero
    • 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

Baking the benefits outlined above into a single package, glaze was born.

🚀 Key features

  • Simple API inspired by inline styles
  • Near-zero runtime built upon treat
  • Personalizable design tokens inherited from Tailwind CSS and Theme UI
  • Composable property aliases and shorthands mapped to scales
    • E.g. paddingX or px for defining horizontal padding

🚧 In development

  • Responsive values defined as an array
  • Pseudo-class support

📚 Usage

  1. Install the package and its peer dependencies:

    npm install glaze treat react-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):

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.