From 5d4e8f4cf6a1f595d8b8c89d5c367e797fdbbd4e Mon Sep 17 00:00:00 2001 From: florent giraud Date: Wed, 25 Sep 2024 12:12:53 -0400 Subject: [PATCH 1/3] feat(props): add class props property on side with className --- packages/core/src/tailwind-buddy.ts | 6 ++++++ packages/core/src/types/props.ts | 1 + packages/core/tests/setup/specific.ts | 2 +- packages/ui/src/components/Button/Button.tsx | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/src/tailwind-buddy.ts b/packages/core/src/tailwind-buddy.ts index cfeeb52..284406e 100644 --- a/packages/core/src/tailwind-buddy.ts +++ b/packages/core/src/tailwind-buddy.ts @@ -203,6 +203,12 @@ export const setupCompose = ( .forEach((cls) => classSet.add(cls)); } + if (props?.class) { + cleanString(props.class) + .split(" ") + .forEach((cls) => classSet.add(cls)); + } + const result = mergeClasses(uniquifyClasses(Array.from(classSet))); variantCache.set(cacheKey, result); return result; diff --git a/packages/core/src/types/props.ts b/packages/core/src/types/props.ts index 6e3fa65..27a5b8c 100644 --- a/packages/core/src/types/props.ts +++ b/packages/core/src/types/props.ts @@ -7,6 +7,7 @@ export type MergedProps< R extends ResponsiveVariants > = { className?: string; + class?: string; } & { [K in keyof V]?: R extends undefined ? keyof V[K] diff --git a/packages/core/tests/setup/specific.ts b/packages/core/tests/setup/specific.ts index 2c4d5f7..ef56341 100644 --- a/packages/core/tests/setup/specific.ts +++ b/packages/core/tests/setup/specific.ts @@ -78,4 +78,4 @@ export const labelVariants = compose({ class: ["opacity-200"], }, ], -})(); +})(); diff --git a/packages/ui/src/components/Button/Button.tsx b/packages/ui/src/components/Button/Button.tsx index 4e465f9..9dfb078 100644 --- a/packages/ui/src/components/Button/Button.tsx +++ b/packages/ui/src/components/Button/Button.tsx @@ -33,7 +33,7 @@ export const Button: React.FC = ({ diff --git a/packages/documentation/pages/slots.md b/packages/documentation/pages/slots.md index 67a49f2..cd9eecf 100644 --- a/packages/documentation/pages/slots.md +++ b/packages/documentation/pages/slots.md @@ -38,9 +38,9 @@ export const Card = () => { const { root, header, body } = cardVariants; return ( -
-
header
-
body
+
+
header
+
body
); }; diff --git a/packages/documentation/pages/usage.md b/packages/documentation/pages/usage.md index 45cd7ac..cc6003d 100644 --- a/packages/documentation/pages/usage.md +++ b/packages/documentation/pages/usage.md @@ -54,16 +54,15 @@ export const Button: React.FC> = ({ return ( {children} diff --git a/packages/ui/src/components/Dumb.tsx b/packages/ui/src/components/Dumb.tsx index bff7bed..b3acde4 100644 --- a/packages/ui/src/components/Dumb.tsx +++ b/packages/ui/src/components/Dumb.tsx @@ -1,6 +1,5 @@ import { compose } from "../tailwind-buddy-interface"; import React from "react"; -import { twMerge } from "tailwind-merge"; export const fooVariants = compose({ slots: { @@ -33,5 +32,5 @@ export const fooVariants = compose({ export const Dumb: React.FC = () => { const { root } = fooVariants; - return
Hello
; + return
Hello
; }; From 28d12dd7560e1af65e3a1e10de1d7888a268bae0 Mon Sep 17 00:00:00 2001 From: florent giraud Date: Wed, 25 Sep 2024 12:22:39 -0400 Subject: [PATCH 3/3] feat(props): add class props property on side with className --- packages/documentation/.gitignore | 1 + packages/documentation/pages/responsive-variants.md | 1 - packages/documentation/pages/usage.md | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 packages/documentation/.gitignore diff --git a/packages/documentation/.gitignore b/packages/documentation/.gitignore new file mode 100644 index 0000000..6dc972e --- /dev/null +++ b/packages/documentation/.gitignore @@ -0,0 +1 @@ +.vitepress/cache \ No newline at end of file diff --git a/packages/documentation/pages/responsive-variants.md b/packages/documentation/pages/responsive-variants.md index f13fe3b..91559ce 100644 --- a/packages/documentation/pages/responsive-variants.md +++ b/packages/documentation/pages/responsive-variants.md @@ -20,7 +20,6 @@ export const buttonVariants = compose({ })(); // Usage in a React component -import { twMerge } from "tailwind-merge"; // class .font-bold will be applied as the condition is fulfilled. export const Button: React.FC<{}> = () => { diff --git a/packages/documentation/pages/usage.md b/packages/documentation/pages/usage.md index cc6003d..45f2221 100644 --- a/packages/documentation/pages/usage.md +++ b/packages/documentation/pages/usage.md @@ -40,7 +40,6 @@ export const buttonVariants = compose({ export type ButtonProps = VariantsProps; // Usage in a React component -import { twMerge } from "tailwind-merge"; export const Button: React.FC> = ({ as: Component = "button",