-
Notifications
You must be signed in to change notification settings - Fork 955
fix(site): standardize headers for Admin Settings page #16911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
de69ee3
fix: migrate deployment workspace proxies page to new header style
Parkreiner a1da1c1
fix: update other proxy page to use proper render key values
Parkreiner e5d581b
fix: make secondary styling more obvious
Parkreiner 9b4928b
refactor: move SettingsHeader to Tailwind
Parkreiner a35a9ae
fix: resolve header level bugs
Parkreiner 9872c5d
fix: constrain max width
Parkreiner 1fe0022
fix: apply formatting
Parkreiner 7d0903a
fix: update HTML semantics
Parkreiner a512bf5
fix: flush semantics fix
Parkreiner 734f59d
fix: update leading
Parkreiner 49b9dfe
fix: resolve styling edge case for beta badge
Parkreiner 840d6df
fix: set correct font size
Parkreiner f169c4e
fix: remove redundant class
Parkreiner 2325982
Merge branch 'main' into mes/headers-fix-b
Parkreiner 99c2dbc
refactor: switch to CVA
Parkreiner 50eddd0
refactor: update API design of SettingsHeader
Parkreiner 2b77784
chore: add first-ever stories for SettingsHeader
Parkreiner e2523cb
fix: make header more responsive
Parkreiner 7f53666
fix: format
Parkreiner daf6da9
fix: update beta badge styling for Notifications page
Parkreiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: update API design of SettingsHeader
- Loading branch information
commit 50eddd01ef0d45ce21cfdfd0212849dcccbe0727
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,79 +1,109 @@ | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import { Button } from "components/Button/Button"; | ||
import { SquareArrowOutUpRightIcon } from "lucide-react"; | ||
import type { FC, ReactNode } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
import type { FC, PropsWithChildren, ReactNode } from "react"; | ||
import { cn } from "utils/cn"; | ||
|
||
const headerVariants = cva("m-0 pb-1 flex items-center gap-2 leading-tight", { | ||
type SettingsHeaderProps = Readonly< | ||
PropsWithChildren<{ | ||
actions?: ReactNode; | ||
className?: string; | ||
}> | ||
>; | ||
export const SettingsHeader: FC<SettingsHeaderProps> = ({ | ||
children, | ||
actions, | ||
className, | ||
}) => { | ||
return ( | ||
<hgroup className="flex flex-row justify-between align-baseline"> | ||
{/* | ||
* The text-sm class is only meant to adjust the font size of | ||
* SettingsDescription, but we need to apply it here. That way, | ||
* text-sm combines with the max-w-prose class and makes sure | ||
* we have a predictable max width for the header + description by | ||
* default. | ||
*/} | ||
<div className={cn("text-sm max-w-prose pb-6", className)}> | ||
{children} | ||
</div> | ||
{actions} | ||
</hgroup> | ||
); | ||
}; | ||
|
||
type SettingsHeaderDocsLinkProps = Readonly< | ||
PropsWithChildren<{ href: string }> | ||
>; | ||
export const SettingsHeaderDocsLink: FC<SettingsHeaderDocsLinkProps> = ({ | ||
href, | ||
children = "Read the docs", | ||
}) => { | ||
return ( | ||
<Button asChild variant="outline"> | ||
<a href={href} target="_blank" rel="noreferrer"> | ||
<SquareArrowOutUpRightIcon /> | ||
{children} | ||
<span className="sr-only"> (link opens in new tab)</span> | ||
</a> | ||
</Button> | ||
); | ||
}; | ||
|
||
const titleVariants = cva("m-0 pb-1 flex items-center gap-2 leading-tight", { | ||
variants: { | ||
titleVisualHierarchy: { | ||
hierarchy: { | ||
primary: "text-3xl font-bold", | ||
secondary: "text-2xl font-medium", | ||
}, | ||
}, | ||
defaultVariants: { | ||
titleVisualHierarchy: "primary", | ||
hierarchy: "primary", | ||
}, | ||
}); | ||
|
||
type HeaderLevel = `h${1 | 2 | 3 | 4 | 5 | 6}`; | ||
|
||
type HeaderProps = Readonly< | ||
VariantProps<typeof headerVariants> & { | ||
title: ReactNode; | ||
description?: ReactNode; | ||
titleHeaderLevel?: HeaderLevel; | ||
docsHref?: string; | ||
tooltip?: ReactNode; | ||
} | ||
type SettingsHeaderTitleProps = Readonly< | ||
PropsWithChildren< | ||
VariantProps<typeof titleVariants> & { | ||
level?: `h${1 | 2 | 3 | 4 | 5 | 6}`; | ||
tooltip?: ReactNode; | ||
className?: string; | ||
} | ||
> | ||
>; | ||
|
||
export const SettingsHeader: FC<HeaderProps> = ({ | ||
title, | ||
description, | ||
docsHref, | ||
export const SettingsHeaderTitle: FC<SettingsHeaderTitleProps> = ({ | ||
children, | ||
tooltip, | ||
titleHeaderLevel = "h1", | ||
titleVisualHierarchy = "primary", | ||
className, | ||
level = "h1", | ||
hierarchy = "primary", | ||
}) => { | ||
const HeaderTitle = titleHeaderLevel; | ||
// Explicitly not using Radix's Slot component, because we don't want to | ||
// allow any arbitrary element to be composed into this. We specifically | ||
// only want to allow the six HTML headers. Anything else will likely result | ||
// in invalid markup | ||
Comment on lines
+78
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment to call out why the code isn't using |
||
const Title = level; | ||
return ( | ||
<hgroup className="flex flex-row justify-between align-baseline"> | ||
{/* | ||
* The text-sm class only adjusts the font size of the description, | ||
* but we need to apply it here and not on the <p> tag itself. That | ||
* way, text-sm combines with the max-w-prose class and makes sure | ||
* we have a predictable max width for the header + description. | ||
*/} | ||
<div className="text-sm max-w-prose pb-6"> | ||
<div className="flex flex-row gap-2 align-middle"> | ||
<HeaderTitle | ||
className={twMerge( | ||
"m-0 pb-1 text-3xl font-bold flex items-center gap-2 leading-tight", | ||
titleVisualHierarchy === "secondary" && "text-2xl font-medium", | ||
)} | ||
> | ||
{title} | ||
</HeaderTitle> | ||
{tooltip} | ||
</div> | ||
|
||
{description && ( | ||
<p className="m-0 text-content-secondary leading-relaxed"> | ||
{description} | ||
</p> | ||
)} | ||
</div> | ||
<div className="flex flex-row gap-2 align-middle"> | ||
<Title className={cn(titleVariants({ hierarchy }), className)}> | ||
{children} | ||
</Title> | ||
{tooltip} | ||
</div> | ||
); | ||
}; | ||
|
||
{docsHref && ( | ||
<Button asChild variant="outline"> | ||
<a href={docsHref} target="_blank" rel="noreferrer"> | ||
<SquareArrowOutUpRightIcon /> | ||
Read the docs | ||
<span className="sr-only"> (link opens in new tab)</span> | ||
</a> | ||
</Button> | ||
)} | ||
</hgroup> | ||
type SettingsHeaderDescriptionProps = Readonly< | ||
PropsWithChildren<{ | ||
className?: string; | ||
}> | ||
>; | ||
export const SettingsHeaderDescription: FC<SettingsHeaderDescriptionProps> = ({ | ||
children, | ||
className, | ||
}) => { | ||
return ( | ||
<p className={cn("m-0 text-content-secondary leading-relaxed", className)}> | ||
{children} | ||
</p> | ||
); | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?