Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add drop-shadow-* color support
  • Loading branch information
thecrypticace committed Mar 28, 2025
commit 0e7970a0d6a186c3171362ded3c04c042c388dd4
169 changes: 157 additions & 12 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3921,6 +3921,9 @@ export function createUtilities(theme: Theme) {
property('--tw-saturate'),
property('--tw-sepia'),
property('--tw-drop-shadow'),
property('--tw-drop-shadow-color'),
property('--tw-drop-shadow-alpha', '100%', '<percentage>'),
property('--tw-drop-shadow-size'),
])
}

Expand Down Expand Up @@ -4313,20 +4316,162 @@ export function createUtilities(theme: Theme) {
['--tw-drop-shadow', ' '],
['filter', cssFilterValue],
])
functionalUtility('drop-shadow', {
themeKeys: ['--drop-shadow'],
handle: (value) => [
filterProperties(),
decl(
'--tw-drop-shadow',
segment(value, ',')
.map((v) => `drop-shadow(${v})`)
.join(' '),
),
decl('filter', cssFilterValue),
],

utilities.functional('drop-shadow', (candidate) => {
let alpha: string | undefined

if (candidate.modifier) {
if (candidate.modifier.kind === 'arbitrary') {
alpha = candidate.modifier.value
} else {
if (isPositiveInteger(candidate.modifier.value)) {
alpha = `${candidate.modifier.value}%`
}
}
}

if (!candidate.value) {
let value = theme.get(['--drop-shadow'])
if (value === null) return

return [
filterProperties(),
decl('--tw-drop-shadow-alpha', alpha),
decl(
'--tw-drop-shadow-size',
segment(value, ',')
.map(
(v) =>
`drop-shadow(${replaceShadowColors(
v,
alpha,
(color) => `var(--tw-drop-shadow-color, ${color})`,
)})`,
)
.join(' '),
),
decl('--tw-drop-shadow', `drop-shadow(${theme.resolve(null, ['--drop-shadow'])})`),
decl('filter', cssFilterValue),
]
}

if (candidate.value.kind === 'arbitrary') {
let value: string | null = candidate.value.value
let type = candidate.value.dataType ?? inferDataType(value, ['color'])

switch (type) {
case 'color': {
value = asColor(value, candidate.modifier, theme)
if (value === null) return
return [
filterProperties(),
decl('--tw-drop-shadow-color', withAlpha(value, 'var(--tw-drop-shadow-alpha)')),
decl('--tw-drop-shadow', `var(--tw-drop-shadow-size)`),
]
}
default: {
if (candidate.modifier && !alpha) return

return [
filterProperties(),
decl('--tw-drop-shadow-alpha', alpha),
decl(
'--tw-drop-shadow-size',
segment(value, ',')
.map(
(v) =>
`drop-shadow(${replaceShadowColors(
v,
alpha,
(color) => `var(--tw-drop-shadow-color, ${color})`,
)})`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the API changed here because this is passing 3 values instead of 2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think it's because I pressed the update button (because of conflicts in the CHANGELOG.md file)

)
.join(' '),
),
decl('--tw-drop-shadow', `var(--tw-drop-shadow-size)`),
decl('filter', cssFilterValue),
]
}
}
}

// Shadow size
{
let value = theme.get([`--drop-shadow-${candidate.value.value}`])
if (value) {
if (candidate.modifier && !alpha) return

if (alpha) {
return [
filterProperties(),
decl('--tw-drop-shadow-alpha', alpha),
decl(
'--tw-drop-shadow-size',
segment(value, ',')
.map(
(v) =>
`drop-shadow(${replaceShadowColors(
v,
alpha,
(color) => `var(--tw-drop-shadow-color, ${color})`,
)})`,
)
.join(' '),
),
decl('--tw-drop-shadow', `var(--tw-drop-shadow-size)`),
decl('filter', cssFilterValue),
]
}

return [
filterProperties(),
decl('--tw-drop-shadow-alpha', alpha),
decl(
'--tw-drop-shadow-size',
segment(value, ',')
.map(
(v) =>
`drop-shadow(${replaceShadowColors(
v,
alpha,
(color) => `var(--tw-drop-shadow-color, ${color})`,
)})`,
)
.join(' '),
),
decl(
'--tw-drop-shadow',
`drop-shadow(${theme.resolve(candidate.value.value, ['--drop-shadow'])})`,
),
decl('filter', cssFilterValue),
]
}
}

// Shadow color
{
let value = resolveThemeColor(candidate, theme, ['--drop-shadow-color', '--color'])
if (value) {
return [
filterProperties(),
decl('--tw-drop-shadow-color', withAlpha(value, 'var(--tw-drop-shadow-alpha)')),
decl('--tw-drop-shadow', `var(--tw-drop-shadow-size)`),
]
}
}
})

suggest('drop-shadow', () => [
{
values: ['current', 'inherit', 'transparent'],
valueThemeKeys: ['--drop-shadow-color', '--color'],
modifiers: Array.from({ length: 21 }, (_, index) => `${index * 5}`),
},
{
valueThemeKeys: ['--drop-shadow'],
},
])

functionalUtility('backdrop-opacity', {
themeKeys: ['--backdrop-opacity', '--opacity'],
handleBareValue: ({ value }) => {
Expand Down