Skip to content

Commit

Permalink
feat(ApplicationMenu): add appTitleDesktop prop
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-gendron committed Nov 29, 2021
1 parent 6a9dfda commit 51e7dbc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { shallow } from 'enzyme';
import React from 'react';
import { getByTestId } from '../../test-utils/enzyme-selectors';
import { renderWithProviders } from '../../test-utils/renderer';
import { renderWithProviders, mountWithProviders } from '../../test-utils/renderer';
import { ApplicationMenu } from './application-menu';
import { SkipLinkProps } from '../skip-link/skip-link';

Expand Down Expand Up @@ -79,5 +79,23 @@ describe('Application Menu', () => {

expect(getByTestId(wrapper, 'logo-html-link').exists()).toBe(true);
});

it('contains app-title when appTitleDesktop prop is set given device is desktop', () => {
const wrapper = mountWithProviders(
<ApplicationMenu appTitleDesktop="test">test</ApplicationMenu>,
{ wrappingComponentProps: { staticDevice: 'desktop' } },
);

expect(getByTestId(wrapper, 'app-title').exists()).toBe(true);
});

it('does not contain app-title when device is mobile', () => {
const wrapper = mountWithProviders(
<ApplicationMenu appTitleDesktop="test">test</ApplicationMenu>,
{ wrappingComponentProps: { staticDevice: 'mobile' } },
);

expect(getByTestId(wrapper, 'app-title').exists()).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ exports[`Application Menu Matches the snapshot (desktop) 1`] = `
font-size: 1.5rem;
font-weight: var(--font-bold);
height: 100%;
-webkit-text-decoration: none;
text-decoration: none;
}
.c1:focus {
Expand Down Expand Up @@ -171,6 +173,8 @@ exports[`Application Menu Matches the snapshot (mobile) 1`] = `
font-size: 1.5rem;
font-weight: var(--font-bold);
height: 100%;
-webkit-text-decoration: none;
text-decoration: none;
}
.c1:focus {
Expand Down Expand Up @@ -308,6 +312,8 @@ exports[`Application Menu mobileDrawerContent prop adds a side drawer and burger
font-size: 1.5rem;
font-weight: var(--font-bold);
height: 100%;
-webkit-text-decoration: none;
text-decoration: none;
}
.c1:focus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const LinkStyles = css`
font-size: 1.5rem;
font-weight: var(--font-bold);
height: 100%;
text-decoration: none;
${focus}
> * {
Expand All @@ -49,6 +50,18 @@ const HtmlLink = styled.a.attrs({ 'aria-label': 'Home' })`
${LinkStyles}
`;

const StyledSpan = styled.span`
border-left: 1px solid ${({ theme }) => theme.main['primary-1.3']};
color: ${({ theme }) => theme.greys.white};
font-size: 1rem;
font-weight: var(--font-normal);
height: unset;
line-height: 1.5rem;
margin-left: var(--spacing-2x);
padding-left: var(--spacing-2x);
width: max-content;
`;

const StyledSkipLink = styled(SkipLink)<ComponentProps<typeof SkipLink> & { isMobile?: boolean }>`
background-color: ${({ theme }) => theme.greys.white};
transform: translateY(-50%);
Expand All @@ -69,6 +82,8 @@ const StyledSkipLink = styled(SkipLink)<ComponentProps<typeof SkipLink> & { isMo
interface ApplicationMenuProps {
/** Set the app name to get the proper logos */
appName?: LogoName;
/** Sets app title which appears next to logo on desktop */
appTitleDesktop?: string;
/** Right-side content */
children: ReactNode;
className?: string;
Expand All @@ -86,6 +101,7 @@ interface ApplicationMenuProps {

export function ApplicationMenu({
appName = 'default',
appTitleDesktop,
children,
className,
customLogo,
Expand All @@ -97,6 +113,17 @@ export function ApplicationMenu({
const { device, isMobile } = useDeviceContext();
const appLogo = customLogo ?? <Logo name={appName} mobile={isMobile} />;

function renderLogoContent(): ReactElement {
return (
<>
{appLogo}
{(!isMobile && appTitleDesktop) && (
<StyledSpan data-testid="app-title">{appTitleDesktop}</StyledSpan>
)}
</>
);
}

return (
<Header className={className} device={device}>
{skipLink && (
Expand All @@ -105,9 +132,13 @@ export function ApplicationMenu({
)}

{usesReactRouter ? (
<ReactRouterLink data-testid="logo-react-router-link" to={logoHref}>{appLogo}</ReactRouterLink>
<ReactRouterLink data-testid="logo-react-router-link" to={logoHref}>
{renderLogoContent()}
</ReactRouterLink>
) : (
<HtmlLink data-testid="logo-html-link" href={logoHref}>{appLogo}</HtmlLink>
<HtmlLink data-testid="logo-html-link" href={logoHref}>
{renderLogoContent()}
</HtmlLink>
)}

<Content mobileDrawerContent={mobileDrawerContent}>
Expand Down
6 changes: 6 additions & 0 deletions packages/storybook/stories/application-menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export const WithCustomLogo: Story = () => (
</ApplicationMenu>
);

export const WithAppTitleDesktop: Story = () => (
<ApplicationMenu appTitleDesktop="App title">
<p>Hello world</p>
</ApplicationMenu>
);

export const WithMobileDrawer: Story = () => (
<ApplicationMenu mobileDrawerContent={drawerContent}>
<p>Hello world</p>
Expand Down

0 comments on commit 51e7dbc

Please sign in to comment.