Skip to content

Commit

Permalink
feat: Selected -style for ActionBarSubItem
Browse files Browse the repository at this point in the history
  • Loading branch information
timwessman committed Nov 14, 2024
1 parent ba2ebdc commit 5a39c0e
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions packages/react/src/components/header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,38 @@ export const WithUserMenu = (args: HeaderProps) => {
</>
);
};

export const WithCustomMenu = (args: HeaderProps) => {
const lang = 'fi';
const I18n = translations[lang];
const versions = ['Version 4.0.0', 'Version 3.11.0', 'Version 2.17.1'];
const selectedVersion = 'Version 3.11.0';

return (
<>
<Header {...args}>
<Header.SkipLink skipTo="#content" label={I18n.skipToContent} />
<Header.ActionBar
frontPageLabel={I18n.frontPage}
title={translations[lang].headerTitle}
titleAriaLabel={translations[lang].headerAriaLabel}
titleHref="https://hel.fi"
logo={
<Logo
src={logoSrcFromLanguageAndTheme(lang, args.theme as HeaderTheme)}
alt={translations[lang].headerTitle}
/>
}
logoAriaLabel={I18n.ariaLogo}
>
<Header.ActionBarItem id="VersionMenu" label={selectedVersion} fixedRightPosition>
{versions.map((version) => (
<Header.ActionBarSubItem label={version} selected={version === selectedVersion} href="/" />
))}
</Header.ActionBarItem>
</Header.ActionBar>
</Header>
<div id="content" />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@
& > h4 {
padding: 0 !important;
}

&.selected {
border-left: 4px solid var(--color-black);
}
}

& .dropdownItem button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const HeaderActionBarItem = (properties: HeaderActionBarItemProps) => {
activeStateLabel: closeLabel,
}
: {};
const heading = visible && !fullWidth && label && avatar;

/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
return (
Expand All @@ -165,7 +166,7 @@ export const HeaderActionBarItem = (properties: HeaderActionBarItemProps) => {
{hasSubItems && (
<div className={classes.dropdownWrapper}>
<div id={`${id}-dropdown`} className={dropdownClassName} ref={dropdownContentElementRef}>
{visible && !fullWidth && label && <h3>{label}</h3>}
{heading && <h3>{label}</h3>}
<ul>{children}</ul>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ h4.actionBarSubItem {
font-weight: bold;
}

&.selected {
text-decoration: underline;
}

&:focus-visible {
border: none;
outline: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface HeaderActionBarSubItemProps extends ElementProps {
* If bold
*/
bold?: boolean;
/**
* If selected
*/
selected?: boolean;
/**
* Hypertext Reference of the link.
*/
Expand Down Expand Up @@ -75,6 +79,7 @@ export const HeaderActionBarSubItem = forwardRef<HTMLButtonElement | HTMLAnchorE
onClick,
className,
bold,
selected,
external,
openInExternalDomainAriaLabel,
...rest
Expand All @@ -85,6 +90,7 @@ export const HeaderActionBarSubItem = forwardRef<HTMLButtonElement | HTMLAnchorE
[classes.actionBarSubItem]: true,
...(className && { [className]: true }),
[classes.bold]: bold,
[classes.selected]: selected,
});

const composeAriaLabel = () => {
Expand Down Expand Up @@ -151,7 +157,14 @@ export const HeaderActionBarSubItem = forwardRef<HTMLButtonElement | HTMLAnchorE
return isHeading ? (
<h4 className={itemClassName}>{children}</h4>
) : (
<li className={actionBarItemClasses.dropdownItem}>{children}</li>
<li
className={classNames({
[actionBarItemClasses.dropdownItem]: true,
[actionBarItemClasses.selected]: selected,
})}
>
{children}
</li>
);
},
[isHeading, itemClassName],
Expand Down
18 changes: 10 additions & 8 deletions site/src/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,16 @@ const Layout = ({ location, children, pageContext }) => {
logo={<Logo src={logoFi} alt="Helsingin kaupunki" />}
>
<Header.ActionBarItem label={versionLabel} fixedRightPosition>
{versions.map((versionNumber, index) => (
<Header.ActionBarSubItem
label={`Version ${versionNumber}`}
href={index > 0
? hrefWithVersion(locationWithoutVersion, `release-${versionNumber}`)
: withPrefix(locationWithoutVersion)}
/>
))}
<Header.ActionBarSubItemGroup label="Versions">
{versions.map((versionNumber, index) => (
<Header.ActionBarSubItem
label={`Version ${versionNumber}`}
href={index > 0
? hrefWithVersion(locationWithoutVersion, `release-${versionNumber}`)
: withPrefix(locationWithoutVersion)}
/>
))}
</Header.ActionBarSubItemGroup>
</Header.ActionBarItem>
</Header.ActionBar>
<Header.NavigationMenu>
Expand Down

0 comments on commit 5a39c0e

Please sign in to comment.