-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Integrate Joy UI and Jotai
- Loading branch information
Showing
75 changed files
with
1,137 additions
and
2,362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* SPDX-FileCopyrightText: 2014-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
import { DarkModeRounded, LightModeRounded } from "@mui/icons-material"; | ||
import { | ||
Dropdown, | ||
IconButton, | ||
IconButtonProps, | ||
ListItemContent, | ||
ListItemDecorator, | ||
Menu, | ||
MenuButton, | ||
MenuItem, | ||
useColorScheme, | ||
} from "@mui/joy"; | ||
import { memo } from "react"; | ||
|
||
export function ColorSchemeButton(props: ColorSchemeButtonProps): JSX.Element { | ||
const { mode, systemMode } = useColorScheme(); | ||
|
||
return ( | ||
<Dropdown> | ||
<MenuButton slots={{ root: IconButton }} slotProps={{ root: props }}> | ||
{mode === "light" || (mode === "system" && systemMode === "light") ? ( | ||
<DarkModeRounded /> | ||
) : ( | ||
<LightModeRounded /> | ||
)} | ||
</MenuButton> | ||
|
||
<Menu size="sm"> | ||
<ModeMenuItem mode="light" /> | ||
<ModeMenuItem mode="dark" /> | ||
<ModeMenuItem mode="system" /> | ||
</Menu> | ||
</Dropdown> | ||
); | ||
} | ||
|
||
const ModeMenuItem = memo(function ModeMenuItem({ | ||
mode, | ||
}: ModeMenuItemProps): JSX.Element { | ||
const scheme = useColorScheme(); | ||
|
||
return ( | ||
<MenuItem | ||
onClick={() => { | ||
scheme.setMode(mode); | ||
}} | ||
selected={scheme.mode === mode} | ||
> | ||
<ListItemDecorator sx={{ ml: 0.5 }}> | ||
{mode === "light" || | ||
(mode !== "dark" && scheme.systemMode === "light") ? ( | ||
<LightModeRounded /> | ||
) : ( | ||
<DarkModeRounded /> | ||
)} | ||
</ListItemDecorator> | ||
<ListItemContent sx={{ pr: 2 }}> | ||
{mode === "light" | ||
? "Light theme" | ||
: mode === "dark" | ||
? "Dark theme" | ||
: "Device default"} | ||
</ListItemContent> | ||
</MenuItem> | ||
); | ||
}); | ||
|
||
type ColorSchemeButtonProps = Omit<IconButtonProps, "children">; | ||
type ModeMenuItemProps = { mode: "dark" | "light" | "system" }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* SPDX-FileCopyrightText: 2014-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
import { Button, ButtonProps } from "@mui/joy"; | ||
import { SignInMethod, useSignIn } from "../core/auth"; | ||
import { AnonymousIcon, GoogleIcon } from "../icons"; | ||
|
||
export function LoginButton(props: LoginButtonProps): JSX.Element { | ||
const { signInMethod, ...other } = props; | ||
const [signIn, inFlight] = useSignIn(signInMethod); | ||
|
||
const icon = | ||
signInMethod === "google.com" ? ( | ||
<GoogleIcon /> | ||
) : signInMethod === "anonymous" ? ( | ||
<AnonymousIcon /> | ||
) : null; | ||
|
||
return ( | ||
<Button | ||
startDecorator={icon} | ||
variant="outlined" | ||
onClick={signIn} | ||
loading={inFlight} | ||
children={ | ||
signInMethod === "google.com" | ||
? "Continue via Google" | ||
: signInMethod === "anonymous" | ||
? "Continue as anonymous" | ||
: "unknown" | ||
} | ||
{...other} | ||
/> | ||
); | ||
} | ||
|
||
export type LoginButtonProps = Omit< | ||
ButtonProps< | ||
"button", | ||
{ | ||
signInMethod: SignInMethod; | ||
} | ||
>, | ||
"children" | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* SPDX-FileCopyrightText: 2014-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
import { LogoutRounded, SettingsRounded } from "@mui/icons-material"; | ||
import { | ||
Avatar, | ||
Dropdown, | ||
IconButton, | ||
IconButtonProps, | ||
ListItemContent, | ||
ListItemDecorator, | ||
Menu, | ||
MenuButton, | ||
MenuItem, | ||
} from "@mui/joy"; | ||
import { getAuth, signOut } from "firebase/auth"; | ||
import { useCurrentUser } from "../core/auth"; | ||
|
||
export function UserAvatarButton(props: UserAvatarButtonProps): JSX.Element { | ||
const { sx, ...other } = props; | ||
const user = useCurrentUser()!; | ||
|
||
return ( | ||
<Dropdown> | ||
<MenuButton | ||
slots={{ root: IconButton }} | ||
slotProps={{ | ||
root: { | ||
sx: { borderRadius: "50%", p: "2px", ...sx }, | ||
...other, | ||
}, | ||
}} | ||
> | ||
<Avatar sx={{ width: 36, height: 36 }} src={user.photoURL ?? undefined}> | ||
{user.displayName} | ||
</Avatar> | ||
</MenuButton> | ||
|
||
<Menu size="sm"> | ||
<MenuItem> | ||
<ListItemDecorator sx={{ ml: 0.5 }}> | ||
<SettingsRounded /> | ||
</ListItemDecorator> | ||
<ListItemContent sx={{ mr: 2 }}>Settings</ListItemContent> | ||
</MenuItem> | ||
<MenuItem onClick={() => signOut(getAuth())}> | ||
<ListItemDecorator sx={{ ml: 0.5 }}> | ||
<LogoutRounded /> | ||
</ListItemDecorator> | ||
<ListItemContent sx={{ mr: 2 }}>Logout</ListItemContent> | ||
</MenuItem> | ||
</Menu> | ||
</Dropdown> | ||
); | ||
} | ||
|
||
export type UserAvatarButtonProps = Omit<IconButtonProps, "children">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-FileCopyrightText: 2014-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
export * from "./button-login"; | ||
export * from "./error"; | ||
export * from "./layout"; | ||
export * from "./logo"; |
Oops, something went wrong.