@@ -5,6 +5,7 @@ import * as React from 'react';
5
5
import { StyleSheet , View } from 'react-native' ;
6
6
import Paper from './Paper' ;
7
7
import Icon from './Icon' ;
8
+ import Text from './Typography/Text' ;
8
9
import TouchableRipple from './TouchableRipple' ;
9
10
import { white } from '../styles/colors' ;
10
11
import withTheme from '../core/withTheme' ;
@@ -13,19 +14,23 @@ import type { IconSource } from './Icon';
13
14
14
15
type Props = {
15
16
/**
16
- * Whether FAB is mini-sized, used to create visual continuity with other elements.
17
+ * Icon to display for the `FAB`.
18
+ */
19
+ icon : IconSource ,
20
+ /**
21
+ * Optional label for extended `FAB`.
22
+ */
23
+ label ?: string ,
24
+ /**
25
+ * Whether FAB is mini-sized, used to create visual continuity with other elements. This has no effect if `label` is specified.
17
26
*/
18
27
small ?: boolean ,
19
28
/**
20
29
* Icon color of button, a dark button will render light text and vice-versa.
21
30
*/
22
31
dark ?: boolean ,
23
32
/**
24
- * Icon to display for the `FAB`.
25
- */
26
- icon : IconSource ,
27
- /**
28
- * Custom color for the FAB.
33
+ * Custom color for the `FAB`.
29
34
*/
30
35
color ?: string ,
31
36
/**
@@ -43,7 +48,8 @@ type Props = {
43
48
* A floating action button represents the primary action in an application.
44
49
*
45
50
* <div class="screenshots">
46
- * <img src="screenshots/fab.png" />
51
+ * <img src="screenshots/fab-1.png" />
52
+ * <img src="screenshots/fab-2.png" />
47
53
* </div>
48
54
*
49
55
* ## Usage
@@ -66,12 +72,14 @@ class FAB extends React.Component<Props> {
66
72
small,
67
73
dark,
68
74
icon,
75
+ label,
69
76
color : iconColor ,
70
77
onPress,
71
78
theme,
72
79
style,
73
80
...rest
74
81
} = this . props ;
82
+
75
83
const backgroundColor = theme . colors . accent ;
76
84
const isDark =
77
85
typeof dark === 'boolean' ? dark : ! color ( backgroundColor ) . light ( ) ;
@@ -84,21 +92,31 @@ class FAB extends React.Component<Props> {
84
92
return (
85
93
< Paper
86
94
{ ...rest }
87
- style = { [
88
- { backgroundColor, elevation : 12 } ,
89
- styles . content ,
90
- small ? styles . small : styles . standard ,
91
- style ,
92
- ] }
95
+ style = { [ { backgroundColor, elevation : 12 } , styles . container , style ] }
93
96
>
94
97
< TouchableRipple
95
98
borderless
96
99
onPress = { onPress }
97
100
rippleColor = { rippleColor }
98
- style = { [ styles . content , small ? styles . small : styles . standard ] }
101
+ style = { styles . container }
99
102
>
100
- < View >
103
+ < View
104
+ style = { [
105
+ styles . content ,
106
+ label ? styles . extended : small ? styles . small : styles . standard ,
107
+ ] }
108
+ >
101
109
< Icon name = { icon } size = { 24 } color = { textColor } />
110
+ { label ? (
111
+ < Text
112
+ style = { [
113
+ styles . label ,
114
+ { color : textColor , fontFamily : theme . fonts . medium } ,
115
+ ] }
116
+ >
117
+ { label . toUpperCase ( ) }
118
+ </ Text >
119
+ ) : null }
102
120
</ View >
103
121
</ TouchableRipple >
104
122
</ Paper >
@@ -107,19 +125,28 @@ class FAB extends React.Component<Props> {
107
125
}
108
126
109
127
const styles = StyleSheet . create ( {
110
- content : {
111
- alignItems : 'center' ,
112
- justifyContent : 'center' ,
128
+ container : {
129
+ borderRadius : 28 ,
113
130
} ,
114
131
standard : {
115
132
height : 56 ,
116
133
width : 56 ,
117
- borderRadius : 28 ,
118
134
} ,
119
135
small : {
120
136
height : 40 ,
121
137
width : 40 ,
122
- borderRadius : 20 ,
138
+ } ,
139
+ extended : {
140
+ height : 48 ,
141
+ paddingHorizontal : 16 ,
142
+ } ,
143
+ content : {
144
+ flexDirection : 'row' ,
145
+ alignItems : 'center' ,
146
+ justifyContent : 'center' ,
147
+ } ,
148
+ label : {
149
+ marginHorizontal : 8 ,
123
150
} ,
124
151
} ) ;
125
152
0 commit comments