Skip to content

Commit ad2e4e5

Browse files
authored
Merge pull request #148 from conceptadev/feature/app-bar-docs
Feature/app bar docs
2 parents 1739976 + 7a1e7df commit ad2e4e5

15 files changed

+159
-155
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
77
lerna-debug.log*
8-
.yarn/install-state.gz
8+
.yarn
99

1010
# Diagnostic reports (https://nodejs.org/api/report.html)
1111
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

packages/react-material-ui/__tests__/AppBar.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 } from '@testing-library/react';
8-
import AppBar from '../src/components/AppBar';
8+
import { AppBar } from '../src/components/AppBar';
99

1010
describe('AppBar Component', () => {
1111
const items = [

packages/react-material-ui/__tests__/AppBarDrawer.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 } from '@testing-library/react';
8-
import AppBar from '../src/components/AppBar';
8+
import { AppBar } from '../src/components/AppBar';
99

1010
describe('AppBarDrawer Component', () => {
1111
const items = [

packages/react-material-ui/__tests__/AppBarMain.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 } from '@testing-library/react';
8-
import AppBar from '../src/components/AppBar';
8+
import { AppBar } from '../src/components/AppBar';
99

1010
describe('AppBarMain Component', () => {
1111
it('should render correctly', () => {

packages/react-material-ui/__tests__/AppBarNav.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 AppBar from '../src/components/AppBar';
8+
import { AppBar } from '../src/components/AppBar';
99

1010
describe('AppBar.Nav Component', () => {
1111
it('should render correctly', () => {

packages/react-material-ui/__tests__/AppBarRoot.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 } from '@testing-library/react';
8-
import AppBar from '../src/components/AppBar';
8+
import { AppBar } from '../src/components/AppBar';
99

1010
describe('AppBarRoot Component', () => {
1111
it('should render correctly', () => {

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import React from 'react';
22
import { Drawer, DrawerProps } from '../Drawer';
33
import { useAppBarRoot } from './hooks/useAppBarRoot';
44

5-
const AppBarDrawer = (props: DrawerProps) => {
5+
/**
6+
* The list of the app routes rendered as a vertical navigation list on the Drawer component.
7+
*
8+
* @see {@link AppBar}
9+
* @see {@link Drawer}
10+
* @param props - {@link DrawerProps}
11+
*/
12+
export const AppBarDrawer = (props: DrawerProps) => {
613
const { isMobileOpen, toggleMobileOpen } = useAppBarRoot();
714

815
return (
@@ -13,5 +20,3 @@ const AppBarDrawer = (props: DrawerProps) => {
1320
/>
1421
);
1522
};
16-
17-
export default AppBarDrawer;

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import React from 'react';
22
import { Box, BoxProps } from '@mui/material';
33

4-
const AppBarMain = ({ sx, children, ...props }: BoxProps) => {
4+
/**
5+
* The AppBarMain component serves as a wrapper for the navigation bar and page content.
6+
*
7+
* The AppBar.Main props extend from [Material UI's Box](https://mui.com/material-ui/api/box/#props)
8+
* component props, so every prop is interchangeable between those two.
9+
*
10+
* @see {@link AppBar}
11+
* @see {@link [MUI Box Component](https://mui.com/material-ui/react-box/)}
12+
* @param boxProps - MUI {@link [BoxProps](https://mui.com/material-ui/api/box/#props)}
13+
*/
14+
export const AppBarMain = (boxProps: BoxProps) => {
15+
const { sx, children, ...props } = boxProps;
16+
517
return (
618
<Box
719
component="main"
@@ -20,5 +32,3 @@ const AppBarMain = ({ sx, children, ...props }: BoxProps) => {
2032
</Box>
2133
);
2234
};
23-
24-
export default AppBarMain;

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import React from 'react';
22
import Navbar, { NavbarProps } from '../Navbar';
33
import { useAppBarRoot } from './hooks/useAppBarRoot';
44

5-
const AppBarNav = (props: NavbarProps) => {
5+
/**
6+
* The AppBarNav component renders the user info ({@link Avatar} and Name) and
7+
* a list of actions related to user and auth, such as Logout.
8+
*
9+
* @see {@link AppBar}
10+
* @see {@link Navbar}
11+
* @param props - {@link NavbarProps}
12+
*/
13+
export const AppBarNav = (props: NavbarProps) => {
614
const { toggleMobileOpen } = useAppBarRoot();
715

816
return <Navbar drawerToggle={toggleMobileOpen} {...props} />;
917
};
10-
11-
export default AppBarNav;

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@ import React, { ReactNode, useState } from 'react';
22
import Box from '@mui/material/Box';
33
import { AppBarContext } from './hooks/useAppBarRoot';
44

5+
/**
6+
* AppBarRoot component props.
7+
*/
58
export type AppBarRootProps = {
9+
/** Child nodes rendered inside the Main component */
610
children: ReactNode;
711
};
812

9-
const AppBarRoot = ({ children }: AppBarRootProps) => {
13+
/**
14+
* The AppBarRoot component acts as a wrapper for the context API shared
15+
* with the other parts of the AppBar composition.
16+
*
17+
* @see {@link AppBar}
18+
* @param props - Component props.
19+
*/
20+
export const AppBarRoot = (props: AppBarRootProps) => {
21+
const { children } = props;
22+
1023
const [isMobileOpen, setIsMobileOpen] = useState(false);
1124

1225
const toggleMobileOpen = () => {
@@ -26,5 +39,3 @@ const AppBarRoot = ({ children }: AppBarRootProps) => {
2639
</AppBarContext.Provider>
2740
);
2841
};
29-
30-
export default AppBarRoot;

packages/react-material-ui/src/components/AppBar/README.md

-124
This file was deleted.

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

+70-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,76 @@
1-
import AppBarMain from './AppBarMain';
2-
import AppBarDrawer from './AppBarDrawer';
3-
import AppBarNav from './AppBarNav';
4-
import AppBarRoot from './AppBarRoot';
1+
import { AppBarMain } from './AppBarMain';
2+
import { AppBarDrawer } from './AppBarDrawer';
3+
import { AppBarNav } from './AppBarNav';
4+
import { AppBarRoot } from './AppBarRoot';
55

6-
const AppBar = {
6+
/**
7+
* The AppBar component is a wrapper for the page content, that renders a
8+
* lateral menu containing the list of pages rendered by the app and a top
9+
* navigation bar containing information related to the current user with a
10+
* dropdown menu with a list of actions.
11+
*
12+
* It is composed by the {@link AppBarRoot}, {@link AppBarDrawer},
13+
* {@link AppBarMain} and {@link AppBarNav} components.
14+
*
15+
* A sandbox of this componet is available on our
16+
* [AppBar Story](https://storybook.rockets.tools/?path=/docs/appbar)
17+
*
18+
* @example The following example describes the full composition that mounts the AppBar component:
19+
*
20+
* ```tsx
21+
* import { AppBar } from '@concepta/react-material-ui';
22+
*
23+
* <AppBar.Root key={pathname}>
24+
* <AppBar.Drawer
25+
* currentId={pathname}
26+
* logo="/logo.svg"
27+
* collapsable
28+
* items={[
29+
* {
30+
* id: '/users',
31+
* icon: <GroupsOutlinedIcon />,
32+
* text: 'Users',
33+
* onClick: () => router.push('/users'),
34+
* },
35+
* {
36+
* id: '/profile',
37+
* icon: <PersonOutlinedIcon />,
38+
* text: 'Profile',
39+
* onClick: () => router.push('/profile'),
40+
* },
41+
* ]}
42+
* expandedWidth={120}
43+
* />
44+
* <AppBar.Main>
45+
* <AppBar.Nav
46+
* text={user.fullName}
47+
* avatar="https://source.unsplash.com/random"
48+
* headerMenuOptions={(handleClose) => (
49+
* <MenuItem
50+
* onClick={() => {
51+
* handleClose();
52+
* doLogout();
53+
* router.replace('/login');
54+
* }}
55+
* >
56+
* Sign Out
57+
* </MenuItem>
58+
* )}
59+
* />
60+
* <Container>{children}</Container>
61+
* </AppBar.Main>
62+
* </AppBar.Root>;
63+
* ```
64+
*
65+
* @see {@link AppBarMain}
66+
* @see {@link AppBarDrawer}
67+
* @see {@link AppBarNav}
68+
* @see {@link AppBarRoot}
69+
* @see [Storybook - AppBar](https://storybook.rockets.tools/?path=/docs/appbar)
70+
*/
71+
export const AppBar = {
772
Main: AppBarMain,
873
Drawer: AppBarDrawer,
974
Nav: AppBarNav,
1075
Root: AppBarRoot,
1176
};
12-
13-
export default AppBar;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { SxProps, Theme } from '@mui/material/styles';
1717
export type DrawerProps = {
1818
/** Array of items to display in the drawer */
1919
items: DrawerItemProps[];
20-
/** ID of the currently active item */
20+
/** ID of the currently active item, changing the menu item to active when the page selected corresponds to the path name. */
2121
currentId?: string;
22-
/** Custom toggle component for the drawer */
22+
/** Custom node that can be rendered on the bottom of the Drawer, serving as toggle for expanded/collapsed state. */
2323
customToggle?: (toggleDrawer: () => void, collapsed?: boolean) => ReactNode;
2424
/** Whether the drawer is open on mobile devices */
2525
mobileIsOpen?: boolean;
@@ -29,9 +29,9 @@ export type DrawerProps = {
2929
logo?: string | ReactNode | ((collapsed?: boolean) => ReactNode);
3030
/** Props for text elements inside the drawer */
3131
textProps?: TextProps;
32-
/** Custom styles for the drawer */
32+
/** Custom styles for the drawer, following the [sx](https://mui.com/system/getting-started/the-sx-prop/) */
3333
sx?: StyledDrawerProps['sx'];
34-
/** Custom styles for drawer buttons */
34+
/** Custom styles for drawer buttons, following the [sx](https://mui.com/system/getting-started/the-sx-prop/) pattern. */
3535
buttonSx?: SxProps<Theme>;
3636
/** Whether the drawer items should be displayed horizontally */
3737
horizontal?: boolean;

0 commit comments

Comments
 (0)