All files / owid-grapher/grapher/controls SortIcon.tsx

93.75% Statements 30/32
60% Branches 3/5
100% Functions 1/1
93.75% Lines 30/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 381x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 5x 5x 5x 7x 7x     7x 7x 7x 7x            
import React from "react"
import classnames from "classnames"
import { IconDefinition } from "@fortawesome/fontawesome-svg-core"
import { faSortAlphaUpAlt } from "@fortawesome/free-solid-svg-icons/faSortAlphaUpAlt"
import { faSortAlphaDown } from "@fortawesome/free-solid-svg-icons/faSortAlphaDown"
import { faSortAmountUpAlt } from "@fortawesome/free-solid-svg-icons/faSortAmountUpAlt"
import { faSortAmountDown } from "@fortawesome/free-solid-svg-icons/faSortAmountDown"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { SortOrder } from "../../coreTable/CoreTableConstants"
 
export function SortIcon(props: {
    type?: "text" | "numeric"
    isActiveIcon?: boolean
    order: SortOrder
}): JSX.Element {
    const type = props.type ?? "numeric"
    const isActiveIcon = props.isActiveIcon ?? false
 
    let faIcon: IconDefinition
 
    if (type === "text")
        faIcon =
            props.order === SortOrder.desc ? faSortAlphaUpAlt : faSortAlphaDown
    else
        faIcon =
            props.order === SortOrder.desc
                ? faSortAmountDown
                : faSortAmountUpAlt
 
    return (
        <span
            className={classnames({ "sort-icon": true, active: isActiveIcon })}
        >
            <FontAwesomeIcon icon={faIcon} />
        </span>
    )
}