nextui-org / tailwind-variants

🦄 Tailwindcss first-class variant API
https://tailwind-variants.org
MIT License
2.42k stars 68 forks source link

Feature: edit default configuration #95

Closed wilsonlewis closed 1 year ago

wilsonlewis commented 1 year ago

Would like the ability to edit the default config:

type TvConfig = {
  twMerge?: boolean,
  twMergeConfig?:TwMergeConfig,
  responsiveVariants?: string[] | boolean
}

Mostly just want to turn off twMerge by default

You could do it one of two ways:

import { globalConfig } from 'tailwind-variants'

globalConfig({
  twMerge: false
})

...

or

import { createTV } from 'tailwind-variants'

const tv = createTV({
  twMerge: false
})

const button = tv({
  ...
})

...
adonaicandido commented 1 year ago

Have you found a way to do this?

mskelton commented 1 year ago

You can modify the defaultConfig variable.

import { defaultConfig } from 'tailwind-variants'
defaultConfig.twMerge = false
adonaicandido commented 1 year ago

Awkward API but ok. Thanks a bunch.

jrgarciadev commented 1 year ago

Hey @adonaicandido another way is to create your own instance of tailwind-variants without twMerge

Example:

import {tv as tvBase, TV} from "tailwind-variants";

export const tv: TV = (options, config) =>
  tvBase(options, {
    ...config,
    twMerge: false,
    twMergeConfig: {
      ...config?.twMergeConfig,
    },
 });

// button.tsx
import {tv} from "./your-tv-file.ts"

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",
  }
});
mskelton commented 1 year ago

The new createTV function is released and the new config docs are published!

https://www.tailwind-variants.org/docs/config