Skip to content

Commit

Permalink
Merge pull request #150 from Dias999/feature/Storybook-Navbar
Browse files Browse the repository at this point in the history
Storybook - Navbar stories / TSDocs for Navbar component
  • Loading branch information
andreneto97 authored Jul 19, 2024
2 parents 82e9011 + 3e273fd commit daf0b1f
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 12 deletions.
11 changes: 11 additions & 0 deletions .storybook/preview.ts → .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
import type { Preview } from '@storybook/react';
import { initialize, mswLoader } from 'msw-storybook-addon';

import { ThemeProvider } from '@concepta/react-material-ui/dist/styles';
import { themeLight } from '@concepta/react-material-ui/dist/styles/theme';

initialize();

const preview: Preview = {
Expand All @@ -13,6 +17,13 @@ const preview: Preview = {
},
},
loaders: [mswLoader],
decorators: [
(Story) => (
<ThemeProvider theme={themeLight}>
<Story />
</ThemeProvider>
),
],
};

export default preview;
2 changes: 1 addition & 1 deletion packages/react-material-ui/__tests__/Navbar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import Navbar, { NavbarProps } from '../src/components/Navbar/Navbar';
import { Navbar, NavbarProps } from '../src/components/Navbar/Navbar';

describe('Navbar', () => {
const defaultProps: NavbarProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Navbar, { NavbarProps } from '../Navbar';
import { Navbar, NavbarProps } from '../Navbar';
import { useAppBarRoot } from './hooks/useAppBarRoot';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const HeaderAccount = ({
>
{avatar && <Avatar src={avatar} alt="Avatar" size={avatarSize} />}

<Box display="flex" flexDirection="column">
<Box display="flex" flexDirection="column" ml={avatar ? 1 : 0}>
<Box display="flex">
<Text {...textProps}>{text}</Text>{' '}
<ExpandMore sx={{ display: 'inline', color: iconColor }} />
Expand Down
23 changes: 20 additions & 3 deletions packages/react-material-ui/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,26 @@ export type NavbarProps = {
sx?: SxProps<Theme>;
};

const Navbar = ({
/**
* The Navbar component is a UI element used to display a navigation bar
* that includes a menu icon for drawer toggling, notification icon, and
* user account information.
*
* @example
* ```tsx
* <Navbar
* showNotifications={true}
* notificationsNumber={5}
* notificationsOnClick={handleNotificationsClick}
* avatar="https://example.com/avatar.jpg"
* text="John Doe"
* subText="Administrator"
* />
* ```
*
* @param props - Navbar component props
*/
export const Navbar = ({
drawerToggle,
showNotifications,
notificationsNumber,
Expand Down Expand Up @@ -116,5 +135,3 @@ const Navbar = ({
</Box>
);
};

export default Navbar;
5 changes: 1 addition & 4 deletions packages/react-material-ui/src/components/Navbar/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import Navbar, { NavbarProps } from './Navbar';

export type { NavbarProps };
export default Navbar;
export { Navbar, NavbarProps } from './Navbar';
3 changes: 1 addition & 2 deletions packages/react-material-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export { HeaderAccount, HeaderAccountProps };
export { default as Image } from './components/Image';
export { default as Link } from './components/Link';

import Navbar, { NavbarProps } from './components/Navbar';
export { Navbar, NavbarProps };
export { Navbar, NavbarProps } from './components/Navbar';

export { default as Notifications } from './components/Notifications';
export { default as RadioGroup } from './components/RadioGroup';
Expand Down
118 changes: 118 additions & 0 deletions stories/Navbar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';

import { Navbar } from '@concepta/react-material-ui';
import { Box, MenuItem } from '@mui/material';

const meta = {
component: Navbar,
tags: ['autodocs'],
args: {
text: 'John Doe',
subText: 'Admin',
},
argTypes: {
drawerToggle: {
type: 'function',
description: 'Function to call when the drawer toggle button is clicked',
},
showNotifications: {
control: 'boolean',
description: 'Whether to show the notifications icon',
},
notificationsNumber: {
control: 'number',
description: 'Number of notifications to display',
},
notificationsOnClick: {
type: 'function',
description: 'Function to call when the notifications icon is clicked',
},
avatar: { control: 'text', description: 'URL of the user avatar' },
text: {
control: 'text',
description: 'Text to display next to the avatar',
},
subText: {
control: 'text',
description: 'Subtext to display below the text',
},
headerMenuOptions: {
type: 'function',
description:
'Function to render the dropdown menu options and handle the close action',
},
},
} satisfies Meta<typeof Navbar>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
showNotifications: true,
notificationsNumber: 8,
notificationsOnClick: fn(),
avatar: 'https://picsum.photos/40/40',
},
};

/**
* Please preview it in a mobile viewPort to see the drawer toggle button.
*/
export const NavbarWithDrawerToggle: Story = {
parameters: { viewport: { defaultViewport: 'mobile1' } },
args: {
drawerToggle: fn(),
},
};

export const NavbarWithNotifications: Story = {
args: {
showNotifications: true,
notificationsNumber: 3,
},
};

export const NavbarWithUserAccountInfo: Story = {
args: {
avatar: 'https://picsum.photos/40/40',
text: 'John Doe',
subText: 'Admin',
},
};

export const NavbarWithCustomStyles: Story = {
args: {
sx: {
backgroundColor: '#93d6ff',
color: 'white',
padding: '16px 32px',
},
},
};

export const NavbarWithClickableNotifications: Story = {
args: {
showNotifications: true,
notificationsNumber: 5,
notificationsOnClick: fn(),
},
};

export const NavbarWithDropdownMenu: Story = {
args: {
avatar: 'https://picsum.photos/40/40',
text: 'John Doe',
subText: 'Admin',
headerMenuOptions: (handleClose) => (
<Box>
<MenuItem onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={handleClose}>My account</MenuItem>
<MenuItem onClick={handleClose}>Logout</MenuItem>
</Box>
),
},
};

0 comments on commit daf0b1f

Please sign in to comment.