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
Prev Previous commit
Next Next commit
Add support for “intensity” modifiers on inset box shadows
  • Loading branch information
thecrypticace committed Mar 28, 2025
commit 22cd1f71b0ba1b41f7952d8024e6a1172bd22396
42 changes: 36 additions & 6 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4421,6 +4421,7 @@ export function createUtilities(theme: Theme) {
property('--tw-shadow-intensity', '100%'),
property('--tw-inset-shadow', nullShadow),
property('--tw-inset-shadow-color'),
property('--tw-inset-shadow-intensity', '100%'),
property('--tw-ring-color'),
property('--tw-ring-shadow', nullShadow),
property('--tw-inset-ring-color'),
Expand Down Expand Up @@ -4564,15 +4565,32 @@ export function createUtilities(theme: Theme) {
])

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

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

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

return [
boxShadowProperties(),
decl('--tw-inset-shadow-intensity', intensity),
decl(
'--tw-inset-shadow',
replaceShadowColors(value, (color) => `var(--tw-inset-shadow-color, ${color})`),
replaceShadowColors(
value,
(color) =>
`var(--tw-inset-shadow-color, ${intensity ? replaceAlpha(color, 'var(--tw-inset-shadow-intensity)') : color})`,
),
),
decl('box-shadow', cssBoxShadowValue),
]
Expand All @@ -4587,14 +4605,18 @@ export function createUtilities(theme: Theme) {
value = asColor(value, candidate.modifier, theme)
if (value === null) return

return [boxShadowProperties(), decl('--tw-inset-shadow-color', value)]
return [
boxShadowProperties(),
decl('--tw-inset-shadow-color', withAlpha(value, 'var(--tw-inset-shadow-intensity)')),
]
}
default: {
return [
boxShadowProperties(),
decl('--tw-inset-shadow-intensity', intensity),
decl(
'--tw-inset-shadow',
`inset ${replaceShadowColors(value, (color) => `var(--tw-inset-shadow-color, ${color})`)}`,
`inset ${replaceShadowColors(value, (color) => `var(--tw-inset-shadow-color, ${intensity ? replaceAlpha(color, 'var(--tw-inset-shadow-intensity)') : color})`)}`,
),
decl('box-shadow', cssBoxShadowValue),
]
Expand All @@ -4617,12 +4639,16 @@ export function createUtilities(theme: Theme) {
let value = theme.get([`--inset-shadow-${candidate.value.value}`])

if (value) {
if (candidate.modifier) return
return [
boxShadowProperties(),
decl('--tw-inset-shadow-intensity', intensity),
decl(
'--tw-inset-shadow',
replaceShadowColors(value, (color) => `var(--tw-inset-shadow-color, ${color})`),
replaceShadowColors(
value,
(color) =>
`var(--tw-inset-shadow-color, ${intensity ? replaceAlpha(color, 'var(--tw-inset-shadow-intensity)') : color})`,
),
),
decl('box-shadow', cssBoxShadowValue),
]
Expand All @@ -4633,7 +4659,10 @@ export function createUtilities(theme: Theme) {
{
let value = resolveThemeColor(candidate, theme, ['--box-shadow-color', '--color'])
if (value) {
return [boxShadowProperties(), decl('--tw-inset-shadow-color', value)]
return [
boxShadowProperties(),
decl('--tw-inset-shadow-color', withAlpha(value, 'var(--tw-inset-shadow-intensity)')),
]
}
}
})
Expand All @@ -4647,6 +4676,7 @@ export function createUtilities(theme: Theme) {
{
values: [],
valueThemeKeys: ['--inset-shadow'],
modifiers: Array.from({ length: 21 }, (_, index) => `${index * 5}`),
hasDefaultValue: true,
},
])
Expand Down