UNPKG

2.16 kBJavaScriptView Raw
1function _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
3import * as React from 'react';
4import { View, StyleSheet } from 'react-native';
5import Text from '../Typography/Text';
6import { withTheme } from '../../core/theming';
7import { white } from '../../styles/colors';
8import getContrastingColor from '../../utils/getContrastingColor';
9const defaultSize = 64;
10
11/**
12 * Avatars can be used to represent people in a graphical way.
13 *
14 * <div class="screenshots">
15 * <figure>
16 * <img class="medium" src="screenshots/avatar-text.png" />
17 * </figure>
18 * </div>
19 *
20 * ## Usage
21 * ```js
22 * import * as React from 'react';
23 * import { Avatar } from 'react-native-paper';
24 *
25 * const MyComponent = () => (
26 * <Avatar.Text size={24} label="XD" />
27 * );
28 * ```
29 */
30const 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 /*#__PURE__*/React.createElement(View, _extends({
46 style: [{
47 width: size,
48 height: size,
49 borderRadius: size / 2,
50 backgroundColor
51 }, styles.container, restStyle]
52 }, rest), /*#__PURE__*/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
62AvatarText.displayName = 'Avatar.Text';
63const styles = StyleSheet.create({
64 container: {
65 justifyContent: 'center',
66 alignItems: 'center'
67 },
68 text: {
69 textAlign: 'center',
70 textAlignVertical: 'center'
71 }
72});
73export default withTheme(AvatarText);
74//# sourceMappingURL=AvatarText.js.map
\No newline at end of file