Skip to content
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

feat(main-nav): Main Nav refactoring, refactor the logo #20135

Merged
merged 6 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 41 additions & 17 deletions packages/core/admin/admin/src/components/LeftMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { Menu } from '../hooks/useMenu';
import { usePersistentState } from '../hooks/usePersistentState';
import { getDisplayName } from '../utils/users';

import { NavBrand as NewNavBrand } from './MainNav/NavBrand';

const LinkUserWrapper = styled(Box)`
width: ${150 / 16}rem;
position: absolute;
Expand Down Expand Up @@ -105,23 +107,45 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }: LeftMenuProps) =

return (
<MainNav condensed={condensed}>
<NavBrand
as={RouterNavLink}
workplace={formatMessage({
id: 'app.components.LeftMenu.navbrand.workplace',
defaultMessage: 'Workplace',
})}
title={menuTitle}
icon={
<img
src={menu.custom?.url || menu.default}
alt={formatMessage({
id: 'app.components.LeftMenu.logo.alt',
defaultMessage: 'Application logo',
})}
/>
}
/>
{condensed ? (
/**
* TODO: remove the conditional rendering once the new Main nav is fully implemented
*/
<NewNavBrand
workplace={formatMessage({
id: 'app.components.LeftMenu.navbrand.workplace',
defaultMessage: 'Workplace',
})}
title={menuTitle}
icon={
<img
src={menu.custom?.url || menu.default}
alt={formatMessage({
id: 'app.components.LeftMenu.logo.alt',
defaultMessage: 'Application logo',
})}
/>
simotae14 marked this conversation as resolved.
Show resolved Hide resolved
}
/>
) : (
<NavBrand
as={RouterNavLink}
workplace={formatMessage({
id: 'app.components.LeftMenu.navbrand.workplace',
defaultMessage: 'Workplace',
})}
title={menuTitle}
icon={
<img
src={menu.custom?.url || menu.default}
alt={formatMessage({
id: 'app.components.LeftMenu.logo.alt',
defaultMessage: 'Application logo',
})}
/>
}
/>
)}

<Divider />

Expand Down
35 changes: 35 additions & 0 deletions packages/core/admin/admin/src/components/MainNav/NavBrand.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';

import { Box, VisuallyHidden } from '@strapi/design-system';
import styled from 'styled-components';

const BrandIconWrapper = styled.div`
simotae14 marked this conversation as resolved.
Show resolved Hide resolved
svg,
img {
border-radius: ${({ theme }) => theme.borderRadius};
object-fit: contain;
height: ${24 / 16}rem;
width: ${24 / 16}rem;
margin: ${3 / 16}rem;
}
`;

export interface NavBrandProps {
icon: React.ReactNode;
title: string;
workplace: string;
}

export const NavBrand = ({ workplace, title, icon }: NavBrandProps) => {
return (
<Box paddingLeft={3} paddingRight={3} paddingTop={3} paddingBottom={3}>
simotae14 marked this conversation as resolved.
Show resolved Hide resolved
<BrandIconWrapper>
{icon}
<VisuallyHidden>
<span>{title}</span>
<span>{workplace}</span>
</VisuallyHidden>
</BrandIconWrapper>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { render, screen } from '@tests/utils';

import { NavBrand } from '../NavBrand';

describe('NavBrand', () => {
it('shows the NavBrand with no action on click', () => {
render(<NavBrand workplace="Workplace" title="Title" icon={<img src="icon" alt="icon" />} />);
expect(screen.getByRole('img')).toBeInTheDocument();
expect(screen.getByText('Title')).toBeInTheDocument();
expect(screen.getByText('Workplace')).toBeInTheDocument();
expect(screen.queryByRole('link')).not.toBeInTheDocument();
});
});