Tailwind CSS, a popular CSS framework, offers a unique plugin called Signals for Tailwind CSS. This plugin revolutionizes the way developers apply styles based on ancestor states by introducing a more declarative and straightforward approach.
Table of contents:
Signals for Tailwind CSS utilizes style queries, specifically container queries, to enable a custom state reactively. This state can be consumed by any descendants in the DOM, streamlining the styling process.
While similar to the group variant/utility, signal states provide a more explicit way to set and consume states, reducing the need for complex variant chains.
You just need to install the npm dependency and add the plugin to your tailwind.config.js
.
npm install tailwindcss-signals
module.exports = {
plugins: [
require('tailwindcss-signals'),
]
}
Here's an example comparing the traditional approach with the new signals approach:
<input type="checkbox" class="peer" />
<div
class="hover:[&>div]:bg-green-800 peer-checked:[&>div]:bg-green-800"
>
<div class="bg-red-800 p-1 text-white">
or hover here
</div>
</div>
<input type="checkbox" class="peer" />
<div class="peer-checked:signal hover:signal">
<div class="signal:bg-green-800 bg-red-800 p-1 text-white">
or hover here
</div>
</div>
Signals can also be activated based on a descendant's state using the :has()
CSS pseudo-class, enabling more dynamic styling based on specific conditions.
To differentiate signals, names can be assigned to ensure uniqueness and prevent conflicts, enhancing clarity and organization in complex styling structures.
For example, here we have two signals, one named peer/checkable
and another as peer/hoverable
. You can assing as many names as you want.
<input type="checkbox" class="peer/checkable origin-bottom-left" /> 👈🏼 check/uncheck here
<div class="peer/hoverable bg-slate-700 text-white">✨ hover/unhover here ✨</div>
<div class="active:signal/custom peer-checked/checkable:signal peer-hover/hoverable:signal">
<div class="
text-white
bg-red-800 after:content-['_👀']
signal/custom:!bg-purple-800 signal:bg-green-800
signal/custom:after:!content-['_🦄'] signal:after:content-['_😱']
">press me</div>
</div>
Check this example in Tailwind Play.
In conclusion, Tailwind Signals offer a powerful tool for simplifying styling based on ancestor states, enhancing code maintainability, and improving the developer experience. While browser support considerations remain, the benefits of using Signals for Tailwind CSS are significant for modern web development practices.
For more information and examples, visit the official Tailwind Signals documentation and explore the capabilities of Signals in your projects.
Do you own a company or need help with your Laravel project? I can help you with that. Check the plans and let me know if you have any questions.
Get 1 month free with yearly plan during checkout.
$ 3 ,995
/m
What's included:
$ 5 ,995
/m
What's included:
Ok, just book a call now.
Good question! For starters, the annual cost of a full-time senior-level developer now exceeds $100,000, plus benefits (and good luck finding one available).
Aside from that, you may not always have enough work to keep them busy at all times, so you're stuck paying for time you aren't able to utilize.
With the monthly plan, you can pause and resume your subscription as often as you need to ensure you're only paying your developer when you have work available for them.
No, once subscribed you're able to request as many things as you'd like, and they will be delivered one by one.
Delivery will always be fast without compromising quality. Very complex requests will be divided into smaller products for continuous delivery.
Always, before starting to work, we can make a planning so that you know, before starting, when each change will be delivered.
You'll work directly with me, the founder and only person behind DeveloperJoy.
We understand you may not have enough work to fill up entire month. Perhaps you only have one or two requests at the moment. That's where pausing your subscription comes in handy.
Billing cycles are based on 31 day period. Let's say you sign up and use the service for 21 days, and then decide to pause your subscription. This means that the billing cycle will be paused and you'll have 10 days of service remaining to be used anytime in the future
I had experience making products with PHP, Go, and JavaScript/TypeScript.
Also I feel really comfortable working with WordPress, Laravel, Symfony, Vue.js, React, Svelte, and more.
Mail me and we will see how best to collaborate.
You can make this request by email, sharing a task board with me or, depending on your plan, by call or Slack.
That's fine. You can pause your subscription when finished and return when you have additional requests needs. There's no need to let the remainder of your subscription go to waste.
Due to the high quality nature of the work, there will be no refunds issued.