The user wants me to create a Tailwind CSS plugin that:
Uses matchUtilities to create a dynamic text-shadow utility
Allows arbitrary values like text-shadow-[2px_2px_4px_red]
Expose default theme values like shadow-sm and shadow-md in the config
Let me build a comprehensive solution that includes:
A plugin file with the text-shadow utility configuration
Configuration setup for Tailwind
Examples of how to use it
Documentation
Here's what I need to do:
Create a Tailwind plugin that uses matchUtilities to handle dynamic text-shadow values
Set up theme values for predefined shadows (shadow-sm, shadow-md, etc.)
Make sure it supports both predefined values and arbitrary values
Let me think about the structure:
javascript Copy code
// tailwind-text-shadow-plugin.js
import plugin from 'tailwindcss/plugin'
const textShadowPlugin = plugin(
function({ matchUtilities, theme }) {
matchUtilities(
{
'text-shadow': (value) => ({
textShadow: value,
}),
},
{
values: theme('textShadow'),
}
)
},
{
theme: {
textShadow: {
'sm': '1px 1px 2px rgba(0, 0, 0, 0.25)',
'md': '2px 2px 4px rgba(0, 0, 0, 0.25)',
'lg': '4px 4px 8px rgba(0, 0, 0, 0.25)',
'xl': '8px 8px 16px rgba(0, 0, 0, 0.25)',
},
},
}
)
export default textShadowPlugin
I need to reconsider this approach. The user wants both predefined values like text-shadow-sm and arbitrary values like text-shadow-[2px_2px_4px_red]. For arbitrary values to work with bracket syntax, I need to ensure the plugin properly handles the modifier values passed through the brackets.
Using matchUtilities with a values object from the theme actually handles both cases automatically. Tailwind will generate utilities for each predefined theme value while simultaneously supporting arbitrary values through bracket notation. The implementation becomes straightforward: define the utility generator that applies the value to textShadow, then reference the theme values.
Here's the complete plugin with predefined shadow values and full arbitrary value support:
javascript Copy code
const textShadowPlugin = plugin(
function({ matchUtilities, theme }) {
matchUtilities(
{
'text-shadow': (value) => ({
textShadow: value,
}),
},
{
values: theme('textShadow'),
}
)
},
{
theme: {
textShadow: {
'sm': '1px 1px 2px rgba(0, 0, 0, 0.25)',
'md': '2px 2px 4px rgba(0, 0, 0, 0.25)',
'lg': '4px 4px 8px rgba(0, 0, 0, 0.25)',
'xl': '8px 8px 16px rgba(0, 0, 0, 0.25)',
},
},
}
)
This approach creates utilities for each predefined size while automatically enabling bracket notation for custom values.
Tailwind CSS Text-Shadow Plugin
I'll create a comprehensive text-shadow plugin that supports both predefined theme values and arbitrary values.
1. Plugin File
javascript Copy code
// tailwind-text-shadow-plugin.js
import plugin from 'tailwindcss/plugin'
const textShadowPlugin = plugin(
function({ matchUtilities, theme }) {
matchUtilities(
{
'text-shadow': (value) => ({
textShadow: value,
}),
},
{
values: theme('textShadow'),
}
)
},
{
theme: {
extend: {
textShadow: {
'sm': '1px 1px 2px rgba(0, 0, 0, 0.25)',
'md': '2px 2px 4px rgba(0, 0, 0, 0.25)',
'lg': '4px 4px 8px rgba(0, 0, 0, 0.25)',
'xl': '8px 8px 16px rgba(0, 0, 0, 0.25)',
'2xl': '8px 8px 16px rgba(0, 0, 0, 0.5)',
'none': '0 0 0 transparent',
},
},
},
}
)
export default textShadowPlugin
2. Tailwind Configuration
javascript Copy code
// tailwind.config.js
import textShadowPlugin from './tailwind-text-shadow-plugin'
export default {
content: ['./src/**/*.{js,jsx,ts,tsx}'],
theme: {
extend: {
textShadow: {
// Custom theme values can override defaults
'glow': '0 0 20px rgba(255, 0, 255, 0.8)',
'neon': '0 0 10px #00ff00, 0 0 20px #00ff00',
},
},
},
plugins: [textShadowPlugin],
}
3. Usage Examples
html Copy code
<!-- Predefined values -->
<h1 class="text-shadow-sm">Small Shadow</h1>
<h2 class="text-shadow-md">Medium Shadow</h2>
<h3 class="text-shadow-lg">Large Shadow</h3>
<h4 class="text-shadow-xl">Extra Large Shadow</h4>
<h5 class="text-shadow-2xl">Double Extra Large</h5>
<!-- No shadow -->
<p class="text-shadow-none">No shadow</p>
<!-- Custom theme values -->
<p class="text-shadow-glow">Glowing text</p>
<p class="text-shadow-neon">Neon effect</p>
<!-- Arbitrary values with square brackets -->
<p class="text-shadow-[2px_2px_4px_red]">Custom red shadow</p>
<p class="text-shadow-[3px_3px_0px_rgb(59,130,246)]">Blue shadow</p>
<p class="text-shadow-[0_0_10px_rgba(255,0,255,0.8)]">Purple glow</p>
<p class="text-shadow-[-2px_-2px_4px_gray]">Negative offset shadow</p>
<!-- Multiple shadows -->
<p class="text-shadow-[2px_2px_4px_red,_4px_4px_8px_blue]">Dual shadow</p>
<!-- With responsive variants -->
<p class="text-shadow-sm md:text-shadow-md lg:text-shadow-lg">Responsive shadow</p>
<!-- With hover/focus states -->
<button class="text-shadow-sm hover:text-shadow-md focus:text-shadow-lg">
Interactive Shadow
</button>
4. Advanced Plugin with Color Variants
For more control, here's an enhanced version with built-in color support:
javascript Copy code
// tailwind-text-shadow-plugin-advanced.js
import plugin from 'tailwindcss/plugin'
const textShadowPlugin = plugin(
function({ matchUtilities, theme }) {
// Main text-shadow utility
matchUtilities(
{
'text-shadow': (value) => ({
textShadow: value,
}),
},
{
values: theme('textShadow'),
}
)
// Color-specific text-shadow utilities
matchUtilities(
{
'text-shadow': (value) => {
const [offsetX = '2px', offsetY = '2px', blur = '4px'] =
value.split('_') || []
return {
textShadow: `${offsetX} ${offsetY} ${blur} currentColor`,
}
},
},
{
values: {
'sm': '1px_1px_2px',
'md': '2px_2px_4px',
'lg': '4px_4px_8px',
'xl': '8px_8px_16px',
},
}
)
},
{
theme: {
extend: {
textShadow: {
'sm': '1px 1px 2px rgba(0, 0, 0, 0.25)',
'md': '2px 2px 4px rgba(0, 0, 0, 0.25)',
'lg': '4px 4px 8px rgba(0, 0, 0, 0.25)',
'xl': '8px 8px 16px rgba(0, 0, 0, 0.25)',
'2xl': '8px 8px 16px rgba(0, 0, 0, 0.5)',
'none': '0 0 0 transparent',
// Color variants
'red-sm': '1px 1px 2px rgba(239, 68, 68, 0.5)',
'red-md': '2px 2px 4px rgba(239, 68, 68, 0.5)',
'blue-sm': '1px 1px 2px rgba(59, 130, 246, 0.5)',
'blue-md': '2px 2px 4px rgba(59, 130, 246, 0.5)',
'green-sm': '1px 1px 2px rgba(34, 197, 94, 0.5)',
'green-md': '2px 2px 4px rgba(34, 197, 94, 0.5)',
'purple-sm': '1px 1px 2px rgba(168, 85, 247, 0.5)',
'purple-md': '2px 2px 4px rgba(168, 85, 247, 0.5)',
},
},
},
}
)
export default textShadowPlugin
5. React Component Example
jsx Copy code
// TextShadowShowcase.jsx
export default function TextShadowShowcase() {
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 to-slate-800 p-8">
<div className="max-w-4xl mx-auto space-y-12">
{/* Predefined Shadows */}
<section>
<h2 className="text-3xl font-bold mb-4 text-white">Predefined Shadows</h2>
<div className="space-y-4">
<p className="text-2xl text-white text-shadow-sm">Small (text-shadow-sm)</p>
<p className="text-2xl text-white text-shadow-md">Medium (text-shadow-md)</p>
<p className="text-2xl text-white text-shadow-lg">Large (text-shadow-lg)</p>
<p className="text-2xl text-white text-shadow-xl">XL (text-shadow-xl)</p>
</div>
</section>
{/* Arbitrary Values */}
<section>
<h2 className="text-3xl font-bold mb-4 text-white">Arbitrary Values</h2>
<div className="space-y-4">
<p className="text-2xl text-white text-shadow-[2px_2px_4px_red]">
Red Shadow
</p>
<p className="text-2xl text-white text-shadow-[0_0_20px_rgb(168,85,247)]">
Purple Glow
</p>
<p className="text-2xl text-white text-shadow-[3px_3px_0px_rgb(34,197,94)]">
Green Offset
</p>
<p className="text-2xl text-white text-shadow-[2px_2px_4px_red,_4px_4px_8px_blue]">
Multi-color
</p>
</div>
</section>
{/* Interactive */}
<section>
<h2 className="text-3xl font-bold mb-4 text-white">Interactive</h2>
<button className="px-6 py-3 bg-blue-600 text-white text-lg font-semibold rounded-lg text-shadow-md hover:text-shadow-lg hover:bg-blue-700 transition-all cursor-pointer">
Hover me for more shadow
</button>
</section>
{/* Responsive */}
<section>
<h2 className="text-3xl font-bold mb-4 text-white">Responsive</h2>
<p className="text-2xl text-white text-shadow-sm sm:text-shadow-md md:text-shadow-lg lg:text-shadow-xl">
Shadow increases on larger screens
</p>
</section>
</div>
</div>
)
}
6. Dark Mode Support
javascript Copy code
// Enhanced config with dark mode
export default {
content: ['./src/**/*.{js,jsx,ts,tsx}'],
darkMode: 'class',
theme: {
extend: {
textShadow: {
'sm': '1px 1px 2px rgba(0, 0, 0, 0.25)',
'md': '2px 2px 4px rgba(0, 0, 0, 0.25)',
'lg': '4px 4px 8px rgba(0, 0, 0, 0.25)',
'xl': '8px 8px 16px rgba(0, 0, 0, 0.25)',
'dark-sm': '1px 1px 2px rgba(255, 255, 255, 0.1)',
'dark-md': '2px 2px 4px rgba(255, 255, 255, 0.1)',
},
},
},
plugins: [textShadowPlugin],
}
Key Features
✅ Predefined values : text-shadow-{sm|md|lg|xl|2xl|none}
✅ Arbitrary values : text-shadow-[...] with any CSS values
✅ Theme extensible : Easy to add custom values
✅ Responsive variants : md:text-shadow-lg
✅ State variants : hover:text-shadow-md, focus:text-shadow-lg
✅ No dependencies : Pure Tailwind plugin
Notes
The plugin uses matchUtilities which automatically handles:
Arbitrary values via bracket notation
Theme value integration
Variant application (responsive, hover, etc.)
Values use CSS text-shadow format: offsetX offsetY blur color
Supports multiple shadows separated by commas