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

@icxy/theme

v0.2.1

Published

2113ic's website theme component and color library

Downloads

3

Readme

Theme

Add color themes to your website.

Features

  • Dark mode
  • CSS class control for theme switching

install

pnpm add @icxy/theme

Usage

Here is an example using a Vue application.

Of course, you can also use it in native applications or other frameworks; it is allowed.

Add the following code to the head tag of your index.html:

<script>
  ;(function initTheme() {
    const html = document.documentElement
    const storedTheme = localStorage.getItem('theme')
    const systemTheme = window.matchMedia(
      '(prefers-color-scheme: dark)'
    ).matches
    const applyTheme = storedTheme || (systemTheme ? 'dark' : 'light')

    localStorage.setItem('theme', applyTheme)
    html.setAttribute('data-theme', applyTheme)
  })()
</script>

In your main.ts:

import { createApp } from 'vue'
import App from './App.vue'

// import theme
import '@icxy/theme/index.css'

createApp(App).mount('#app')

In your theme-switching button component:

<script setup>
import { useTheme } from '@icxy/theme'

const { toggleTheme } = useTheme()
</script>

<template>
  <button @click="toggleTheme">Toggle Theme</button>
</template>

Custom Themes

If you want to customize your own theme, you can use the @forward directive in Sass to modify the default theme.

@forward '@icxy/theme/src/vars' with (
  // Change the variable prefix
  $prefix: 'o',
);

You can see the customizable content in var.scss.

Tools

@icxy/theme provides some SCSS tools for you.

Get CSS Variables

@icxy/theme will mount the CSS variables needed for the theme on the root element. These variables will all start with a certain prefix (default: x).

The get function can help you retrieve these CSS variables without worrying about the prefix.

Example:

.box1 {
  width: 100px;
  height: 100px;
  border: 1px solid get('border');
  color: get('font');
}

.box2 {
  width: 100px;
  height: 100px;
  border: 1px solid get('bg-card');
  color: get('font-sub');

  &:hover {
    color: get('primary');
  }
}

You should notice that some variables are classified with bg, font, hover, border. So @icxy/theme also provides these more direct methods.

For example, the above example can be written as:

.box1 {
  width: 100px;
  height: 100px;
  border: 1px solid border();
  color: font();
}

.box2 {
  width: 100px;
  height: 100px;
  border: 1px solid bg('card');
  color: font('sub');

  &:hover {
    color: get('primary');
  }
}

Namespace

Sometimes, you want to use the same prefix in CSS class names.

@icxy/theme provides SCSS mixins named ns and ns-child to help you create BEM-style class names.

Example:

@include ns('box') {
  display: inline-flex;
  justify-content: center;
  align-items: center;

  @include ns-child('item') {
    // ...
  }
}

This is equivalent to:

.x-box {
  display: inline-flex;
  justify-content: center;
  align-items: center;

  .x-box__item {
    // ...
  }
}

Using these, you can easily create BEM-style class names without worrying about the class name prefix.