summaryrefslogtreecommitdiff
path: root/ui/tailwindcss/.claude/commands/add-plugin.md
blob: 36f16ed25a6e1a545684caad65e00e47cee01899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
---
name: add-plugin
description: Add and configure TailwindCSS plugins for extended functionality, forms, typography, animations, and custom utilities
tools: Bash, Edit, Read, Write
---

# Add TailwindCSS Plugin

This command helps you add, configure, and optimize TailwindCSS plugins to extend functionality and enhance your design system.

## What This Command Does

1. **Plugin Installation**
   - Installs official and community TailwindCSS plugins
   - Configures plugin settings for optimal performance
   - Integrates plugins with existing configuration
   - Updates content paths for plugin-specific classes

2. **Configuration Setup**
   - Configures plugin options and customizations
   - Sets up plugin-specific utility classes
   - Optimizes for CSS bundle size and purging
   - Integrates with design system tokens

3. **Usage Examples**
   - Provides implementation examples for each plugin
   - Shows best practices and common patterns
   - Demonstrates responsive and interactive usage
   - Includes accessibility considerations

4. **Performance Optimization**
   - Configures plugins for optimal bundle size
   - Sets up effective purging strategies
   - Optimizes for build performance
   - Monitors plugin impact on CSS output

## Official Plugins

### Typography Plugin (@tailwindcss/typography)

#### Installation and Setup

```bash
# Install typography plugin
npm install -D @tailwindcss/typography

# Or with yarn
yarn add -D @tailwindcss/typography
```

#### Configuration

```javascript
// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      typography: ({ theme }) => ({
        // Default prose styles
        DEFAULT: {
          css: {
            maxWidth: 'none',
            color: theme('colors.gray.700'),
            '[class~="lead"]': {
              color: theme('colors.gray.600'),
              fontSize: theme('fontSize.xl')[0],
              lineHeight: theme('fontSize.xl')[1].lineHeight,
            },
            a: {
              color: theme('colors.blue.600'),
              textDecoration: 'none',
              fontWeight: theme('fontWeight.medium'),
              '&:hover': {
                color: theme('colors.blue.700'),
                textDecoration: 'underline',
              },
            },
            'h1, h2, h3, h4, h5, h6': {
              color: theme('colors.gray.900'),
              fontWeight: theme('fontWeight.bold'),
            },
            h1: {
              fontSize: theme('fontSize.4xl')[0],
              lineHeight: theme('fontSize.4xl')[1].lineHeight,
            },
            h2: {
              fontSize: theme('fontSize.3xl')[0],
              lineHeight: theme('fontSize.3xl')[1].lineHeight,
            },
            h3: {
              fontSize: theme('fontSize.2xl')[0],
              lineHeight: theme('fontSize.2xl')[1].lineHeight,
            },
            code: {
              color: theme('colors.gray.900'),
              backgroundColor: theme('colors.gray.100'),
              padding: theme('spacing.1'),
              borderRadius: theme('borderRadius.sm'),
              fontSize: theme('fontSize.sm')[0],
            },
            'pre code': {
              backgroundColor: 'transparent',
              padding: 0,
            },
            pre: {
              backgroundColor: theme('colors.gray.900'),
              color: theme('colors.gray.100'),
              padding: theme('spacing.4'),
              borderRadius: theme('borderRadius.lg'),
              overflow: 'auto',
            },
            blockquote: {
              borderLeftWidth: theme('borderWidth.4'),
              borderLeftColor: theme('colors.gray.300'),
              paddingLeft: theme('spacing.4'),
              fontStyle: 'italic',
              color: theme('colors.gray.600'),
            },
          },
        },
        
        // Dark mode typography
        invert: {
          css: {
            '--tw-prose-body': theme('colors.gray.300'),
            '--tw-prose-headings': theme('colors.gray.100'),
            '--tw-prose-lead': theme('colors.gray.400'),
            '--tw-prose-links': theme('colors.blue.400'),
            '--tw-prose-bold': theme('colors.gray.100'),
            '--tw-prose-counters': theme('colors.gray.400'),
            '--tw-prose-bullets': theme('colors.gray.500'),
            '--tw-prose-hr': theme('colors.gray.700'),
            '--tw-prose-quotes': theme('colors.gray.200'),
            '--tw-prose-quote-borders': theme('colors.gray.700'),
            '--tw-prose-captions': theme('colors.gray.400'),
            '--tw-prose-code': theme('colors.gray.100'),
            '--tw-prose-pre-code': theme('colors.gray.100'),
            '--tw-prose-pre-bg': theme('colors.gray.800'),
            '--tw-prose-th-borders': theme('colors.gray.600'),
            '--tw-prose-td-borders': theme('colors.gray.700'),
          },
        },
        
        // Size variants
        sm: {
          css: {
            fontSize: theme('fontSize.sm')[0],
            lineHeight: theme('fontSize.sm')[1].lineHeight,
            h1: { fontSize: theme('fontSize.2xl')[0] },
            h2: { fontSize: theme('fontSize.xl')[0] },
            h3: { fontSize: theme('fontSize.lg')[0] },
          },
        },
        
        lg: {
          css: {
            fontSize: theme('fontSize.lg')[0],
            lineHeight: theme('fontSize.lg')[1].lineHeight,
            h1: { fontSize: theme('fontSize.5xl')[0] },
            h2: { fontSize: theme('fontSize.4xl')[0] },
            h3: { fontSize: theme('fontSize.3xl')[0] },
          },
        },
        
        xl: {
          css: {
            fontSize: theme('fontSize.xl')[0],
            lineHeight: theme('fontSize.xl')[1].lineHeight,
            h1: { fontSize: theme('fontSize.6xl')[0] },
            h2: { fontSize: theme('fontSize.5xl')[0] },
            h3: { fontSize: theme('fontSize.4xl')[0] },
          },
        },
      }),
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
  ],
}
```

