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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@unifycss/react

v1.1.0

Published

React integration for UnifyCSS featuring ThemeProvider, custom hooks & theme switcher

Readme

@unifycss/react

React integration for UnifyCSS — ThemeProvider, custom hooks, and theme switching system.

npm version npm downloads License: MIT


Table of Contents


Installation

npm install @unifycss/react @unifycss/unifycss
# or
pnpm add @unifycss/react @unifycss/unifycss
# or
yarn add @unifycss/react @unifycss/unifycss

Quick Start

// main.tsx or index.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import { ThemeProvider } from '@unifycss/react';
import '@unifycss/unifycss/unifycss.css';
import App from './App';

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <ThemeProvider>
      <App />
    </ThemeProvider>
  </React.StrictMode>
);

Then use any UnifyCSS classes anywhere in your components:

// App.tsx
export default function App() {
  return (
    <main className="min-h-screen bg-dark-base p-8">
      <h1 className="heading-1 text-white">Hello UnifyCSS + React</h1>
      <button className="btn-gold mt-4">Click me</button>
    </main>
  );
}

ThemeProvider

ThemeProvider wraps your application and provides theme context to all child components.

import { ThemeProvider } from '@unifycss/react';
import { lightTheme, darkTheme } from '@unifycss/shared';

// Default: light theme
<ThemeProvider>
  <App />
</ThemeProvider>

// Start in dark mode
<ThemeProvider initialTheme={darkTheme} initialThemeName="dark">
  <App />
</ThemeProvider>

Props

| Prop | Type | Default | Description | |---|---|---|---| | children | ReactNode | — | Required. Your app component tree | | initialTheme | ThemeConfig | lightTheme | Starting theme configuration object | | initialThemeName | string | "light" | Starting theme name string identifier |


Hooks API

useTheme()

Access full theme context: current theme object, theme name, and the apply function.

import { useTheme } from '@unifycss/react';
import { darkTheme } from '@unifycss/shared';

export function MyComponent() {
  const { theme, currentThemeName, applyTheme } = useTheme();

  return (
    <div>
      <p>Current theme: <strong>{currentThemeName}</strong></p>
      <p>Primary color: {theme?.colors?.primary}</p>
      <button onClick={() => applyTheme(darkTheme, 'dark')}>
        Switch to Dark
      </button>
    </div>
  );
}

Returns:

{
  theme: ThemeConfig | null;            // The currently applied theme object
  appliedThemeName: string | null;      // The name identifier of the applied theme
  currentThemeName: string | null;      // Alias for appliedThemeName
  applyTheme: (theme: ThemeConfig, themeName?: string) => void; // Applies a new theme
}

useApplyTheme()

Get a memoized function to switch themes without re-subscribing to the full context.

import { useApplyTheme } from '@unifycss/react';
import { darkTheme, lightTheme } from '@unifycss/shared';

export function ThemeToggle() {
  const applyTheme = useApplyTheme();

  return (
    <div className="flex gap-2">
      <button className="btn-ghost" onClick={() => applyTheme(lightTheme, 'light')}>
        ☀️ Light
      </button>
      <button className="btn-ghost" onClick={() => applyTheme(darkTheme, 'dark')}>
        🌙 Dark
      </button>
    </div>
  );
}

useCurrentThemeName()

Get only the current theme name string — ideal for conditional rendering.

import { useCurrentThemeName } from '@unifycss/react';

export function ThemeIndicator() {
  const themeName = useCurrentThemeName();

  return (
    <span className={`badge ${themeName === 'dark' ? 'badge-info' : 'badge-warning'}`}>
      {themeName === 'dark' ? '🌙 Dark Mode' : '☀️ Light Mode'}
    </span>
  );
}

useCurrentTheme()

Get only the current ThemeConfig object.

import { useCurrentTheme } from '@unifycss/react';

export function ThemeDebugger() {
  const theme = useCurrentTheme();

  if (!theme) return null;

  return (
    <pre className="glass-panel p-4 font-mono text-xs">
      {JSON.stringify(theme.colors, null, 2)}
    </pre>
  );
}

Custom Themes

Create custom themes by extending or composing ThemeConfig:

import type { ThemeConfig } from '@unifycss/shared';
import { lightTheme } from '@unifycss/shared';
import { useApplyTheme } from '@unifycss/react';

// Brand-specific theme
const brandTheme: ThemeConfig = {
  ...lightTheme,
  colors: {
    ...lightTheme.colors,
    primary: '#7c3aed',        // Purple brand
    secondary: '#4ade80',      // Emerald accent
    background: '#f5f3ff',     // Purple-tinted surface
    text: '#1e1b4b',           // Dark purple text
  },
  typography: {
    ...lightTheme.typography,
    fontFamily: '"Outfit", system-ui, sans-serif',
    fontSize: '16px',
  },
};

export function BrandThemeButton() {
  const applyTheme = useApplyTheme();

  return (
    <button
      className="btn-primary"
      onClick={() => applyTheme(brandTheme, 'brand')}
    >
      Apply Brand Theme
    </button>
  );
}

Dark / Light Toggle Pattern

Complete dark/light mode switcher component:

import { useState, useCallback } from 'react';
import { useTheme } from '@unifycss/react';
import { lightTheme, darkTheme } from '@unifycss/shared';

export function DarkModeToggle() {
  const { currentThemeName, applyTheme } = useTheme();
  const isDark = currentThemeName === 'dark';

  const toggle = useCallback(() => {
    if (isDark) {
      applyTheme(lightTheme, 'light');
      document.documentElement.classList.remove('dark');
    } else {
      applyTheme(darkTheme, 'dark');
      document.documentElement.classList.add('dark');
    }
  }, [isDark, applyTheme]);

  return (
    <button
      className={isDark ? 'btn-gold-outline' : 'btn-outline-primary'}
      onClick={toggle}
      aria-label="Toggle dark mode"
    >
      {isDark ? '☀️ Light Mode' : '🌙 Dark Mode'}
    </button>
  );
}

Persistent Theme (localStorage)

ThemeProvider automatically persists the last applied theme to localStorage. On page reload, the saved theme is restored:

// ThemeProvider handles localStorage automatically.
// You can read the saved theme manually with:
const savedTheme = localStorage.getItem('unifycss-theme-name');
// → 'dark', 'light', or your custom theme name

With CSS Classes

Use @unifycss/react together with @unifycss/unifycss class names:

import { useCurrentThemeName } from '@unifycss/react';

export function ThemedCard({ title, children }: { title: string; children: React.ReactNode }) {
  const themeName = useCurrentThemeName();
  const isDark = themeName === 'dark';

  return (
    <div className={`card ${isDark ? 'card-dark' : 'card-bordered'}`}>
      <div className="card-header">
        <h3 className="heading-3 text-white">{title}</h3>
      </div>
      <div className="card-body">{children}</div>
    </div>
  );
}

License

MIT © UnifyCSS Team