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

variable-theming

v2.0.1

Published

CSS theming based on custom properties

Downloads

12

Readme

variable-theming

Version Build Status Coverage Dependencies Vulnerabilities License Types

CSS theming based on custom properties.

Install

npm install variable-theming

Usage

Theming

theming takes a non opinionated approach regarding the contents of your theme.

import inject from 'style-inject';
import theming from 'variable-theming';

const mainTheme = {
  custom: {
    primaryPalette: {
      main: 'red',
      contrast: 'blue',
      tint: 'white',
      shade: 'black'
    }
  },
  elements: {
    h1: {
      fontSize: '2em',
      color: 'var(--primary-palette-main)',
      background: 'green'
    }
  }
}

const secondaryTheme = {
  custom: {
    primaryPalette: {
      main: 'green',
      contrast: 'red',
      tint: 'white',
      shade: 'black'
    }
  },
  elements: {
    h1: {
      fontSize: '1em',
      color: 'var(--primary-palette-main)',
      background: 'yellow'
    }
  }
}

/*
 `elements` properties will be assigned
  to variables on `setup` styles
*/
const { setup, ...main } = theming(
  mainTheme.custom,
  mainTheme.elements
);

/*
  Add setup styles as globals:
    - use setup.css string to create a global <style> tag,
    - or the setup.styles if you're using css-in-js.
  Then, add variable assignments on the :root scope.
*/
inject(setup.css);
inject(`:root { ${main.css} }`);

/*
  We don't need to assign element properties to variables
  anymore as they are already globally set, so we don't need
  to separate element styles and custom properties for setup.
*/
const secondary = theming({
  ...secondaryTheme.elements,
  ...secondaryTheme.custom
});
inject(`.someClassSecondaryWillApplyTo { ${secondary.css} }`);

Palettes

palettes(options?: PaletteOptions): Function

Returns a function that, taking a record of PaletteInputs, returns a record of complete Palettes.

import { palettes, theming } from 'variable-theming';

const theme = theming({
  unit: { text: '1rem', space: '1rem', radius: '0.5rem' },
  palette: palettes()({
    primary: {
      main: 'rgba(49, 50, 52, 0.85)',
      tint: '#B2B2B2',
      contrast: '#fafafa'
    },
    dark: {
      main: '#222428',
      tint: '#383a3e',
      shade: '#1e2023'
    },
    light: {
      main: '#fafafa',
      contrast: 'rgba(49, 50, 52, 0.85)',
      shade: '#f5f5f5',
      accent: '#B2B2B2'
    }
  })
});

palettes.mui(palettes: Record<string, Palette>): Record<string, MuiPalette>

Creates a Material UI compatible palette from a Palette.

import { palettes } from 'variable-theming';
import { createMuiTheme } from '@material-ui/core/styles';

const mui = createMuiTheme({
  palette: palettes.mui(
    palettes()({
      dark: {
        main: '#222428',
        tint: '#383a3e',
        shade: '#1e2023'
      },
      light: {
        main: '#fafafa',
        contrast: 'rgba(49, 50, 52, 0.85)',
        shade: '#f5f5f5',
        accent: '#B2B2B2'
      }
    })
  )
});