#### Usage Examples

```html
<!-- Basic prose content -->
<article class="prose lg:prose-xl max-w-none">
  <h1>Article Title</h1>
  <p class="lead">This is a lead paragraph with emphasis.</p>
  <p>Regular paragraph content with <a href="#">links</a> and <strong>bold text</strong>.</p>
  
  <blockquote>
    This is a blockquote with proper styling.
  </blockquote>
  
  <pre><code>console.log('Code blocks are styled too')</code></pre>
</article>

<!-- Dark mode prose -->
<article class="prose dark:prose-invert">
  <h2>Dark Mode Compatible</h2>
  <p>Content that adapts to dark themes.</p>
</article>

<!-- Size variants -->
<div class="prose prose-sm">Small typography</div>
<div class="prose prose-lg">Large typography</div>
<div class="prose prose-xl">Extra large typography</div>

<!-- Custom prose without max-width -->
<div class="prose max-w-none">
  <p>Full width content without prose max-width constraint.</p>
</div>
```

### Forms Plugin (@tailwindcss/forms)

#### Installation and Setup

```bash
# Install forms plugin
npm install -D @tailwindcss/forms
```

#### Configuration

```javascript
// tailwind.config.js
module.exports = {
  plugins: [
    require('@tailwindcss/forms')({
      strategy: 'class', // 'base' or 'class'
    }),
  ],
}
```

#### Usage Examples

```html
<!-- Form inputs with class strategy -->
<form class="space-y-4">
  <div>
    <label for="name" class="block text-sm font-medium text-gray-700">Name</label>
    <input 
      type="text" 
      id="name"
      class="form-input mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
    />
  </div>
  
  <div>
    <label for="email" class="block text-sm font-medium text-gray-700">Email</label>
    <input 
      type="email" 
      id="email"
      class="form-input mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
    />
  </div>
  
  <div>
    <label for="message" class="block text-sm font-medium text-gray-700">Message</label>
    <textarea 
      id="message" 
      rows="4"
      class="form-textarea mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
    ></textarea>
  </div>
  
  <div>
    <label class="flex items-center">
      <input type="checkbox" class="form-checkbox rounded text-blue-600 focus:ring-blue-500" />
      <span class="ml-2 text-sm text-gray-700">I agree to the terms</span>
    </label>
  </div>
  
  <div>
    <label class="block text-sm font-medium text-gray-700">Options</label>
    <div class="mt-2 space-y-2">
      <label class="flex items-center">
        <input type="radio" name="option" value="1" class="form-radio text-blue-600 focus:ring-blue-500" />
        <span class="ml-2 text-sm text-gray-700">Option 1</span>
      </label>
      <label class="flex items-center">
        <input type="radio" name="option" value="2" class="form-radio text-blue-600 focus:ring-blue-500" />
        <span class="ml-2 text-sm text-gray-700">Option 2</span>
      </label>
    </div>
  </div>
  
  <div>
    <label for="select" class="block text-sm font-medium text-gray-700">Select</label>
    <select id="select" class="form-select mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
      <option>Option 1</option>
      <option>Option 2</option>
      <option>Option 3</option>
    </select>
  </div>
  
  <button type="submit" class="w-full bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
    Submit
  </button>
</form>
```

