Introducing Arto: A Flexible, Variant-Driven Class Management Library for Accessible UIs #7697
hamidelgendy
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Introduction
I’ve always enjoyed building fully accessible UI components with utility-first CSS (Tailwind) and advanced accessibility hooks (like those found in React Aria). But no matter the framework, one problem keeps surfacing: managing complex variants and states in a clean, flexible way.
Existing libraries such as
cva
and Tailwind Variants are great for smaller use cases, but I frequently hit situations that required advanced logic, dependencies between states, or replacing classes under certain conditions. To solve that, I created Arto—a library that takes a more robust approach while remaining easy to integrate with any UI framework.What Is Arto?
Arto is a variant- and state-driven class name management library. It helps you define and merge:
size: 'small' | 'large'
,theme: 'primary' | 'secondary'
),disabled
,hover
,pressed
,focus
),It’s framework-agnostic—use it with React, Vue, Svelte, or plain JavaScript. If you are a Tailwind user, it fits right in with utility classes. If you want to incorporate advanced accessibility hooks or ephemeral states from any library, Arto handles that seamlessly.
Core Features
Why Another Library?
theme=primary
anddisabled=true
).hover
,focusVisible
, orpressed
often need precise rules. Arto helps you manage them systematically.Quick Example (Using a React Snippet)
Here’s a minimal example to illustrate how Arto merges variants and states into a final class string. This snippet uses React for demonstration.
Handling More Complex Logic
Let’s say you want to remove or replace classes when certain variant-state combos occur. That’s where rules come in:
So if
theme='primary'
anddisabled=true
, Arto removes the originalbg-blue-500 text-white
and addsbg-blue-300 text-white
. Instead of writing conditionals in your component, you’ve defined a self-contained rule.Adding Accessibility States
If you want to manage ephemeral states like
hover
,pressed
, orfocusVisible
from advanced hooks (e.g., React Aria or any other library providing those states), you simply pass booleans to Arto:Arto merges them all and produces the final output. This approach scales well for any front-end setup.
Getting Started
Install with your preferred package manager:
Then define an Arto config in your code. For more guides and deeper examples:
Conclusion
Arto aims to solve the advanced use cases around variants, states, and utility classes. It’s especially useful if:
Ultimately, you can drop Arto into any framework or plain JavaScript project. The React examples are just that—examples.
I’d love for you to try it out, share feedback, and help me refine it. Feel free to open an issue on GitHub if you spot any bugs or have suggestion.
Beta Was this translation helpful? Give feedback.
All reactions