Code Monkey home page Code Monkey logo

classname-variants's People

Contributors

fgnass avatar jamesopstad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

classname-variants's Issues

How do I use it `tailwind-merge`?

Hi, awesome library. Thanks! Just would like to know if it's possible to use it together with tailwind-merge so I can override classes if necessary.

Support for `as` prop

It would be useful to have support for as props. For example, for this component:

export const SquareButton = styled('button', {
  base: '',
  variants: {
    size: {
      xs: '',
    },
  },
});

It would be cool if we could do <SquareButton as="a" size="xs" /> similar to StyledComponents

responsive variants

good day, is there a way we can have responsive variants like this?

<Button
    color={{
      '@initial': 'gray',
      '@bp1': 'violet',
    }}
  >
    Button
  </Button>

Conditional logic

Would it be possible to add conditional logic such as AND, OR and NOT?

For example, I would like to only apply padding if the variant is NOT a link:

NOT:

{
    variants: {
        size: 'sm',
        variant: not('link')
    },
    className: 'xxx'
},

Other conditional examples

AND:

{
    variants: {
        size: 'sm',
        variant: and('link', 'solid', 'subtle')
    },
    className: 'xxx'
},

OR:

{
    variants: {
        size: 'sm',
        variant: or('link', 'solid', 'subtle')
    },
    className: 'xxx'
},

Compound Variants in React

I'm not able to have multiple variants work within the compoundVariants array. The only way I am able to get this to work is throwing an important tag on the bg-transparent which I'd like to avoid doing.

Here's my code you can throw into a sandbox.

import { variantProps } from "classname-variants/react";

const buttonProps = variantProps({
base: "flex flex-row justify-center items-center text-center text-white py-1 px-3 rounded-md font-medium text-xs min-h-[1.875rem] w-fit",
variants: {
color: {
primary: "bg-violet-500",
positive: "bg-green-600",
warning: "bg-orange-500",
negative: "bg-red-500"
},
outlined: {
true: "border bg-transparent"
}
},
compoundVariants: [
{
variants: { color: "primary", outlined: true },
className: "text-violet-500 border-violet-500"
},
{
variants: { color: "positive", outlined: true },
className: "text-green-600 border-green-600"
},
{
variants: { color: "warning", outlined: true },
className: "text-orange-500 border-orange-500"
},
{
variants: { color: "negative", outlined: true },
className: "text-red-500 border-red-500"
}
],
defaultVariants: {
color: "positive"
}
});

const Button = ({ color, outlined, children }) => {
return <div {...buttonProps({ outlined, color })}>{children}</div>;
};

export default function App() {
return (
<div className="flex items-center gap-2 p-4">
<Button color="primary" outlined>
Click Me!
</Button>
<Button color="positive" outlined>
Click Me!
</Button>
<Button color="warning" outlined>
Click Me!
</Button>
<Button color="warning">
Click Me!
</Button>
</div>
);
}

Next build failed `Type error; '?' expected` from react.d.ts

Hi, i tried to build my nextjs project (through next build) but I get this error:

./node_modules/classname-variants/lib/react.d.ts:20:281
Type error: '?' expected.

  18 | };
  19 | declare type PolymorphicComponentProps<T extends ElementType> = AsProps<T> & Omit<ComponentProps<T>, "as">;
> 20 | export declare function styled<T extends ElementType, C extends VariantsConfig<V>, V extends Variants = C["variants"]>(type: T, config: string | Simplify<C>): <As extends ElementType<any> = T>(props: AsProps<As> & Omit<ComponentProps<As>, "as"> & (C["variants"] extends infer T_1 extends Variants ? { [K in keyof T_1 as K extends keyof (C["variants"] extends infer T_2 extends Variants ? { [K_1 in keyof T_2 as C["variants"][K_1] extends {
     |                                                                                                                                                                                                                                                                                         ^
  21 |     true: any;
  22 | } | {
  23 |     false: any;

Any tips to manage that @fgnass?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.