Rename InputOtp to OTPInput (#74)
This commit is contained in:
parent
d278d85058
commit
55822144c4
4 changed files with 15 additions and 15 deletions
|
|
@ -16,7 +16,7 @@ A UI components for building desktop application by using [GPUI](https://gpui.rs
|
|||
- [x] Input icon
|
||||
- [ ] Textarea
|
||||
- [ ] ContextMenu to let user copy, cut, paste
|
||||
- [x] InputOTP
|
||||
- [x] OTPInput
|
||||
- [x] Button
|
||||
- [x] Button with Icon
|
||||
- [x] IconButton
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use gpui::{
|
|||
use ui::{
|
||||
button::Button,
|
||||
h_flex,
|
||||
input::{InputEvent, InputOtp, TextInput},
|
||||
input::{InputEvent, OTPInput, TextInput},
|
||||
prelude::FluentBuilder as _,
|
||||
v_flex, Clickable, FocusableCycle, IconName, Size,
|
||||
};
|
||||
|
|
@ -33,9 +33,9 @@ pub struct InputStory {
|
|||
both_input1: View<TextInput>,
|
||||
large_input: View<TextInput>,
|
||||
small_input: View<TextInput>,
|
||||
otp_input: View<InputOtp>,
|
||||
otp_input: View<OTPInput>,
|
||||
otp_value: Option<SharedString>,
|
||||
opt_input2: View<InputOtp>,
|
||||
opt_input2: View<OTPInput>,
|
||||
}
|
||||
|
||||
impl InputStory {
|
||||
|
|
@ -87,7 +87,7 @@ impl InputStory {
|
|||
.placeholder("This input have prefix and suffix.")
|
||||
});
|
||||
|
||||
let otp_input = cx.new_view(|cx| InputOtp::new(6, cx).masked(true));
|
||||
let otp_input = cx.new_view(|cx| OTPInput::new(6, cx).masked(true));
|
||||
cx.subscribe(&otp_input, |this, _, ev: &InputEvent, cx| match ev {
|
||||
InputEvent::Change(text) => {
|
||||
this.otp_value = Some(text.clone());
|
||||
|
|
@ -123,7 +123,7 @@ impl InputStory {
|
|||
both_input1,
|
||||
otp_input,
|
||||
otp_value: None,
|
||||
opt_input2: cx.new_view(|cx| InputOtp::new(6, cx).groups(3)),
|
||||
opt_input2: cx.new_view(|cx| OTPInput::new(6, cx).groups(3)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -210,12 +210,12 @@ impl Render for InputStory {
|
|||
),
|
||||
)
|
||||
.child(
|
||||
section("Input OTP", cx).child(
|
||||
section("OTP Input", cx).child(
|
||||
v_flex()
|
||||
.gap_3()
|
||||
.child(self.otp_input.clone())
|
||||
.when_some(self.otp_value.clone(), |this, otp| {
|
||||
this.child(format!("You input OTP: {}", otp))
|
||||
this.child(format!("Your OTP: {}", otp))
|
||||
})
|
||||
.child(self.opt_input2.clone()),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
mod blink_cursor;
|
||||
mod history;
|
||||
mod input;
|
||||
mod input_otp;
|
||||
mod otp_input;
|
||||
|
||||
pub use input::*;
|
||||
pub use input_otp::*;
|
||||
pub use otp_input::*;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub enum InputOptEvent {
|
|||
Change(SharedString),
|
||||
}
|
||||
|
||||
pub struct InputOtp {
|
||||
pub struct OTPInput {
|
||||
focus_handle: FocusHandle,
|
||||
length: usize,
|
||||
number_of_groups: usize,
|
||||
|
|
@ -22,7 +22,7 @@ pub struct InputOtp {
|
|||
blink_cursor: Model<BlinkCursor>,
|
||||
}
|
||||
|
||||
impl InputOtp {
|
||||
impl OTPInput {
|
||||
pub fn new(length: usize, cx: &mut ViewContext<Self>) -> Self {
|
||||
let focus_handle = cx.focus_handle();
|
||||
let blink_cursor = cx.new_model(|cx| BlinkCursor::new(cx));
|
||||
|
|
@ -128,14 +128,14 @@ impl InputOtp {
|
|||
}
|
||||
}
|
||||
|
||||
impl FocusableView for InputOtp {
|
||||
impl FocusableView for OTPInput {
|
||||
fn focus_handle(&self, _: &gpui::AppContext) -> FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
impl EventEmitter<InputEvent> for InputOtp {}
|
||||
impl EventEmitter<InputEvent> for OTPInput {}
|
||||
|
||||
impl Render for InputOtp {
|
||||
impl Render for OTPInput {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let blink_show = self.blink_cursor.read(cx).visible();
|
||||
let is_focused = self.focus_handle.is_focused(cx);
|
||||
Loading…
Reference in a new issue