This repository was archived by the owner on Jan 14, 2025. It is now read-only.
File tree 7 files changed +41
-8
lines changed
7 files changed +41
-8
lines changed Original file line number Diff line number Diff line change 59
59
},
60
60
"devDependencies" : {
61
61
"@google-cloud/storage" : " ^1.6.0" ,
62
- "@material/button" : " ^0.41 .0" ,
62
+ "@material/button" : " ^0.43 .0" ,
63
63
"@material/card" : " ^0.41.0" ,
64
64
"@material/checkbox" : " ^0.41.0" ,
65
65
"@material/chips" : " ^0.41.0" ,
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ unelevated | Boolean | Enables unelevated variant.
48
48
outlined | Boolean | Enables outlined variant.
49
49
dense | Boolean | Enables dense variant.
50
50
icon | Element | Icon to render within root element.
51
+ trailingIcon | Element | Icon to render on the right side of the element
51
52
children | String | Text to be displayed within root element.
52
53
disabled | Boolean | Disables button if true.
53
54
href | String | Sets a hyperlink & uses anchor tag instead of a button.
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ export interface ButtonProps<T extends ButtonTypes> extends Ripple.InjectedProps
37
37
className ?: string ;
38
38
icon ?: React . ReactElement < React . HTMLProps < HTMLOrSVGElement > > ;
39
39
href ?: string ;
40
+ trailingIcon ?: React . ReactElement < React . HTMLProps < HTMLOrSVGElement > > ;
40
41
}
41
42
42
43
export const Button = < T extends ButtonTypes > (
@@ -51,6 +52,7 @@ export const Button = <T extends ButtonTypes>(
51
52
href,
52
53
children,
53
54
initRipple,
55
+ trailingIcon,
54
56
// eslint disabled since we do not want to include
55
57
// this in ...otherProps.
56
58
// if unbounded is passed to the <button> element, it will throw
@@ -74,16 +76,22 @@ export const Button = <T extends ButtonTypes>(
74
76
if ( href ) {
75
77
return (
76
78
< a { ...props as React . HTMLProps < HTMLAnchorElement > } href = { href } >
77
- { renderIcon ( icon ) }
78
- { children }
79
+ { ! trailingIcon ? renderIcon ( icon ) : null }
80
+ < span className = 'mdc-button__label' >
81
+ { children }
82
+ </ span >
83
+ { trailingIcon ? renderIcon ( trailingIcon ) : null }
79
84
</ a >
80
85
) ;
81
86
}
82
87
83
88
return (
84
89
< button { ...props as React . HTMLProps < HTMLButtonElement > } >
85
- { renderIcon ( icon ) }
86
- { children }
90
+ { ! trailingIcon ? renderIcon ( icon ) : null }
91
+ < span className = 'mdc-button__label' >
92
+ { children }
93
+ </ span >
94
+ { trailingIcon ? renderIcon ( trailingIcon ) : null }
87
95
</ button >
88
96
) ;
89
97
} ;
Original file line number Diff line number Diff line change 17
17
"url" : " https://github.com/material-components/material-components-web-react.git"
18
18
},
19
19
"dependencies" : {
20
- "@material/button" : " ^0.41 .0" ,
20
+ "@material/button" : " ^0.43 .0" ,
21
21
"@material/react-ripple" : " ^0.8.0" ,
22
22
"classnames" : " ^2.2.5" ,
23
23
"react" : " ^16.4.2"
Original file line number Diff line number Diff line change @@ -67,6 +67,18 @@ const ButtonScreenshotTest = () => {
67
67
Svg Icon
68
68
</ Button >
69
69
</ div >
70
+
71
+ < div className = 'button-container' >
72
+ < Button raised trailingIcon = { < MaterialIcon icon = 'menu' /> } >
73
+ Raised
74
+ </ Button >
75
+ </ div >
76
+
77
+ < div className = 'button-container' >
78
+ < Button raised trailingIcon = { svgIcon } >
79
+ Svg Icon
80
+ </ Button >
81
+ </ div >
70
82
</ div >
71
83
) ;
72
84
} ;
Original file line number Diff line number Diff line change 1
1
{
2
- "button" : " 8941ec5719bb5c82418d335f37dd6e4d523bf8a1121b50a4df4c5a784ca41fbe " ,
2
+ "button" : " 57cb8769600669ec4d44dd23fcf2f6ded528ce8eec612d832c2b9e0271a640c3 " ,
3
3
"card" : " b2fd82763c383be438ff6578083bf9009711c7470333d07eb916ab690fc42d31" ,
4
4
"checkbox" : " 9c61177f0f927e178e7c6687d74cdfa08abc15ea8fc3c381f570b7c7d1f46d2a" ,
5
5
"chips" : " e100a23df0b92c37920127c62d7d694ce3fe40c101c0ed05d535f5cafee62b27" ,
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ test('classNames adds classes', () => {
13
13
assert . isTrue ( wrapper . hasClass ( 'mdc-button' ) ) ;
14
14
} ) ;
15
15
16
- test ( 'does not render icon if props.icon is null' , ( ) => {
16
+ test ( 'does not render icon if props.icon is null and props.trailingIcon is null ' , ( ) => {
17
17
const wrapper = shallow ( < Button /> ) ;
18
18
assert . equal ( wrapper . find ( '.mdc-button__icon' ) . length , 0 ) ;
19
19
} ) ;
@@ -24,6 +24,18 @@ test('renders an icon', () => {
24
24
assert . isTrue ( wrapper . find ( '.test-icon' ) . hasClass ( 'mdc-button__icon' ) ) ;
25
25
} ) ;
26
26
27
+ test ( 'renders a trailing icon' , ( ) => {
28
+ const icon = < i className = 'test-icon' /> ;
29
+ const wrapper = shallow ( < Button trailingIcon = { icon } /> ) ;
30
+ assert . isTrue ( wrapper . find ( '.test-icon' ) . hasClass ( 'mdc-button__icon' ) ) ;
31
+ } ) ;
32
+
33
+ test ( 'renders a link with trailing icon' , ( ) => {
34
+ const icon = < i className = 'test-icon' /> ;
35
+ const wrapper = shallow ( < Button href = '/' trailingIcon = { icon } /> ) ;
36
+ assert . isTrue ( wrapper . find ( '.test-icon' ) . hasClass ( 'mdc-button__icon' ) ) ;
37
+ } ) ;
38
+
27
39
test ( 'renders a raised button' , ( ) => {
28
40
const wrapper = shallow ( < Button raised /> ) ;
29
41
assert . isTrue ( wrapper . hasClass ( 'mdc-button--raised' ) ) ;
You can’t perform that action at this time.
0 commit comments