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

easy-theme

v1.0.10

Published

A SCSS based theme generation tool that builds down to CSS variables as well as some nice-to-have SCSS tools for modern day application styling.

Downloads

170

Readme

Easy Theme 🎨

This package has a bunch of helpful SCSS tools that you can use to theme your application in a fast and reliable way.

Theming is made super easy and it all generates down to CSS variables. As well as that, this package also has some useful SCSS mixins that cover the basics from dark-mode, responsiveness, mobiles and more!

npm install easy-theme

"Here's one I made earlier" 🧱

This is just a quick overview of some of the features within easy-theme and how they work. Just @use the package in any SCSS file you want to use the tooling, or import helper functions within JavaScript or TypeScript with import { setLightTheme } from 'easy-theme';.

// index.scss

// 1. Import the tools.
@use "easy-theme" as theme;

// 2. Create your theme.
$light-theme: (
    'background': (#FFFFFF, #000000),
    'primary': (#1BFF72, #FFFFFF, true),
);

$dark-theme: (
    'background': (#000000, #FFFFFF),
);

$variables: (
    'spacing': .75rem,
    'radius': .2rem,
);

// 3. Let easy-theme do the rest!
@include theme.UseTheme((
    light: $light-theme,
    dark: $dark-theme,
    variables: $variables,
));

html, body {
    background: theme.Color('background');
}
// button.scss
@use "easy-theme" as theme;

button {
    background: theme.Color('primary');
    color: theme.Text('primary');
    border: 1px solid theme.Color('primary', 'darker');
    padding: theme.Variable('spacing');
}
// index.js
import { setLightTheme } from 'easy-theme';

setLightTheme({
    'primary': ['#1BFF72', '#ffffff', true]
});

Getting Started 🎬

  1. Import easy-theme into any file that you want to use the tooling.
@use "easy-theme" as theme;
  1. Define your colours
$light-theme: (
    // Basic Variables
    'background': (#FFFFFF, #000000),

    // Stepped Variables
    'primary': (#1BFF72, #FFFFFF, true),

    // Syntax:
    // 'color-name': (color, contrast, create-steps?),
);
  1. Generate the theme (normally you would define this in your index or global style sheet but anywhere will work).
@include theme.UseTheme((
    light: $light-theme
));
  1. Use your theme!
button {
    background: theme.Color('primary');
    color: theme.Text('primary');
    border: 1px solid theme.Color('primary', 'darker');

    &:disabled {
        background: theme.Color('primary', .5);
        color: theme.Text('primary', .5);
    }
}

// Above will be compiled into the following for the browser.

button {
    background: var(--theme-primary);
    color: var(--theme-primary-contrast);
    border: 1px solid var(--theme-primary-darker);

    &:disabled {
        background: rgba(var(--theme-primary-rgb), .5);
        color: rgba(var(--theme-primary-contrast-rgb), .5);
    }
}

Theming Syntax ⚙️

  • color-name: string: The name of the css variable to generate (e.g. background, navbar, primary, etc.)
  • color: hex: The core variable color.
  • contrast: hex: This is a contrasting color, this is mainly used for when you want to display text or icons on top of the colour provided.
  • create-steps?: boolean: This is an optional value that if true will create extra variables for consistent theme steps (e.g. lighter, darker, darkest, etc.).

Variable Syntax 🧑‍💻

  • variable-name: css-value: The name of the CSS variable to generate (e.g. background, navbar, primary, etc.) and any valid CSS value
  • default?: css-value: Any valid CSS value should the variable not be found.

Dark-mode theming and custom steps.

If you want to give your application some extra ✨ spice ✨ you can jazz up your theme with a dark mode and also some custom steps.

Dark theme 🌙

Dark mode is super easy to get going, just create another object like the $light-mode we have above and shove your variables in there. These will overwrite any variables when a user has @media (prefers-color-scheme: dark) (aka: "Dark Mode") active on their device.

$light-theme: (
    'background': (#FFFFFF, #000000),
    'primary': (#1BFF72, #FFFFFF, true),
);

$dark-theme: (
    'background': (#000000, #FFFFFF),
);

@include theme.UseTheme((
    light: $light-theme,
    dark: $dark-theme,
));

Custom Steps 🦶

By default if you don't provide any custom steps we will generate the following when you pass true to a theme colour definition.

  • Lighter: +25%
  • Light: +15%
  • Dark: -15%
  • Darker: -25%

All you need to do is include a new map of values within the theme and you'll be off to the races with your custom steps.

@include theme.UseTheme((
    light: $light-theme,
    dark: $dark-theme,
    steps: (
        'really-light': 50%,
        'just-a-touch-lighter': 5%,
        'a-little-darker': -10%,
        'super-dark': -90%
    )
));

Helpers, Tools & Mixins 🔨

Here is a list of some "niceities" I've made that you can use to access media queries etc, but with a little more ease.

Mobile / Responsiveness 📱

@include theme.NotMobile {
    // 📵 We're a computer or something...
}

@include theme.Tablet {
    // 💻 We're probably a tablet, or at least a small computer...
}

@include theme.Mobile {
    // 📱 We are a mobile (most-likely)!
}

@include theme.MobileTiny {
    // 🐜 We are an itty-bitty little device.
}

Preferences & Accessibility 🔤

@include theme.DarkMode {
    // 🌙 Dark-mode is enabled
}

@include theme.ReducedMotion {
    // 🏃‍♂️ The user want's to reduce animations on their device
}

@include theme.Landscape {
    // ⛰ The device is landscape...
}

@include theme.Portrait {
    // 🖼 The device is portrait...
}

@include theme.JavaScriptDisabled {
    // ❌ Scripting is not allowed on the device.
}

@include theme.JavaScriptEnabled {
    // 👩‍💻 Scripting is allowed!
}