Vue Tailwind

screenshot of Vue Tailwind
vue
tailwind

Vue Tailwind

Vue UI components with configurable classes ready for TailwindCSS

Overview:

VueTailwind is a set of Vue components that can be customized to adapt to the unique design of any application. Unlike other UI libraries, which rely on CSS frameworks with limited styles, VueTailwind allows users to define custom CSS classes and configure component settings, providing a balance between pre-defined styles and customization. With VueTailwind, users can define the look and feel of their components, add unlimited variants for different use cases, override default props, and create different versions of components with different default settings.

Features:

  • Customizable Vue components
  • Ability to define custom default CSS classes
  • Configurable component settings
  • Support for unlimited variants
  • Override default prop values
  • Create different versions of components with different default settings

Installation:

  1. Install the dependencies.

    npm install
    
  2. Install TailwindCSS (Optional).
    This library uses TailwindCSS classes by default, but it should work with any CSS framework. To install TailwindCSS, follow the official documentation here.

  3. Add the @tailwindcss/forms plugin.
    The default theme of this library depends on the @tailwindcss/forms plugin. To use it, follow the steps on the plugin source page here.

  4. Add variants for disabled pseudo-class.
    This step is strongly recommended as it adds the ability to use some classes like disabled:opacity-50 and disabled:cursor-not-allowed for disabled inputs. Refer to the TailwindCSS documentation here for more information. As a reference, your tailwind.config.js may look like this:

    module.exports = {
      variants: {
        extend: {
          opacity: ['disabled'],
          cursor: ['disabled'],
        },
      },
    }
    
  5. Configure Vue to use vue-tailwind.

    5.1 Import and install the components.

    import Vue from 'vue'
    import VueTailwind from 'vue-tailwind'
    
    import { TButton, TInput } from 'vue-tailwind/dist/components'
    
    const settings = {
      't-button': {
        component: TButton,
        props: {
          classes: 'text-white bg-blue-500 border-0 py-2 px-4 focus:outline-none hover:bg-blue-600 rounded',
          variants: {
            secondary: 'text-blue-500 bg-white border-blue-500 hover:text-white hover:bg-blue-600 hover:border-blue-600',
          },
          fixedClasses: 'focus:outline-none',
        },
      },
      't-input': {
        classes: 'appearance-none bg-transparent border-none w-full text-gray-700 mr-3 py-1 px-2 leading-tight focus:outline-none',
        variants: {
          error: 'border-red-500 bg-red-100',
          disabled: 'opacity-50 cursor-not-allowed',
        },
        fixedClasses: 'focus:border-blue-500',
      },
    }
    
    Vue.use(VueTailwind, settings)
    

    5.2 Alternatively, you can use the v1.0 syntax.

    import Vue from 'vue'
    import VueTailwind from 'vue-tailwind'
    
    import { TButton, TInput } from 'vue-tailwind/dist/components'
    
    const settings = {
      't-button': {
        component: TButton,
        props: {
          classes: 'text-white bg-blue-500 border-0 py-2 px-4 focus:outline-none hover:bg-blue-600 rounded',
          variants: {
            secondary: 'text-blue-500 bg-white border-blue-500 hover:text-white hover:bg-blue-600 hover:border-blue-600',
          },
          fixedClasses: 'focus:outline-none',
        },
      },
      't-input': {
        component: TInput,
        props: {
          classes: 'appearance-none bg-transparent border-none w-full text-gray-700 mr-3 py-1 px-2 leading-tight focus:outline-none',
          variants: {
            error: 'border-red-500 bg-red-100',
            disabled: 'opacity-50 cursor-not-allowed',
          },
          fixedClasses: 'focus:border-blue-500',
        },
      },
    }
    
    Vue.use(VueTailwind, settings)
    

    5.3 Or install only the components you need.

    import Vue from 'vue'
    import VueTailwind from 'vue-tailwind'
    
    import { TButton, TInput } from 'vue-tailwind/dist/components'
    
    const settings = {
      't-button': {
        component: TButton,
        props: {
          class: 'text-white bg-blue-500 border-0 py-2 px-4 focus:outline-none hover:bg-blue-600 rounded',
          fixedClasses: 'focus:outline-none',
        },
      },
      't-input': TInput,
    }
    
    Vue.use(VueTailwind, settings)
    

Note: Using the syntax from point 5.3 is the best way to prevent a large bundle size, but it is only recommended if you are importing a few components. If the number of components you install increases, it is recommended to use the syntax from points 5.1 or 5.2 to help the library reuse some code and keep the bundle size minimal.

Summary:

VueTailwind is a customizable Vue component library that allows users to define their own default CSS classes and configure component settings. It provides the flexibility to create unique designs while still benefiting from pre-defined components. The installation process involves installing dependencies, optionally installing TailwindCSS and the @tailwindcss/forms plugin, and configuring Vue to use vue-tailwind. With VueTailwind, users can easily customize the look and feel of their components, add unlimited variants for different use cases, override default props, and create different versions of components with different default settings.

vue
Vue

Vue.js is a lightweight and flexible JavaScript framework that allows developers to easily build dynamic and reactive user interfaces. Its intuitive syntax, modular architecture, and focus on performance make it a popular choice for modern web development.

tailwind
Tailwind

Tailwind CSS is a utility-first CSS framework that provides pre-defined classes for building responsive and customizable user interfaces.

eslint
Eslint

ESLint is a linter for JavaScript that analyzes code to detect and report on potential problems and errors, as well as enforce consistent code style and best practices, helping developers to write cleaner, more maintainable code.

postcss
Postcss

PostCSS is a popular open-source tool that enables web developers to transform CSS styles with JavaScript plugins. It allows for efficient processing of CSS styles, from applying vendor prefixes to improving browser compatibility, ultimately resulting in cleaner, faster, and more maintainable code.

rollup
Rollup

RollupJS is a popular and efficient JavaScript module bundler that takes the code from multiple modules and packages them into a single optimized file, minimizing the overall size of the application and improving its performance.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.