### Aspect Ratio Plugin (@tailwindcss/aspect-ratio)

#### Installation and Setup

```bash
# Install aspect ratio plugin
npm install -D @tailwindcss/aspect-ratio
```

#### Configuration

```javascript
// tailwind.config.js
module.exports = {
  plugins: [
    require('@tailwindcss/aspect-ratio'),
  ],
}
```

#### Usage Examples

```html
<!-- Video embed with 16:9 aspect ratio -->
<div class="aspect-w-16 aspect-h-9">
  <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>
</div>

<!-- Square image container -->
<div class="aspect-w-1 aspect-h-1">
  <img src="image.jpg" alt="Square image" class="object-cover" />
</div>

<!-- Card with consistent aspect ratios -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
  <div class="bg-white rounded-lg shadow-md overflow-hidden">
    <div class="aspect-w-16 aspect-h-9">
      <img src="image1.jpg" alt="Card 1" class="object-cover" />
    </div>
    <div class="p-4">
      <h3 class="font-semibold">Card Title 1</h3>
    </div>
  </div>
  
  <div class="bg-white rounded-lg shadow-md overflow-hidden">
    <div class="aspect-w-16 aspect-h-9">
      <img src="image2.jpg" alt="Card 2" class="object-cover" />
    </div>
    <div class="p-4">
      <h3 class="font-semibold">Card Title 2</h3>
    </div>
  </div>
</div>

<!-- Modern CSS aspect-ratio property (newer alternative) -->
<div class="aspect-video">
  <iframe src="video.mp4" class="w-full h-full object-cover"></iframe>
</div>

<div class="aspect-square">
  <img src="square-image.jpg" alt="Square" class="w-full h-full object-cover" />
</div>

<!-- Custom aspect ratios -->
<div class="aspect-w-4 aspect-h-3">
  <div class="bg-gradient-to-br from-blue-500 to-purple-600 flex items-center justify-center text-white font-bold">
    4:3 Aspect Ratio
  </div>
</div>
```

### Container Queries Plugin (@tailwindcss/container-queries)

#### Installation and Setup

```bash
# Install container queries plugin
npm install -D @tailwindcss/container-queries
```

#### Configuration

```javascript
// tailwind.config.js
module.exports = {
  plugins: [
    require('@tailwindcss/container-queries'),
  ],
}
```

#### Usage Examples

```html
<!-- Component-level responsive design -->
<div class="@container">
  <div class="@md:flex @md:items-center @md:space-x-4">
    <img class="@md:w-24 @md:h-24 w-full h-48 object-cover rounded-lg" />
    <div class="@md:flex-1 mt-4 @md:mt-0">
      <h3 class="text-lg @lg:text-xl font-semibold">Product Title</h3>
      <p class="text-gray-600 @lg:text-base text-sm">Product description</p>
      <div class="@lg:flex @lg:items-center @lg:justify-between mt-2">
        <span class="font-bold @lg:text-lg">$99.99</span>
        <button class="@lg:ml-4 bg-blue-600 text-white px-4 py-2 rounded">
          Add to Cart
        </button>
      </div>
    </div>
  </div>
</div>

<!-- Card grid with container queries -->
<div class="@container">
  <div class="grid @sm:grid-cols-1 @md:grid-cols-2 @lg:grid-cols-3 @xl:grid-cols-4 gap-4">
    <div class="bg-white rounded-lg p-4 shadow">
      <h4 class="font-semibold @lg:text-lg">Card Title</h4>
      <p class="text-sm @lg:text-base text-gray-600">Card content that adapts to container size.</p>
    </div>
  </div>
</div>

<!-- Sidebar with container-specific styling -->
<div class="flex">
  <aside class="@container w-64 bg-gray-100 p-4">
    <nav class="@md:space-y-4 @sm:space-y-2">
      <a class="block @md:text-base @sm:text-sm hover:text-blue-600">Navigation Item</a>
    </nav>
  </aside>
  
  <main class="flex-1 p-6">
    <div class="@container">
      <h1 class="@lg:text-4xl @md:text-3xl text-2xl font-bold">Main Content</h1>
    </div>
  </main>
</div>
```

