perspective_viewer/components/style/mod.rs
1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13//! A micro-framework for associating local CSS snippets with `yew::Component`s
14//! in a Custom Element's `ShadowRoot`.
15//!
16//! Embedding a `<LocalStyle>` element will only create the underlying `<style>`
17//! tag once (when `Component::view()` is called the first time), even if
18//! multiple copies of the `Component` exist in the tree.
19//!
20//! # Example
21//!
22//! ```
23//! html! {
24//! <StyleProvider>
25//! <LocalStyle href={ css!("my-style") } />
26//! <h1>{ "I am styled!" }</h1>
27//! </StyleProvider>
28//! }
29//! ```
30
31mod local_style;
32mod style_cache;
33mod style_provider;
34
35pub use local_style::LocalStyle;
36pub use style_provider::StyleProvider;
37
38#[macro_export]
39macro_rules! css {
40 ($name:expr) => {{
41 (
42 $name,
43 include_str!(concat!(env!("OUT_DIR"), "/css/", $name, ".css")),
44 )
45 }};
46 ($path:expr, $name:expr) => {{
47 (
48 $name,
49 include_str!(concat!(env!("OUT_DIR"), "/", $path, "/", $name, ".css")),
50 )
51 }};
52}