File tree 4 files changed +165
-0
lines changed
4 files changed +165
-0
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
+
5
+ type BtnSizeType = 'normal' | 'large' ;
6
+ export interface IButton extends React . ComponentProps < 'a' > {
7
+ /**
8
+ * Default size is normal
9
+ */
10
+ size ?: BtnSizeType ;
11
+ }
12
+
13
+ export const defaultButtonClassName = 'btn' ;
14
+
15
+ export function Button ( props : React . PropsWithChildren < IButton > ) {
16
+ const { className, children, size = 'normal' , ...others } = props ;
17
+
18
+ const claNames = classNames (
19
+ prefixClaName ( defaultButtonClassName ) ,
20
+ size ,
21
+ className
22
+ ) ;
23
+
24
+ return (
25
+ < a className = { claNames } { ...others } >
26
+ { children }
27
+ </ a >
28
+ ) ;
29
+ }
Original file line number Diff line number Diff line change
1
+ @import ' mo/style/common' ;
2
+ $btn : ' btn' ;
3
+
4
+ #{prefix ($btn )} {
5
+ align-items : center ;
6
+ border : 0 ;
7
+ box-sizing : border-box ;
8
+ cursor : pointer ;
9
+ display : flex ;
10
+ justify-content : center ;
11
+ margin : 10px ;
12
+ outline-offset : 2px ;
13
+ text-align : center ;
14
+ width : 100% ;
15
+
16
+ & .normal {
17
+ padding : 4px ;
18
+ }
19
+
20
+ & .large {
21
+ font-size : 16px ;
22
+ padding : 8px ;
23
+ }
24
+
25
+ & :hover {
26
+ opacity : 0.9 ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change 21
21
@import ' mo/components/menu/style' ;
22
22
@import ' mo/components/toolbar/style' ;
23
23
@import ' mo/components/tree/style' ;
24
+ @import ' mo/components/button/style' ;
24
25
25
26
// =============== Workbench =============== //
26
27
#{prefix ($workbench )} {
167
168
background : rgba (0 , 0 , 0 , 0.1 );
168
169
}
169
170
}
171
+
172
+ // =============== Button =============== //
173
+ #{prefix ($btn )} {
174
+ background-color : #316ac5 ;
175
+ color : rgb (255 , 255 , 255 );
176
+ }
Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+ import { storiesOf } from '@storybook/react' ;
3
+ import { withKnobs } from '@storybook/addon-knobs' ;
4
+ import { propsTable } from '../common/propsTable' ;
5
+
6
+ import { Button } from 'mo/components/button' ;
7
+ import { Icon } from 'mo/components/icon' ;
8
+
9
+ const stories = storiesOf ( 'Button' , module ) ;
10
+ stories . addDecorator ( withKnobs ) ;
11
+
12
+ const propDefinitions = [
13
+ {
14
+ property : 'render' ,
15
+ propType : '() => React.ReactNode' ,
16
+ required : false ,
17
+ description : 'Default render content' ,
18
+ defaultValue : null ,
19
+ } ,
20
+ ] ;
21
+
22
+ stories . add (
23
+ 'Basic Usage' ,
24
+ ( ) => {
25
+ return (
26
+ < div >
27
+ < h2 > 简述</ h2 >
28
+ < p > Button Component</ p >
29
+ < div >
30
+ < h3 > 使用示例 1</ h3 >
31
+ < Button > Btn</ Button >
32
+ </ div >
33
+ < div >
34
+ < h3 > 使用示例 2 - size</ h3 >
35
+ < Button > Normal Button</ Button >
36
+ < Button size = "large" > Large Button</ Button >
37
+ </ div >
38
+ < div >
39
+ < h3 > 使用示例 2 - Icon</ h3 >
40
+ < Button >
41
+ < Icon type = "refresh" />
42
+ </ Button >
43
+ < Button
44
+ style = { {
45
+ width : 100 ,
46
+ } }
47
+ >
48
+ < Icon type = "play" /> < span > Play</ span >
49
+ </ Button >
50
+ </ div >
51
+ </ div >
52
+ ) ;
53
+ } ,
54
+ {
55
+ info : {
56
+ inline : true ,
57
+ TableComponent : ( ) => propsTable ( { propDefinitions } ) ,
58
+ // propTablesExclude: [],
59
+ text : `
60
+ 代码示例:
61
+ ~~~js
62
+ import { useContextView } from 'mo/components/contextview';
63
+
64
+ const contextView = useContextView();
65
+
66
+ const mouseMove = (event: React.MouseEvent): void => {
67
+ contextView.show({
68
+ x: event.clientX,
69
+ y: event.clientY,
70
+ }, () => {
71
+ return (
72
+ <h1>Hello World</h1>
73
+ );
74
+ });
75
+ };
76
+
77
+ return (
78
+ <div>
79
+ <div id="topLeft"
80
+ onMouseMove={mouseMove}
81
+ style={
82
+ {
83
+ position: 'absolute',
84
+ width: 200,
85
+ height: 200,
86
+ top: 0,
87
+ left: 0,
88
+ right: 0,
89
+ bottom: 0,
90
+ background: '#dddddd',
91
+ }
92
+ }>
93
+ Hover me!
94
+ </div>
95
+ </div>
96
+ );
97
+ ~~
98
+ ` ,
99
+ } ,
100
+ }
101
+ ) ;
You can’t perform that action at this time.
0 commit comments