Skip to content

Commit a683b48

Browse files
committed
feat(theme): 🎨 add useTailwind hook to create short hand for tailwind functions
1 parent 510d203 commit a683b48

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/theme/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function useTheme<T extends ThemeKeys>(
4848
return context;
4949
}
5050

51-
type TWType = typeof tw;
51+
export type TWType = typeof tw;
5252

5353
const AdaptUIProvider: React.FC<
5454
Partial<ThemeContextType & { children: React.ReactNode }>

src/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./context";
2+
export * from "./useTailwind";

src/theme/useTailwind.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { TWType, useTheme } from "./context";
2+
3+
type TailwindFunctions = {
4+
/**
5+
* ts is a function that takes any number of string/CSS classnames
6+
* as arguments and returns a Style object.
7+
*/
8+
ts: TWType["style"];
9+
/**
10+
* `gc` is a function that takes a Tailwind Color Classname
11+
* and returns the Hexcode.
12+
*/
13+
gc: TWType["color"];
14+
sc: TWType["setColorScheme"];
15+
};
16+
17+
export const useTailwind = (): TailwindFunctions => {
18+
const tailwind = useTheme();
19+
return {
20+
ts: tailwind.style,
21+
gc: tailwind.getColor,
22+
sc: tailwind.setColorScheme,
23+
};
24+
};

0 commit comments

Comments
 (0)