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

@tame-your-theme/css-style-declaration

v0.1.3

Published

native css style declarations api helper to change theme in run time and to tame your theme

Downloads

33

Readme

Tame Your Theme

https://github.com/wellgrisa/tame-your-theme/workflows/.github/workflows/main.yml/badge.svg Npm package version Statements Lines

Overview

For the full and interactive documentation go here.

The main idea of this lib is to help creating themes by using CSS custom variables alongside with HSL colors and the CSS Object Model to change the css variables in runtime.

To achieve that, this lib is split in two packages:

Each package can be used independently.

If you don't need to change in run time, you can just use the @tame-your-theme/scss to create your variables and play with its colors easily.

Installation

Using npm:

npm install @tame-your-theme/css-style-declaration
npm install @tame-your-theme/scss

Using yarn:

yarn add @tame-your-theme/css-style-declaration
yarn add @tame-your-theme/scss

TL;DR

How to use in just a few steps:

  • create the themed colors by using the mixin create-theme-color from the @tame-your-theme/scss
  • create the themes using a list of names and values in your javascript preferred language (typescript, vanilla, react, angular...)
  • call the setTheme from the @tame-your-theme/css-style-declaration with the desired theme

The package @tame-your-theme/css-style-declaration

setTheme

Changes the theme according to the given variables. This method uses the native css set property method to change the css variable.

This method accepts two arguments:

export interface Theme {
  variables: ThemeAttribute[]
  getHueSaturationAndLightness: GetHueSaturationAndLightnessType
}

Following some principles from the Clean Architecture this lib aims to be dependencyless and this can be seen particularly in the parameter getHueSaturationAndLightness.

The idea of this method is basically avoid an extra dependency, so it receives a function which needs to return the specific values used in the lib.

export type GetHueSaturationAndLightnessType = (value: string) => {
  hue: number
  saturation: number
  lightness: number
}

In the example shown in the the documentation the lib being used to get these values is hex-to-hsl, but one can use any lib or even create the logic to get the values from a hexadecimal color. The following example uses the setTheme function to change the theme dynamically. To achieve this change, it's necessary to have a proper css set in place in the components.

Using only this package

:root {
  --primary-color-h: 39deg;
  --primary-color-s: 100%;
  --primary-color-l: 50%;
  --primary-color: hsl(var(--primary-color-h), var(--primary-color-s), var(--primary-color-l));

  --background-color-h: 0deg;
  --background-color-s: 0%;
  --background-color-l: 100%;
  --background-color: hsl(var(--background-color-h), var(--background-color-s), var(--background-color-l));

  --background-contrast-color-h: 0deg;
  --background-contrast-color-s: 0%;
  --background-contrast-color-l: 13%;
  --background-contrast-color: hsl(
    var(--background-contrast-color-h),
    var(--background-contrast-color-s),
    var(--background-contrast-color-l)
  );
}

After creating these variables, it's just a matter of calling the setThemes.