Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Card RS

Edit Component

Y Card RS Yew Usage

Adding Card RS to your project is simple:

  1. Make sure your project is set up with Yew. Follow their Getting Started Guide for setup instructions.

  2. Add the Card RS component to your dependencies by including it in your Cargo.toml file:

    cargo add card-rs --features=yew
    
  3. Import the card components into your Yew component and start using them in your app.

🛠️ Usage

Basic Card

use card_rs::yew::{Card, Header, Title, Description, Content, Footer};
use card_rs::Variant;
use yew::prelude::*;

#[function_component(BasicCard)]
pub fn basic_card() -> Html {
    html! {
        <Card variant={Variant::Default} aria_labelledby="basic-title">
            <Header>
                <Title id="basic-title">{"Hello, Card!"}</Title>
                <Description>{"A simple card with header and footer."}</Description>
            </Header>
            <Content>
                <p>{"This is the main content area of the card."}</p>
            </Content>
            <Footer>
                <button>{"Action"}</button>
            </Footer>
        </Card>
    }
}

Variants

use card_rs::yew::{Card, Header, Title, Description, Content};
use card_rs::Variant;
use yew::prelude::*;

#[function_component(CardVariants)]
pub fn card_variants() -> Html {
    html! {
        <>
            <Card variant={Variant::Transparent}>
                <Header>
                    <Title>{"Transparent"}</Title>
                    <Description>{"Minimal prominence."}</Description>
                </Header>
                <Content><p>{"For nested or low-priority cards."}</p></Content>
            </Card>
            <Card variant={Variant::Default}>
                <Header>
                    <Title>{"Default"}</Title>
                    <Description>{"Standard surface."}</Description>
                </Header>
                <Content><p>{"Most common use case."}</p></Content>
            </Card>
            <Card variant={Variant::Secondary}>
                <Header>
                    <Title>{"Secondary"}</Title>
                    <Description>{"Medium prominence."}</Description>
                </Header>
                <Content><p>{"Draw moderate attention."}</p></Content>
            </Card>
            <Card variant={Variant::Tertiary}>
                <Header>
                    <Title>{"Tertiary"}</Title>
                    <Description>{"Higher prominence."}</Description>
                </Header>
                <Content><p>{"For featured content."}</p></Content>
            </Card>
        </>
    }
}

Custom Styles

use card_rs::yew::{Card, Header, Title, Description, Footer};
use card_rs::Variant;
use yew::prelude::*;

#[function_component(StyledCard)]
pub fn styled_card() -> Html {
    html! {
        <Card
            variant={Variant::Default}
            style="border: 2px solid #7c3aed; border-radius: 1rem;"
            aria_labelledby="styled-title"
        >
            <Header>
                <Title id="styled-title" style="color: #7c3aed;">{"Pro Plan"}</Title>
                <Description>{"Unlock advanced features."}</Description>
            </Header>
            <Footer>
                <button>{"Upgrade Now"}</button>
            </Footer>
        </Card>
    }
}

🔧 Props

Card

PropertyTypeDescriptionDefault
variantVariantVisual prominence level.Variant::Default
class&'static strExtra CSS classes on the root element.""
style&'static strExtra inline CSS on the root element.""
id&'static strid attribute on the root element.""
role&'static strARIA role."article"
aria_label&'static strAccessible label.""
aria_labelledby&'static strID of labelling element.""
data_testid&'static strTest selector.""
PropertyTypeDescriptionDefault
class&'static strExtra CSS classes.""
style&'static strExtra inline CSS.""
id&'static strid attribute.""

Title

PropertyTypeDescriptionDefault
id&'static strUse with aria-labelledby on the parent Card.""
class&'static strExtra CSS classes.""
style&'static strExtra inline CSS.""

Description

PropertyTypeDescriptionDefault
class&'static strExtra CSS classes.""
style&'static strExtra inline CSS.""
id&'static strid attribute.""

Content

PropertyTypeDescriptionDefault
class&'static strExtra CSS classes.""
style&'static strExtra inline CSS.""
id&'static strid attribute.""
PropertyTypeDescriptionDefault
class&'static strExtra CSS classes.""
style&'static strExtra inline CSS.""
id&'static strid attribute.""

💡 Notes

  • Title, Description, Content, and Footer can be used without a Header wrapper.
  • Set id on Title and pass it to Card’s aria_labelledby for full WCAG compliance.
  • The variant prop maps to semantic BEM classes (card--default, etc.) and inline styles. Override either for custom themes.

Usage

CLI Usage

You can import Card RS directly into your project to customize and modify it using the opensass cli:

os add card-rs yew