Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

feat(FontWeight): Add Font Weight to Tailwind Config #77

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/formatters/tailwind/buildTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ const getFontSize = ({ tokens }) => {
return fonts;
};

const getFontWeight = ({ tokens }) => {
const matchingWeightTokens = tokens.filter(
(token) =>
token.attributes.category === "font" &&
token.attributes.type === "weight" &&
token.filePath.includes("alias")
);

const matchingWeightNameTokens = tokens.filter(
(token) =>
token.attributes.category === "font" &&
token.attributes.type === "name" &&
token.filePath.includes("alias")
);

return matchingWeightNameTokens.reduce((acc, cur) => {
const key = cur.name.replace("-weight", "").replace("-name", "");
const { value } = matchingWeightTokens.find(
(token) => token.name === cur.name.replace("-name", "-number")
);

return { ...acc, [key]: `${value}` };
}, {});
};

const getColors = ({ tokens }) => {
const matchingTokens = tokens.filter(
(token) =>
Expand Down Expand Up @@ -93,6 +118,7 @@ const getTheme = (dictionary) => {
token.attributes.category === "font" &&
token.attributes.type === "family",
}),
fontWeight: getFontWeight({ tokens }),
boxShadow: getObject({
remove: "shadow",
tokens,
Expand Down
2 changes: 1 addition & 1 deletion tokens/alias.code.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
"family-stack" : { value: ["{code.family.value}", "Courier", "monospace"], attributes: { category: "font", type: 'family' } },
// Weights
"weight-name" : { value: "{font.menlo-regular-weight-name.value}", attributes: { category: 'font', type: 'name' } },
"weight-number" : { value: "{font.menlo-regular-weight-name.value}", attributes: { category: 'font', type: 'weight' } },
"weight-number" : { value: "{font.menlo-regular-weight-number.value}", attributes: { category: 'font', type: 'weight' } },
"weight-strong-name" : { value: "{font.menlo-bold-weight-name.value}", attributes: { category: 'font', type: 'name' } },
"weight-strong-number" : { value: "{font.menlo-bold-weight-number.value}", attributes: { category: 'font', type: 'weight' } },
// Small Size
Expand Down