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

@justweb3/ui

v0.0.75

Published

The **@justweb3/ui** library provides a unified UI experience and handles theme generation for the **@justweb3/widget** package. It simplifies theming across widgets by dynamically generating color variations and supports custom theming through its contex

Downloads

3,463

Readme

@justweb3/ui

The @justweb3/ui library provides a unified UI experience and handles theme generation for the @justweb3/widget package. It simplifies theming across widgets by dynamically generating color variations and supports custom theming through its context provider.

This library was inspired by shadcn

Table of Contents


Installation

Install the library using npm or yarn:

npm install @justweb3/ui

# or

yarn add @justweb3/ui

Usage

Setup with JustWeb3ThemeProvider

To enable the theme context for your widget, wrap your application or component with the JustWeb3ThemeProvider. This ensures consistent theming across components and allows you to customize colors dynamically.

'use client';

import { JustWeb3ThemeProvider } from '@justweb3/ui';

const App = ({ children }) => {
  return (
    <JustWeb3ThemeProvider
      color={{
        primary: 'hsl(216, 90%, 58%)', // Custom primary color
        background: 'hsl(0, 0%, 98%)', // Custom background color
        destructive: 'hsl(0, 100%, 50%)', // Custom destructive color
      }}
    >
      {children}
    </JustWeb3ThemeProvider>
  );
};

export default App;

Changing Theme Dynamically

The JustWeb3ThemeProvider offers a changeTheme function to dynamically change the primary, background, or destructive colors. Here's an example demonstrating dynamic theme switching.

import React, { useState } from 'react';
import { useJustWeb3Theme } from '@justweb3/ui';

const ThemeSwitcher = () => {
  const { changeTheme, color } = useJustWeb3Theme();
  const [newColor, setNewColor] = useState(color.primary);

  const handleThemeChange = () => {
    changeTheme('primary', newColor);
  };

  return (
    <div>
      <h1>Current Primary Color: {color.primary}</h1>
      <input
        type="color"
        value={newColor}
        onChange={(e) => setNewColor(e.target.value)}
      />
      <button onClick={handleThemeChange}>Change Primary Color</button>
    </div>
  );
};

export default ThemeSwitcher;

Hooks

useJustWeb3Theme

The useJustWeb3Theme hook provides access to the current theme and allows you to modify theme colors dynamically.

Usage

import { useJustWeb3Theme } from '@justweb3/ui';

const Component = () => {
  const { theme, color, changeTheme } = useJustWeb3Theme();

  console.log('Current Theme:', theme);

  const switchToDarkBackground = () => {
    changeTheme('background', 'hsl(0, 0%, 10%)');
  };

  return (
    <div>
      <button onClick={switchToDarkBackground}>Switch to Dark Background</button>
    </div>
  );
};

Hook Output

  • theme: The current theme values.
  • color: The current primary, background, and destructive colors.
  • changeTheme: A function to dynamically change specific theme colors.

How It Works

The JustWeb3ThemeProvider internally generates color variations for:

  • Primary Color: Base color with light and dark variations.
  • Destructive Color: Used for alerts and destructive actions.
  • Background Color: Provides variations for background and foreground colors.

The provider uses CSS variables for theme management, ensuring that components and styles are synchronized.

Example CSS Variables:

:root {
  --justweb3-primary-color: hsl(216, 90%, 58%);
  --justweb3-primary-color-light: hsl(216, 90%, 68%);
  --justweb3-primary-color-dark: hsl(216, 90%, 48%);
  --justweb3-background-color: hsl(0, 0%, 100%);
  --justweb3-border-color: hsl(0, 0%, 0%);
  --justweb3-destructive-color: hsl(0, 100%, 50%);
  --justweb3-font-family: 'Inter', sans-serif;
}

Contributing

We welcome contributions! Please submit issues or pull requests on our GitHub repository.