## Popular Community Plugins

### Line Clamp Plugin (@tailwindcss/line-clamp)

#### Installation and Setup

```bash
# Install line clamp plugin (now built into Tailwind v3.3+)
npm install -D @tailwindcss/line-clamp
```

#### Usage Examples

```html
<!-- Clamp text to specific number of lines -->
<p class="line-clamp-3 text-sm text-gray-600">
  This is a long paragraph that will be clamped to exactly 3 lines with an ellipsis at the end when it overflows beyond the specified number of lines.
</p>

<!-- Different line clamp values -->
<div class="space-y-4">
  <p class="line-clamp-1">Single line with ellipsis</p>
  <p class="line-clamp-2">Two lines maximum with ellipsis</p>
  <p class="line-clamp-4">Up to four lines with ellipsis</p>
  <p class="line-clamp-none">No line clamping applied</p>
</div>

<!-- Responsive line clamping -->
<p class="line-clamp-2 md:line-clamp-3 lg:line-clamp-4">
  Responsive line clamping that shows more lines on larger screens.
</p>
```

### Animations Plugin (tailwindcss-animate)

#### Installation and Setup

```bash
# Install animations plugin
npm install -D tailwindcss-animate
```

#### Configuration

```javascript
// tailwind.config.js
module.exports = {
  plugins: [
    require('tailwindcss-animate'),
  ],
}
```

#### Usage Examples

```html
<!-- Predefined animations -->
<div class="animate-fade-in">Fades in smoothly</div>
<div class="animate-slide-up">Slides up from bottom</div>
<div class="animate-scale-in">Scales in from center</div>
<div class="animate-bounce-in">Bounces in with spring effect</div>

<!-- Loading animations -->
<div class="animate-spin h-8 w-8 border-4 border-blue-500 border-t-transparent rounded-full"></div>
<div class="animate-pulse bg-gray-300 h-4 rounded"></div>

<!-- Hover animations -->
<button class="transform transition-transform hover:animate-bounce">
  Bounce on Hover
</button>

<div class="group">
  <div class="transform transition-transform group-hover:animate-wiggle">
    <span>Wiggle on group hover</span>
  </div>
</div>

<!-- Staggered animations -->
<div class="space-y-2">
  <div class="animate-slide-in-left" style="animation-delay: 0ms;">Item 1</div>
  <div class="animate-slide-in-left" style="animation-delay: 100ms;">Item 2</div>
  <div class="animate-slide-in-left" style="animation-delay: 200ms;">Item 3</div>
</div>
```

### Debugging Plugin (tailwindcss-debug-screens)

#### Installation and Setup

```bash
# Install debug plugin (development only)
npm install -D tailwindcss-debug-screens
```

#### Configuration

```javascript
// tailwind.config.js
module.exports = {
  plugins: [
    process.env.NODE_ENV === 'development' && require('tailwindcss-debug-screens'),
  ].filter(Boolean),
}
```

#### Usage

```html
<!-- Add debug indicator to body -->
<body class="debug-screens">
  <!-- Your content -->
</body>
```

## Custom Plugin Development

### Creating a Custom Plugin

