Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

CSS theming for web apps

License

NotificationsYou must be signed in to change notification settings

streamich/nano-theme

 
 

Repository files navigation

A light and opinionated distribution ofnano-css.It ships all necessary dynamic tooling for most CSS-in-JS use cases, while in verylightweight packaging.nano-theme also ships predefined light and dark themes.As well as colorful color palette, predefined breakpoints and global CSS reset.

Installation

npm i nano-theme

Usage

First you might want to reset the global CSS.

import'nano-theme/lib/global-reset';

Now use therule utility to create CSS classes.

import{rule}from'nano-theme';constclassName=rule({color:'red',fontSize:16,'@media screen and (min-width: 768px)':{color:'blue',},});

You can useshorthand "atoms":

import{rule}from'nano-theme';constclassName=rule({col:'red',fz:16,'@media screen and (min-width: 768px)':{col:'blue',},});

Create CSS animations.

import{keyframes}from'nano-theme';constanimationName=keyframes({from:{opacity:0,},to:{opacity:1,},});

Import various theming helpers.

import{theme,font,colors,b1,b2,b3,b4}from'nano-theme';

React Usage

React integration is also provided:

import{Provider,GlobalCss,useTheme,useRule,makeRule}from'nano-theme';

TheProvider components sets the theme for the entire application. AndGlobalCsscomponent applies some global CSS, based on the current theme.

<Providertheme={'light'}><GlobalCss/><MyApp/><Provider/>

TheuseTheme hook returns the current theme.

consttheme=useTheme();

TheuseRule hook andmakeRule function are used to dynamically create CSS classes at render-time.

useRule example:

constMyComponent=()=>{constclassName=useRule({col:'red',fz:16,'@media screen and (min-width: 768px)':{col:'blue',},});return<divclassName={className}>Hello</div>;};

makeRule example:

constuseClassName=makeRule({color:'red',fontSize:16,'@media screen and (min-width: 768px)':{color:'blue',},});constMyComponent=()=>{constclassName=useClassName();return<divclassName={className}>Hello</div>;};

About

CSS theming for web apps

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp