Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions site/src/pages/LoginPage/OAuthSignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ import Button from "@mui/material/Button";
import GitHubIcon from "@mui/icons-material/GitHub";
import KeyIcon from "@mui/icons-material/VpnKey";
import Box from "@mui/material/Box";
import { type FC } from "react";
import { useId, type FC } from "react";
import { Language } from "./SignInForm";
import { type AuthMethods } from "api/typesGenerated";
import { visuallyHidden } from "@mui/utils";

type OAuthSignInFormProps = {
isSigningIn: boolean;
redirectTo: string;
authMethods?: AuthMethods;
};

const iconStyles = {
width: 16,
height: 16,
};

export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
isSigningIn,
redirectTo,
authMethods,
}) => {
const iconStyles = {
width: 16,
height: 16,
};

return (
<Box display="grid" gap="16px">
{authMethods?.github.enabled && (
Expand Down Expand Up @@ -51,11 +52,7 @@ export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
size="xlarge"
startIcon={
authMethods.oidc.iconUrl ? (
<img
alt="Open ID Connect icon"
src={authMethods.oidc.iconUrl}
css={iconStyles}
/>
<OidcIcon iconUrl={authMethods.oidc.iconUrl} />
) : (
<KeyIcon css={iconStyles} />
)
Expand All @@ -70,3 +67,24 @@ export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
</Box>
);
};

type OidcIconProps = {
iconUrl: string;
};

function OidcIcon({ iconUrl }: OidcIconProps) {
const hookId = useId();
const oidcId = `${hookId}-oidc`;

// Even if the URL is defined, there is a chance that the request for the
// image fails. Have to use blank alt text to avoid button from getting ugly
// if that happens, but also still need a way to inject accessible text
return (
<>
<img alt="" src={iconUrl} css={iconStyles} aria-labelledby={oidcId} />
<div id={oidcId} css={{ ...visuallyHidden }}>
Open ID Connect
</div>
</>
);
}