cargo add coders --features lepuse coders::leptos::{Code, Block, Header, Title, CopyTrigger, Content, LanguageBadge};
use coders::{Color, Language, Size, Variant};
use leptos::prelude::*;use coders::leptos::Code;
use coders::{Color, Size, Variant};
use leptos::prelude::*;
#[component]
pub fn Example() -> impl IntoView {
view! {
<Code color=Color::Accent variant=Variant::Subtle size=Size::Sm>
"console.log(\"Hello, world!\")"
</Code>
}
}use coders::leptos::{Block, Content, Header, Title, CopyTrigger};
use coders::Language;
use leptos::prelude::*;
#[component]
pub fn Example() -> impl IntoView {
view! {
<Block code="fn main() {\n println!(\"Hello, world!\");\n}" language={Language::Rust}>
<Header>
<Title>"main.rs"</Title>
<CopyTrigger />
</Header>
<Content />
</Block>
}
}| Prop | Default | Type | Description |
|---|---|---|---|
color |
Color::Default |
Color |
Color palette applied to the component |
variant |
Variant::Subtle |
Variant |
Visual style variant |
size |
Size::Sm |
Size |
Font size and padding |
class |
"" |
&'static str |
Additional CSS class names |
style |
"" |
&'static str |
Inline CSS override |
id |
"" |
&'static str |
HTML id attribute |
aria_label |
"" |
&'static str |
Accessible label |
data_testid |
"" |
&'static str |
Test identifier |
| Prop | Default | Type | Description |
|---|---|---|---|
code |
- | &'static str |
Raw code content (required) |
language |
Language::Plain |
Language |
Language hint for badge |
class |
"" |
&'static str |
Additional CSS class names |
style |
"" |
&'static str |
Inline CSS override |
id |
"" |
&'static str |
HTML id attribute |
aria_label |
"Code block" |
&'static str |
Accessible region label |
data_testid |
"" |
&'static str |
Test identifier |
| Prop | Default | Type | Description |
|---|---|---|---|
copy_label |
"Copy" |
&'static str |
Label before copying |
copied_label |
"Copied!" |
&'static str |
Label after copy |
reset_ms |
2000 |
u32 |
Reset delay in milliseconds |
aria_label |
"Copy code to clipboard" |
&'static str |
Accessible label |
Default, Red, Orange, Yellow, Green, Teal, Blue, Cyan, Accent, Pink, Success, Warning, Danger
Solid, Subtle, Outline, Surface, Plain
Xs, Sm, Md, Lg, Custom(&'static str)
Plain, Rust, JavaScript, TypeScript, Python, Html, Css, Json, Bash, Toml, Sql, Go, Java, Cpp, C, Kotlin, Swift, Ruby, Php, Yaml, Custom(&'static str)
OneDark (default), Dracula, NightOwl, GithubDark, GithubLight, Solarized, Monokai, Nord, Custom(ThemeColors)
- MDN:
<pre>, Preformatted Text element: The semantic root of everyContentrendering. - MDN:
<code>, Inline Code element: Used for both the inlineCodecomponent and the highlighted code node insideContent. - MDN:
<figure>, Figure with Optional Caption element: The landmark wrapper rendered byBlock. - MDN:
Clipboard.writeText(): The Web API called byCopyTriggerto copy code to the clipboard.