From 55822144c48c22b96a7201b38362f82798df76ca Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Fri, 26 Jul 2024 17:12:23 +0800 Subject: [PATCH] Rename `InputOtp` to `OTPInput` (#74) --- README.md | 2 +- crates/story/src/input_story.rs | 14 +++++++------- crates/ui/src/input/mod.rs | 4 ++-- crates/ui/src/input/{input_otp.rs => otp_input.rs} | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) rename crates/ui/src/input/{input_otp.rs => otp_input.rs} (97%) diff --git a/README.md b/README.md index 76607680..c401b7aa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/crates/story/src/input_story.rs b/crates/story/src/input_story.rs index f2e1d0b7..8ba1ff37 100644 --- a/crates/story/src/input_story.rs +++ b/crates/story/src/input_story.rs @@ -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, large_input: View, small_input: View, - otp_input: View, + otp_input: View, otp_value: Option, - opt_input2: View, + opt_input2: View, } 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()), ), diff --git a/crates/ui/src/input/mod.rs b/crates/ui/src/input/mod.rs index b11478d2..e1649142 100644 --- a/crates/ui/src/input/mod.rs +++ b/crates/ui/src/input/mod.rs @@ -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::*; diff --git a/crates/ui/src/input/input_otp.rs b/crates/ui/src/input/otp_input.rs similarity index 97% rename from crates/ui/src/input/input_otp.rs rename to crates/ui/src/input/otp_input.rs index f9f877e3..fa042ccb 100644 --- a/crates/ui/src/input/input_otp.rs +++ b/crates/ui/src/input/otp_input.rs @@ -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, } -impl InputOtp { +impl OTPInput { pub fn new(length: usize, cx: &mut ViewContext) -> 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 for InputOtp {} +impl EventEmitter for OTPInput {} -impl Render for InputOtp { +impl Render for OTPInput { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { let blink_show = self.blink_cursor.read(cx).visible(); let is_focused = self.focus_handle.is_focused(cx);