Repository navigation
website-feature: add page size menu to catalogs and Learning Hub #5111
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
Open
jhauga
wants to merge
6
commits into
github:main
Choose a base branch
from
jhauga:website-select-resource-page-size
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+519
−104
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5cd258c
website-feature: add page size menu to catalogs and Learning Hub
jhauga 30be27c
Update aria-label for CatalogResourceSizeControl
jhauga 8f144bd
apply recommended changes
jhauga b0a856b
Merge branch 'main' into website-select-resource-page-size
jhauga de23acc
apply code review suggestion
jhauga 14a6bb7
apply code review suggestion
jhauga 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
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
82 changes: 82 additions & 0 deletions
82
website/src/components/brand/CatalogResourceSizeControl.tsx
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { CheckIcon, ChevronDownIcon } from "@primer/octicons-react"; | ||
| import { clsx } from "clsx"; | ||
|
|
||
| export type CatalogResourceSizeOption<T extends number> = { | ||
| value: T; | ||
| label: string; | ||
| }; | ||
|
|
||
| export const CATALOG_RESOURCE_SIZE_OPTIONS = [ | ||
| { value: 6, label: "6" }, | ||
| { value: 25, label: "25" }, | ||
| { value: 50, label: "50" }, | ||
| { value: 100, label: "100" }, | ||
| ] as const satisfies readonly CatalogResourceSizeOption<number>[]; | ||
|
|
||
| /** A page size the catalogs offer: 6, 25, 50, or 100 items. */ | ||
| export type CatalogResourceSize = | ||
| (typeof CATALOG_RESOURCE_SIZE_OPTIONS)[number]["value"]; | ||
|
|
||
| /** How many items a catalog page shows until the reader picks a size. */ | ||
| export const DEFAULT_CATALOG_RESOURCE_SIZE: CatalogResourceSize = 6; | ||
|
|
||
| type CatalogResourceSizeControlProps<T extends number> = { | ||
| ariaLabel: string; | ||
| onChange: (value: T) => void; | ||
| options: readonly CatalogResourceSizeOption<T>[]; | ||
| /** The catalog's CSS module. The menu reuses the sort menu's classes so the | ||
| * two toolbar menus look the same. */ | ||
| styles: Record<string, string | undefined>; | ||
| value: T; | ||
| }; | ||
|
|
||
| export function CatalogResourceSizeControl<T extends number>({ | ||
| ariaLabel, | ||
| onChange, | ||
| options, | ||
| styles, | ||
| value, | ||
| }: CatalogResourceSizeControlProps<T>) { | ||
| const selectedLabel = | ||
| options.find((option) => option.value === value)?.label ?? String(value); | ||
|
|
||
| return ( | ||
| <div className={styles.sortControl}> | ||
| <span className={styles.sortLabel}>Resource page size:</span> | ||
| <details className={styles.sortMenu}> | ||
| <summary | ||
| className={styles.sortTrigger} | ||
| aria-label={`${ariaLabel}: ${selectedLabel}`} | ||
| > | ||
| {selectedLabel} | ||
| <ChevronDownIcon size={16} className={styles.sortChevron} /> | ||
| </summary> | ||
| <div className={styles.sortOverlay} role="menu"> | ||
|
jhauga marked this conversation as resolved.
Outdated
|
||
| {options.map((option) => ( | ||
| <button | ||
| key={option.value} | ||
| type="button" | ||
| role="menuitemradio" | ||
| aria-checked={value === option.value} | ||
| className={clsx( | ||
| styles.sortOption, | ||
| value === option.value && styles.sortOptionActive, | ||
| )} | ||
| onClick={(event) => { | ||
| onChange(option.value); | ||
| event.currentTarget.closest("details")?.removeAttribute("open"); | ||
| }} | ||
| > | ||
| {option.label} | ||
| <CheckIcon | ||
| size={16} | ||
| className={styles.sortOptionCheck} | ||
| aria-hidden={value !== option.value} | ||
| /> | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </details> | ||
| </div> | ||
| ); | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.