Skip to content

Commit

Permalink
Tailwind shadows plugin inherits colors from config
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rich committed Aug 24, 2024
1 parent 40d887f commit 167fbab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-peaches-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@d0rich/esprit-design': patch
---

Tailwind shadows plugin inherits colors from config
22 changes: 13 additions & 9 deletions packages/esprit-design/plugins/shadows.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ function generateDirections() {
return result
}

function generateColors() {
function generateColors(themeColors) {
const result = {}
for (const colorKey in colors) {
const localColors = {
...colors,
...themeColors
}
for (const colorKey in localColors) {
if (
[
'inherit',
Expand All @@ -63,25 +67,25 @@ function generateColors() {
) {
continue
}
if (typeof colors[colorKey] === 'string') {
if (typeof localColors[colorKey] === 'string') {
result[`.ss-${colorKey}`] = {
[COLOR_VAR]: colors[colorKey]
[COLOR_VAR]: localColors[colorKey]
}
} else if (typeof colors[colorKey] === 'object') {
for (const colorVariantKey in colors[colorKey]) {
} else if (typeof localColors[colorKey] === 'object') {
for (const colorVariantKey in localColors[colorKey]) {
result[`.ss-${colorKey}-${colorVariantKey}`] = {
[COLOR_VAR]: colors[colorKey][colorVariantKey]
[COLOR_VAR]: localColors[colorKey][colorVariantKey]
}
}
}
}
return result
}

module.exports = plugin(function ({ addUtilities }) {
module.exports = plugin(function ({ addUtilities, config }) {
addUtilities({
'.sharp-shadow': defaultStyle,
...generateDirections(),
...generateColors()
...generateColors(config().theme.colors)
})
})

0 comments on commit 167fbab

Please sign in to comment.