Skip to content

Commit 77941be

Browse files
committed
feat(dropdown): add basic component and stories
1 parent 75ef5d9 commit 77941be

File tree

5 files changed

+401
-1
lines changed

5 files changed

+401
-1
lines changed

src/components/dropdown/index.tsx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import './style.scss';
2+
import * as React from 'react';
3+
import { classNames, prefixClaName } from 'mo/common/className';
4+
import { useContextView } from '../contextview';
5+
import { triggerEvent, TriggerEvent } from 'mo/common/dom';
6+
7+
export interface IDropDown extends HTMLElementProps {
8+
overlay: ReactNode;
9+
trigger?: TriggerEvent;
10+
placement?: 'top' | 'right' | 'bottom' | 'left';
11+
}
12+
13+
export const defaultDropDownClassName = 'drop-down';
14+
15+
export function DropDown(props: React.PropsWithChildren<IDropDown>) {
16+
const {
17+
className,
18+
overlay,
19+
children,
20+
placement = 'bottom',
21+
trigger = 'click',
22+
...others
23+
} = props;
24+
const contextView = useContextView({
25+
render: () => overlay,
26+
});
27+
28+
const claNames = classNames(
29+
prefixClaName(defaultDropDownClassName),
30+
placement,
31+
className
32+
);
33+
const events = {
34+
[triggerEvent(trigger)]: function (e: React.MouseEvent) {
35+
const target = e.currentTarget;
36+
const rect = target.getBoundingClientRect();
37+
contextView.show({
38+
x: rect.x + rect.width,
39+
y: rect.y,
40+
});
41+
},
42+
};
43+
44+
return (
45+
<div className={claNames} {...events} {...others}>
46+
{children}
47+
</div>
48+
);
49+
}

src/components/dropdown/style.scss

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import 'mo/style/const';
2+
$dropDown: 'drop-down';
3+
4+
#{prefix($dropDown)} {
5+
align-items: center;
6+
display: flex;
7+
height: 100%;
8+
justify-content: center;
9+
width: 100%;
10+
}

src/style/const.scss

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO Refactor the class name to camel style
12
$prefix: 'mo';
23
$activityBar: 'activityBar';
34
$sidebar: 'sidebar';
@@ -7,6 +8,9 @@ $settings: 'settings';
78
$panel: 'panel';
89
$statusBar: 'statusBar';
910

11+
// Component parts below
12+
$dropDown: 'drop-down';
13+
1014
@function prefix($name) {
1115
@return '.' + $prefix + '-' + $name;
1216
}

src/workbench/menuBar/menuBar.tsx

+114-1
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,134 @@ import 'mo/workbench/menuBar/style.scss';
22
import * as React from 'react';
33
import { prefixClaName } from 'mo/common/className';
44
import { IMenuBar } from 'mo/model/workbench/menuBar';
5+
import { Menu } from 'mo/components/menu';
6+
import { DropDown } from 'mo/components/dropdown';
7+
import { Icon } from 'mo/components/icon';
58

69
export interface IMenuBarProps {
710
// menuBar: IMenuBar;
811
}
912

13+
const initialMenuData = [
14+
{
15+
id: 'File',
16+
name: 'File',
17+
data: [
18+
{
19+
id: 'New File',
20+
name: 'New File',
21+
},
22+
{
23+
id: 'OpenFile',
24+
name: 'Open',
25+
},
26+
],
27+
},
28+
{
29+
id: 'Edit',
30+
name: 'Edit',
31+
data: [
32+
{
33+
id: 'Undo',
34+
name: 'Undo',
35+
},
36+
{
37+
id: 'Redo',
38+
name: 'Redo',
39+
},
40+
],
41+
},
42+
{
43+
id: 'Selection',
44+
name: 'Selection',
45+
data: [
46+
{
47+
id: 'SelectAll',
48+
name: 'Select All',
49+
},
50+
{
51+
id: 'CopyLineUp',
52+
name: 'Copy Line Up',
53+
},
54+
],
55+
},
56+
{
57+
id: 'View',
58+
name: 'View',
59+
data: [
60+
{
61+
id: 'Command Palette',
62+
name: 'Command Palette',
63+
},
64+
{
65+
id: 'OpenView',
66+
name: 'Open View',
67+
},
68+
{
69+
id: 'Appearance',
70+
name: 'Appearance',
71+
data: [
72+
{
73+
icon: 'check',
74+
id: 'ShowMenuBar',
75+
name: 'Show Menu Bar',
76+
},
77+
{
78+
icon: 'check',
79+
id: 'ShowSideBar',
80+
name: 'Show Side Bar',
81+
},
82+
{
83+
icon: 'check',
84+
id: 'ShowStatusBar',
85+
name: 'Show Status Bar',
86+
},
87+
{
88+
icon: 'check',
89+
id: 'ShowActivityBar',
90+
name: 'Show Activity Bar',
91+
},
92+
],
93+
},
94+
],
95+
},
96+
{
97+
id: 'Run',
98+
name: 'Run',
99+
data: [
100+
{
101+
id: 'RunTask',
102+
name: 'Run Task',
103+
},
104+
],
105+
},
106+
{
107+
id: 'Help',
108+
name: 'Help',
109+
data: [
110+
{
111+
id: 'About',
112+
name: 'About',
113+
},
114+
],
115+
},
116+
];
117+
10118
function MenuBar(props: IMenuBar) {
11119
const menuBar = props;
12120
const click = function (e) {
13121
menuBar.onClick(e, {
14122
name: 'test',
15123
});
16124
};
125+
const menu = (
126+
<Menu onClick={click} style={{ width: 200 }} data={initialMenuData} />
127+
);
17128
return (
18129
<div className={prefixClaName('menuBar')}>
19-
<a className="menu-action codicon codicon-menu" onClick={click}></a>
130+
<DropDown className="menu-action" placement="right" overlay={menu}>
131+
<Icon type="menu" />
132+
</DropDown>
20133
</div>
21134
);
22135
}

0 commit comments

Comments
 (0)