windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation

use super::traits::Renderable
pub struct CollapsibleSection {
    title: string,
    content: string,
    open: bool,
}

impl CollapsibleSection {
    pub fn new(title: string, content: string) -> CollapsibleSection {
        CollapsibleSection {
            title,
            content,
            open: false,
        }
    }

    pub fn open(self, open: bool) -> CollapsibleSection {
        self.open = open
        self
    }


}

impl Renderable for CollapsibleSection {
pub fn render(self) -> string {
        let icon = if self.open { "▼" } else { "▶" }
        let content_style = if self.open { "display: block;" } else { "display: none;" }

        format!("<div class='wj-collapsible'>
  <div class='wj-collapsible-header'>
    <span class='wj-collapsible-icon'>{}</span>
    <span>{}</span>
  </div>
  <div class='wj-collapsible-content' style='{}'>
    {}
  </div>
</div>", icon, self.title, content_style, self.content)
    }
}

fn main() {
    let collapsible = CollapsibleSection::new("Advanced Options".to_string(), "<p>Hidden content here</p>".to_string())
        .open(true)

    println!("{}", collapsible.render())
}