// tailwind.plugin.js
// Sherlock Tailwind Extension: Adds neumorphism utilities, advanced shadows, gradient utilities, and pre-built components.
/** @type {import('tailwindcss').Config} */
const plugin = require('tailwindcss/plugin');
module.exports = plugin(function ({ addUtilities, addComponents, addBase, theme, matchUtilities }) {
// Custom Neumorphism Utilities
// Base neumorph shadow (soft UI)
addUtilities({
'.neumorph': {
boxShadow: '8px 8px 16px #d1d9e6, -8px -8px 16px #f8f9fa',
},
'.neumorph-inset': {
boxShadow: 'inset 8px 8px 16px #d1d9e6, inset -8px -8px 16px #f8f9fa',
},
'.neumorph-light': {
boxShadow: '4px 4px 8px #e0e6ed, -4px -4px 8px #ffffff',
},
'.neumorph-dark': {
boxShadow: '6px 6px 12px #c8d0e0, -6px -6px 12px #f0f2f5',
},
});
// Advanced Gradient Utilities (using matchUtilities for arbitrary values)
matchUtilities(
{
'bg-gradient': (value) => ({
backgroundImage: `linear-gradient(${value})`,
}),
'bg-gradient-conic': (value) => ({
backgroundImage: `conic-gradient(${value})`,
}),
},
{ values: theme('colors') }
);
// Custom Glassmorphism Utilities
addUtilities({
'.glass': {
background: 'rgba(255, 255, 255, 0.1)',
backdropFilter: 'blur(10px)',
border: '1px solid rgba(255, 255, 255, 0.2)',
},
'.glass-dark': {
background: 'rgba(0, 0, 0, 0.2)',
backdropFilter: 'blur(10px)',
border: '1px solid rgba(255, 255, 255, 0.1)',
},
});
// Custom Animations
addUtilities({
'.animate-pulse-slow': 'animation: pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite;',
'.animate-float': `
animation: float 6s ease-in-out infinite;
@keyframes float {
0%, 100% { transform: translateY(0px); }
50% { transform: translateY(-20px); }
}
`,
'.animate-shimmer': `
overflow: hidden;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
background-size: 200% 100%;
animation: shimmer 2s infinite;
@keyframes shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
`,
});
// Pre-built Components (@layer components)
const buttons = {
'.btn': {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
borderRadius: '0.5rem',
fontWeight: '600',
fontSize: '0.875rem',
lineHeight: '1.25rem',
transitionProperty: 'all',
transitionDuration: '0.2s',
transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
cursor: 'pointer',
userSelect: 'none',
WebkitUserSelect: 'none',
},
'.btn-primary': {
base: [
'btn',
'bg-blue-500 hover:bg-blue-600',
'text-white',
'shadow-lg hover:shadow-xl',
'neumorph',
],
},
'.btn-secondary': {
base: [
'btn',
'bg-gray-200 hover:bg-gray-300',
'text-gray-800',
'neumorph-light',
],
},
'.btn-danger': {
base: [
'btn',
'bg-red-500 hover:bg-red-600',
'text-white',
'shadow-lg hover:shadow-xl',
],
},
};
const cards = {
'.card': {
'@apply bg-white rounded-xl shadow-lg overflow-hidden transition-all duration-300 hover:shadow-2xl hover:-translate-y-1': {},
},
'.card-glass': {
'@apply card glass p-6 border-0': {},
},
'.card-neumorph': {
'@apply card neumorph p-8 m-4': {},
},
};
addComponents(buttons);
addComponents(cards);
// Custom Typography Scale (extend base)
addBase({
h0: { fontSize: '3.75rem', fontWeight: '800', lineHeight: '1' }, // 60px
h1: { fontSize: '3rem', fontWeight: '800', lineHeight: '1' }, // 48px
h2: { fontSize: '2.25rem', fontWeight: '700', lineHeight: '1.2' }, // 36px
h3: { fontSize: '1.875rem', fontWeight: '700', lineHeight: '1.25' }, // 30px
h4: { fontSize: '1.5rem', fontWeight: '700', lineHeight: '1.25' }, // 24px
});
});
Setup Instructions
-
Install Tailwind CSS (if not already):
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
-
Update your tailwind.config.js:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{html,js,ts,jsx,tsx}'], // Adjust paths as needed
theme: {
extend: {},
},
plugins: [
require('./tailwind.plugin.js'), // Path to the plugin file above
],
};
-
Include Tailwind in your CSS (e.g., src/input.css):
@tailwind base;
@tailwind components;
@tailwind utilities;
-
Build your CSS:
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
Usage Examples
HTML Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./dist/output.css" rel="stylesheet">
<title>Sherlock Tailwind Extension</title>
</head>
<body class="bg-gradient-to-br from-slate-900 to-slate-700 min-h-screen p-8 text-white">
<!-- Custom Typography -->
<h0 class="text-4xl mb-2">H0: Massive Heading</h0>
<h1 class="text-3xl mb-2">H1: Hero Title</h1>
<h2 class="text-2xl mb-4">H2: Section Title</h2>
<!-- Buttons -->
<div class="space-x-4 mb-8">
<button class="btn-primary px-6 py-3">Primary Button</button>
<button class="btn-secondary px-6 py-3">Secondary Button</button>
<button class="btn-danger px-6 py-3">Danger Button</button>
</div>
<!-- Cards -->
<div class="grid md:grid-cols-3 gap-6 mb-8">
<div class="card p-6 text-gray-800">
<h3 class="mb-2">Standard Card</h3>
<p>Classic card with shadow.</p>
</div>
<div class="card-neumorph text-gray-800">
<h3 class="mb-2">Neumorph Card</h3>
<p>Soft embossed design.</p>
</div>
<div class="card-glass">
<h3 class="mb-2">Glass Card</h3>
<p>Frosted glass effect.</p>
</div>
</div>
<!-- Utilities -->
<div class="space-y-4 max-w-md">
<div class="w-32 h-32 neumorph-light bg-white rounded-xl flex items-center justify-center animate-float">
Floating
</div>
<div class="w-32 h-32 neumorph-inset bg-gray-100 rounded-xl flex items-center justify-center animate-shimmer">
Shimmer
</div>
<div class="w-full h-20 bg-gradient(to-r, from-purple-500 to-pink-500) rounded-lg flex items-center justify-center">
Gradient Utility
</div>
</div>
</body>
</html>
Features Added
- Neumorphism Utilities:
.neumorph, .neumorph-inset, etc., for soft UI designs.
- Glassmorphism:
.glass and .glass-dark for modern frosted effects.
- Gradient Utilities:
bg-gradient(to-r, from-blue-500 to-purple-500) or arbitrary.
- Animations:
.animate-float, .animate-shimmer, .animate-pulse-slow.
- Components: Fully styled
.btn-*, .card-* with hover states.
- Typography:
h0-h4 base classes for consistent headings.
This extension is modular, performant (JIT-friendly), and extensible. Customize further by editing the plugin! 🚀