forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagBadge.tsx
69 lines (66 loc) · 2.54 KB
/
TagBadge.tsx
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
import React from "react"
import { observer } from "mobx-react"
import { KeyChartLevel, DbChartTagJoin } from "@ourworldindata/utils"
import { Link } from "./Link.js"
import Tippy from "@tippyjs/react"
import { TagBucketSortingIcon } from "./TagBucketSortingIcon.js"
import cx from "classnames"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { faClock } from "@fortawesome/free-solid-svg-icons"
@observer
export class TagBadge extends React.Component<{
tag: DbChartTagJoin
onToggleKey?: () => void
onApprove?: () => void
searchHighlight?: (text: string) => string | React.ReactElement
}> {
levelToDesc(level?: KeyChartLevel) {
switch (level) {
case KeyChartLevel.Bottom:
return "at the bottom"
case KeyChartLevel.Middle:
return "in the middle"
case KeyChartLevel.Top:
return "at the top"
default:
return ""
}
}
render() {
const { tag, searchHighlight, onToggleKey, onApprove } = this.props
const isPending = !tag.isApproved && onApprove
const keyChartLevelDesc =
tag.keyChartLevel === KeyChartLevel.None
? "Not a key chart, will be hidden in the all charts block of the topic page"
: `Chart will show ${this.levelToDesc(
tag.keyChartLevel
)} of the all charts block on the topic page`
return (
<span
className={cx("TagBadge", {
"TagBadge--is-pending": isPending,
})}
>
<Link className="TagBadge__name" to={`/tags/${tag.id}`}>
{searchHighlight ? searchHighlight(tag.name) : tag.name}
</Link>
{isPending ? (
<Tippy content="Click to approve">
<span className="TagBadge__approve" onClick={onApprove}>
<FontAwesomeIcon icon={faClock} />
</span>
</Tippy>
) : onToggleKey ? (
<Tippy content={`${keyChartLevelDesc} "${tag.name}"`}>
<span
className="TagBadge__sorting"
onClick={onToggleKey}
>
<TagBucketSortingIcon level={tag.keyChartLevel} />
</span>
</Tippy>
) : null}
</span>
)
}
}