LoginForm takes an email and a password, keeps one signed in on a box, and signs in on Enter once the address reads and a password is typed; a failed try says why above Sign in. SignupForm ticks a new password's rules as they hold and waits for all of them and the terms. OAuthButtons offer each provider, one spinning while the rest rest. MagicLinkForm and ForgotPassword send a link to an address and, once sent, say where it went and offer it again. TwoFactorInput takes a six-digit code at once and, after one fails, clears the boxes through forms::PinInput's new attempt, keeping its focus. The Account chapter splits into sign-in, profile and access, and billing and team. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
2.7 KiB
Rust
89 lines
2.7 KiB
Rust
use std::rc::Rc;
|
|
|
|
use gpui::{
|
|
App, ElementId, IntoElement, ParentElement, RenderOnce, SharedString, Styled, Window, div,
|
|
};
|
|
|
|
use crate::buttons::{Button, ButtonVariant};
|
|
|
|
type OnKey = Rc<dyn Fn(&SharedString, &mut Window, &mut App)>;
|
|
|
|
/// A button for each sign-in provider, stacked full width: "Continue with GitHub". While one is on its way it spins and the others rest.
|
|
#[derive(IntoElement)]
|
|
pub struct OAuthButtons {
|
|
id: ElementId,
|
|
providers: Vec<(SharedString, SharedString)>,
|
|
busy: Option<SharedString>,
|
|
on_pick: Option<OnKey>,
|
|
}
|
|
|
|
impl OAuthButtons {
|
|
/// `providers` are each a key and the name shown.
|
|
pub fn new(
|
|
id: impl Into<ElementId>,
|
|
providers: impl IntoIterator<Item = (impl Into<SharedString>, impl Into<SharedString>)>,
|
|
) -> Self {
|
|
let id = id.into();
|
|
let providers: Vec<_> = providers
|
|
.into_iter()
|
|
.map(|(key, name)| (key.into(), name.into()))
|
|
.collect();
|
|
assert!(!providers.is_empty(), "oauth buttons {id:?}: no provider");
|
|
Self {
|
|
id,
|
|
providers,
|
|
busy: None,
|
|
on_pick: None,
|
|
}
|
|
}
|
|
|
|
/// The provider on its way.
|
|
pub fn busy(mut self, key: impl Into<SharedString>) -> Self {
|
|
let key = key.into();
|
|
assert!(
|
|
self.providers.iter().any(|(each, _)| *each == key),
|
|
"oauth buttons: no provider {key}"
|
|
);
|
|
self.busy = Some(key);
|
|
self
|
|
}
|
|
|
|
pub fn on_pick(
|
|
mut self,
|
|
handler: impl Fn(&SharedString, &mut Window, &mut App) + 'static,
|
|
) -> Self {
|
|
self.on_pick = Some(Rc::new(handler));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl RenderOnce for OAuthButtons {
|
|
fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
|
|
let id = self.id;
|
|
let on_pick = self
|
|
.on_pick
|
|
.unwrap_or_else(|| panic!("oauth buttons {id:?} have no on_pick"));
|
|
let busy = self.busy;
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_2()
|
|
.children(self.providers.into_iter().map(|(key, name)| {
|
|
let mine = busy.as_ref() == Some(&key);
|
|
let pick = on_pick.clone();
|
|
Button::new(
|
|
(id.clone(), format!("provider-{key}")),
|
|
format!("Continue with {name}"),
|
|
)
|
|
.variant(ButtonVariant::Outline)
|
|
.full_width()
|
|
.loading(mine)
|
|
.disabled(busy.is_some() && !mine)
|
|
.on_click(move |_, window, cx| {
|
|
log::info!("oauth buttons: {key}");
|
|
pick(&key, window, cx);
|
|
})
|
|
}))
|
|
}
|
|
}
|