Skip to content

Commit

Permalink
feat: support different illustration styles (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
bswags authored and moldy530 committed Aug 13, 2024
1 parent 5fec28e commit 6e4d1d7
Show file tree
Hide file tree
Showing 26 changed files with 2,122 additions and 352 deletions.
25 changes: 15 additions & 10 deletions account-kit/react/src/components/auth/card/add-passkey.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { useAddPasskey } from "../../../hooks/useAddPasskey.js";
import { AddPasskeyIllustration } from "../../../icons/illustrations/add-passkey.js";
import {
PasskeyIllustration,
PasskeyShield,
PasskeySmiley,
} from "../../../icons/passkey.js";
PasskeyShieldIllustration,
PasskeySmileyIllustration,
} from "../../../icons/illustrations/passkeys.js";
import { ls } from "../../../strings.js";
import { Button } from "../../button.js";
import { PoweredBy } from "../../poweredby.js";
import { useAuthContext } from "../context.js";
import type { AuthCardProps } from "./index.js";

const BENEFITS = [
{
icon: <PasskeySmiley />,
icon: PasskeySmileyIllustration,
title: ls.addPasskey.simplerLoginTitle,
description: ls.addPasskey.simplerLoginDescription,
},
{
icon: <PasskeyShield />,
icon: PasskeyShieldIllustration,
title: ls.addPasskey.enhancedSecurityTitle,
description: ls.addPasskey.enhancedSecurityDescription,
},
];

