Skip to content
2 changes: 1 addition & 1 deletion examples/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function UnauthenticatedApp() {
<div className="space-y-1">
<h2 className="font-medium text-sm">Full Customization Demo</h2>
<p className="text-xs text-gray-400 dark:text-gray-300">
A complete sign in flow with its own UI and three switchable themes, built on the ui-react hooks.
A complete sign in flow with its own UI and four switchable themes, built on the ui-react hooks.
</p>
</div>
<div className="text-neutral-600 dark:text-neutral-400">
Expand Down
2 changes: 1 addition & 1 deletion examples/react/src/full-customization/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function PhoneFields({ country, onCountryChange, value, onChange }: Phone

return (
<div className="fc-row">
<div className="fc-field" style={{ flex: "0 0 128px" }}>
<div className="fc-field fc-row__country">
<select
className="fc-field__input"
aria-label="Country code"
Expand Down
43 changes: 41 additions & 2 deletions examples/react/src/full-customization/full-customization.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

@import url("https://fonts.googleapis.com/css2?family=Bagel+Fat+One&family=Chivo+Mono:wght@500&family=JetBrains+Mono:wght@400;500&family=Onest:wght@500;700&family=Roboto+Mono:wght@500&family=Roboto:wght@500;600&family=Rowdies:wght@300;400&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400..700,0..1,0&icon_names=alternate_email,arrow_back,check,coffee,lock,palette,person,phone,visibility,visibility_off&display=block");
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400..700,0..1,0&icon_names=alternate_email,arrow_back,check,chevron_left,chevron_right,coffee,dark_mode,drafts,error,key,light_mode,lock,mail,more_horiz,palette,person,phone,qr_code_2,shield,smartphone,sms,tag,verified_user,visibility,visibility_off&display=block");

/* Doggo: Figma 20:6031 */
.fc-root[data-theme="doggo"] {
Expand Down Expand Up @@ -372,6 +372,10 @@
min-width: 0;
}

.fc-row > .fc-row__country {
flex: 0 0 128px;
}

/* Text field: Figma component "text-field", 56px tall with a 48px leading icon slot */

.fc-field {
Expand Down Expand Up @@ -652,6 +656,7 @@

.fc-dialog {
width: min(100% - 32px, 560px);
margin: auto;
padding: 0;
border: 0;
background: transparent;
Expand Down Expand Up @@ -707,6 +712,16 @@
color: #ffffff;
}

.fc-theme-switcher button.fc-theme-switcher__mode {
display: grid;
place-items: center;
padding: 6px 8px;
}

.fc-theme-switcher__mode .fc-icon {
font-size: 18px;
}

.fc-exit {
position: fixed;
z-index: 10;
Expand All @@ -729,6 +744,10 @@
font-size: 18px;
}

.fc-label--short {
display: none;
}

@media (max-width: 640px) {
.fc-main {
padding-top: 80px;
Expand All @@ -743,13 +762,33 @@
flex-direction: column;
}

.fc-row > .fc-row__country {
flex-basis: auto;
}

.fc-button {
flex-basis: 100%;
max-width: none;
}

/* Stay clear of the back button, scrolling as a last resort. */
.fc-theme-switcher {
max-width: calc(100vw - 80px);
overflow-x: auto;
scrollbar-width: none;
}

.fc-theme-switcher button {
padding: 6px 8px;
flex: none;
padding: 6px 7px;
}

.fc-label--long {
display: none;
}

.fc-label--short {
display: inline;
}

.fc-theme-switcher > .fc-icon,
Expand Down
107 changes: 69 additions & 38 deletions examples/react/src/full-customization/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ import { useEffect, useState, type ReactElement } from "react";
import { Link, Navigate, Route, Routes } from "react-router";
import type { User } from "firebase/auth";
import { completeEmailLinkSignIn } from "@firebase-oss/ui-core";
import { useUI } from "@firebase-oss/ui-react";
import { useMultiFactorAssertionCleanup, useUI } from "@firebase-oss/ui-react";

import { useUser } from "~/firebase/hooks";
import "./full-customization.css";
import { DemoProvider, paths } from "./state";
import { ThemeArt, ThemeSwitcher, useTheme } from "./theme";
import { ProAccount } from "./professional/account";
import { ProMfaChallengeStep } from "./professional/mfa-challenge";
import { ProMfaEnrollment } from "./professional/mfa-enrollment";
import { ProPhone } from "./professional/phone";
import { ProEmailLink, ProResetPassword, ProSignIn, ProSignUp } from "./professional/sign-in";
import { ThemeArt, ThemeIdContext, ThemeSwitcher, useTheme } from "./theme";
import { AccountStep } from "./steps/account";
import { EmailEntryStep } from "./steps/email-entry";
import { LoginStep } from "./steps/login";
Expand All @@ -32,6 +37,12 @@ import { MfaEnrollmentStep } from "./steps/mfa-enrollment";
import { PhoneStep } from "./steps/phone";
import { SignUpStep } from "./steps/sign-up";

/** Owns the sign-in resolver, so switching theme mid-challenge swaps the screen without cancelling the sign in. */
function SignInChallenge({ children }: { children: ReactElement }) {
useMultiFactorAssertionCleanup();
return children;
}

/**
* A complete sign in flow with its own UI, where FirebaseUI supplies only the auth logic through
* the ui-react action hooks. Sign in state drives the routing: a signed-in user is sent to the
Expand All @@ -55,42 +66,62 @@ export default function FullCustomizationDemo() {
const signedOut = (step: ReactElement) => (user ? <Navigate to={paths.account} replace /> : step);
const signedIn = (step: (user: User) => ReactElement) => (user ? step(user) : <Navigate to={paths.email} replace />);

// Professional brings its own screens; the other themes share one set and differ only in styling.
const pro = theme === "professional";
const screens = pro
? {
email: <ProSignIn />,
login: <ProSignIn />,
signUp: <ProSignUp />,
phone: <ProPhone />,
resetPassword: <ProResetPassword />,
emailLink: <ProEmailLink />,
account: (u: User) => <ProAccount user={u} />,
twoFactor: (u: User) => <ProMfaEnrollment user={u} />,
challenge: <ProMfaChallengeStep />,
}
: {
email: <EmailEntryStep />,
login: <LoginStep />,
signUp: <SignUpStep />,
phone: <PhoneStep />,
resetPassword: <LoginStep />,
emailLink: <LoginStep />,
account: (u: User) => <AccountStep user={u} />,
twoFactor: (u: User) => <MfaEnrollmentStep user={u} />,
challenge: <MfaChallengeStep />,
};

return (
<div className="fc-root" data-theme={theme}>
<ThemeArt theme={theme} />
<Link className="fc-exit" to="/" aria-label="All examples">
<span className="fc-icon" aria-hidden="true">
arrow_back
</span>
<span className="fc-exit__label">All examples</span>
</Link>
<ThemeSwitcher theme={theme} onChange={setTheme} />
<DemoProvider linkError={linkError}>
{/* A signed-in user with a resolver is reauthenticating; the reauth dialog completes that one. */}
{ui.multiFactorResolver && !user ? (
<MfaChallengeStep />
) : (
<Routes>
<Route index element={signedOut(<EmailEntryStep />)} />
<Route path="login" element={signedOut(<LoginStep />)} />
<Route path="sign-up" element={signedOut(<SignUpStep />)} />
<Route path="phone" element={signedOut(<PhoneStep />)} />
<Route
path="account"
element={signedIn((u) => (
<AccountStep user={u} />
))}
/>
<Route
path="account/two-factor"
element={signedIn((u) => (
<MfaEnrollmentStep user={u} />
))}
/>
<Route path="*" element={<Navigate to={paths.email} replace />} />
</Routes>
)}
</DemoProvider>
</div>
<ThemeIdContext.Provider value={theme}>
<div className="fc-root" data-theme={theme}>
<ThemeArt theme={theme} />
<Link className="fc-exit" to="/" aria-label="All examples">
<span className="fc-icon" aria-hidden="true">
arrow_back
</span>
<span className="fc-exit__label">All examples</span>
</Link>
<ThemeSwitcher theme={theme} onChange={setTheme} />
<DemoProvider linkError={linkError}>
{/* A signed-in user with a resolver is reauthenticating; the reauth dialog completes that one. */}
{ui.multiFactorResolver && !user ? (
<SignInChallenge>{screens.challenge}</SignInChallenge>
) : (
<Routes>
<Route index element={signedOut(screens.email)} />
<Route path="login" element={signedOut(screens.login)} />
<Route path="sign-up" element={signedOut(screens.signUp)} />
<Route path="phone" element={signedOut(screens.phone)} />
<Route path="reset-password" element={signedOut(screens.resetPassword)} />
<Route path="email-link" element={signedOut(screens.emailLink)} />
<Route path="account" element={signedIn(screens.account)} />
<Route path="account/two-factor" element={signedIn(screens.twoFactor)} />
<Route path="*" element={<Navigate to={paths.email} replace />} />
</Routes>
)}
</DemoProvider>
</div>
</ThemeIdContext.Provider>
);
}
Loading