windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation
// Popover - Floating content component

pub struct Popover {
    trigger: string,
    content: string,
    position: PopoverPosition,
    class: string,
}

pub enum PopoverPosition {
    Top,
    Bottom,
    Left,
    Right,
}

impl Popover {
    pub fn new(trigger: string, content: string) -> Popover {
        Popover {
            trigger,
            content,
            position: PopoverPosition::Bottom,
            class: String::new(),
        }
    }
    
    pub fn position(position: PopoverPosition) -> Popover {
        self.position = position
        self
    }
    
    pub fn class(class: string) -> Popover {
        self.class = class
        self
    }
    
    pub fn render() -> string {
        let position_style = match self.position {
            PopoverPosition::Top => "bottom: 100%; left: 50%; transform: translateX(-50%); margin-bottom: 8px;",
            PopoverPosition::Bottom => "top: 100%; left: 50%; transform: translateX(-50%); margin-top: 8px;",
            PopoverPosition::Left => "right: 100%; top: 50%; transform: translateY(-50%); margin-right: 8px;",
            PopoverPosition::Right => "left: 100%; top: 50%; transform: translateY(-50%); margin-left: 8px;",
        }
        
        let mut html = String::new()
        html.push_str("<div class=\"wj-popover ")
        html.push_str(self.class.as_str())
        html.push_str("\" style=\"position: relative; display: inline-block;\">")
        
        // Trigger
        html.push_str(self.trigger.as_str())
        
        // Popover content
        html.push_str("<div class=\"wj-popover-content\" style=\"position: absolute; ")
        html.push_str(position_style)
        html.push_str(" background: white; border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); min-width: 200px; z-index: 1000; display: none;\">")
        html.push_str(self.content.as_str())
        html.push_str("</div>")
        
        html.push_str("</div>")
        
        // Add hover behavior
        html.push_str("<style>.wj-popover:hover .wj-popover-content { display: block; }</style>")
        
        html
    }
}