// eslint-disable-next-line jsdoc/require-jsdoc
export const AddPasskey = () => {
export const AddPasskey = ({ config }: { config: AuthCardProps }) => {
const { setAuthStep } = useAuthContext();
const { addPasskey, isAddingPasskey } = useAddPasskey({
onSuccess: () => {
Expand All @@ -34,16 +35,20 @@ export const AddPasskey = () => {
return (
<div className="flex flex-col gap-5 items-center">
<div className="flex flex-col items-center justify-center h-12 w-12">
<PasskeyIllustration />
<AddPasskeyIllustration
illustrationStyle={config.illustrationStyle ?? "flat"}
height="48"
width="48"
/>
</div>

<h3 className="font-semibold text-lg">{ls.addPasskey.title}</h3>

<div className="flex flex-col w-full gap-3">
{BENEFITS.map(({ title, icon, description }) => (
{BENEFITS.map(({ title, icon: Icon, description }) => (
<div key={title} className="flex gap-2">
<div className="h-5 w-5 flex items-center justify-center">
{icon}
<Icon illustrationStyle={config.illustrationStyle ?? "flat"} />
</div>
<div className="flex flex-col">
<p className="font-semibold text-sm">{title}</p>
Expand Down
3 changes: 2 additions & 1 deletion account-kit/react/src/components/auth/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { useSignerStatus } from "../../../hooks/useSignerStatus.js";
import { IS_SIGNUP_QP } from "../../constants.js";
import { useAuthContext } from "../context.js";
import type { AuthType } from "../types.js";
import type { AuthIllustrationStyle, AuthType } from "../types.js";
import { Step } from "./steps.js";
import { Notification } from "../../notification.js";
import { useAuthError } from "../../../hooks/useAuthError.js";
Expand All @@ -20,6 +20,7 @@ export type AuthCardProps = {
hideError?: boolean;
header?: ReactNode;
showSignInText?: boolean;
illustrationStyle?: AuthIllustrationStyle;
// Each section can contain multiple auth types which will be grouped together
// and separated by an OR divider
sections?: AuthType[][];
Expand Down
13 changes: 10 additions & 3 deletions account-kit/react/src/components/auth/card/loading/email.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { useEffect, useState } from "react";
import { useAuthenticate } from "../../../../hooks/useAuthenticate.js";
import { useSignerStatus } from "../../../../hooks/useSignerStatus.js";
import { MailIllustration } from "../../../../icons/mail.js";
import { Button } from "../../../button.js";
import { PoweredBy } from "../../../poweredby.js";
import { useAuthContext, type AuthStep } from "../../context.js";
import { Spinner } from "../../../../icons/spinner.js";
import { ls } from "../../../../strings.js";
import { EmailIllustration } from "../../../../icons/illustrations/email.js";
import type { AuthCardProps } from "../index.js";

interface LoadingEmailProps {
config: AuthCardProps;
context: Extract<AuthStep, { type: "email_verify" }>;
}

// eslint-disable-next-line jsdoc/require-jsdoc
export const LoadingEmail = ({ context }: LoadingEmailProps) => {
export const LoadingEmail = ({ config, context }: LoadingEmailProps) => {
// yup, re-sent and resent. I'm not fixing it
const [emailResent, setEmailResent] = useState(false);
const { setAuthStep } = useAuthContext();
Expand All @@ -35,7 +37,12 @@ export const LoadingEmail = ({ context }: LoadingEmailProps) => {
return (
<div className="flex flex-col gap-5 items-center">
<div className="flex flex-col items-center justify-center h-12 w-12">
<MailIllustration className="animate-pulse" />
<EmailIllustration
illustrationStyle={config.illustrationStyle ?? "flat"}
height="48"
width="48"
className="animate-pulse"
/>
</div>

<h3 className="font-semibold text-lg">{ls.loadingEmail.title}</h3>
Expand Down
8 changes: 5 additions & 3 deletions account-kit/react/src/components/auth/card/loading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import type { AuthCardProps } from "..";
import type { AuthStep } from "../../context";
import { CompletingEmailAuth, LoadingEmail } from "./email.js";
import { LoadingPasskeyAuth } from "./passkey.js";

type LoadingAuthProps = {
config: AuthCardProps;
context?: AuthStep;
};

// eslint-disable-next-line jsdoc/require-jsdoc
export const LoadingAuth = ({ context }: LoadingAuthProps) => {
export const LoadingAuth = ({ context, config }: LoadingAuthProps) => {
switch (context?.type) {
case "email_verify":
return <LoadingEmail context={context} />;
return <LoadingEmail config={config} context={context} />;
case "passkey_verify":
return <LoadingPasskeyAuth />;
return <LoadingPasskeyAuth config={config} />;
case "email_completing":
return <CompletingEmailAuth context={context} />;
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { ls } from "../../../../strings.js";
import { LoadingPasskey } from "../../../../icons/passkey.js";
import { Button } from "../../../button.js";
import { PoweredBy } from "../../../poweredby.js";
import type { AuthCardProps } from "../index.js";

// eslint-disable-next-line jsdoc/require-jsdoc
export const LoadingPasskeyAuth = () => {
export const LoadingPasskeyAuth = ({ config }: { config: AuthCardProps }) => {
return (
<div className="flex flex-col gap-5 items-center">
<div className="flex flex-col items-center justify-center">
<LoadingPasskey />
<LoadingPasskey
illustrationStyle={config.illustrationStyle ?? "flat"}
/>
</div>

<h3 className="font-semibold text-lg">{ls.loadingPasskey.title}</h3>
Expand Down
11 changes: 8 additions & 3 deletions account-kit/react/src/components/auth/card/passkey-added.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { PasskeyIllustration } from "../../../icons/passkey.js";
import { AddedPasskeyIllustration } from "../../../icons/illustrations/added-passkey.js";
import { PoweredBy } from "../../poweredby.js";
import type { AuthCardProps } from "./index.js";

// eslint-disable-next-line jsdoc/require-jsdoc
export function PasskeyAdded() {
export function PasskeyAdded({ config }: { config: AuthCardProps }) {
return (
<div className="flex flex-col gap-5 items-center">
<div className="flex flex-col items-center justify-center h-12 w-12">
<PasskeyIllustration />
<AddedPasskeyIllustration
illustrationStyle={config.illustrationStyle ?? "flat"}
height="48"
width="48"
/>
</div>
<h3 className="font-semibold text-lg">Passkey added!</h3>
<p className="text-fg-secondary text-sm text-center">
Expand Down
6 changes: 3 additions & 3 deletions account-kit/react/src/components/auth/card/steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const Step = (props: AuthCardProps) => {
case "email_verify":
case "passkey_verify":
case "email_completing":
return <LoadingAuth context={authStep} />;
return <LoadingAuth config={props} context={authStep} />;
case "passkey_create":
return <AddPasskey />;
return <AddPasskey config={props} />;
case "passkey_create_success":
return <PasskeyAdded />;
return <PasskeyAdded config={props} />;
case "eoa_connect":
return <EoaConnectCard authStep={authStep} />;
case "complete":
Expand Down
1 change: 1 addition & 0 deletions account-kit/react/src/components/auth/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const AuthModal = ({ open, hideError, auth }: AuthModalProps) => {
hideError={hideError}
header={auth.header}
sections={auth.sections}
illustrationStyle={auth.illustrationStyle}
onAuthSuccess={() => closeAuthModal()}
showClose
/>
Expand Down
2 changes: 2 additions & 0 deletions account-kit/react/src/components/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export type AuthType =
}
| { type: "passkey" }
| { type: "injected" };

export type AuthIllustrationStyle = "outline" | "linear" | "filled" | "flat";
22 changes: 0 additions & 22 deletions account-kit/react/src/icons/hourglass.tsx

This file was deleted.

Loading

0 comments on commit 6e4d1d7

Please sign in to comment.