Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: resolve header level bugs
  • Loading branch information
Parkreiner committed Mar 11, 2025
commit a35a9aeafd02af06b18c7d178501e0658961627a
14 changes: 9 additions & 5 deletions site/src/components/SettingsHeader/SettingsHeader.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a storybook for it covering the new variants?

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import type { FC, ReactNode } from "react";
import { twMerge } from "tailwind-merge";

type HeaderHierarchy = "primary" | "secondary";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it like this so that we can add additional variants over time

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For creating variants, I would recommend you to use class-variance-authority package. You can see how it is used in the Button component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've used CVA before – I actually used it in the take-home that got me into Coder. I thought it was a bit too much overhead here, but if we're switching to CVA as a go-to, I can swap that in

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of shadcn, our base components are using CVA so I think it would be nice to use it but it is up to you.

type HeaderLevel = `h${1 | 2 | 3 | 4 | 5 | 6}`;

type HeaderProps = Readonly<{
title: ReactNode;
description?: ReactNode;
hierarchy?: HeaderHierarchy;
titleVisualHierarchy?: HeaderHierarchy;
titleHeaderLevel?: HeaderLevel;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is how we did before but since we are touching this, could we also improve the abstraction? I see something like:

<SettingsHeader actions={[<SeeDocsButton />]}>
  <SettingsHeaderTitle>Mytitle</SettingsHeaderTitle>
  <SettingsHeaderSubtitle>Some text hear</SettingsHeaderSubtitle>
</SettingsHeader>

docsHref?: string;
tooltip?: ReactNode;
}>;
Expand All @@ -18,20 +20,22 @@ export const SettingsHeader: FC<HeaderProps> = ({
description,
docsHref,
tooltip,
hierarchy = "primary",
titleHeaderLevel = "h1",
titleVisualHierarchy = "primary",
}) => {
const Header = titleHeaderLevel;
return (
<div className="flex flex-row justify-between align-baseline">
<div className="max-w-prose pb-6">
<div className="flex flex-row gap-2 align-middle">
<h1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a big accessibility/HTML validity issue. We were using this component multiple times on the same page, but only one h1 is allowed to be on a page, total

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I decoupled the secondary boolean into a styling prop and a semantic prop. There may be cases when we need to change the heading level to make the HTML valid, even though the styling should be exactly the same

<Header
className={twMerge(
"m-0 text-3xl font-bold flex align-baseline leading-relaxed gap-2",
hierarchy === "secondary" && "text-2xl font-medium",
titleVisualHierarchy === "secondary" && "text-2xl font-medium",
)}
>
{title}
</h1>
</Header>
{tooltip}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const NetworkSettingsPageView: FC<NetworkSettingsPageViewProps> = ({
<div>
<SettingsHeader
title="Port Forwarding"
hierarchy="secondary"
titleHeaderLevel="h2"
titleVisualHierarchy="secondary"
description="Port forwarding lets developers securely access processes on their Coder workspace from a local machine."
docsHref={docs("/admin/networking/port-forwarding")}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export const ObservabilitySettingsPageView: FC<
<Stack direction="column" spacing={6}>
<div>
<SettingsHeader title="Observability" />

<SettingsHeader
title="Audit Logging"
hierarchy="secondary"
titleHeaderLevel="h2"
titleVisualHierarchy="secondary"
description="Allow auditors to monitor user operations in your deployment."
docsHref={docs("/admin/security/audit-logs")}
/>
Expand Down Expand Up @@ -64,7 +66,8 @@ export const ObservabilitySettingsPageView: FC<
<div>
<SettingsHeader
title="Monitoring"
hierarchy="secondary"
titleHeaderLevel="h2"
titleVisualHierarchy="secondary"
description="Monitoring your Coder application with logs and metrics."
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const SecuritySettingsPageView: FC<SecuritySettingsPageViewProps> = ({
<div>
<SettingsHeader
title="Browser Only Connections"
hierarchy="secondary"
titleHeaderLevel="h2"
titleVisualHierarchy="secondary"
description="Block all workspace access via SSH, port forward, and other non-browser connections."
docsHref={docs("/admin/networking#browser-only-connections")}
/>
Expand All @@ -64,7 +65,8 @@ export const SecuritySettingsPageView: FC<SecuritySettingsPageViewProps> = ({
<div>
<SettingsHeader
title="TLS"
hierarchy="secondary"
titleHeaderLevel="h2"
titleVisualHierarchy="secondary"
description="Ensure TLS is properly configured for your Coder deployment."
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const UserAuthSettingsPageView = ({

<SettingsHeader
title="Login with OpenID Connect"
hierarchy="secondary"
titleHeaderLevel="h2"
titleVisualHierarchy="secondary"
description="Set up authentication to login with OpenID Connect."
docsHref={docs("/admin/users/oidc-auth#openid-connect")}
/>
Expand All @@ -50,7 +51,8 @@ export const UserAuthSettingsPageView = ({
<div>
<SettingsHeader
title="Login with GitHub"
hierarchy="secondary"
titleHeaderLevel="h2"
titleVisualHierarchy="secondary"
description="Set up authentication to login with GitHub."
docsHref={docs("/admin/users/github-auth")}
/>
Expand Down