From 2235ae9851170cd8f12e6f5f941ecf9b7fbe8777 Mon Sep 17 00:00:00 2001 From: sid <35936587+siddharth-shringarpure@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:40:04 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Modified=20config=20files=20for=20A?= =?UTF-8?q?ceternity.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 12 +++++++++--- package.json | 3 ++- tailwind.config.ts | 46 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index ea562bf..1735469 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "next": "14.2.13", "react": "^18.3.1", "react-dom": "^18.3.1", - "tailwind-merge": "^2.5.2", + "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7" }, "devDependencies": { @@ -39,6 +39,7 @@ "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "@types/tailwindcss": "^3.0.11", "chai": "^4.2.0", "eslint": "^8", "eslint-config-next": "14.2.13", @@ -7461,6 +7462,13 @@ "license": "MIT", "peer": true }, + "node_modules/@types/tailwindcss": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/@types/tailwindcss/-/tailwindcss-3.0.11.tgz", + "integrity": "sha512-PR+BOIrI+rxteHwFvkfIOty+PDJwTG4ute3alxSSXpF/xKpryO1room265m46Auyae0VwqUYs3PuVEOF9Oil3w==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/yargs": { "version": "17.0.33", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz", @@ -13016,7 +13024,6 @@ "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.5.tgz", "integrity": "sha512-HTm14iMQKK2FjFLRTM5lAVcyaUzOnqbPtesFIvREgXpJHdQm8bWS+GkQgIkfaBYRHuCnea7w8UVNfwiAQhlr9A==", "dev": true, - "hasInstallScript": true, "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" @@ -13379,7 +13386,6 @@ "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.7.tgz", "integrity": "sha512-vLt1O5Pp+flcArHGIyKEQq883nBt8nN8tVBcoL0qUXj2XT1n7p70yGIq2VK98I5FdZ1YHc0wk/koOnHjnXWk1Q==", "dev": true, - "hasInstallScript": true, "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" diff --git a/package.json b/package.json index 74f4bca..54c4813 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "next": "14.2.13", "react": "^18.3.1", "react-dom": "^18.3.1", - "tailwind-merge": "^2.5.2", + "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7" }, "devDependencies": { @@ -43,6 +43,7 @@ "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "@types/tailwindcss": "^3.0.11", "chai": "^4.2.0", "eslint": "^8", "eslint-config-next": "14.2.13", diff --git a/tailwind.config.ts b/tailwind.config.ts index 5ea29e2..01d6ddf 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -1,4 +1,10 @@ import type { Config } from 'tailwindcss'; +import tailwindcssAnimate from 'tailwindcss-animate'; + +type ColorValue = string | ColorDictionary; +interface ColorDictionary { + [colorName: string]: ColorValue; +} const config: Config = { darkMode: ['class'], @@ -68,6 +74,44 @@ const config: Config = { }, }, }, - plugins: [require('tailwindcss-animate')], + plugins: [tailwindcssAnimate, addVariablesForColors], }; + export default config; + +// Plugin to add each Tailwind color as a CSS variable +function addVariablesForColors({ + addBase, + theme, +}: { + addBase: (styles: Record>) => void; + theme: (path: string) => unknown; +}) { + const colors = theme('colors') as ColorDictionary; + const flattenedColors = flattenColors(colors); + const newVars = Object.fromEntries( + Object.entries(flattenedColors).map(([key, val]) => [`--${key}`, val]) + ); + + addBase({ + ':root': newVars, + }); +} + +// Recursive function to flatten nested color objects +function flattenColors( + colors: ColorDictionary, + prefix = '' +): Record { + const result: Record = {}; + for (const [key, value] of Object.entries(colors)) { + if (typeof value === 'string') { + // If the value is a string, add it to the result + result[prefix + key] = value; + } else if (typeof value === 'object' && value !== null) { + // If the value is an object, recursively flatten it + Object.assign(result, flattenColors(value, `${prefix}${key}-`)); + } + } + return result; +}