styled()- create components with variantscreateStyledContext()- share variants between componentswithSlots()- compose compound components
Step 1: A Simple Styled Component
Start with the basics. Create a button with size variants.base applies always, variants apply based on props.
Step 2: Add More Variants
Let’s add avariant prop for different styles.
Step 3: Compound Variants
Sometimes you need special styling when multiple variants combine. That’s whatcompoundVariants is for.
<Button variant="primary" size="lg"> gets an extra shadow that smaller or secondary buttons don’t.
Step 4: Context for Parent-Child Communication
Here’s where better-styled shines. Let’s add a label to our button that automatically matches the button’s size.Button.Label automatically receives size="lg" from the parent. No prop drilling.
What You’ve Learned
- ✅
styled(component, config)- Creates components with variant support - ✅
createStyledContext(variants)- Defines which variants should be shared - ✅
withSlots(component, slots)- Creates compound components with dot notation
Next Steps
Understanding styled()
Deep dive into the main API
Variant System
Learn about compound variants and defaults
Context Propagation
Master parent-child communication
Compound Components
Build complex component APIs