Skip to content

Commit 46b634e

Browse files
fadel100adamwathan
andauthored
Update extracting-components.mdx (#939)
* Update extracting-components.mdx added an example of how to generate variants of the custom components. * Update extracting-components.mdx * Update extracting-components.mdx Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
1 parent 56c5701 commit 46b634e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/pages/docs/extracting-components.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ Tailwind will automatically move those styles to the same place as `@tailwind co
194194

195195
Using the `@layer` directive will also instruct Tailwind to consider those styles for purging when purging the `components` layer. Read our [documentation on optimizing for production](/docs/optimizing-for-production) for more details.
196196

197+
Like with custom utilities, you can generate `responsive`, `hover`, `focus`, `active`, and other [variants](/docs/hover-focus-and-other-states) of your own custom components using the `@variants` directive:
198+
199+
```css
200+
/* ... */
201+
202+
@layer components {
203+
@variants responsive, hover {
204+
.btn-blue {
205+
@apply py-2 px-4 bg-blue-500 ...;
206+
}
207+
}
208+
}
209+
```
210+
211+
Learn more in the [@variants directive documentation](/docs/functions-and-directives#variants).
212+
197213
### Writing a component plugin
198214

199215
In addition to writing component classes directly in your CSS files, you can also add component classes to Tailwind by writing your own plugin:

0 commit comments

Comments
 (0)