0.2.21 • Published 1 year ago

@parssa/universal-ui v0.2.21

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Universal UI

Note: This project is very much a work in progress.

See the docs here: https://universal-ui.vercel.app

What is this library?

A customizable Tailwind React UI library, utilizing data-attributes and TW3.2 functionality to have extremely flexible components.

Tenets

  1. All components should be easily themeable project-wide, and per-instance overrideable.
  2. No components should ever require !important selectors of any kind to override any defaults.
  3. Many different custom theme styles should be achieveable through the tailwind.config.js and the UniversalUIThemeProvider
  4. Refs are always forwarded
  5. Composition is king
  6. Full light/dark mode support, with ability to override defaults

Getting Started

This library assumes your project is configured with Tailwind 3.2+.

First install the library with your package manager of choice:

npm install @universal-ui/react

Then, import the UniversalUIThemeProvider and wrap your app in it:

import { UniversalUIThemeProvider } from '@universal-ui/react';

function App() {
  return (
    <UniversalUIThemeProvider>
      <YourApp />
    </UniversalUIThemeProvider>
  );
}

Lastly, add the following to your tailwind.config.js:

content: [
  ...,
  "./node_modules/@parssa/universal-ui/src/components/**/*.{ts,tsx,js,jsx}",
  ...
],
plugins: [
  ...
    require("@parssa/universal-ui/src/plugin"),
  ...
  ]

Theming / Configuration

There are two main ways to theme this library: through the tailwind.config.js and through the UniversalUIThemeProvider.

Tailwind Config

Here is where you can apply overrides for the semantic colors, and things such as the spacing scale.

Example theme replacing the brand color with some green hues.

theme: {
   universalUI: {
    themes: [
      {
          name: "brand",
          colors: {
            50: "#f1f8f4",
            100: "#ddeee3",
            200: "#bdddc9",
            300: "#9ac8af",
            400: "#63a482",
            500: "#428766",
            600: "#306b50",
            700: "#265641",
            800: "#204536",
            900: "#1b392d"
          }
        },
    ]
  }
}

One thing to note is it's ideal to provide a color scale from 50-900, as these colors are all used when determining the light/dark variants for the components.

UniversalUIThemeProvider

The UniversalUIThemeProvider is a React Context Provider that allows you to override the theme on a per-instance basis. This is useful for changing the feel of all components on a page, or for a specific component.

Per component, you can pass in a string, or a function which returns the instance's props, to apply styles conditionally.

import { UniversalUIThemeProvider } from '@universal-ui/react';

const config = {
  components: {
    button: ({ theme }: ButtonProps) => {
      if (theme === 'error') {
        return 'cursor-not-allowed';
      }
      return '';
    },
    text: ({ variant }: TextProps) => {
      if (variant === 'h1') {
        return 'underline'
      }

      return '';
    },
  }
}

function App() {
  return (
    <UniversalUIThemeContext.Provider value={config}>
      <YourApp />
    </UniversalUIThemeContext.Provider>
  );
}

SSR

To ensure components respond to the user's OS theme preference, you'll need to wrap your app in the UniversalUIThemeProvider and pass in the ssr prop.

const config = {
  components: { ... },
  ssr: true
}
0.2.21

1 year ago

0.2.20

1 year ago

0.2.19

1 year ago

0.2.18

1 year ago

0.2.17

1 year ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.1.96

1 year ago

0.1.97

1 year ago

0.1.98

1 year ago

0.1.99

1 year ago

0.1.90

1 year ago

0.1.91

1 year ago

0.1.92

1 year ago

0.1.93

1 year ago

0.1.94

1 year ago

0.1.95

1 year ago

0.1.85

1 year ago

0.1.86

1 year ago

0.1.87

1 year ago

0.1.88

1 year ago

0.1.89

1 year ago

0.1.84

1 year ago

0.2.1

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.1.82

1 year ago

0.1.83

1 year ago

0.1.52

1 year ago

0.1.53

1 year ago

0.1.54

1 year ago

0.1.55

1 year ago

0.1.56

1 year ago

0.1.57

1 year ago

0.1.58

1 year ago

0.1.59

1 year ago

0.1.50

1 year ago

0.1.51

1 year ago

0.1.41

1 year ago

0.1.42

1 year ago

0.1.43

1 year ago

0.1.44

1 year ago

0.1.45

1 year ago

0.1.47

1 year ago

0.1.48

1 year ago

0.1.80

1 year ago

0.1.81

1 year ago

0.1.74

1 year ago

0.1.75

1 year ago

0.1.76

1 year ago

0.1.77

1 year ago

0.1.78

1 year ago

0.1.79

1 year ago

0.1.70

1 year ago

0.1.71

1 year ago

0.1.72

1 year ago

0.1.73

1 year ago

0.1.63

1 year ago

0.1.64

1 year ago

0.1.65

1 year ago

0.1.66

1 year ago

0.1.67

1 year ago

0.1.68

1 year ago

0.1.69

1 year ago

0.1.60

1 year ago

0.1.61

1 year ago

0.1.62

1 year ago

0.1.40

1 year ago

0.1.39

1 year ago

0.1.38

1 year ago

0.1.37

1 year ago

0.1.36

1 year ago

0.1.35

1 year ago

0.1.34

1 year ago

0.1.33

1 year ago

0.1.32

1 year ago

0.1.31

1 year ago

0.1.30

1 year ago

0.1.27

1 year ago

0.1.26

1 year ago

0.1.25

1 year ago

0.1.24

1 year ago

0.1.23

1 year ago

0.1.22

1 year ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago