Skip to content

Commit

Permalink
Update the theme merge function to accept and overide the font-family
Browse files Browse the repository at this point in the history
  • Loading branch information
sajadevo committed Mar 18, 2022
1 parent 8ba451d commit 53279a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 49 deletions.
34 changes: 10 additions & 24 deletions packages/material-tailwind-html/utils/withMT.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { alert } = require("../theme/components/alert");

const materialTailwindConfig = {
darkMode: "class",
content: [],
content: ["hello"],
theme: {
colors,
fontFamily: typography,
Expand All @@ -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;
30 changes: 9 additions & 21 deletions packages/material-tailwind-react/src/utils/withMT.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export default function Home() {
<button className="button button-text button-pink" data-ripple-dark>
Button
</button>
<h2 className="font-sans shadow-md">Hello World</h2>
<h2 className="shadow-md">Hello World</h2>

<div className="alert alert-gradient alert-brown">Alert primary</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = withMT({
500: "#ff4444"
}
},
fontFamily: {
sans: ["Roboto Slab", "sans-serif"]
},
extend: {}
},
plugins: []
Expand Down

0 comments on commit 53279a9

Please sign in to comment.