1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 21:14:18 +00:00
pds-2021-g2-nest/code/frontend/src/components/interactive/ConditionBadge.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

import React, { useContext } from "react"
import Style from "./ConditionBadge.module.css"
import classNames from "classnames"
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
2021-04-29 14:58:31 +00:00
import ButtonSmallX from "../base/ButtonSmallX"
2021-05-07 03:02:20 +00:00
import { faAt, faClock, faGlobe, faHashtag, faMapPin } from "@fortawesome/free-solid-svg-icons"
2021-04-29 14:58:31 +00:00
import ContextRepositoryEditor from "../../contexts/ContextRepositoryEditor"
const CONDITION_COLORS = {
0: "Grey", // Hashtag
2: "Yellow", // Time
2021-05-07 03:02:20 +00:00
3: "Red", // Coordinates
4: "Red", // Place
5: "Green", // User
}
const CONDITION_ICONS = {
0: faHashtag, // Hashtag
2: faClock, // Time
2021-05-07 03:02:20 +00:00
3: faGlobe, // Coordinates
4: faMapPin, // Place
5: faAt, // User
}
/**
* A small colored badge representing a Condition for a filter.
*
* @param condition - The Condition that this badge represents.
* @returns {JSX.Element}
* @constructor
*/
2021-04-29 14:17:22 +00:00
export default function ConditionBadge({ ...condition }) {
const { id, type, content } = condition
const color = CONDITION_COLORS[type]
const icon = CONDITION_ICONS[type]
2021-05-07 03:02:20 +00:00
const {removeRawCondition} = useContext(ContextRepositoryEditor)
return (
<div
2021-05-07 03:02:20 +00:00
title={id ? `💠 Condition ID: ${id}` : "✨ New Condition"}
className={classNames(Style.ConditionBadge, Style[`ConditionBadge${color}`])}
>
<div className={Style.Icon}>
<FontAwesomeIcon icon={icon}/>
</div>
2021-05-07 03:02:20 +00:00
<div className={Style.Text}>
{content}
</div>
<div>
2021-04-29 14:17:22 +00:00
<ButtonSmallX onClick={() => {
console.debug(`Removing Condition: `, condition)
2021-05-07 03:02:20 +00:00
removeRawCondition(condition)
2021-04-29 14:17:22 +00:00
}}/>
</div>
</div>
)
}