0.2.1 • Published 1 year ago

tailwind-variants v0.2.1

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

Features

  • First-class variant API
  • Responsive variants
  • Slots support
  • Composition support
  • Fully typed
  • Framework agnostic
  • Automatic conflict resolution

Documentation

For full documentation, visit tailwind-variants.org

Quick Start

  1. Installation: To use Tailwind Variants in your project, you can install it as a dependency:
yarn add tailwind-variants
# or
npm i tailwind-variants
  1. Usage:
import { tv } from 'tailwind-variants';
 
const button = tv({
  base: "font-medium bg-blue-500 text-white rounded-full active:opacity-80",
  variants: {
    color: {
      primary: "bg-blue-500 text-white",
      secondary: "bg-purple-500 text-white",
    },
    size: {
      sm: "text-sm",
      md: "text-base",
      lg: "px-4 py-3 text-lg",
    },
  },
  compoundVariants: [
    {
      size: ["sm", "md"],
      class: "px-3 py-1",
    },
  ],
  defaultVariants: {
    size: "md",
    color: "primary",
  }
});
 
return (
  <button className={button({ size: 'sm', color: 'secondary' })}>Click me</button>
)
  1. Responsive variants configuration (optional): If you want to use responsive variants you need to add the Tailwind Variants wrapper to your TailwindCSS config file tailwind.config.js.
// tailwind.config.js
 
const { withTV } = require('tailwind-variants/transformer')

/** @type {import('tailwindcss').Config} */
module.exports = withTV({
  content:  ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
  theme: {
    extend: {},
  },
  plugins: [],
})

If you're using a custom path to import Tailwind variants, such as creating a custom tv instance with createTV, it's recommended to include this path in the transformer configuration:

// tailwind.config.js

const { withTV } = require('tailwind-variants/transformer')

/** @type {import('tailwindcss').Config} */
module.exports = withTV({
  content:  ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
  theme: {
    extend: {},
  },
  plugins: [],
}, {
  aliases: ["@/lib/tv"]
})

Acknowledgements

  • cva (Joe Bell) This project as started as an extension of Joe's work on cva – a great tool for generating variants for a single element with Tailwind CSS. Big shoutout to Joe Bell and contributors you guys rock! 🤘 - we recommend to use cva if don't need any of the Tailwind Variants features listed here.

  • Stitches (Modulz)
    The pioneers of the variants API movement. Inmense thanks to Modulz for their work on Stitches and the community around it. 🙏

Community

We're excited to see the community adopt NextUI, raise issues, and provide feedback. Whether it's a feature request, bug report, or a project to showcase, please get involved!

Contributing

Contributions are always welcome!

Please follow our contributing guidelines.

Please adhere to this project's CODE_OF_CONDUCT.

Authors

License

Licensed under the MIT License.

See LICENSE for more information.

@namcchan/theme@thisisclicktest/ktnext-microsite-reactsxtd-ui-theme@everything-registry/sub-chunk-2874@universekit/themessrmg-ui-component-library-testtiox-ds@anrivera/component-library-packagetw-material3-react@angular-neo/elementsbwsoft-ui-components@typeweave/theme@zoobzio/foundation@zoobzio/uitailwind-variants-issuetera-system-uisvltktsvolwhitenose-projecttechno-chat-aitechno-chat-ai-assistanttechnoverce-chat-ai-assistantstokit-dsteste-ex-libsvelte-5-ui-libthick3-uivite-build-issuevody-corevitepress-theme-snowawal-ui@codefast/ui@cryptotea/lvsteaone@dinhvdk/testsdk@dinui/react@dashx/react@deeptrekker/react@deepnoid/ui@bwsoft/alert@rosnga/theme@rdsaude/pulso-react-components@root-sphere/root-ui@teacoder/ui@webstudiou/uijobseeker-ui-devionia-uishared-library-ipc-8@annui/theme@aisvoo/ui@ozguruysal/spectre@kkoms/themewire-ui@kcngg/nexus@saanaa-ui/themeoss-translator@bwsoft/composition-accordion@nivovideo/uitawuniya-js@marketplace-ui/core@marketplace-ui/hooksfoom-uifarsoft-uifarsoft-ui-test@esaconn/form-components@mojaui/reactmockline-edgemojauistlato-uitwrnc-componentstw-variants-themetnext-hanta-core-componentstribe-react-componenttremor-react-ariatoiled@air/tailwind-variants@arisbh/coulisse@anjun-express/styles@anjun-express/react-accordion@anjun-express/react-alert-dialog@anjun-express/react-avatar@anjun-express/react-breadcrumb@anjun-express/react-button@anjun-express/react-calendar@anjun-express/react-card@anjun-express/react-checkbox@anjun-express/react-combobox@anjun-express/react-command@anjun-express/react-date-picker@anjun-express/react-dialog@anjun-express/react-drawer@anjun-express/react-dropdown-menu@anjun-express/react-dropzone@anjun-express/react-form@anjun-express/react-icons@anjun-express/react-label@anjun-express/react-navigation-menu@anjun-express/react-popover@anjun-express/react-scroll-area@anjun-express/react-select@anjun-express/react-separator@anjun-express/react-skeleton
0.2.1

1 year ago

0.2.0

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.15

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.6

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.17-dev.1

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.0.3

2 years ago

0.1.1

2 years ago

0.0.2

2 years ago

0.0.26

2 years ago

0.0.9

2 years ago

0.0.27

2 years ago

0.0.8

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.1.4

2 years ago

0.0.5

2 years ago

0.1.3

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.1.5

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago