Change InputOpt default masked: false and publish masked method.
This commit is contained in:
parent
c7336fd5ea
commit
b8a7d6a2dd
2 changed files with 25 additions and 11 deletions
|
|
@ -35,11 +35,12 @@ pub struct InputStory {
|
||||||
small_input: View<TextInput>,
|
small_input: View<TextInput>,
|
||||||
otp_input: View<InputOtp>,
|
otp_input: View<InputOtp>,
|
||||||
otp_value: Option<SharedString>,
|
otp_value: Option<SharedString>,
|
||||||
|
opt_input2: View<InputOtp>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputStory {
|
impl InputStory {
|
||||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||||
cx.new_view(|cx| Self::new(cx))
|
cx.new_view(Self::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(cx: &mut ViewContext<Self>) -> Self {
|
fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
|
|
@ -81,11 +82,13 @@ impl InputStory {
|
||||||
|
|
||||||
let view = cx.view().clone();
|
let view = cx.view().clone();
|
||||||
let otp_input = cx.new_view(|cx| {
|
let otp_input = cx.new_view(|cx| {
|
||||||
InputOtp::new(6, cx).on_change(move |value: &SharedString, cx| {
|
InputOtp::new(6, cx)
|
||||||
view.update(cx, |view, _| {
|
.masked(true)
|
||||||
view.otp_value = Some(value.clone());
|
.on_change(move |value: &SharedString, cx| {
|
||||||
|
view.update(cx, |view, _| {
|
||||||
|
view.otp_value = Some(value.clone());
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -113,6 +116,7 @@ impl InputStory {
|
||||||
both_input1,
|
both_input1,
|
||||||
otp_input,
|
otp_input,
|
||||||
otp_value: None,
|
otp_value: None,
|
||||||
|
opt_input2: cx.new_view(|cx| InputOtp::new(6, cx).groups(3)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,11 +184,15 @@ impl Render for InputStory {
|
||||||
.child(self.small_input.clone()),
|
.child(self.small_input.clone()),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
section("Input OTP", cx)
|
section("Input OTP", cx).child(
|
||||||
.child(self.otp_input.clone())
|
v_flex()
|
||||||
.when_some(self.otp_value.clone(), |this, otp| {
|
.gap_3()
|
||||||
this.child(format!("You input OTP: {}", otp))
|
.child(self.otp_input.clone())
|
||||||
}),
|
.when_some(self.otp_value.clone(), |this, otp| {
|
||||||
|
this.child(format!("You input OTP: {}", otp))
|
||||||
|
})
|
||||||
|
.child(self.opt_input2.clone()),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ impl InputOtp {
|
||||||
length,
|
length,
|
||||||
number_of_groups: 2,
|
number_of_groups: 2,
|
||||||
value: SharedString::default(),
|
value: SharedString::default(),
|
||||||
masked: true,
|
masked: false,
|
||||||
on_change: None,
|
on_change: None,
|
||||||
blink_cursor: blink_cursor.clone(),
|
blink_cursor: blink_cursor.clone(),
|
||||||
};
|
};
|
||||||
|
|
@ -59,6 +59,12 @@ impl InputOtp {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set masked to true use masked input.
|
||||||
|
pub fn masked(mut self, masked: bool) -> Self {
|
||||||
|
self.masked = masked;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set callback to be called when the value of the OTP Input changes (All OTP input have filled).
|
/// Set callback to be called when the value of the OTP Input changes (All OTP input have filled).
|
||||||
pub fn on_change<F>(mut self, f: F) -> Self
|
pub fn on_change<F>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue