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:
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bard"
|
name = "bard"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "Dioxus components that will display a Tavern blogging system Blog."
|
description = "Dioxus components that will display a Tavern blogging system Blog."
|
||||||
repository = "/CyberMages/tavern"
|
repository = "/CyberMages/tavern"
|
||||||
|
|||||||
@ -40,6 +40,7 @@
|
|||||||
.blog_title
|
.blog_title
|
||||||
{
|
{
|
||||||
margin-top: 0px;
|
margin-top: 0px;
|
||||||
|
color: var(--accent-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.blog_item
|
.blog_item
|
||||||
@ -89,6 +90,15 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.blog_post_tale
|
||||||
|
{
|
||||||
|
all: initial;
|
||||||
|
|
||||||
|
pre
|
||||||
|
{
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.embeded_video
|
.embeded_video
|
||||||
{
|
{
|
||||||
margin-top: 50px;
|
margin-top: 50px;
|
||||||
@ -101,6 +111,7 @@
|
|||||||
box-shadow: 0 0 80px var(--accent-color);
|
box-shadow: 0 0 80px var(--accent-color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,9 +155,10 @@
|
|||||||
|
|
||||||
legend
|
legend
|
||||||
{
|
{
|
||||||
min-width: 120px;
|
min-width: 130px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag_list
|
.tag_list
|
||||||
@ -155,14 +167,48 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toggle_button {
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-right: 5px;
|
||||||
|
padding: 0px 6px;
|
||||||
|
border: 2px solid var(--text-color);
|
||||||
|
border-radius: 5px;
|
||||||
|
color: var(--text-color);
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
transition: 0.1s ease-in;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle_button:hover {
|
||||||
|
color: var(--accent-color);
|
||||||
|
border-color: var(--accent-color);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle_button input[type="checkbox"] {
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Checked state using :has() — modern browsers only */
|
||||||
|
.toggle_button:has(input:checked) {
|
||||||
|
color: var(--accent-color);
|
||||||
|
border-color: var(--accent-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@container site (max-width: 1230px)
|
@container site (max-width: 1230px)
|
||||||
{
|
{
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag_list
|
.tag_list
|
||||||
{
|
{
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
@ -174,7 +220,7 @@
|
|||||||
|
|
||||||
a
|
a
|
||||||
{
|
{
|
||||||
display: block;
|
display: inline-block;
|
||||||
padding: 0px 4px;
|
padding: 0px 4px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border: 2px solid var(--text-color);
|
border: 2px solid var(--text-color);
|
||||||
@ -191,4 +237,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,7 +82,12 @@ pub fn Story(text: String) -> Element
|
|||||||
{
|
{
|
||||||
rsx!
|
rsx!
|
||||||
{
|
{
|
||||||
div { dangerous_inner_html: "{text}" }
|
div
|
||||||
|
{
|
||||||
|
class: "blog_post_tale",
|
||||||
|
|
||||||
|
dangerous_inner_html: "{text}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ mod components;
|
|||||||
mod page;
|
mod page;
|
||||||
mod pages;
|
mod pages;
|
||||||
mod server;
|
mod server;
|
||||||
|
mod settings;
|
||||||
mod togglable;
|
mod togglable;
|
||||||
|
|
||||||
|
|
||||||
@ -14,5 +15,6 @@ pub use crate::components::*;
|
|||||||
pub use crate::info::{get_name, get_version};
|
pub use crate::info::{get_name, get_version};
|
||||||
pub use crate::page::Page;
|
pub use crate::page::Page;
|
||||||
pub use crate::pages::*;
|
pub use crate::pages::*;
|
||||||
|
pub use crate::settings::*;
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
pub use crate::server::*;
|
pub use crate::server::*;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
use crate::pages::{Blog, Post, Root};
|
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]
|
#[component]
|
||||||
fn BlogLayout() -> Element
|
fn BlogLayout() -> Element
|
||||||
{
|
{
|
||||||
|
// Retrieve the provided settings from context.
|
||||||
|
let settings = use_context::<BardSettings>();
|
||||||
|
|
||||||
|
rsx!
|
||||||
|
{
|
||||||
|
match settings.stylesheet
|
||||||
|
{
|
||||||
|
StylesheetBehavior::Override(asset) =>
|
||||||
|
{
|
||||||
|
rsx!
|
||||||
|
{
|
||||||
|
document::Stylesheet { href: asset }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StylesheetBehavior::Extend(asset) =>
|
||||||
|
{
|
||||||
rsx!
|
rsx!
|
||||||
{
|
{
|
||||||
document::Stylesheet { href: BLOG_CSS }
|
document::Stylesheet { href: BLOG_CSS }
|
||||||
|
document::Stylesheet { href: asset }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StylesheetBehavior::None =>
|
||||||
|
{
|
||||||
|
rsx!
|
||||||
|
{
|
||||||
|
document::Stylesheet { href: BLOG_CSS }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Outlet::<Page> {}
|
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