Skip to content

Commit daf0b1f

Browse files
authored
Merge pull request #150 from Dias999/feature/Storybook-Navbar
Storybook - Navbar stories / TSDocs for Navbar component
2 parents 82e9011 + 3e273fd commit daf0b1f

File tree

8 files changed

+154
-12
lines changed

8 files changed

+154
-12
lines changed

.storybook/preview.ts .storybook/preview.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import React from 'react';
12
import type { Preview } from '@storybook/react';
23
import { initialize, mswLoader } from 'msw-storybook-addon';
34

5+
import { ThemeProvider } from '@concepta/react-material-ui/dist/styles';
6+
import { themeLight } from '@concepta/react-material-ui/dist/styles/theme';
7+
48
initialize();
59

610
const preview: Preview = {
@@ -13,6 +17,13 @@ const preview: Preview = {
1317
},
1418
},
1519
loaders: [mswLoader],
20+
decorators: [
21+
(Story) => (
22+
<ThemeProvider theme={themeLight}>
23+
<Story />
24+
</ThemeProvider>
25+
),
26+
],
1627
};
1728

1829
export default preview;

packages/react-material-ui/__tests__/Navbar.spec.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import '@testing-library/jest-dom';
66
import React from 'react';
77
import { render, fireEvent } from '@testing-library/react';
8-
import Navbar, { NavbarProps } from '../src/components/Navbar/Navbar';
8+
import { Navbar, NavbarProps } from '../src/components/Navbar/Navbar';
99

1010
describe('Navbar', () => {
1111
const defaultProps: NavbarProps = {

packages/react-material-ui/src/components/AppBar/AppBarNav.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import Navbar, { NavbarProps } from '../Navbar';
2+
import { Navbar, NavbarProps } from '../Navbar';
33
import { useAppBarRoot } from './hooks/useAppBarRoot';
44

55
/**

packages/react-material-ui/src/components/HeaderAccount/HeaderAccount.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const HeaderAccount = ({
6161
>
6262
{avatar && <Avatar src={avatar} alt="Avatar" size={avatarSize} />}
6363

64-
<Box display="flex" flexDirection="column">
64+
<Box display="flex" flexDirection="column" ml={avatar ? 1 : 0}>
6565
<Box display="flex">
6666
<Text {...textProps}>{text}</Text>{' '}
6767
<ExpandMore sx={{ display: 'inline', color: iconColor }} />

packages/react-material-ui/src/components/Navbar/Navbar.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,26 @@ export type NavbarProps = {
4949
sx?: SxProps<Theme>;
5050
};
5151

52-
const Navbar = ({
52+
/**
53+
* The Navbar component is a UI element used to display a navigation bar
54+
* that includes a menu icon for drawer toggling, notification icon, and
55+
* user account information.
56+
*
57+
* @example
58+
* ```tsx
59+
* <Navbar
60+
* showNotifications={true}
61+
* notificationsNumber={5}
62+
* notificationsOnClick={handleNotificationsClick}
63+
* avatar="https://example.com/avatar.jpg"
64+
* text="John Doe"
65+
* subText="Administrator"
66+
* />
67+
* ```
68+
*
69+
* @param props - Navbar component props
70+
*/
71+
export const Navbar = ({
5372
drawerToggle,
5473
showNotifications,
5574
notificationsNumber,
@@ -116,5 +135,3 @@ const Navbar = ({
116135
</Box>
117136
);
118137
};
119-
120-
export default Navbar;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
import Navbar, { NavbarProps } from './Navbar';
2-
3-
export type { NavbarProps };
4-
export default Navbar;
1+
export { Navbar, NavbarProps } from './Navbar';

packages/react-material-ui/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export { HeaderAccount, HeaderAccountProps };
2525
export { default as Image } from './components/Image';
2626
export { default as Link } from './components/Link';
2727

28-
import Navbar, { NavbarProps } from './components/Navbar';
29-
export { Navbar, NavbarProps };
28+
export { Navbar, NavbarProps } from './components/Navbar';
3029

3130
export { default as Notifications } from './components/Notifications';
3231
export { default as RadioGroup } from './components/RadioGroup';

stories/Navbar.stories.tsx

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import React from 'react';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
import { fn } from '@storybook/test';
4+
5+
import { Navbar } from '@concepta/react-material-ui';
6+
import { Box, MenuItem } from '@mui/material';
7+
8+
const meta = {
9+
component: Navbar,
10+
tags: ['autodocs'],
11+
args: {
12+
text: 'John Doe',
13+
subText: 'Admin',
14+
},
15+
argTypes: {
16+
drawerToggle: {
17+
type: 'function',
18+
description: 'Function to call when the drawer toggle button is clicked',
19+
},
20+
showNotifications: {
21+
control: 'boolean',
22+
description: 'Whether to show the notifications icon',
23+
},
24+
notificationsNumber: {
25+
control: 'number',
26+
description: 'Number of notifications to display',
27+
},
28+
notificationsOnClick: {
29+
type: 'function',
30+
description: 'Function to call when the notifications icon is clicked',
31+
},
32+
avatar: { control: 'text', description: 'URL of the user avatar' },
33+
text: {
34+
control: 'text',
35+
description: 'Text to display next to the avatar',
36+
},
37+
subText: {
38+
control: 'text',
39+
description: 'Subtext to display below the text',
40+
},
41+
headerMenuOptions: {
42+
type: 'function',
43+
description:
44+
'Function to render the dropdown menu options and handle the close action',
45+
},
46+
},
47+
} satisfies Meta<typeof Navbar>;
48+
49+
export default meta;
50+
51+
type Story = StoryObj<typeof meta>;
52+
53+
export const Default: Story = {
54+
args: {
55+
showNotifications: true,
56+
notificationsNumber: 8,
57+
notificationsOnClick: fn(),
58+
avatar: 'https://picsum.photos/40/40',
59+
},
60+
};
61+
62+
/**
63+
* Please preview it in a mobile viewPort to see the drawer toggle button.
64+
*/
65+
export const NavbarWithDrawerToggle: Story = {
66+
parameters: { viewport: { defaultViewport: 'mobile1' } },
67+
args: {
68+
drawerToggle: fn(),
69+
},
70+
};
71+
72+
export const NavbarWithNotifications: Story = {
73+
args: {
74+
showNotifications: true,
75+
notificationsNumber: 3,
76+
},
77+
};
78+
79+
export const NavbarWithUserAccountInfo: Story = {
80+
args: {
81+
avatar: 'https://picsum.photos/40/40',
82+
text: 'John Doe',
83+
subText: 'Admin',
84+
},
85+
};
86+
87+
export const NavbarWithCustomStyles: Story = {
88+
args: {
89+
sx: {
90+
backgroundColor: '#93d6ff',
91+
color: 'white',
92+
padding: '16px 32px',
93+
},
94+
},
95+
};
96+
97+
export const NavbarWithClickableNotifications: Story = {
98+
args: {
99+
showNotifications: true,
100+
notificationsNumber: 5,
101+
notificationsOnClick: fn(),
102+
},
103+
};
104+
105+
export const NavbarWithDropdownMenu: Story = {
106+
args: {
107+
avatar: 'https://picsum.photos/40/40',
108+
text: 'John Doe',
109+
subText: 'Admin',
110+
headerMenuOptions: (handleClose) => (
111+
<Box>
112+
<MenuItem onClick={handleClose}>Profile</MenuItem>
113+
<MenuItem onClick={handleClose}>My account</MenuItem>
114+
<MenuItem onClick={handleClose}>Logout</MenuItem>
115+
</Box>
116+
),
117+
},
118+
};

0 commit comments

Comments
 (0)