Skip to content

Commit

Permalink
feat: add stylesheet component to dioxus document (#3138)
Browse files Browse the repository at this point in the history
* feat: add stylesheet component to dioxus document

* fix asset path

* add cache key to playwright
  • Loading branch information
jkelleyrtp authored Oct 29, 2024
1 parent 9ebcbc6 commit 42f6b91
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ jobs:
with:
cache-all-crates: "true"
cache-on-failure: "true"
key: "playwright-tests"

- name: Playwright
working-directory: ./packages/playwright-tests
Expand Down Expand Up @@ -346,7 +347,7 @@ jobs:

- uses: Swatinem/rust-cache@v2
with:
key: "${{ matrix.platform.target }}"
key: "matrix-${{ matrix.platform.target }}"
cache-all-crates: "true"
cache-on-failure: "true"

Expand Down
2 changes: 2 additions & 0 deletions packages/document/src/elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use dioxus_core_macro::*;

mod link;
pub use link::*;
mod stylesheet;
pub use stylesheet::*;
mod meta;
pub use meta::*;
mod script;
Expand Down
32 changes: 32 additions & 0 deletions packages/document/src/elements/stylesheet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use super::*;

/// Render a [`link`](crate::elements::link) tag into the head of the page with the stylesheet rel.
/// This is equivalent to the [`Link`](crate::Link) component with a slightly more ergonomic API.
///
///
/// # Example
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// fn RedBackground() -> Element {
/// rsx! {
/// document::Stylesheet {
/// src: asset!("/assets/style.css")
/// }
/// }
/// }
/// ```
///
/// <div class="warning">
///
/// Any updates to the props after the first render will not be reflected in the head.
///
/// </div>
#[component]
pub fn Stylesheet(props: LinkProps, src: Option<String>) -> Element {
super::Link(LinkProps {
href: src.or_else(|| props.href.clone()),
rel: Some("stylesheet".into()),
r#type: Some("text/css".into()),
..props
})
}

0 comments on commit 42f6b91

Please sign in to comment.