1 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2 |
|
3 | import * as React from 'react';
|
4 | import { View, StyleSheet } from 'react-native';
|
5 | import Text from '../Typography/Text';
|
6 | import { withTheme } from '../../core/theming';
|
7 | import { white } from '../../styles/colors';
|
8 | import getContrastingColor from '../../utils/getContrastingColor';
|
9 | const defaultSize = 64;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | const AvatarText = _ref => {
|
31 | let {
|
32 | label,
|
33 | size = defaultSize,
|
34 | style,
|
35 | theme,
|
36 | labelStyle,
|
37 | color: customColor,
|
38 | ...rest
|
39 | } = _ref;
|
40 | const {
|
41 | backgroundColor = theme.colors.primary,
|
42 | ...restStyle
|
43 | } = StyleSheet.flatten(style) || {};
|
44 | const textColor = customColor !== null && customColor !== void 0 ? customColor : getContrastingColor(backgroundColor, white, 'rgba(0, 0, 0, .54)');
|
45 | return React.createElement(View, _extends({
|
46 | style: [{
|
47 | width: size,
|
48 | height: size,
|
49 | borderRadius: size / 2,
|
50 | backgroundColor
|
51 | }, styles.container, restStyle]
|
52 | }, rest), React.createElement(Text, {
|
53 | style: [styles.text, {
|
54 | color: textColor,
|
55 | fontSize: size / 2,
|
56 | lineHeight: size
|
57 | }, labelStyle],
|
58 | numberOfLines: 1
|
59 | }, label));
|
60 | };
|
61 |
|
62 | AvatarText.displayName = 'Avatar.Text';
|
63 | const styles = StyleSheet.create({
|
64 | container: {
|
65 | justifyContent: 'center',
|
66 | alignItems: 'center'
|
67 | },
|
68 | text: {
|
69 | textAlign: 'center',
|
70 | textAlignVertical: 'center'
|
71 | }
|
72 | });
|
73 | export default withTheme(AvatarText);
|
74 |
|
\ | No newline at end of file |