#[derive(Clone, Debug)]
pub struct ComboOption {
pub label: String,
pub value: Option<String>,
pub disabled: bool,
pub group: Option<String>,
}
impl ComboOption {
pub fn new(label: impl Into<String>) -> Self {
Self {
label: label.into(),
value: None,
disabled: false,
group: None,
}
}
pub fn value(mut self, value: impl Into<String>) -> Self {
self.value = Some(value.into());
self
}
pub fn disabled(mut self, disabled: bool) -> Self {
self.disabled = disabled;
self
}
pub fn group(mut self, group: impl Into<String>) -> Self {
self.group = Some(group.into());
self
}
pub fn get_value(&self) -> &str {
self.value.as_deref().unwrap_or(&self.label)
}
}
impl<T: Into<String>> From<T> for ComboOption {
fn from(s: T) -> Self {
ComboOption::new(s)
}
}