You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What if I have nested elements that also depend of variant prop? Should I call cva() multiple times or use object map?
Here is my incomplete example in Astro and BEM:
Alert.astro:
---import{Icon}from'astro-icon/components';import{cva}from'class-variance-authority';import{capitalizeFirstLetter}from'@/utils/strings';import{cn}from'@/utils/styles';importtype{HTMLAttributes}from'astro/types';importtype{VariantProps}from'class-variance-authority';constalertVariants=cva('alert',{variants: {variant: {note: 'alert-note',info: 'alert-info',tip: 'alert-tip',warning: 'alert-warning',danger: 'alert-danger',},},});// is this ok or I should call cva() again? what about eventual compoundVariants?constalertTitleVariants={note: 'alert__title--note',info: 'alert__title--info',tip: 'alert__title--tip',warning: 'alert__title--warning',danger: 'alert__title--danger',};exportinterfacePropsextendsHTMLAttributes<'aside'>,VariantProps<typeofalertVariants>{title?: string;}const{title: titleProp,class: className,variant: variantProp, ...props}=Astro.props;// defailtsconstvariant=variantProp??'note';consttitle=titleProp??capitalizeFirstLetter(variant);---<asideclass={alertVariants({ variant, className })}aria-label={title}{...props}><h4aria-hidden="true"class={cn('alert__title',alertTitleVariants[variant])}><Iconname={variant}class="inline h-6 w-6"/>
{title}</h4><div><slot/></div></aside>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
There is a BEM example in docs but it shows just block with modifiers:
https://cva.style/docs/examples/bem
What if I have nested elements that also depend of variant prop? Should I call
cva()
multiple times or use object map?Here is my incomplete example in Astro and BEM:
Alert.astro:
components.css:
Beta Was this translation helpful? Give feedback.
All reactions