Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc-43] add stories to atoms #810

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
1,227 changes: 796 additions & 431 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
]
},
"devDependencies": {
"@storybook/addon-actions": "^6.3.2",
"@storybook/addon-essentials": "^6.3.2",
"@storybook/addon-links": "^6.3.2",
"@storybook/node-logger": "^6.3.2",
"@storybook/addon-actions": "^6.3.6",
"@storybook/addon-essentials": "^6.3.6",
"@storybook/addon-links": "^6.3.6",
"@storybook/node-logger": "^6.3.6",
"@storybook/preset-create-react-app": "^3.2.0",
"@storybook/react": "^6.3.2",
"@storybook/react": "^6.3.6",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.1.9",
Expand Down
2 changes: 1 addition & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"all": "all"
},
"header": {
"Search":"Search",
"Search": "Search",
"User Greeting": "Hello",
"User Info Update": "Update Info"
},
Expand Down
2 changes: 1 addition & 1 deletion public/locales/he/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"all": "הכל"
},
"header": {
"Search":"חיפוש",
"Search": "חיפוש",
"User Greeting": "שלום",
"User Info Update": "פרטי משתמש"
},
Expand Down
8 changes: 6 additions & 2 deletions src/components/atoms/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC } from 'react';
import { Button as MatButton, IconButton as MatIconButton } from '@material-ui/core';

interface IProps {
export interface IProps {
onClick?: () => any;
isSubmit?: boolean;
}
Expand All @@ -25,7 +25,11 @@ const TextButton: FC<IProps> = ({ isSubmit = false, onClick, children }) => (
</MatButton>
);

const IconButton: FC<IProps> = ({ onClick, children }) => <MatIconButton onClick={onClick}>{children}</MatIconButton>;
const IconButton: FC<IProps> = ({ isSubmit = false, onClick, children }) => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

icon button does not need isSubmit (it is never used for submit)

<MatIconButton type={isSubmit ? 'submit' : 'button'} onClick={onClick}>
{children}
</MatIconButton>
);

const Button = {
Standard: StandardButton,
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const useStyles = makeStyles({
},
},
});
interface IProps extends LinkProps {
export interface IProps extends LinkProps {
to: string;
}

Expand Down
7 changes: 3 additions & 4 deletions src/components/atoms/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { FC } from 'react';
import CircularProgress from '@material-ui/core/CircularProgress';

interface IProps {
}
export interface IProps {}

const Loader: FC<IProps> = () => <CircularProgress />
export default Loader;
const Loader: FC<IProps> = () => <CircularProgress />;
export default Loader;
2 changes: 1 addition & 1 deletion src/components/atoms/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, ReactElement } from 'react';
import MaterialMenu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
interface IProps {
export interface IProps {
items: Array<ReactElement>;
handleClose: () => any;
anchorEl: HTMLElement | null;
Expand Down
16 changes: 16 additions & 0 deletions src/components/atoms/stories/AnyWayButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { ComponentProps } from 'react';
import { Story, Meta } from '@storybook/react';
import { AnyWayButton } from '../AnyWayButton';

export default {
title: 'Components/atoms/AnyWayButton',
Copy link
Collaborator

Choose a reason for hiding this comment

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

AnyWayButton is about to be refactored / remove, no need a story for this one

component: AnyWayButton,
} as Meta;

const Template: Story<ComponentProps<typeof AnyWayButton>> = (args) => <AnyWayButton {...args} />;

export const AnyWayButtonS = Template.bind({});
AnyWayButtonS.args = {
onClick: () => console.log('You clicked it!'),
children: 'Anyway Button',
};
15 changes: 15 additions & 0 deletions src/components/atoms/stories/AppBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { ComponentProps } from 'react';
import { Story, Meta } from '@storybook/react';
import AppBar from '../AppBar';

export default {
title: 'Components/atoms/AppBar',
component: AppBar,
} as Meta;

const Template: Story<ComponentProps<typeof AppBar>> = (args) => <AppBar {...args} />;

export const AppBarS = Template.bind({});
Copy link
Collaborator

Choose a reason for hiding this comment

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

image

The following can be applied for all stories

