UNPKG

@arpitbhalla/rneui-base-dev

Version:
105 lines (104 loc) 5.44 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Avatar = exports.avatarSizes = void 0; var react_1 = __importDefault(require("react")); var react_native_1 = require("react-native"); var helpers_1 = require("../helpers"); var Icon_1 = require("../Icon"); var Image_1 = require("../Image"); exports.avatarSizes = { small: 34, medium: 50, large: 75, xlarge: 150, }; var Avatar = function (_a) { var onPress = _a.onPress, onLongPress = _a.onLongPress, onPressIn = _a.onPressIn, onPressOut = _a.onPressOut, _b = _a.Component, Component = _b === void 0 ? onPress || onLongPress || onPressIn || onPressOut ? react_native_1.Pressable : react_native_1.View : _b, containerStyle = _a.containerStyle, icon = _a.icon, iconStyle = _a.iconStyle, source = _a.source, _c = _a.size, size = _c === void 0 ? 'small' : _c, avatarStyle = _a.avatarStyle, rounded = _a.rounded, title = _a.title, titleStyle = _a.titleStyle, overlayContainerStyle = _a.overlayContainerStyle, imageProps = _a.imageProps, placeholderStyle = _a.placeholderStyle, renderPlaceholderContent = _a.renderPlaceholderContent, _d = _a.ImageComponent, ImageComponent = _d === void 0 ? react_native_1.Image : _d, children = _a.children, pressableProps = _a.pressableProps, rest = __rest(_a, ["onPress", "onLongPress", "onPressIn", "onPressOut", "Component", "containerStyle", "icon", "iconStyle", "source", "size", "avatarStyle", "rounded", "title", "titleStyle", "overlayContainerStyle", "imageProps", "placeholderStyle", "renderPlaceholderContent", "ImageComponent", "children", "pressableProps"]); var width = typeof size === 'number' ? size : exports.avatarSizes[size] || exports.avatarSizes.small; var height = width; var titleSize = width / 2; var iconSize = width / 2; var PlaceholderContent = (renderPlaceholderContent && (0, helpers_1.renderNode)(undefined, renderPlaceholderContent)) || (title && (react_1.default.createElement(react_native_1.Text, { style: react_native_1.StyleSheet.flatten([ styles.title, { fontSize: titleSize }, titleStyle, ]) }, title))) || (icon && (react_1.default.createElement(Icon_1.Icon, { style: react_native_1.StyleSheet.flatten([iconStyle && iconStyle]), color: icon.color || 'white', name: icon.name || 'account', size: icon.size || iconSize, type: icon.type || 'material-community' }))); var hidePlaceholder = !(source && source.uri); var imageContainerStyle = react_native_1.StyleSheet.flatten([ styles.overlayContainer, rounded && { borderRadius: width / 2, overflow: 'hidden' }, overlayContainerStyle, imageProps && imageProps.containerStyle, ]); if (imageProps && imageProps.containerStyle) { delete imageProps.containerStyle; } return (react_1.default.createElement(Component, __assign({ style: react_native_1.StyleSheet.flatten([ styles.container, { height: height, width: width }, rounded && { borderRadius: width / 2 }, containerStyle, ]) }, __assign(__assign({ onPress: onPress, onLongPress: onLongPress, onPressIn: onPressIn, onPressOut: onPressOut }, pressableProps), rest)), react_1.default.createElement(Image_1.Image, __assign({ testID: "RNE__Avatar__Image", placeholderStyle: react_native_1.StyleSheet.flatten([ placeholderStyle, hidePlaceholder && styles.hiddenPlaceholderStyle, ]), PlaceholderContent: PlaceholderContent, containerStyle: imageContainerStyle, source: source, borderRadius: rounded ? width / 2 : undefined }, imageProps, { style: react_native_1.StyleSheet.flatten([ styles.avatar, imageProps && imageProps.style, avatarStyle, ]), ImageComponent: ImageComponent })), children)); }; exports.Avatar = Avatar; var styles = react_native_1.StyleSheet.create({ container: { backgroundColor: 'transparent', }, avatar: { flex: 1, width: undefined, height: undefined, }, overlayContainer: { flex: 1, }, title: { color: '#ffffff', backgroundColor: 'transparent', textAlign: 'center', }, hiddenPlaceholderStyle: { backgroundColor: 'transparent', }, }); exports.Avatar.displayName = 'Avatar';