Skip to content

Commit

Permalink
Feat/responsive header (#88)
Browse files Browse the repository at this point in the history
* feat: added HeaderMobile, HeaderNav

refactor: modified Header, SearchBar, SidebarMenu, CollapseButton
  • Loading branch information
MorganeLeCaignec authored Dec 14, 2023
1 parent 25be4ad commit 480af11
Show file tree
Hide file tree
Showing 24 changed files with 1,373 additions and 201 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-pillows-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@smile/react-front-kit': minor
---

Added `HeaderMobile` and `HeaderNav` components, reworked `Header` with mobile mode, added optional placeholder to `SearchBar`, improved info returned by collapseButtonProps in `SidebarMenu`
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export function CollapseButtonControlled<
{...buttonProps}
>
<Component
className={classes.button}
className={[classes.button, componentProps?.className].join(' ')}
data-testid="select"
type={Component === 'button' ? 'button' : undefined}
{...componentProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`CollapseButton matches snapshot 1`] = `
class="mantine-Button-label mantine-12tfho7"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports[`FiltersBar matches snapshot 1`] = `
class="mantine-Button-label mantine-28zsh7"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
>
Expand Down Expand Up @@ -209,7 +209,7 @@ exports[`FiltersBar matches snapshot 1`] = `
class="mantine-Button-label mantine-m141sh"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
>
Expand Down Expand Up @@ -264,7 +264,7 @@ exports[`FiltersBar matches snapshot 1`] = `
class="mantine-Button-label mantine-m141sh"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
>
Expand Down Expand Up @@ -318,7 +318,7 @@ exports[`FiltersBar matches snapshot 1`] = `
class="mantine-Button-label mantine-m141sh"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
>
Expand Down Expand Up @@ -373,7 +373,7 @@ exports[`FiltersBar matches snapshot 1`] = `
class="mantine-Button-label mantine-m141sh"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
>
Expand Down Expand Up @@ -430,7 +430,7 @@ exports[`FiltersBar matches snapshot 1`] = `
class="mantine-Button-label mantine-m141sh"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
>
Expand Down Expand Up @@ -485,7 +485,7 @@ exports[`FiltersBar matches snapshot 1`] = `
class="mantine-Button-label mantine-m141sh"
>
<button
class="mantine-pax7vz"
class="mantine-pax7vz "
data-testid="select"
type="button"
>
Expand Down
63 changes: 63 additions & 0 deletions packages/react-front-kit/src/Components/Header/Header.mock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { IHeaderNavMenu } from '../HeaderNav/HeaderNav';
import type { ReactElement } from 'react';

import { Avatar, Menu } from '@mantine/core';

import { DropdownButton } from '../DropdownButton/DropdownButton';
import { HeaderNav } from '../HeaderNav/HeaderNav';

export const menusMock: IHeaderNavMenu<number>[] = [
{
children: [
{ id: 4, label: 'Releases', url: '#' },
{ id: 5, label: 'Account', url: '#' },
{
children: [
{ id: 8, label: 'Wiki pages', url: '#' },
{ id: 9, label: 'Settings', url: '#' },
],
id: 6,
label: 'Upcoming releases',
url: '#',
},
{ id: 7, label: 'Lorem ipsum dolor', url: '#' },
],
id: 1,
label: 'Espace documentaire',
url: '#',
},
{ id: 2, label: 'Espace workflow', url: '#' },
{ id: 3, label: 'Archives', url: '#' },
];

export const childrenMock = (isMobile: boolean): ReactElement => {
return <HeaderNav isMobile={isMobile} menus={menusMock} />;
};

export const leftContentMock = (
<img alt="logo" height="58" src="./logo.svg" width="128" />
);

export const rightContentMobileMock = (
<DropdownButton label="Mon espace">
<Menu.Item component="a" href="#">
Calico
</Menu.Item>
<Menu.Item component="a" href="#">
Espace RH
</Menu.Item>
<Menu.Item component="a" href="#">
Aventure IA
</Menu.Item>
<Menu.Item component="a" href="#">
Lunette & CO
</Menu.Item>
</DropdownButton>
);

export const rightContentMock = (
<>
{rightContentMobileMock}
<Avatar src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=250&q=80" />
</>
);
46 changes: 16 additions & 30 deletions packages/react-front-kit/src/Components/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Avatar, Menu } from '@mantine/core';
import { primaryTheme } from '@smile/react-front-kit-shared';
import { useStorybookArgsConnect } from '@smile/react-front-kit-shared/storybook-utils';
import { action } from '@storybook/addon-actions';
import { expect } from '@storybook/jest';
import { userEvent, within } from '@storybook/testing-library';

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

