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

@ramosdiego/ui

v0.0.15

Published

A TailwindCSS plugin which serves a as UI library.

Downloads

534

Readme

@ramosdiego/ui

Easily generate fully styled buttons, input elements and badges with any default TailwindCSS color or custom color.

The styles include hover, focus and disabled states, as well as, dark and light modes.

Demo Website

Demo Video

Install

With NPM

npm install @ramosdiego/ui

With yarn

yarn add @ramosdiego/ui

Getting started

Add @ramosdiego/ui to your TailwindCSS configuration.

// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')()],
}

Syntax

You have access to the following classes.

# Buttons
btn-{color}-{fill|outline|ghost}{-dark}

# Inputs
input-{color}-{outline|underline}{-dark}

# Badges
badge-{color}-{fill|outline}{-dark}

Here are some examples using these classes in code:

<!-- Buttons -->
<button class="btn-rose-outline">A rose button</button>

<button disabled class="btn-myTotallyCustomColor-fill-dark">
  A myTotallyCustomColor button
</button>

<!-- Inputs -->
<input placeholder="Enter name" class="input-blue-underline-dark" />

<input type="search" placeholder="Search" class="input-violet-outline" />

<!-- Badges -->
<span class="badge-green-outline-dark">Cash Money</span>

<div class="badge-pink-fill">Certified certificate of certification</div>

Adding custom colors

@ramosdiego/ui takes the colors from your TailwindCSS configuration, as such, there are two possible scenarios.

1. Your config file extends tailwindcss colors

// tailwind.config.js
module.exports = {
  content: [],
  ...
  theme: {
    extend: {
      colors: {
        brown: {
            50: '#fdf8f6',
            100: '#f2e8e5',
            200: '#eaddd7',
            300: '#e0cec7',
            400: '#d2bab0',
            500: '#bfa094',
            600: '#a18072',
            700: '#977669',
            800: '#846358',
            900: '#43302b',
        },
      },
    },
  },
  plugins: [
    require('@ramosdiego/ui')(),
  ],
}

In this scenario you'll have access to all tailwindcss colors, plus your custom colors, such that:

<button class="btn-blue-fill-dark">A blue button</button>

<button class="btn-myTotallyCustomColor-fill-dark">
  A myTotallyCustomColor button
</button>

are both valid.

2. Your config file overrides tailwindcss colors

// tailwind.config.js
module.exports = {
  content: [],
  ...
  theme: {
    colors: {
        brown: {
            50: '#fdf8f6',
            100: '#f2e8e5',
            200: '#eaddd7',
            300: '#e0cec7',
            400: '#d2bab0',
            500: '#bfa094',
            600: '#a18072',
            700: '#977669',
            800: '#846358',
            900: '#43302b',
        },
    },
  },
  plugins: [
    require('@ramosdiego/ui')(),
  ],
}

In this scenario you'll only have access to your custom colors, such that only:

<button class="btn-myTotallyCustomColor-fill">
  A myTotallyCustomColor button
</button>

is valid.

In both scenarios your colors MUST conform to tailwindcss default color's type:

// A tailwindcss color
[x: string]: {
    {
        50: string
        100: string
        200: string
        300: string
        400: string
        500: string
        600: string
        700: string
        800: string
        900: string
    }
}

Your colors may contain any other values, but they must include all these values.

Customizing design

Adding custom global styles

@ramosdiego/ui has some default styles for each kind of element. You may want to modify them to adjust to your project. For example, if you want all elements to NOT have rounded corners you can set the following global style in your @ramosdiego/ui config.

Note: Use CSS-in-JS syntax to set up your configuration.

  • Using TailwindCSS theme() function. theme() is used to look up values in the user’s theme configuration.
// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')({
      // Add custom global base styles using `theme()`
      globalStyles: ({ theme }) => ({
        fontWeight: theme('fontWeight[bold]'),
        fontSize: theme('fontSize[xl]'),
      }),
)],
}
  • Using CSS values
// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')({
      // Add custom global base styles using css
      globalStyles: {
        textTransform: 'lowercase',
        fontWeight: 300,
        borderRadius: '10px',
      },
)],
}

Adding custom element styles

You can also set different custom styles for each element type.

  • Using TailwindCSS theme() function. theme() is used to look up values in the user’s theme configuration.
// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')({
    // Add custom element base styles using `theme()`
  buttons: {
    baseStyles: ({ theme }) => ({
        fontWeight: theme('fontWeight[bold]'),
        fontSize: theme('fontSize[xl]'),
      })
  },
  inputs: {
    baseStyles: ({ theme }) => ({
        fontWeight: theme('fontWeight[DEFAULT]'),
      })
  },
  badges: {
    baseStyles: ({ theme }) => ({
        fontSize: theme('fontSize[sm]'),
      })
  }
)],
}
  • Using CSS values
// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')({
    // Add custom element base styles using css
  buttons: {
    baseStyles: {
        textTransform: 'uppercase',
        borderRadius: '10px',
      }
  },
  inputs: {
    baseStyles: {
        textTransform: 'lowercase',
        borderRadius: '0px',
      }
  },
  badges: {
    baseStyles: {
        textTransform: 'normal-case',
        borderRadius: '20px',
      }
  }
)],
}

If you include both, custom global styles and element styles, the element styles will override any overlapping values from your global styles.

// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')({
    globalStyles: {
        textTransform: 'lowercase',
    },
    buttons: {
        baseStyles: {
            textTransform: 'uppercase',
            borderRadius: '10px',
        }
    }
)],
}

With this configuration buttons will have text-transform: uppercase; while inputs and badges have text-transform: lowercase;.

Extra features

You can choose to animate buttons when they are pressed.

// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')({
    buttons: {
        animate: true
    }
)],
}

You can choose to between three button presets.

// tailwind.config.js
module.exports = {
  content: [],
  ...
  plugins: [require('@ramosdiego/ui')({
    buttons: {
        animate: true,
        preset: 'playful',
        // OR
        preset: 'elegant',
        // OR DEFAULT
    }
)],
}

To choose the default preset, DO NOT set a preset.

Types

Here are all the options available to @ramosdiego/ui.

require('@ramosdiego/ui')(options: PluginOptions)

type UserStyles = ({ theme }: { theme: Helpers['theme'] }) =>
  | {
      [x: string]: any
    }
  | { [x: string]: any }

type PluginOptions =
  | {
      globalStyles?: UserStyles
      buttons?: {
        animate?: boolean
        spreadRadius?: string
        preset?: 'playful' | 'elegant'
        baseStyles?: UserStyles
      }
      inputs?: {
        baseStyles?: UserStyles
      }
      badges?: {
        baseStyles?: UserStyles
      }
    }
  | undefined