0.0.138 • Published 7 months ago

@justweb3/ui v0.0.138

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

@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.

0.0.117

11 months ago

0.0.84

1 year ago

0.0.116

11 months ago

0.0.85

1 year ago

0.0.115

11 months ago

0.0.114

11 months ago

0.0.88

1 year ago

0.0.89

1 year ago

0.0.119

11 months ago

0.0.118

11 months ago

0.0.113

11 months ago

0.0.80

1 year ago

0.0.112

11 months ago

0.0.111

11 months ago

0.0.82

1 year ago

0.0.110

11 months ago

0.0.83

1 year ago

0.0.128

8 months ago

0.0.73

1 year ago

0.0.127

8 months ago

0.0.74

1 year ago

0.0.126

8 months ago

0.0.75

1 year ago

0.0.125

8 months ago

0.0.76

1 year ago

0.0.77

1 year ago

0.0.78

1 year ago

0.0.79

1 year ago

0.0.129

8 months ago

0.0.120

11 months ago

0.0.124

8 months ago

0.0.123

8 months ago

0.0.70

1 year ago

0.0.122

8 months ago

0.0.71

1 year ago

0.0.121

8 months ago

0.0.138

7 months ago

0.0.68

1 year ago

0.0.69

1 year ago

0.0.131

7 months ago

0.0.130

8 months ago

0.0.135

7 months ago

0.0.133

7 months ago

0.0.106

11 months ago

0.0.95

1 year ago

0.0.105

11 months ago

0.0.104

12 months ago

0.0.97

1 year ago

0.0.103

12 months ago

0.0.98

1 year ago

0.0.99

1 year ago

0.0.109

11 months ago

0.0.108

11 months ago

0.0.90

1 year ago

0.0.102

12 months ago

0.0.91

1 year ago

0.0.101

1 year ago

0.0.92

1 year ago

0.0.100

1 year ago

0.0.93

1 year ago

0.0.94

1 year ago

0.0.62

1 year ago

0.0.63

1 year ago

0.0.64

1 year ago

0.0.42

1 year ago

0.0.65

1 year ago

0.0.43

1 year ago

0.0.66

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.60

1 year ago

0.0.61

1 year ago

0.0.59

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.55

1 year ago

0.0.56

1 year ago

0.0.57

1 year ago

0.0.58

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.40

1 year ago

0.0.41

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.36

1 year ago