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