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

Code RS

Edit Component

Y Yew Code RS

Installation

cargo add coders --features yew

Usage

use coders::yew::{Code, Block, Header, Title, CopyTrigger, Content, LanguageBadge};
use coders::{Color, Language, Size, Variant};
use yew::prelude::*;

Inline Code

use coders::yew::Code;
use coders::{Color, Size, Variant};
use yew::prelude::*;

#[function_component(Example)]
pub fn example() -> Html {
    html! {
        <Code color={Color::Accent} variant={Variant::Subtle} size={Size::Sm}>
            {"console.log(\"Hello, world!\")"}
        </Code>
    }
}

Code Block (Basic)

use coders::yew::{Block, Content, Header, Title, CopyTrigger};
use coders::Language;
use yew::prelude::*;

#[function_component(Example)]
pub fn example() -> Html {
    html! {
        <Block code="fn main() {\n    println!(\"Hello, world!\");\n}" language={Language::Rust}>
            <Header>
                <Title>{"main.rs"}</Title>
                <CopyTrigger />
            </Header>
            <Content />
        </Block>
    }
}

Props

Code

PropDefaultTypeDescription
colorColor::DefaultColorColor palette applied to the component
variantVariant::SubtleVariantVisual style variant
sizeSize::SmSizeFont size and padding
class""&'static strAdditional CSS class names
style""&'static strInline CSS override
id""&'static strHTML id attribute
aria_label""&'static strAccessible label
data_testid""&'static strTest identifier

Block

PropDefaultTypeDescription
code-&'static strRaw code content (required)
languageLanguage::PlainLanguageLanguage hint for badge
class""&'static strAdditional CSS class names
style""&'static strInline CSS override
id""&'static strHTML id attribute
aria_label"Code block"&'static strAccessible region label
data_testid""&'static strTest identifier

CopyTrigger

PropDefaultTypeDescription
copy_label"Copy"&'static strLabel before copying
copied_label"Copied!"&'static strLabel after copy
reset_ms2000u32Reset delay in milliseconds
aria_label"Copy code to clipboard"&'static strAccessible label

Color variants

Default, Red, Orange, Yellow, Green, Teal, Blue, Cyan, Accent, Pink, Success, Warning, Danger

Variant variants

Solid, Subtle, Outline, Surface, Plain

Size variants

Xs, Sm, Md, Lg, Custom(&'static str)

Language variants

Plain, Rust, JavaScript, TypeScript, Python, Html, Css, Json, Bash, Toml, Sql, Go, Java, Cpp, C, Kotlin, Swift, Ruby, Php, Yaml, Custom(&'static str)

Theme variants

OneDark (default), Dracula, NightOwl, GithubDark, GithubLight, Solarized, Monokai, Nord, Custom(ThemeColors)

See Also

Usage

CLI Usage

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

os add coders yew