  1. This will leave "AppBarS" to be displayed on the storybook site. rename it so it will have a displayable name
  2. you can use ComponentStory and ComponentMeta for better typing:
  3. Atoms with a single story, doesn't need a 3rd level nesting ( 'Components/atoms/AppBar' => 'Components/atoms')
import { ComponentStory, ComponentMeta } from '@storybook/react';
import AppBarComp from '../AppBar';

export default {
  title: 'Components/atoms',
  component: AppBar,
} as ComponentMeta<typeof AppBarComp>;

const Template: ComponentStory<typeof AppBar> = (args) => <AppBarComp {...args} />;
export const AppBar = Template.bind({});

AppBarS.args = {
children: <div>This is the AppBar</div>,
};
48 changes: 48 additions & 0 deletions src/components/atoms/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ComponentProps, ReactNode } from 'react';
import { Story, Meta } from '@storybook/react';
import Button, { IProps } from 'components/atoms/Button';

export default {
title: 'Components/atoms/Button',
component: Button,
argTypes: {
variant: {
options: ['outlined', 'standard', 'icon', 'text'],
control: { type: 'select' },
},
},
} as unknown as Meta;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why unknown?


const Template: Story = ({ children, ...args }) => {
if (args.variant === 'standard') {
return <Button.Standard {...args}>{children}</Button.Standard>;
} else if (args.variant === 'outlined') {
return <Button.Outlined {...args}>{children}</Button.Outlined>;
} else if (args.variant === 'icon') {
return <Button.Icon {...args}>{children}</Button.Icon>;
} else if (args.variant === 'text') {
return <Button.Text {...args}>{children}</Button.Text>;
} else {
return <div>This component must have a type prop</div>;
}
};

export const Buttons = Template.bind({});
Buttons.args = {
children: 'Button',
variant: 'standard',
isSubmit: false,
onClick: () => 'text',
};

// export const ButtonOutlinedS = Template.bind({});
// ButtonOutlinedS.args = {
// type: 'outlined',
// children: 'Button',
// };

// export const ButtonIconS = Template.bind({});
// ButtonIconS.args = {
// type: 'icon',
// children: 'Button',
// };
Comment on lines +38 to +48
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove if not needed

15 changes: 15 additions & 0 deletions src/components/atoms/stories/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { ComponentProps } from 'react';
import { Story, Meta } from '@storybook/react';
import Dialog from '../Dialog';

export default {
title: 'Components/atoms/Dialog',
component: Dialog,
} as Meta;

const Template: Story<ComponentProps<typeof Dialog>> = (args) => <Dialog {...args} />;

export const DialogS = Template.bind({});
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is not possible to display the dialog from the main content area. can you include a button which will open it?

DialogS.args = {
children: 'DialogS',
};
15 changes: 15 additions & 0 deletions src/components/atoms/stories/Grid.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { ComponentProps } from 'react';
import { Story, Meta } from '@storybook/react';
import Grid from '../Grid';

export default {
title: 'Components/atoms/Grid',
component: Grid,
} as unknown as Meta;

const Template: Story<ComponentProps<typeof Grid.Container>> = (args) => <Grid.Container {...args} />;

export const GridS = Template.bind({});
GridS.args = {
children: 'GridS',
};
22 changes: 22 additions & 0 deletions src/components/atoms/stories/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { ComponentProps } from 'react';
import { Story, Meta } from '@storybook/react';
import Link, { IProps } from '../Link';
import { BrowserRouter as Router } from 'react-router-dom';
export default {
title: 'Components/atoms/Link',
component: Link,
} as Meta;

const Template: Story<IProps> = (args) => {
return (
<Router>
<Link {...args} />
</Router>
);
};

export const LinkS = Template.bind({});
LinkS.args = {
children: 'Example link',
to: '#',
};
10 changes: 10 additions & 0 deletions src/components/atoms/stories/Loader.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { ComponentProps, FC } from 'react';
import { Story, Meta } from '@storybook/react';
import Loader, { IProps } from '../Loader';

export default {
title: 'Components/atoms/Loader',
component: Loader,
} as Meta;

export const LoaderS: FC<IProps> = (args) => <Loader {...args} />;
34 changes: 34 additions & 0 deletions src/components/atoms/stories/Menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { ComponentProps, FC } from 'react';
import { Story, Meta } from '@storybook/react';
import Menu, { IProps } from '../Menu';

export default {
title: 'Components/atoms/Menu',
component: Menu,
argTypes: {
anchorEl: {
control: { type: 'boolean' },
},
},
} as Meta;

const Item: FC<ItemProps> = ({ number }) => {
return <div>Item no^{number}</div>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return <div>Item no^{number}</div>;
return <div>Item {number}</div>;

};
const NUM_ITEMS = Array.from(Array(10).keys());
const Items = NUM_ITEMS.map((itemNum) => <Item number={itemNum} />);

const handleClose = () => console.log('Menu Close Function');

const Template: Story<ComponentProps<typeof Menu>> = (args) => <Menu {...args} />;

export const MenuS = Template.bind({});
MenuS.args = {
items: Items,
handleClose,
anchorEl: document.body,
};

interface ItemProps {
number: number;
}
15 changes: 8 additions & 7 deletions src/components/molecules/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { observer } from 'mobx-react-lite';
import { useTranslation } from 'react-i18next';
import { makeStyles } from '@material-ui/core/styles';
import { Box } from '@material-ui/core';
import { AppBar,Button, Logo } from 'components/atoms';
import { AppBar, Button, Logo } from 'components/atoms';
import LogInLinkGoogle from './LogInLinkGoogle';
import { useStore } from 'store/storeConfig';
import RootStore from 'store/root.store';
Expand All @@ -15,7 +15,6 @@ import { SignInIcon } from 'components/atoms/SignInIcon';
import MapDialog from 'components/molecules/MapDialog';
import { IPoint } from 'models/Point';


const useStyles = makeStyles({
userSection: {
display: 'flex',
Expand Down Expand Up @@ -49,7 +48,7 @@ const Header: FC = () => {
store.fetchSelectedNewsFlashWidgetsByLocation(roadSegmentLocation?.road_segment_id, selectedLanguage);
setOpen(false);
}
}
};

useEffect(() => {
store.getUserLoginDetails();
Expand All @@ -72,10 +71,12 @@ const Header: FC = () => {
/>
);
} else {
authElement = <>
<LogInLinkGoogle />
<SignInIcon/>
</>;
authElement = (
<>
<LogInLinkGoogle />
<SignInIcon />
</>
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/molecules/MapDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ const useStyles = makeStyles((theme: Theme) =>
}),
);

const MapDialog: FC<IProps> = ({ section='', open, onClose, location, onLocationChange, onSearch }) => {
const MapDialog: FC<IProps> = ({ section = '', open, onClose, location, onLocationChange, onSearch }) => {
const classes = useStyles();
const { t } = useTranslation();

return (
<Dialog isShowing={open} onClose={onClose} maxWidth='lg' fullWidth>
<Dialog isShowing={open} onClose={onClose} maxWidth="lg" fullWidth>
<Box className={classes.wrapper}>
<Box className={classes.dialogHeader}>
<Typography.Title1>{t('mapDialog.searchSection')}</Typography.Title1>
</Box>
<Box display='flex' flexDirection='column' height='75vh'>
<Box display='contents'>
<Box display="flex" flexDirection="column" height="75vh">
<Box display="contents">
<LocationSelect location={location} onLocationChange={onLocationChange} />
</Box>
<div className={classes.chosenSection}>
Expand Down