mirror of
https://github.com/yewprint/yewprint
synced 2024-11-22 03:23:03 +00:00
Make selected value of Slider optional (#115)
The Slider's value should be able to be deselected.
This commit is contained in:
parent
2e240fdb07
commit
ec208f13e6
2 changed files with 8 additions and 8 deletions
|
@ -6,7 +6,7 @@ pub struct Example {
|
|||
props: ExampleProps,
|
||||
float: f64,
|
||||
integer: i32,
|
||||
log_level: LogLevel,
|
||||
log_level: Option<LogLevel>,
|
||||
link: ComponentLink<Self>,
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ impl Component for Example {
|
|||
props,
|
||||
float: 1.2,
|
||||
integer: 30,
|
||||
log_level: LogLevel::Info,
|
||||
log_level: None,
|
||||
link,
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ impl Component for Example {
|
|||
self.integer = value;
|
||||
}
|
||||
Msg::LogLevelUpdate(value) => {
|
||||
self.log_level = value;
|
||||
self.log_level = Some(value);
|
||||
}
|
||||
Msg::Noop => {}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct SliderProps<T: Clone + PartialEq + 'static> {
|
|||
pub value_label: Option<Cow<'static, str>>,
|
||||
pub onchange: Callback<T>,
|
||||
pub values: Vec<(T, Option<Cow<'static, str>>)>,
|
||||
pub selected: T,
|
||||
pub selected: Option<T>,
|
||||
}
|
||||
|
||||
pub enum Msg {
|
||||
|
@ -104,7 +104,7 @@ impl<T: Clone + PartialEq + 'static> Component for Slider<T> {
|
|||
.get(position)
|
||||
.unwrap_or_else(|| self.props.values.last().expect("No value in the vec"));
|
||||
|
||||
if *value != self.props.selected {
|
||||
if Some(value) != self.props.selected.as_ref() {
|
||||
self.props.onchange.emit(value.clone());
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ impl<T: Clone + PartialEq + 'static> Component for Slider<T> {
|
|||
.props
|
||||
.values
|
||||
.iter()
|
||||
.position(|(value, _)| *value == self.props.selected)
|
||||
.position(|(value, _)| Some(value) == self.props.selected.as_ref())
|
||||
.map(|i| i.saturating_sub(1))
|
||||
.unwrap_or(0);
|
||||
let (value, _) = self.props.values[index].clone();
|
||||
|
@ -151,7 +151,7 @@ impl<T: Clone + PartialEq + 'static> Component for Slider<T> {
|
|||
.props
|
||||
.values
|
||||
.iter()
|
||||
.position(|(value, _)| *value == self.props.selected)
|
||||
.position(|(value, _)| Some(value) == self.props.selected.as_ref())
|
||||
.map(|i| i.saturating_add(1))
|
||||
.unwrap_or(0);
|
||||
let (value, _) = self
|
||||
|
@ -188,7 +188,7 @@ impl<T: Clone + PartialEq + 'static> Component for Slider<T> {
|
|||
.props
|
||||
.values
|
||||
.iter()
|
||||
.position(|(value, _)| *value == self.props.selected);
|
||||
.position(|(value, _)| Some(value) == self.props.selected.as_ref());
|
||||
let labels = if self.props.values.len() > 1 {
|
||||
self.props
|
||||
.values
|
||||
|
|
Loading…
Reference in a new issue