Skip to content

Commit 64b256f

Browse files
authored
Merge pull request mxdi9i7#29 from mxdi9i7/tobyz/buttonicon
add button icon
2 parents 1648999 + 5d53c59 commit 64b256f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/components/Button/index.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ a.#{$baseClass} {
4040
opacity: 0;
4141
content: ' ';
4242
}
43+
&:first-child {
44+
i {
45+
margin: 0px;
46+
}
47+
}
4348

4449
&:active {
4550
&::before {

src/components/Button/index.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ export const BlockButtons = () => (
114114

115115
export const IconButton = () => (
116116
<div className='container'>
117-
<Button icon='https://img.yzcdn.cn/vant/logo.png'>
117+
<Button icon='star-o' type='primary' />
118+
<Button icon='star-o' type='info'>
119+
Custom Icon Button
120+
</Button>
121+
<Button icon='https://img.yzcdn.cn/vant/logo.png' type='primary'>
118122
Custom Icon Button
119123
</Button>
120124
</div>

src/components/Button/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import { renderLoadingIcon, getContrastTextColor, colorType } from './helper';
44
import classnames from '../../utils/classNames';
55

66
import { Props } from './types';
7+
import Icon from '../Icons';
78

89
import './index.scss';
910

1011
const baseClass = 'vant-button';
1112

12-
// TODO: add hairline props
13-
// TODO: enable icon buttons, need to have icon library done first
14-
// TODO: accept linear gradient
15-
1613
export default function Button({
1714
text,
1815
children,
@@ -125,9 +122,13 @@ export default function Button({
125122
});
126123
}
127124

125+
const NAV_ICON_SIZE = '16px';
126+
128127
return (
129128
<CustomTag {...props}>
130-
{icon && <img src={icon} alt='button icon' />}
129+
{icon?.includes('.') || icon?.includes('http')
130+
? icon && <img src={icon} alt='button icon' />
131+
: icon && <Icon name={icon} size={NAV_ICON_SIZE} />}
131132
{loading
132133
? renderLoadingIcon({
133134
className: loadingType

0 commit comments

Comments
 (0)