```javascript
// plugins/custom-utilities.js
const plugin = require('tailwindcss/plugin')

module.exports = plugin(function({ addUtilities, addComponents, theme }) {
  // Add custom utilities
  addUtilities({
    '.text-shadow': {
      textShadow: '2px 2px 4px rgba(0, 0, 0, 0.1)',
    },
    '.text-shadow-lg': {
      textShadow: '4px 4px 8px rgba(0, 0, 0, 0.2)',
    },
    '.scrollbar-hide': {
      '-ms-overflow-style': 'none',
      'scrollbar-width': 'none',
      '&::-webkit-scrollbar': {
        display: 'none',
      },
    },
    '.backdrop-blur-xs': {
      backdropFilter: 'blur(2px)',
    },
  })
  
  // Add custom components
  addComponents({
    '.btn-primary': {
      backgroundColor: theme('colors.blue.600'),
      color: theme('colors.white'),
      padding: `${theme('spacing.2')} ${theme('spacing.4')}`,
      borderRadius: theme('borderRadius.md'),
      fontWeight: theme('fontWeight.medium'),
      '&:hover': {
        backgroundColor: theme('colors.blue.700'),
      },
      '&:focus': {
        outline: 'none',
        boxShadow: `0 0 0 3px ${theme('colors.blue.500')}33`,
      },
    },
    '.card': {
      backgroundColor: theme('colors.white'),
      borderRadius: theme('borderRadius.lg'),
      boxShadow: theme('boxShadow.md'),
      padding: theme('spacing.6'),
    },
  })
})
```

#### Using Custom Plugin

```javascript
// tailwind.config.js
module.exports = {
  plugins: [
    require('./plugins/custom-utilities'),
  ],
}
```

### Advanced Custom Plugin with Variants

```javascript
// plugins/advanced-utilities.js
const plugin = require('tailwindcss/plugin')

module.exports = plugin(
  function({ addUtilities, matchUtilities, theme }) {
    // Static utilities
    addUtilities({
      '.writing-vertical': {
        'writing-mode': 'vertical-rl',
      },
    })
    
    // Dynamic utilities with arbitrary values
    matchUtilities(
      {
        'text-shadow': (value) => ({
          textShadow: value,
        }),
      },
      { values: theme('textShadow') }
    )
    
    matchUtilities(
      {
        'animation-delay': (value) => ({
          animationDelay: value,
        }),
      },
      { values: theme('animationDelay') }
    )
  },
  {
    // Extend theme
    theme: {
      textShadow: {
        sm: '1px 1px 2px rgba(0, 0, 0, 0.1)',
        DEFAULT: '2px 2px 4px rgba(0, 0, 0, 0.1)',
        lg: '4px 4px 8px rgba(0, 0, 0, 0.15)',
      },
      animationDelay: {
        '75': '75ms',
        '100': '100ms',
        '150': '150ms',
        '200': '200ms',
        '300': '300ms',
        '500': '500ms',
        '700': '700ms',
        '1000': '1000ms',
      },
    },
  }
)
```

## Plugin Performance Optimization

### Bundle Size Analysis Script

```javascript
// scripts/analyze-plugins.js
const fs = require('fs')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')

async function analyzePluginImpact(configPath) {
  // Base configuration without plugins
  const baseConfig = {
    content: ['./test.html'],
    plugins: [],
  }
  
  // Configuration with plugins
  const pluginConfig = require(configPath)
  
  // Generate CSS for both configurations
  const baseCSS = await generateCSS(baseConfig)
  const pluginCSS = await generateCSS(pluginConfig)
  
  console.log('Plugin Impact Analysis:')
  console.log(`Base CSS size: ${baseCSS.length} bytes`)
  console.log(`With plugins: ${pluginCSS.length} bytes`)
  console.log(`Difference: ${pluginCSS.length - baseCSS.length} bytes`)
  console.log(`Increase: ${(((pluginCSS.length - baseCSS.length) / baseCSS.length) * 100).toFixed(2)}%`)
}

async function generateCSS(config) {
  const result = await postcss([tailwindcss(config)])
    .process('@tailwind base; @tailwind components; @tailwind utilities;', { from: undefined })
  
  return result.css
}

analyzePluginImpact('./tailwind.config.js')
```

Remember: **Choose plugins based on actual needs, configure them properly, and monitor their impact on bundle size and performance!**