Skip to content

Commit

Permalink
Rename InputOtp to OTPInput
Browse files Browse the repository at this point in the history
  • Loading branch information
madcodelife committed Jul 26, 2024
1 parent d278d85 commit 596012b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions crates/story/src/input_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)),
}
}

Expand Down Expand Up @@ -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()),
),
Expand Down
4 changes: 2 additions & 2 deletions crates/ui/src/input/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum InputOptEvent {
Change(SharedString),
}

pub struct InputOtp {
pub struct OTPInput {
focus_handle: FocusHandle,
length: usize,
number_of_groups: usize,
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 596012b

Please sign in to comment.