Client side settings can now be specified.
Here we use a context provider on the app itself to handle passing the settings to our library. This way even the layout can use them.
This commit is contained in:
@ -82,7 +82,12 @@ pub fn Story(text: String) -> Element
|
||||
{
|
||||
rsx!
|
||||
{
|
||||
div { dangerous_inner_html: "{text}" }
|
||||
div
|
||||
{
|
||||
class: "blog_post_tale",
|
||||
|
||||
dangerous_inner_html: "{text}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ mod components;
|
||||
mod page;
|
||||
mod pages;
|
||||
mod server;
|
||||
mod settings;
|
||||
mod togglable;
|
||||
|
||||
|
||||
@ -14,5 +15,6 @@ pub use crate::components::*;
|
||||
pub use crate::info::{get_name, get_version};
|
||||
pub use crate::page::Page;
|
||||
pub use crate::pages::*;
|
||||
pub use crate::settings::*;
|
||||
#[cfg(feature = "server")]
|
||||
pub use crate::server::*;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
use crate::pages::{Blog, Post, Root};
|
||||
use crate::settings::{BardSettings, StylesheetBehavior};
|
||||
|
||||
|
||||
|
||||
@ -11,9 +12,38 @@ const BLOG_CSS: Asset = asset!("/assets/css/blog.css");
|
||||
#[component]
|
||||
fn BlogLayout() -> Element
|
||||
{
|
||||
// Retrieve the provided settings from context.
|
||||
let settings = use_context::<BardSettings>();
|
||||
|
||||
rsx!
|
||||
{
|
||||
document::Stylesheet { href: BLOG_CSS }
|
||||
match settings.stylesheet
|
||||
{
|
||||
StylesheetBehavior::Override(asset) =>
|
||||
{
|
||||
rsx!
|
||||
{
|
||||
document::Stylesheet { href: asset }
|
||||
}
|
||||
}
|
||||
|
||||
StylesheetBehavior::Extend(asset) =>
|
||||
{
|
||||
rsx!
|
||||
{
|
||||
document::Stylesheet { href: BLOG_CSS }
|
||||
document::Stylesheet { href: asset }
|
||||
}
|
||||
}
|
||||
|
||||
StylesheetBehavior::None =>
|
||||
{
|
||||
rsx!
|
||||
{
|
||||
document::Stylesheet { href: BLOG_CSS }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Outlet::<Page> {}
|
||||
}
|
||||
|
||||
33
bard/src/settings.rs
Normal file
33
bard/src/settings.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum StylesheetBehavior
|
||||
{
|
||||
/// Overrides the default stylesheet.
|
||||
Override(Asset),
|
||||
|
||||
/// Extends the default stylesheet. The library will load both.
|
||||
Extend(Asset),
|
||||
|
||||
/// Uses the library's default stylesheet.
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct BardSettings
|
||||
{
|
||||
/// A user defined stylesheet and how the library should include it.
|
||||
pub stylesheet: StylesheetBehavior
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Default for StylesheetBehavior
|
||||
{
|
||||
fn default() -> Self
|
||||
{
|
||||
StylesheetBehavior::None
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user