forked from tomphill/twcss-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const plugin = require("tailwindcss/plugin"); | ||
const { default: lightOrDarkColor } = require("@check-light-or-dark/color"); | ||
|
||
const buttonPlugin = plugin(function ({ | ||
addComponents, | ||
matchComponents, | ||
theme, | ||
}) { | ||
console.log(theme("spacing")["0.5"]); | ||
addComponents({ | ||
".btn": { | ||
display: "inline-block", | ||
cursor: "pointer", | ||
fontWeight: "bold", | ||
padding: `${theme("spacing.2")} ${theme("spacing.4")}`, | ||
borderRadius: theme("borderRadius").lg, | ||
}, | ||
}); | ||
|
||
console.log(theme("colors")); | ||
for (let key in theme("colors")) { | ||
if (typeof theme("colors")[key] !== "string") { | ||
for (let shade in theme("colors")[key]) { | ||
const colorType = lightOrDarkColor(theme("colors")[key][shade]); | ||
addComponents({ | ||
[`.btn-${key}-${shade}`]: { | ||
backgroundColor: theme("colors")[key][shade], | ||
color: colorType === "dark" ? "white" : "black", | ||
}, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
matchComponents({ | ||
btn: (value) => { | ||
return { | ||
backgroundColor: value, | ||
color: lightOrDarkColor(value) === "dark" ? "white" : "black", | ||
}; | ||
}, | ||
}); | ||
}); | ||
|
||
module.exports = buttonPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters