Skip to content

Instantly share code, notes, and snippets.

@yuheiy
Last active May 26, 2022 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuheiy/f9165ad3e51acf4843ee1602c7ee06cf to your computer and use it in GitHub Desktop.
Save yuheiy/f9165ad3e51acf4843ee1602c7ee06cf to your computer and use it in GitHub Desktop.
const plugin = require("tailwindcss/plugin");
const fontFeature = plugin(function () {
const tags = {
locl: 1,
palt: 0,
};
const cssFontFeatureSettingsValue = Object.keys(tags)
.map((tag) => `"${tag}" var(--tw-${tag})`)
.join(", ");
const defaults = {};
for (const [key, value] of Object.entries(tags)) {
defaults[`--tw-${key}`] = value.toString();
}
const utilities = {};
for (const tag of Object.keys(tags)) {
utilities[`.${tag}`] = {
"@defaults font-feature-settings": {},
[`--tw-${tag}`]: "1",
"font-feature-settings": cssFontFeatureSettingsValue,
};
utilities[`.not-${tag}`] = {
"@defaults font-feature-settings": {},
[`--tw-${tag}`]: "0",
"font-feature-settings": cssFontFeatureSettingsValue,
};
}
return function ({ addDefaults, addUtilities }) {
addDefaults("font-feature-settings", defaults);
addUtilities(utilities);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment