From 53279a9a357116f0326adff9b763f0d3c7efa23a Mon Sep 17 00:00:00 2001 From: sajadevo Date: Fri, 18 Mar 2022 14:21:41 +0430 Subject: [PATCH] Update the theme merge function to accept and overide the font-family --- .../material-tailwind-html/utils/withMT.js | 34 ++++++------------- .../src/utils/withMT.js | 30 +++++----------- pages/index.js | 2 +- tailwind.config.js | 3 -- 4 files changed, 20 insertions(+), 49 deletions(-) diff --git a/packages/material-tailwind-html/utils/withMT.js b/packages/material-tailwind-html/utils/withMT.js index 7dde5701a..d7b7248cc 100644 --- a/packages/material-tailwind-html/utils/withMT.js +++ b/packages/material-tailwind-html/utils/withMT.js @@ -14,7 +14,7 @@ const { alert } = require("../theme/components/alert"); const materialTailwindConfig = { darkMode: "class", - content: [], + content: ["hello"], theme: { colors, fontFamily: typography, @@ -28,37 +28,23 @@ const materialTailwindConfig = { ] }; -function arrayMerge(destinationArray, sourceArray) { - return destinationArray.concat(sourceArray).reduce((acc, cur) => { - if (acc.includes(cur)) return acc; - return [...acc, cur]; - }, []); -} - /** * Merge @material-tailwind and Tailwind CSS configurations * @param {object} tailwindConfig - Tailwind config object * @return {object} new config object */ function withTM(tailwindConfig) { - let purge; - if (Array.isArray(tailwindConfig.purge)) { - purge = { - content: tailwindConfig.purge - }; - } else { - purge = tailwindConfig.purge; - } + const themeFont = materialTailwindConfig.theme.fontFamily; - console.log(materialTailwindConfig); + if (tailwindConfig.theme.fontFamily) { + const { sans, serif, body } = tailwindConfig.theme.fontFamily; + + themeFont.sans = sans || themeFont.sans; + themeFont.serif = serif || themeFont.serif; + themeFont.body = body || themeFont.body; + } - return merge( - materialTailwindConfig, - { ...tailwindConfig, purge }, - { - arrayMerge - } - ); + return merge(materialTailwindConfig, { ...tailwindConfig }); } module.exports = withTM; diff --git a/packages/material-tailwind-react/src/utils/withMT.js b/packages/material-tailwind-react/src/utils/withMT.js index 9af35e48c..432498ab6 100644 --- a/packages/material-tailwind-react/src/utils/withMT.js +++ b/packages/material-tailwind-react/src/utils/withMT.js @@ -21,35 +21,23 @@ const materialTailwindConfig = { plugins: [], }; -function arrayMerge(destinationArray, sourceArray) { - return destinationArray.concat(sourceArray).reduce((acc, cur) => { - if (acc.includes(cur)) return acc; - return [...acc, cur]; - }, []); -} - /** * Merge @material-tailwind and Tailwind CSS configurations * @param {object} tailwindConfig - Tailwind config object * @return {object} new config object */ function withTM(tailwindConfig) { - let purge; - if (Array.isArray(tailwindConfig.purge)) { - purge = { - content: tailwindConfig.purge, - }; - } else { - purge = tailwindConfig.purge; + const themeFont = materialTailwindConfig.theme.fontFamily; + + if (tailwindConfig.theme.fontFamily) { + const { sans, serif, body } = tailwindConfig.theme.fontFamily; + + themeFont.sans = sans || themeFont.sans; + themeFont.serif = serif || themeFont.serif; + themeFont.body = body || themeFont.body; } - return merge( - materialTailwindConfig, - { ...tailwindConfig, purge }, - { - arrayMerge, - }, - ); + return merge(materialTailwindConfig, { ...tailwindConfig }); } module.exports = withTM; diff --git a/pages/index.js b/pages/index.js index ae81e6811..cb91870f1 100644 --- a/pages/index.js +++ b/pages/index.js @@ -226,7 +226,7 @@ export default function Home() { -

Hello World

+

Hello World

Alert primary
diff --git a/tailwind.config.js b/tailwind.config.js index a8773cfc1..3371d7b2f 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -11,9 +11,6 @@ module.exports = withMT({ 500: "#ff4444" } }, - fontFamily: { - sans: ["Roboto Slab", "sans-serif"] - }, extend: {} }, plugins: []