rumtk_web/components/html/
details.rs1use crate::components::html::pre::{pre, Pre};
21use crate::components::html::summary::{summary, Summary};
22use crate::utils::defaults::{DEFAULT_TEXT_ITEM, PARAMS_CSS_CLASS};
23use crate::utils::types::{SharedAppState, URLParams, URLPath};
24use crate::{rumtk_web_get_config, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
25use rumtk_core::strings::RUMString;
26
27#[derive(RUMWebTemplate, Debug, Clone)]
28#[template(
29 source = "
30 {% if custom_css_enabled %}
31 <link href='/static/components/details.css' rel='stylesheet'>
32 {% endif %}
33 <details class='details-{{css_class}}'>
34 {{summary}}
35 {{contents}}
36 </details>
37 ",
38 ext = "html"
39)]
40pub struct Details {
41 summary: Summary,
42 contents: Pre,
43 css_class: RUMString,
44 custom_css_enabled: bool,
45}
46
47impl RUMWebTemplateSafe for Details {}
48
49pub fn details<'a>(_path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<Details> {
50 let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
51 let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
52
53 Ok(Details {
54 summary: summary(_path_components, params, state.clone())?,
55 contents: pre(_path_components, params, state)?,
56 css_class,
57 custom_css_enabled
58 })
59}