Skip to content

Commit

Permalink
feat(MainNavigationBar): add menu (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoskolodny authored Nov 14, 2024
1 parent 087c486 commit 3973ead
Show file tree
Hide file tree
Showing 29 changed files with 2,126 additions and 313 deletions.
299 changes: 272 additions & 27 deletions playroom/snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2584,33 +2584,278 @@ const navigationBarSnippets = [
group: 'NavigationBar',
name: 'MainNavigationBar',
code: `
<MainNavigationBar
sections={["Start", "Account", "Explore", "Support"].map((title, idx) => ({
title,
onPress: () => setState("index", idx),
}))}
selectedIndex={getState("index", 0)}
right={
<NavigationBarActionGroup>
<NavigationBarAction
onPress={() => {}}
aria-label="shopping cart with 2 items"
>
<Badge value={2}>
<IconShoppingCartRegular color="currentColor" />
</Badge>
</NavigationBarAction>
<NavigationBarAction onPress={() => {}} aria-label="Open profile">
<Avatar
size={isDesktopOrBigger ? 32 : 24}
initials="ML"
src="${imagePlaceholder}"
/>
{isDesktopOrBigger && "María López Serrano"}
</NavigationBarAction>
</NavigationBarActionGroup>
}
/>`,
<MainNavigationBar
sections={[
{
title: "Start",
onPress: () => setState("index", 0),
},
{
title: "Account",
onPress: () => setState("index", 1),
},
{
title: "Explore",
onPress: () => setState("index", 2),
},
{
title: "Support",
onPress: () => setState("index", 3),
},
]}
selectedIndex={getState("index", 0)}
right={
<NavigationBarActionGroup>
<NavigationBarAction
onPress={() => {}}
aria-label="shopping cart with 2 items"
>
<Badge value={2}>
<IconShoppingCartRegular color="currentColor" />
</Badge>
</NavigationBarAction>
<NavigationBarAction onPress={() => {}} aria-label="Open profile">
<Avatar
size={isDesktopOrBigger ? 32 : 24}
initials="ML"
src="${imagePlaceholder}"
/>
{isDesktopOrBigger && "María López Serrano"}
</NavigationBarAction>
</NavigationBarActionGroup>
}
/>`,
},
{
group: 'NavigationBar',
name: 'MainNavigationBar with menu',
code: `
<MainNavigationBar
sections={[
{
onPress: () => setState("index", 0),
title: "Start",
menu: {
columns: [
{
title: "Start 1",
items: [
{
title: "item 1",
onPress: () => {},
},
{
title: "item 2",
href: "https://www.google.com/",
},
{
title: "item 3",
to: "#",
},
],
},
],
},
},
{
onPress: () => setState("index", 1),
title: "Account",
menu: {
columns: [
{
title: "Account 1",
items: [
{
title: "item 1",
onPress: () => {},
},
],
},
],
},
},
{
onPress: () => setState("index", 2),
title: "Explore",
menu: {
columns: [
{
title: "Explore 1",
items: [
{
title: "item 1",
onPress: () => {},
},
{
title: "item 2",
href: "https://www.google.com/",
},
{
title: "item 3",
to: "#",
},
],
},
],
},
},
]}
selectedIndex={getState("index", 0)}
/>`,
},
{
group: 'NavigationBar',
name: 'MainNavigationBar with large menu',
code: `
<MainNavigationBar
desktopLargeMenu
sections={[
{
onPress: () => setState("index", 0),
title: "Start",
menu: {
columns: [
{
title: "Start 1",
items: [
{
title: "item 1",
onPress: () => {},
},
{
title: "item 2",
href: "https://www.google.com/",
},
{
title: "item 3",
to: "#",
},
],
},
{
title: "Start 2",
items: [
{
title: "item 1",
onPress: () => {},
},
{
title: "item 2",
href: "https://www.google.com/",
},
{
title: "item 3",
to: "#",
},
],
},
],
},
},
{
onPress: () => setState("index", 1),
title: "Account",
menu: {
columns: [
{
title: "Account 1",
items: [
{
title: "item 1",
onPress: () => {},
},
],
},
],
},
},
{
onPress: () => setState("index", 2),
title: "Explore",
menu: {
content: ({ closeMenu }) => (
<Stack space={16}>
<Text2 regular>Custom content</Text2>
<Placeholder />
<ButtonPrimary onPress={closeMenu}>Close menu</ButtonPrimary>
</Stack>
),
},
},
{
onPress: () => setState("index", 3),
title: "Support",
menu: {
content: isDesktopOrBigger ? (
<Grid columns={12} gap={24}>
{Array.from({ length: 3 }, (_, index) => (
<GridItem columnSpan={2} key={index}>
<Stack space={24}>
<Title1>Contenidos</Title1>
<Stack space={16}>
{[
"Destacados",
"Todo fútbol",
"#0",
"Cine",
"Oferta comercial",
"Mi Movistar",
"Movistar Cloud",
].map((title, index) => (
<TextLink
key={index}
onPress={() => {}}
style={{ color: colors.textPrimary }}
>
{title}
</TextLink>
))}
</Stack>
</Stack>
</GridItem>
))}
<GridItem columnSpan={5} columnStart={8}>
<DisplayMediaCard
headline={<Tag type="promo">Oferta</Tag>}
title="Movistar Plus+"
onPress={() => {}}
description="Contrata solo TV por 9,99 €"
backgroundImage="${imagePlaceholder}"
/>
</GridItem>
</Grid>
) : (
<Stack space={40}>
{Array.from({ length: 3 }, (_, index) => (
<Stack space={16} key={index}>
<Title1>Title</Title1>
<NegativeBox>
<RowList>
<Row title="Title" onPress={() => {}} />
<Row title="Title" onPress={() => {}} />
<Row title="Title" onPress={() => {}} />
<Row title="Title" onPress={() => {}} />
</RowList>
</NegativeBox>
</Stack>
))}
<DisplayMediaCard
headline={<Tag type="promo">Oferta</Tag>}
title="Movistar Plus+"
aspectRatio="1:1"
onPress={() => {}}
description="Contrata solo TV por 9,99 €"
backgroundImage="${imagePlaceholder}"
/>
</Stack>
),
},
},
]}
selectedIndex={getState("index", 0)}
/>`,
},
{
group: 'NavigationBar',
Expand Down
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
64 changes: 64 additions & 0 deletions src/__screenshot_tests__/navigation-bar-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,67 @@ test.each(DEVICES)('MainNavigationBar without sections (%s)', async (device) =>

expect(image).toMatchImageSnapshot();
});

test.each`
menuType | content
${'large'} | ${'default'}
${'large'} | ${'custom'}
${'small'} | ${'default'}
${'small'} | ${'custom'}
`('MainNavigationBar with $menuType menu and $content content in DESKTOP', async ({menuType, content}) => {
const page = await openStoryPage({
id: 'components-navigation-bars-mainnavigationbar--default',
device: 'DESKTOP',
args: {sections: true, desktopLargeMenu: menuType === 'large', menu: content},
});

// first section opened
await page.click(await screen.findByRole('button', {name: 'Start'}));
expect(await page.screenshot()).toMatchImageSnapshot();

// second section opened
await page.click(await screen.findByRole('button', {name: 'Account'}));
expect(await page.screenshot()).toMatchImageSnapshot();

// close menu with ESC key
await page.keyboard.press('Escape');
expect(await page.screenshot()).toMatchImageSnapshot();
});

test.each(['default', 'custom'])('MainNavigationBar with menu and %s content in MOBILE_IOS', async (menu) => {
const page = await openStoryPage({
id: 'components-navigation-bars-mainnavigationbar--default',
device: 'MOBILE_IOS',
args: {sections: true, menu},
});

await page.click(await screen.findByRole('button', {name: 'Abrir menú de navegación'}));

// open first section
await page.click(await screen.findByRole('button', {name: 'Start'}));
expect(await page.screenshot()).toMatchImageSnapshot();

// go back
await page.click(await screen.findByRole('button', {name: 'Atrás'}));
expect(await page.screenshot()).toMatchImageSnapshot();

// open second section
await page.click(await screen.findByRole('button', {name: 'Account'}));
expect(await page.screenshot()).toMatchImageSnapshot();

// close menu
await page.click(await screen.findByRole('button', {name: 'Cerrar menú de navegación'}));
expect(await page.screenshot()).toMatchImageSnapshot();
});

test.each(['large', 'small'])('MainNavigationBar inverse with %s menu in DESKTOP', async (menuType) => {
const page = await openStoryPage({
id: 'components-navigation-bars-mainnavigationbar--default',
device: 'DESKTOP',
args: {sections: true, desktopLargeMenu: menuType === 'large', menu: 'default', variant: 'inverse'},
});

// first section opened
await page.click(await screen.findByRole('button', {name: 'Start'}));
expect(await page.screenshot()).toMatchImageSnapshot({failureThreshold: 0.00001});
});
Loading

1 comment on commit 3973ead

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-nbhqrcv1m-flows-projects-65bb050e.vercel.app

Built with commit 3973ead.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.