File tree 5 files changed +401
-1
lines changed
5 files changed +401
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ // TODO Refactor the class name to camel style
1
2
$prefix : ' mo' ;
2
3
$activityBar : ' activityBar' ;
3
4
$sidebar : ' sidebar' ;
@@ -7,6 +8,9 @@ $settings: 'settings';
7
8
$panel : ' panel' ;
8
9
$statusBar : ' statusBar' ;
9
10
11
+ // Component parts below
12
+ $dropDown : ' drop-down' ;
13
+
10
14
@function prefix ($name ) {
11
15
@return ' .' + $prefix + ' -' + $name ;
12
16
}
Original file line number Diff line number Diff line change @@ -2,21 +2,134 @@ import 'mo/workbench/menuBar/style.scss';
2
2
import * as React from 'react' ;
3
3
import { prefixClaName } from 'mo/common/className' ;
4
4
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' ;
5
8
6
9
export interface IMenuBarProps {
7
10
// menuBar: IMenuBar;
8
11
}
9
12
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
+
10
118
function MenuBar ( props : IMenuBar ) {
11
119
const menuBar = props ;
12
120
const click = function ( e ) {
13
121
menuBar . onClick ( e , {
14
122
name : 'test' ,
15
123
} ) ;
16
124
} ;
125
+ const menu = (
126
+ < Menu onClick = { click } style = { { width : 200 } } data = { initialMenuData } />
127
+ ) ;
17
128
return (
18
129
< 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 >
20
133
</ div >
21
134
) ;
22
135
}
You can’t perform that action at this time.
0 commit comments