Skip to content

Commit 6d1f252

Browse files
committed
refactor: extract exported tailwind config
1 parent 655433c commit 6d1f252

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/lib/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { AppProps } from "next/app"
44
import type { StaticImageData } from "next/image"
55
import type { SSRConfig } from "next-i18next"
66
import type { ReactElement, ReactNode } from "react"
7-
import resolveConfig from "tailwindcss/resolveConfig"
87
import type { Icon } from "@chakra-ui/react"
98

109
import type {
@@ -26,8 +25,8 @@ import allQuestionData from "@/data/quizzes/questionBank"
2625

2726
import { WALLETS_FILTERS_DEFAULT } from "./constants"
2827

29-
import tailwindConfig from "@/../tailwind.config"
3028
import { layoutMapping } from "@/pages/[...slug]"
29+
import twConfig from "@/styles/config"
3130

3231
// Credit: https://stackoverflow.com/a/52331580
3332
export type Unpacked<T> = T extends (infer U)[] ? U : T
@@ -829,6 +828,4 @@ export type EventCardProps = {
829828
imageUrl?: string
830829
}
831830

832-
const twConfig = resolveConfig(tailwindConfig)
833-
834831
export type BreakpointKey = keyof typeof twConfig.theme.screens

src/lib/utils/screen.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import resolveConfig from "tailwindcss/resolveConfig"
2-
31
import type { BreakpointKey } from "../types"
42

5-
import tailwindConfig from "@/../tailwind.config"
6-
7-
const fullConfig = resolveConfig(tailwindConfig)
3+
import twConfig from "@/styles/config"
84

9-
export const breakpointAsNumber = Object.entries(
10-
fullConfig.theme.screens
11-
).reduce((acc, curr) => {
12-
const [breakpoint, value] = curr
13-
acc[breakpoint] = +value.split("px")[0]
14-
return acc
15-
}, {}) as Record<BreakpointKey, number>
5+
export const breakpointAsNumber = Object.entries(twConfig.theme.screens).reduce(
6+
(acc, curr) => {
7+
const [breakpoint, value] = curr
8+
acc[breakpoint] = +value.split("px")[0]
9+
return acc
10+
},
11+
{}
12+
) as Record<BreakpointKey, number>

src/styles/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import resolveConfig from "tailwindcss/resolveConfig"
2+
3+
import tailwindConfig from "../../tailwind.config"
4+
5+
const config = resolveConfig(tailwindConfig)
6+
7+
export default config

0 commit comments

Comments
 (0)