Skip to content

Commit

Permalink
fixup! ✨ TopAppBarMenu - add custom menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Castagliola committed Feb 28, 2024
1 parent 5ce7c2e commit 7d65e40
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 47 deletions.
15 changes: 12 additions & 3 deletions Storybook/components/TopAppBar/TopAppBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import TopAppBarMenuItem from '../../../src/components/topAppBar/Menu/TopAppBarM
import type { Title } from 'src/components/topAppBar/TopAppBar';
import { TopAppBarMenuProvider } from '../../../src/components/topAppBar/Menu/TopAppMenuBarContext';
import { IconName } from '../../../src/components/icons/IconProps';
import TopAppBarMenuAction from '../../../src/components/topAppBar/Menu/TopAppBarMenuAction';

const asString = { value: 'menu' };
const asButton = { value: 'menu', onPress: () => {} };
Expand Down Expand Up @@ -109,7 +110,7 @@ export const WithMenuAction = (args) => {
);
}}
>
<TopAppBar.MenuAction />
<TopAppBarMenuAction />
</TopAppBarMenuProvider>
}
/>
Expand All @@ -125,7 +126,13 @@ export const WithCloseAction = (args) => {
size={args.size}
onBack={args.withBackButton ? args.onBack : undefined}
title={titleComponent}
action={<TopAppBar.CloseAction onPress={args.onMenuItemPress} />}
action={
<TopAppBar.Action
icon='close'
accessibilityLabel='Close'
onPress={args.onMenuItemPress}
/>
}
/>
);
};
Expand All @@ -141,7 +148,9 @@ export const WithPrinterSettingsAction = (args) => {
onBack={args.withBackButton ? args.onBack : undefined}
title={titleComponent}
action={
<TopAppBar.PrinterSettingsAction
<TopAppBar.Action
icon='cog'
accessibilityLabel='Settings'
onPress={args.onMenuItemPress}
/>
}
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/components/TopAppBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
import { Text } from 'react-native';
import TopAppBarMenuItem from '../../components/topAppBar/Menu/TopAppBarMenuItem';
import { TopAppBarMenuProvider } from '../../components/topAppBar/Menu/TopAppMenuBarContext';
import { IconName } from 'src/components/icons/IconProps';
import { IconName } from '../../components/icons/IconProps';
import TopAppBarMenuAction from '../../components/topAppBar/Menu/TopAppBarMenuAction';

const topBarTitle = 'Menu';

Expand Down Expand Up @@ -100,7 +101,7 @@ describe('TopAppBar mounting with a menu', () => {
);
}}
>
<TopAppBar.MenuAction />
<TopAppBarMenuAction />
</TopAppBarMenuProvider>
}
/>,
Expand Down
13 changes: 0 additions & 13 deletions src/components/topAppBar/Actions/TopAppBarCloseAction.tsx

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useTopBarMenu } from '../Menu/TopAppMenuBarContext';
import TopAppBarAction from './TopAppBarAction';
import { useTopBarMenu } from './TopAppMenuBarContext';
import TopAppBarAction from '../TopAppBarAction';

const TopAppBarMenuAction = () => {
const { showMenu } = useTopBarMenu();
Expand Down
7 changes: 2 additions & 5 deletions src/components/topAppBar/Menu/TopAppMenuBarContext.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { ComponentProps, ReactNode } from 'react';
import React, { ReactNode } from 'react';
import { StyleSheet, View } from 'react-native';
import { Menu, Modal, Portal } from 'react-native-paper';
import { useTheme } from '../../../styles/themes';
import TopAppBarMenuItem from './TopAppBarMenuItem';

type TopAppBarMenuContextValue =
| {
Expand All @@ -11,11 +10,9 @@ type TopAppBarMenuContextValue =
}
| undefined;

type MenuItemId = ComponentProps<typeof TopAppBarMenuItem>['id'];

type MenuItem<ExtendedMenuItem> = ExtendedMenuItem & {
title: string;
id: MenuItemId;
id: string;
};

const TopAppBarMenuContext =
Expand Down
8 changes: 2 additions & 6 deletions src/components/topAppBar/TopAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { StyleSheet, type ViewStyle } from 'react-native';
import { Headline } from '../typography/Headline';
import DeviceInfo from 'react-native-device-info';
import type { WithTestID } from 'src/shared/type';
import TopAppBarCloseAction from './Actions/TopAppBarCloseAction';
import TopAppBarMenuAction from './Actions/TopAppBarMenuAction';
import TopAppBarPrinterSettingsAction from './Actions/TopAppBarPrinterSettingsAction';
import TopAppBarAction from './TopAppBarAction';

export interface Title {
value: ReactNode;
Expand Down Expand Up @@ -64,9 +62,7 @@ export function TopAppBar({
</Appbar.Header>
);
}
TopAppBar.CloseAction = TopAppBarCloseAction;
TopAppBar.MenuAction = TopAppBarMenuAction;
TopAppBar.PrinterSettingsAction = TopAppBarPrinterSettingsAction;
TopAppBar.Action = TopAppBarAction;

function useStyles(
size: TopAppBarProps['size'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ComponentProps } from 'react';
import { Appbar } from 'react-native-paper';
import { Theme, useTheme } from '../../../styles/themes';
import { Theme, useTheme } from '../../styles/themes';
import DeviceInfo from 'react-native-device-info';
import { StyleSheet } from 'react-native';

Expand Down

0 comments on commit 7d65e40

Please sign in to comment.