Skip to content

Commit f36019d

Browse files
committed
feat(template): Add landing page template
Components: - Add Menu element - Add Navbar widget Tracking example: - Add a static landing page - Track onClick and onChange event on the landing page
1 parent 55e65fd commit f36019d

File tree

11 files changed

+4265
-4668
lines changed

11 files changed

+4265
-4668
lines changed

package-lock.json

Lines changed: 3782 additions & 4668 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
"@types/node": "^12.0.0",
1111
"@types/react": "^17.0.0",
1212
"@types/react-dom": "^17.0.0",
13+
"@types/styled-components": "^5.1.8",
1314
"antd": "^4.12.3",
1415
"react": "^17.0.1",
1516
"react-dom": "^17.0.1",
1617
"react-router": "^5.2.0",
1718
"react-scripts": "4.0.2",
19+
"styled-components": "^5.2.1",
1820
"typescript": "^4.1.2",
1921
"web-vitals": "^1.0.1"
2022
},
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
import {
3+
Menu as AntMenu,
4+
MenuItemProps as AntMenuItemProps,
5+
} from 'antd';
6+
7+
import 'antd/lib/menu/style/css';
8+
9+
import {
10+
withTracking,
11+
} from '../../../../library/user-analytics/react/components/withTracking';
12+
13+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
14+
15+
export interface MenuItemProps extends Omit<AntMenuItemProps, "onClick"> {
16+
onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
17+
}
18+
19+
function MenuItem(props: MenuItemProps) {
20+
const handleClick: AntMenuItemProps["onClick"] = (info) => {
21+
props.onClick && props.onClick(info.domEvent);
22+
}
23+
24+
return (
25+
<AntMenu.Item
26+
{...props}
27+
onClick={handleClick}
28+
>
29+
{props.children}
30+
</AntMenu.Item>
31+
)
32+
}
33+
34+
export default MenuItem;
35+
36+
export const MenuItemWithTracking = withTracking(MenuItem);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { action } from '@storybook/addon-actions';
2+
import { Story } from '@storybook/react/types-6-0';
3+
4+
import Menu, { MenuProps } from './index';
5+
import MenuItem from './MenuItem';
6+
7+
export default {
8+
title: 'Components/Elements/Menu',
9+
component: Menu,
10+
argTypes: {
11+
mode: {
12+
control: {
13+
type: 'select',
14+
options: [
15+
"horizontal",
16+
"vertical",
17+
"vertical-left",
18+
"vertical-right",
19+
"inline"
20+
],
21+
},
22+
},
23+
theme: {
24+
control: {
25+
type: 'select',
26+
options: [
27+
"light",
28+
"dark",
29+
],
30+
},
31+
},
32+
items: {
33+
control: {
34+
type: 'array',
35+
},
36+
},
37+
defaultSelectedKeys: {
38+
control: {
39+
type: 'array',
40+
}
41+
},
42+
},
43+
};
44+
45+
const Template: Story<MenuProps> = (args) => (
46+
<Menu {...args}>
47+
<MenuItem>
48+
Link 11
49+
</MenuItem>
50+
<MenuItem>
51+
Link 22
52+
</MenuItem>
53+
</Menu>
54+
)
55+
56+
export const HorizontalMenu = Template.bind({});
57+
58+
HorizontalMenu.args = {
59+
theme:"dark",
60+
mode:"horizontal",
61+
defaultSelectedKeys:['1'],
62+
style:{
63+
lineHeight: '64px'
64+
},
65+
};
66+
67+
// const TemplateOne: Story<any> = (args) => (<Menu>
68+
// <MenuItem>
69+
// Link 11
70+
// </MenuItem>
71+
// <MenuItem>
72+
// Link 22
73+
// </MenuItem>
74+
// </Menu>)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Menu as AntMenu, MenuProps as AntMenuProps } from 'antd';
2+
3+
import 'antd/lib/menu/style/css';
4+
5+
6+
export interface MenuProps extends AntMenuProps {
7+
8+
}
9+
10+
function Menu(props: MenuProps) {
11+
const { theme, mode, defaultSelectedKeys, style } = props;
12+
13+
const onItemHover = (data: any) => {
14+
console.log("item has been clicked", data)
15+
}
16+
17+
return (
18+
<AntMenu
19+
theme={theme}
20+
mode={mode}
21+
defaultSelectedKeys={defaultSelectedKeys}
22+
style={style}
23+
>
24+
{ props.children }
25+
26+
</AntMenu>
27+
);
28+
}
29+
30+
export default Menu;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { action } from '@storybook/addon-actions';
2+
import { Story } from '@storybook/react/types-6-0';
3+
import MenuItem from '../../elements/Menu/MenuItem';
4+
5+
import LandingPage, { LandingPageProps } from './index';
6+
import logo from './static/logo.png';
7+
8+
export default {
9+
title: 'Components/Templates/Landing Page',
10+
component: LandingPage,
11+
argTypes: {
12+
mode: {
13+
control: {
14+
type: 'select',
15+
options: [
16+
"horizontal",
17+
"vertical",
18+
"vertical-left",
19+
"vertical-right",
20+
"inline",
21+
],
22+
},
23+
},
24+
theme: {
25+
control: {
26+
type: 'select',
27+
options: [
28+
"light",
29+
"dark",
30+
],
31+
},
32+
},
33+
items: {
34+
control: {
35+
type: 'array',
36+
},
37+
},
38+
defaultSelectedKeys: {
39+
control: {
40+
type: 'array',
41+
}
42+
}
43+
},
44+
};
45+
46+
const Template: Story<any> = (args) => {
47+
const { items} = args;
48+
return (
49+
<LandingPage {...args}>
50+
51+
{
52+
items.map((item: string, i: any) => {
53+
return (
54+
<MenuItem key={`${i}`}>{item}</MenuItem>
55+
)})
56+
}
57+
58+
</LandingPage>
59+
)};
60+
61+
export const Default = Template.bind({});
62+
63+
Default.args = {
64+
items: ["Landing 1", "Landing 2", "Landing 3"],
65+
theme: "dark",
66+
style:{ lineHeight: '64px' },
67+
mode: 'horizontal',
68+
logo: logo,
69+
};

0 commit comments

Comments
 (0)