windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation
// Select - Dropdown selection component

pub struct Select {
    options: Vec<SelectOption>,
    selected: string,
    placeholder: string,
    disabled: bool,
    size: SelectSize,
    class: string,
}

pub struct SelectOption {
    value: string,
    label: string,
}

pub enum SelectSize {
    Small,
    Medium,
    Large,
}

impl Select {
    pub fn new() -> Select {
        Select {
            options: Vec::new(),
            selected: String::new(),
            placeholder: "Select an option".to_string(),
            disabled: false,
            size: SelectSize::Medium,
            class: String::new(),
        }
    }
    
    pub fn option(value: string, label: string) -> Select {
        self.options.push(SelectOption { value, label })
        self
    }
    
    pub fn selected(selected: string) -> Select {
        self.selected = selected
        self
    }
    
    pub fn placeholder(placeholder: string) -> Select {
        self.placeholder = placeholder
        self
    }
    
    pub fn disabled(disabled: bool) -> Select {
        self.disabled = disabled
        self
    }
    
    pub fn size(size: SelectSize) -> Select {
        self.size = size
        self
    }
    
    pub fn class(class: string) -> Select {
        self.class = class
        self
    }
    
    pub fn render() -> string {
        let size_style = match self.size {
            SelectSize::Small => "padding: 4px 8px; font-size: 12px;",
            SelectSize::Medium => "padding: 8px 12px; font-size: 14px;",
            SelectSize::Large => "padding: 12px 16px; font-size: 16px;",
        }
        
        let disabled_attr = if self.disabled { " disabled" } else { "" }
        
        let mut html = String::new()
        html.push_str("<select class=\"wj-select ")
        html.push_str(self.class.as_str())
        html.push_str("\" style=\"")
        html.push_str(size_style)
        html.push_str(" border: 1px solid #d1d5db; border-radius: 6px; background: white; cursor: pointer;\"")
        html.push_str(disabled_attr)
        html.push('>')
        
        // Placeholder option
        if !self.placeholder.is_empty() {
            html.push_str("<option value=\"\" disabled")
            if self.selected.is_empty() {
                html.push_str(" selected")
            }
            html.push_str(">")
            html.push_str(self.placeholder.as_str())
            html.push_str("</option>")
        }
        
        // Options
        for opt in self.options {
            html.push_str("<option value=\"")
            html.push_str(opt.value.as_str())
            html.push('"')
            
            if opt.value == self.selected {
                html.push_str(" selected")
            }
            
            html.push('>')
            html.push_str(opt.label.as_str())
            html.push_str("</option>")
        }
        
        html.push_str("</select>")
        html
    }
}