import React from "react"; import { baseStyles, Text, SVG, theme } from "@local-logic/core/ui"; import useMeasure from "~/hooks/useMeasure"; import useTranslator from "~/hooks/useTranslator"; import { useLocalLogic } from "~/context"; import { translations as t } from "./translations"; import useHelpers from "../../useHelpers"; import { useRootElement } from "../context"; import * as S from "./styles"; import { BarChartProps } from "./types"; export const BarChart = ({ options: { locationIcon, cityIcon, neighbourhoodIcon, renderCityAvg, renderNeighbourhoodAvg, } = {}, }: BarChartProps) => { const { options: { scoresData, score }, } = useRootElement(); const { options } = useLocalLogic(); const { scoreVal, cityName, cityScoreVal, neighbourhoodName, neighbourhoodScoreVal, } = useHelpers({ score, scoresData, }); const { translations } = useTranslator([t]); const isUsingIcons = !!locationIcon || !!cityIcon || !!neighbourhoodIcon; const [ref, rect] = useMeasure(); const placeholderElement =
; const renderIcon = (icon: React.FC | undefined) => { if (icon) { return ( ); } return isUsingIcons ? placeholderElement : undefined; }; if (scoreVal === null) { return null; } return ( <> <> {renderIcon(locationIcon)} {translations.LOCATION} {scoreVal} {/* We are removing the neighbourhood average until we determine a bundling strategy for neighbourhood content. */} {neighbourhoodScoreVal !== null && renderNeighbourhoodAvg !== false && ( <> {renderIcon(neighbourhoodIcon)} {neighbourhoodName || translations.NEIGHBOURHOOD} {translations.AVG} {neighbourhoodScoreVal} )} {cityScoreVal !== null && renderCityAvg !== false && ( <> {renderIcon(cityIcon)} {cityName || translations.CITY} {translations.AVG} {cityScoreVal} )} ); };