Vue UI components with configurable classes ready for TailwindCSS
Vue UI components with configurable classes ready for TailwindCSS
For more info, check the official site: https://vue-tailwind.com/.
VueTailwind is a set of Vue components created to be customized to adapt to your application's unique design.
Most component libraries depend on CSS frameworks with an opinionated and limited number of styles defined by the people who maintain those libraries.
Those libraries are great and make our work easy, but hey, we made a beautiful custom design, right?
We can use a framework like TailwindCss to define our style, but that will end with us writing long CSS classes repeatedly, which could quickly become unmaintainable. Also, create some components like modals, date pickers, etc., is a tricky task, and let's admit it, nobody has time for that, right?
The VueTailwind components are meant to be customized with custom CSS classes that you can define when you install the library.
Plus, most component settings are configurable, so using this library is like having your personal set of components for your particular needs.
All that means that with this library, you will be able to:
npm install vue-tailwind --saveOr:
yarn add vue-tailwindThis library uses TailwindCSS classes by default. Still, it should work with any CSS framework since all the CSS classes are configurable.
To install TailwindCSS follow his official documentation: https://tailwindcss.com/docs/installation
The default theme of this library depends on the @tailwindcss/forms plugin. To use it, follow the steps on the plugin source page.
https://github.com/tailwindlabs/tailwindcss-forms
Also needed for the default theme and strongly recommended since it adds the ability to use some classes like disabled:opacity-50 disabled:cursor-not-allowed to disabled inputs.
See https://tailwindcss.com/docs/configuring-variants on the TailwindCSS docs for more info.
As a reference, your tailwind.config.js may look like this:
module.exports = {
variants: {
extend: {
opacity: ['disabled'],
cursor: ['disabled'],
},
},
plugins: [
require('@tailwindcss/forms'),
],
};import Vue from 'vue'
import VueTailwind from 'vue-tailwind'
const components = {
// ...You need to add the components you need here (explained above)
}
Vue.use(VueTailwind, components)…import Vue from 'vue'
// Notice that I am using a different path here:
import VueTailwind from 'vue-tailwind/dist/full'
const settings = {
TInput: {
classes: 'border-2 block w-full rounded text-gray-800',
// ...More settings
},
TButton: {
classes: 'rounded-lg border block inline-flex items-center justify-center',
// ...More settings
},
// ...Rest of the components
}
Vue.use(VueTailwind, settings)…Note: Using the syntax from point 3.3 is the best way to prevent a big bundle size but only if you import a couple of components. If the number of components you install increases, the recommended way to install them is to use the syntax from the points 3.1 or 3.2 to help the library reuse some code and keep the bundle size at a minimum.
To apply a custom theme you should play with the classes, fixedClasses, and variants props.
The classes and fixedClasses props usually expects an string with a CSS class for single-tag components (inputs, button, etc.) and an object for more complex components (modals, datepicker, etc) (see component docs for details).
The variants props expects an object where every key represents the variant name and every value the classes that will be used when that variant is applied.
……All the components on this library have default settings added as component props according to how we understand those settings are most commonly used.
I am aware that in many cases is useful to change the default value, so you don't need to add the prop over and over when needed.
…You can also use this feature to create different versions of the same component.
…Once your different variants were defined you can use the variant prop to define which variant should be applied:
<t-input variant="error" />The variant prop also accepts an object that takes the first attribute with a truthy value
<t-input
:variant="{
error: inputIsNotValid,
success: inputIsValid,
}"
/>Is this project helpful for you? Consider sponsoring me https://github.com/sponsors/alfonsobries.
Of course, any other kind help is welcome, even if you notice some grammar mistakes (English is not my primary language) see contribute page for details.
Please see Release notes for more information about what was changed recently.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Made with love by @alfonsobries
No open issues yet, or sync has not completed.