import { Header as Cmp } from './Header';
import {
childrenMock,
leftContentMock,
rightContentMobileMock,
rightContentMock,
} from './Header.mock';

const meta = {
argTypes: {
Expand Down Expand Up @@ -46,35 +50,17 @@ type IStory = StoryObj<typeof meta>;

export const Header: IStory = {
args: {
children: (
<>
<a href="#">Espace documentaire</a>
<a href="#">Espace workflow</a>
<a href="#">Archives</a>
</>
),
children: childrenMock(false),
childrenComponent: 'nav',
hasResponsiveMode: true,
height: 90,
left: <img alt="logo" height="58" src="./logo.svg" width="128" />,
right: (
<>
<DropdownButton label="Mon espace">
<Menu.Item component="a" href="#">
Calico
</Menu.Item>
<Menu.Item component="a" href="#">
Espace RH
</Menu.Item>
<Menu.Item component="a" href="#">
Aventure IA
</Menu.Item>
<Menu.Item component="a" href="#">
Lunette & CO
</Menu.Item>
</DropdownButton>
<Avatar src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=250&q=80" />
</>
),
left: leftContentMock,
mobileProps: {
children: childrenMock(true),
right: rightContentMobileMock,
},
onSearchSubmit: action('search input submitted'),
right: rightContentMock,
searchTheme: primaryTheme,
searchValue: '',
withBorder: false,
Expand Down
65 changes: 65 additions & 0 deletions packages/react-front-kit/src/Components/Header/Header.style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { createStyles } from '@mantine/core';

export const useStyles = createStyles((theme) => ({
around: {
alignItems: 'center',
gap: theme.spacing.xs,
},
button: {
'&::after': {
background:
theme.colorScheme === 'light'
? theme.colors.gray[3]
: theme.colors.gray[8],
content: '""',
display: 'block',
height: 36,
position: 'absolute',
right: 0,
top: '50%',
translate: '0 -50%',
width: 1,
},
background: 'transparent',
borderRadius: 0,
position: 'relative',
},
buttonOpened: {
'&::after': {
display: 'none',
},
background: theme.fn.primaryColor(),
color: theme.white,
},
container: {
alignItems: 'center',
justifyContent: 'space-between',
padding: '16px 64px',
position: 'relative',
width: '100%',
},
menu: {
alignItems: 'center',
gap: theme.spacing.xl,
left: '50%',
margin: 'auto',
position: 'absolute',
top: '50%',
translate: '-50% -50%',
},
none: {
display: 'none',
},
sizeDesktop: {
display: 'initial',
[theme.fn.smallerThan('md')]: {
display: 'none',
},
},
sizeMobile: {
display: 'none',
[theme.fn.smallerThan('md')]: {
display: 'initial',
},
},
}));
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Header } from './Header';
describe('Header', () => {
it('matches snapshot', () => {
const { container } = renderWithProviders(
<Header>
<Header hasResponsiveMode={false} searchInputProps={{ id: 'test' }}>
<a href="#">Espace documentaire</a>
<a href="#">Espace workflow</a>
<a href="#">Archives</a>
Expand Down
Loading

0 comments on commit 480af11

Please sign in to comment.