1 | var __rest = (this && this.__rest) || function (s, e) {
|
2 | var t = {};
|
3 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
4 | t[p] = s[p];
|
5 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
6 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
8 | t[p[i]] = s[p[i]];
|
9 | }
|
10 | return t;
|
11 | };
|
12 | import React from 'react';
|
13 | import { StyleSheet, View } from 'react-native';
|
14 | import Badge from './Badge';
|
15 | const withBadge = (value, options = {}) => (WrappedComponent) => {
|
16 | const WithBadge = (props) => {
|
17 | const { bottom, hidden = false, left, containerStyle } = options, badgeProps = __rest(options, ["bottom", "hidden", "left", "containerStyle"]);
|
18 | let { right = -16, top = -1 } = options;
|
19 | if (!value) {
|
20 | right = -3;
|
21 | top = 3;
|
22 | }
|
23 | const badgeValue = typeof value === 'function' ? value(props) : value;
|
24 | return (<View style={StyleSheet.flatten([styles.container, containerStyle])}>
|
25 | <WrappedComponent {...props}/>
|
26 |
|
27 | {!hidden && (<Badge value={badgeValue} status="error" containerStyle={StyleSheet.flatten([
|
28 | styles.badgeContainer,
|
29 | { bottom, left, right, top },
|
30 | ])} {...badgeProps}/>)}
|
31 | </View>);
|
32 | };
|
33 | WithBadge.displayName = `WithBadge(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
34 | return WithBadge;
|
35 | };
|
36 | const styles = StyleSheet.create({
|
37 | badgeContainer: {
|
38 | position: 'absolute',
|
39 | },
|
40 | container: {
|
41 | alignItems: 'center',
|
42 | justifyContent: 'center',
|
43 | position: 'relative',
|
44 | },
|
45 | });
|
46 | export default withBadge;
|