Skip to content

Commit 9cb82b7

Browse files
committed
feat: add Button component
1 parent 1f82d95 commit 9cb82b7

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed

src/components/button/index.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

src/components/button/style.scss

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

src/style/theme.scss

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
@import 'mo/components/menu/style';
2222
@import 'mo/components/toolbar/style';
2323
@import 'mo/components/tree/style';
24+
@import 'mo/components/button/style';
2425

2526
// =============== Workbench =============== //
2627
#{prefix($workbench)} {
@@ -167,3 +168,9 @@
167168
background: rgba(0, 0, 0, 0.1);
168169
}
169170
}
171+
172+
// =============== Button =============== //
173+
#{prefix($btn)} {
174+
background-color: #316ac5;
175+
color: rgb(255, 255, 255);
176+
}
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
);

0 commit comments

Comments
 (0)