Qtheme logo
Docs
Github
NPM

Qtheme.js

A utility-first css-in-js theming library. Define theme with atoms like bg-inner, text-primary, btn and use them directly in markup
Size

~5kb.min.js

Themes

Infinite

Dependencies

0

Example theme usage in HTML

bg-accent text-accent-content

Install

Install package from NPM

npm install @quak.lib/qtheme


 

Declare Themes

Example Theme snippets


.js
1   const darkTheme = {
2       name'dark',
3       atoms[
4          ['bg', '#333'],
4          ['bg-inner', '#555'],
5          ['text', 'white'],
6   
7          ['primary', 'rgb(147,99,219)'],
8          ['primary-inner', 'rgb(39 21 77)'],
9          ['primary-focus', 'rgb(69,47,103)'],
10         ['primary-content', 'white'],
11  
12         ['bg-color', 'background-color:var(--bg)'],
13         ['text-color', 'color:var(--text)'],
14         ['text-primary', 'color:var(--primary)']
15         // ...
16      ]
17  }

Use directly in HTML

Atom in markup usage

Take a look how to utilize your theme atoms

.html
1   <body class="bg-color text-color">
2    <h1 class="text-primary">Primary heading</h1>
3    <p>Regular paragraph</p>
4   
5    <!-- compound atoms below -->
6    <button class="btn">btn</button>
7    <button class="btn-primary">btn-primary</button>
8   </body>


Compound Atoms

Create atoms like btn or btn-accent from multiple CSS properties to create this special design you need

Intelisense

Import CSSProps for hints inside your IDE

import {CSSProps} from '@quak.lib/qtheme'


 

Declare compound atoms

Example button atoms snippets


.ts
1   // Example result 

2   const btn: CSSProps = {
3       padd|
  • P
    padding ... string | number | "inherit" | ...
  • P
    paddingLeft  string | number | "inherit" | ...
  • P
    paddingBottom  string | number | "inherit" ...
  • P
    paddingTop  string | number | "inherit" | u...
  • P
    paddingRight  string | number | "inherit" |...
  • P
    scrollPadding  string | number | "auto" | "...
  • P
     ...10 more...
4       color: 'var(--primary)',
5       backgroundColor: 'var(--primary-inner)',
6       outlineColor: 'var(--primary-focus)',
7       border: '1.5px solid var(--primary)',
8       borderRadius: '0.25rem 0.5rem'
9   }
10  
11  const btnHover: CSSProps = {
12      backgroundColor: 'var(--primary)'
13      color: 'var(--primary-content)'
14      cursor: 'pointer'
15  }
16  
17  const btnAtoms: ThemeAtom[] = [
18      ['btn', btn],
19      ['btn:hover', btnHover]
20  ]

Simply - init your theme

Initialize atoms to use them globally across your app

.js
1   import {Qtheme} from "@quak.lib/qtheme"
2   
3   // * will load theme from localStorage else darkTheme
4   Qtheme.init(darkTheme)

Change theme

Change theme freely to any you have created

.js
1   // * will save theme to localStorage
2   Qtheme.setTheme(lightTheme)

Set common atoms

Use common atoms across multiple themes and make theming even simpler

.js
1   const atoms = [
2       ...btnAtoms,
3       ...btnPrimaryAtoms
4   ]
5   Qtheme.setCommonAtoms(atoms)
6   // or with init method
7   // * will load commonAtoms from localStorage else atoms
8   Qtheme.init(darkTheme, {commonAtoms: atoms})

Atoms-usage in CSS

Since atoms are global use them in CSS

.css
1   .your-class {
2       border: 1px solid var(--primary);
3       background: var(--primary-inner);
4       color: var(--primary-content);
5   }
 
Qtheme logo

Any framework

Use with React, Angular, Svelte or any other

Docs

Visit documentation to learn all the details
Qtheme docs