Proposal: @neodx/cva
#151
secundant
announced in
Announcements
Replies: 2 comments
-
Братан, хорош, давай, давай, вперёд! Контент в кайф, можно ещё? Вообще красавчик! Можно вот этого вот почаще? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Additional reference: https://www.tailwind-variants.org/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problems
cva.style isn't strong solution
cva
doesn't introduce any complex concepts on top of the Variants AP. Its beta version only offers the compose API.We have no other options :)
Without CVA-like solutions, we are obligated to constantly write tons of boilerplate code just for styling our components.
But even with the current
cva
state, we remain too far from the boiler-free workflow.Key aspects
Concept
Simple usage
compound
APIUse case - huge amount of crossing nested rules:
Could be redesigned as
Slots API
Extendability
Comparison
Case 1: Simple component
Let's start from writing the easiest variadic component:
Even for that simple example, there are a few obvious issues.
To set up our component, we should:
cva
scheme,className
andchildren
props,cva
instanceclassName
tocva
instancedisplayName
The source problem indicates that the common patterns mentioned can be automated, but they currently are not.
Proposed alternative
The idea is simple:
Case 2: Forward ref and custom props
Usually, we aren't satisfied with using only the directly defined props, but we want to provide all possible HTML attributes and React
ref
to our component.The problem is growing with the following parts:
ref
declaration and forwarding,forwardRef
with hardcodedHTMLDivElement
,ComponentPropsWithoutRef<'div'>
All of these parts are unnecessary.
Proposed alternative
Let's start from the simplest variant:
The main idea here is automatic inheriting
div
behaviour without any additional code.I've been mention additional props previously, but the proposal covers only 1-1 inheritance.
The next session will provide a detailed and illustrative overview of the scale of the problem.
Case 3: Composition of multiple elements that inherit common properties
The previous examples were just an introduction to illustrate the problem at the core level. However, our design system components (which are the crucial case for
cva
) usually require additional features and internal composition. For these reasons, I'm proposing the following concepts:cva
configuration for defining styles of internal elementscva.ui
API for high-level describing our component implementationcva
schemeBut let's look at the original variant:
Tremendous boilerplate!
(here will be explanation...)
Full version
(here will be explanation...)
Proposal alternative
Beta Was this translation helpful? Give feedback.
All reactions