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

Pride RS

Edit Component

Pride RS Yew Usage

Adding Pride 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 Pride RS component to your dependencies by including it in your Cargo.toml file:

    # Halal edition (default)
    cargo add pride-rs --features=yew
    
    # Full edition (includes gender-identity flags)
    cargo add pride-rs --features=yew,haram
    
  3. Import a Flag component into your Yew component and start using it in your app.

🚩 Feature Gate: haram

By default, four flag types are excluded from the crate at compile time because they relate to gender identity change:

TypeExcluded by default
Transgenderβœ…
NonBinaryβœ…
Genderfluidβœ…
Agenderβœ…

Enable the haram feature to opt-in:

pride-rs = { version = "0.1.0", features = ["yew", "haram"] }

You can also inspect the gate at runtime via FlagConfig::haram:

use pride_rs::Type;
use pride_rs::FlagLookup;

let config = Type::Rainbow.config().unwrap();
assert!(!config.haram);

// Only available when --features haram is set:
// let config = Type::Transgender.config().unwrap();
// assert!(config.haram);

And detect haram variants directly on the enum (requires haram feature):

#[cfg(feature = "haram")]
{
    use pride_rs::Type;
    assert!(Type::Transgender.is_haram());
    assert!(!Type::Rainbow.is_haram());
}

πŸ› οΈ Usage

Each flag type is backed by a configuration that returns a list of colors (stripes) and a direction (horizontal or vertical). The component renders a <div> with child <div> stripes, each styled with the color and arranged by direction:

Flag container div (flex layout)
+-------------------------------------------------+
|                                                 |
|  Horizontal direction (flex-direction: column)  |
|  +-------+                                      |
|  | Color |                                      |
|  | Stripe|                                      |
|  +-------+                                      |
|  | Color |                                      |
|  | Stripe|                                      |
|  +-------+                                      |
|  | Color |                                      |
|  | Stripe|                                      |
|  +-------+                                      |
|                                                 |
|                                                 |
|  Vertical direction (flex-direction: row)       |
|  +-------+-------+-------+-------+-------+      |
|  | Color | Color | Color | Color | Color |      |
|  | Stripe| Stripe| Stripe| Stripe| Stripe|      |
|  +-------+-------+-------+-------+-------+      |
|                                                 |
+-------------------------------------------------+

The Direction enum guides the layout style:

  • Horizontal: flex-direction: column;
  • Verticalβ€œ flex-direction: row;
use yew::prelude::*;
use pride_rs::yew::{FlagSection, Flag};
use pride_rs::{Size, Type};


#[function_component(App)]
pub fn app() -> Html {
    html! {
        <>
            <Flag r#type={Type::Bisexual} />
            <Flag size={Size::Large} />
            <FlagSection
                title={"Pride Flags".to_string()}
                flags={vec![Type::Rainbow, Type::Bisexual, Type::Lesbian]}
                id="pride"
            />
        </>
    }
}

πŸ”§ Props

Flag

The Flag component renders a single flag based on the provided Type, with optional sizing, ARIA accessibility labels, hover tooltips, and customizable styles.

FlagProps

PropTypeDescriptionDefault
typeTypeType of the flag. Determines colors and layout.Type::Rainbow
sizeSizeThe size of the flag (Small, Medium, or Large).Size::Medium
class&'static strAdditional CSS classes for the flag container.""
aria_labelStringAccessible label for screen readers.String::new()
style&'static strGeneral style applied to the flag.display: flex; border-radius: 4px; overflow: hidden; ...
horizontal_style&'static strStyle for horizontally oriented flags."flex-direction: column;"
vertical_style&'static strStyle for vertically oriented flags."flex-direction: row;"
stripe_style&'static strStyle for each individual color stripe."flex: 1; min-height: 4px; min-width: 4px;"
small_style&'static strDimensions for small flags."width: 24px; height: 24px;"
medium_style&'static strDimensions for medium flags."width: 48px; height: 32px;"
large_style&'static strDimensions for large flags."width: 96px; height: 64px;"
container_style&'static strStyle for the outer container of the flag."position: relative; display: inline-block;"
tooltip_style&'static strStyle for the tooltip shown on hover or focus."position: absolute; bottom: 100%; left: 50%; ..."
container_class&'static strClass name for the outer container."flag-container"
flag_class&'static strClass name for the main flag element."flag"
stripe_class&'static strClass name for the color stripe elements."stripe"
tooltip_class&'static strClass name for the tooltip."tooltip"

FlagSection

The FlagSection component displays a titled section of multiple flags. It can be used to group flags by type.

FlagSectionProps

PropTypeDescriptionDefault
titleStringThe section heading title.String::new()
flagsVec<Type>A list of flag Types to display.vec![]
id&'static strA unique identifier used for ARIA accessibility labels.""
section_style&'static strStyle for the entire section element."margin-bottom: 32px;"
section_title_style&'static strStyle for the section’s title."font-family: 'SF Pro Text', ...; padding-left: 4px;"
container_style&'static strStyle for the container holding all flag elements."background-color: #fff; border: 2px dashed #7b61ff; ..."
empty_state_style&'static strStyle for the message shown when flags is empty."color: #666; font-style: italic; ..."
section_class&'static strCSS class for the main section container."section"
section_title_class&'static strCSS class for the title."section-title"
container_class&'static strCSS class for the flag container."flag-container"
empty_state_class&'static strCSS class for the empty state message."empty-state"

πŸ’‘ Notes

  • Use FlagSection for grouping related flags with semantic markup and accessible labels.
  • Use Flag alone for isolated flags.
  • Customize styles by overriding style, class, or size props.
  • Supports keyboard navigation and tooltips for improved accessibility.
  • Each Flag renders with role="img" and a descriptive aria-label.
  • Focusable via tabindex=0.
  • Keyboard operable (Enter and Space log selection).
  • Tooltip linked with aria-describedby for screen readers.
  • Flags have aria-roledescription="flag" for better assistive context.
  • FlagSection uses role="group" with aria-labelledby and aria-describedby.
  • Empty state has polite aria-live announcements.
  • Gender-identity flag types are excluded by default; enable --features haram to include them.

Usage

CLI Usage

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

os add pride-rs yew