Skip to content

Commit 8b1ec75

Browse files
committed
Added buttons
1 parent 2d2fc93 commit 8b1ec75

File tree

5 files changed

+66
-19
lines changed

5 files changed

+66
-19
lines changed

src/button/Button.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ const factory = (ripple, FontIcon) => {
1313
size: 'medium',
1414
className: '',
1515
href: '',
16+
iconAlignment: 'left',
1617
};
1718

19+
getIcon = (icon, iconAlignment, theme) => {
20+
const iconClasses = classnames(theme.icon, theme[`icon-${iconAlignment}`]);
21+
return <FontIcon className={iconClasses} value={icon} />;
22+
}
23+
1824
handleMouseUp = (event) => {
1925
this.buttonNode.blur();
2026
if (this.props.onMouseUp) this.props.onMouseUp(event);
@@ -26,13 +32,12 @@ const factory = (ripple, FontIcon) => {
2632
};
2733

2834
render() {
29-
const { children, type, size, className, href, icon, theme, ...others } = this.props;
35+
const {
36+
children, type, size, className, href, icon, iconAlignment, theme, ...others
37+
} = this.props;
3038
const element = href ? 'a' : 'button';
3139

32-
const classes = classnames(theme.button, {
33-
[theme[type]]: true,
34-
[theme[size]]: true,
35-
}, className);
40+
const classes = classnames(theme.button, theme[type], theme[size], className);
3641

3742
const props = {
3843
...others,
@@ -45,7 +50,7 @@ const factory = (ripple, FontIcon) => {
4550
};
4651

4752
return React.createElement(element, props,
48-
icon ? <FontIcon className={theme.icon} value={icon} /> : null,
53+
icon ? this.getIcon(icon, iconAlignment, theme) : null,
4954
children,
5055
);
5156
}

src/button/theme.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@
4242

4343
& .icon {
4444
font-size: 120%;
45+
}
46+
47+
& .icon-left {
48+
float: left;
4549
margin-right: 6px;
46-
vertical-align: middle;
50+
}
51+
52+
& .icon-right {
53+
margin-left: 6px;
54+
float: right;
4755
}
4856

4957
& > input {

src/font_icon/FontIcon.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
4+
import { themr } from 'react-css-themr';
45

5-
const FontIcon = ({ alt, children, className, theme, value, ...other}) => ( // eslint-disable-line
6-
<span
7-
data-react-toolbox="font-icon"
8-
aria-label={alt}
9-
className={classnames({ 'material-icons': typeof value === 'string' || typeof children === 'string' }, className)}
10-
{...other}
11-
>
12-
{value}
13-
{children}
14-
</span>
15-
);
6+
import iconTheme from './theme.scss';
7+
8+
const FontIcon = ({ alt, children, className, theme, value, ...other}) => { // eslint-disable-line
9+
const _classNames = classnames({
10+
[iconTheme.materialIcons]: typeof value === 'string' || typeof children === 'string',
11+
}, className);
12+
13+
return (
14+
<span
15+
aria-label={alt}
16+
className={_classNames}
17+
{...other}
18+
>
19+
{value}
20+
{children}
21+
</span>
22+
);
23+
};
1624

1725
FontIcon.propTypes = {
1826
alt: PropTypes.string,

src/font_icon/theme.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@font-face {
2+
font-family: 'Material Icons';
3+
font-style: normal;
4+
font-weight: 400;
5+
src: url(https://fonts.gstatic.com/s/materialicons/v38/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2) format('woff2');
6+
}
7+
8+
.materialIcons {
9+
font-family: 'Material Icons';
10+
font-weight: normal;
11+
font-style: normal;
12+
font-size: 24px;
13+
line-height: 1;
14+
letter-spacing: normal;
15+
text-transform: none;
16+
display: inline-block;
17+
white-space: nowrap;
18+
word-wrap: normal;
19+
direction: ltr;
20+
-webkit-font-feature-settings: 'liga';
21+
-webkit-font-smoothing: antialiased;
22+
}

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ const Index = () => (
1717
</Card>
1818

1919
<div style={{ margin: '20px' }}>
20-
<Button size="medium">Hello</Button>
20+
<Button size="medium" icon="favorite">Hello</Button>
21+
<Button type="danger" size="medium" icon="bookmark" iconAlignment="right">Hello</Button>
2122
<Button type="secondary" size="small">Hello</Button>
2223
<Button type="primary">Hello</Button>
2324
<Button type="success" size="large">Hello</Button>
25+
<Button type="warning" size="small">Hello</Button>
26+
<Button type="info" size="medium">Hello</Button>
27+
<Button type="dark" size="large">Hello</Button>
2428
</div>
2529
</div>
2630
);

0 commit comments

Comments
 (0)