This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
131 lines (120 loc) · 2.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// @flow
import React from 'react';
import cx from 'classnames';
import pure from 'recompose/pure';
import TooltipTrigger from 'common/components/TooltipTrigger';
import Gw2Icon from 'common/components/Gw2Icon';
import Icon from 'common/components/Icon';
import ResourceLink, { buildLink as buildDefaultLink } from 'common/components/ResourceLink';
import styles from './styles.less';
const buildLink = (inlineText, { name, id }) => {
switch (inlineText) {
case 'gw2spidy':
return `https://www.gw2spidy.com/item/${id || ''}`;
default:
return buildDefaultLink(inlineText, name);
}
};
type Props = {
type?: string,
busy?: boolean,
name?: string,
item?: {
icon?: string,
name?: string,
id?: number,
},
skin?: {
icon?: string,
},
upgrades?: [],
infusions?: [],
stats?: {},
upgradeCounts?: {},
hide?: boolean,
small?: boolean,
size?: 'micro' | 'small',
tooltipType?: string,
className?: string,
tooltipTextOverride?: string,
equipped?: boolean,
inline?: boolean,
count?: number,
onClick?: (SyntheticEvent<*>) => void,
size?: number,
inlineText?: string,
};
const Item = ({
type = '',
busy,
name,
item = {},
skin = {},
upgrades = [],
infusions = [],
stats = {},
upgradeCounts = {},
hide,
small,
tooltipType,
className,
inline,
tooltipTextOverride,
equipped,
count,
onClick,
size,
inlineText,
...props
}: Props) => {
if (hide) return null;
// $FlowFixMe
const error = item && item.error;
const itemLoaded = !error && !!Object.keys(item).length;
let tooltipData;
if (error) {
tooltipData = error;
} else if (tooltipType === 'skins') {
tooltipData = {
skin,
};
} else if (itemLoaded) {
tooltipData = {
name,
item,
skin,
infusions,
upgrades,
upgradeCounts,
stats,
equipped,
count,
};
} else {
tooltipData = name;
}
return (
<TooltipTrigger
type={tooltipType || 'items'}
data={tooltipTextOverride || tooltipData}
{...props}
>
<ResourceLink text={item.name} href={buildLink(inlineText, item)}>
<Icon
name={type && `${type}-slot-icon.png`}
className={cx(styles.root, className, {
[styles.busy]: busy,
[styles.small]: small,
[styles.emptyBg]: !type && !itemLoaded,
[styles.inline]: inline,
})}
onClick={onClick}
sizePx={size}
>
<Gw2Icon count={count} className={styles.item} src={skin.icon || item.icon || ''} />
</Icon>
</ResourceLink>
</TooltipTrigger>
);
};
export default pure(Item);