import React from "react"; import { BoxBackground, ThemedSenseRowBoxSvg, ThemedSenseRowSmallBoxSvg, } from "@dndbeyond/character-components/es"; import { CharacterTheme, Constants, FormatUtils, RuleDataUtils, SenseInfo, } from "@dndbeyond/character-rules-engine/es"; import { TypeScriptUtils } from "../../../Shared/utils"; interface Props { passivePerception: number; passiveInvestigation: number; passiveInsight: number; senses: SenseInfo; rowStyle: "small" | "normal"; onClick?: () => void; theme: CharacterTheme; } export default class Senses extends React.PureComponent { static defaultProps = { rowStyle: "normal", }; handleClick = (evt: React.MouseEvent): void => { const { onClick } = this.props; if (onClick) { evt.stopPropagation(); evt.nativeEvent.stopImmediatePropagation(); onClick(); } }; getSenseSummary = (senseKey: Constants.SenseTypeEnum): string | null => { const { senses } = this.props; let senseValue = senses[senseKey]; if (!senseValue) { return null; } return `${RuleDataUtils.getSenseTypeLabel( senseKey )} ${FormatUtils.renderDistance(senseValue)}`; }; renderSummaryInfo = (): React.ReactNode => { const { theme } = this.props; let senseKeys: Array = [ Constants.SenseTypeEnum.BLINDSIGHT, Constants.SenseTypeEnum.DARKVISION, Constants.SenseTypeEnum.TREMORSENSE, Constants.SenseTypeEnum.TRUESIGHT, ]; let senseSummaries: Array = senseKeys .map((senseKey) => this.getSenseSummary(senseKey)) .filter(TypeScriptUtils.isNotNullOrUndefined); let summaryClasses: Array = ["ct-senses__summary"]; if (!senseSummaries.length) { summaryClasses.push("ct-senses__summary--empty"); } if (theme?.isDarkMode) { summaryClasses.push("ct-senses__summary--dark-mode"); } if (senseSummaries.length) { return (
{senseSummaries.join(", ")}
); } return (
Additional Sense Types
); }; render() { const { passiveInsight, passiveInvestigation, passivePerception, rowStyle, theme, } = this.props; let StyleComponent: React.ComponentType = ThemedSenseRowBoxSvg; if (rowStyle === "small") { StyleComponent = ThemedSenseRowSmallBoxSvg; } return (
{passivePerception}
Passive Perception
{passiveInvestigation}
Passive Investigation
{passiveInsight}
Passive Insight
{this.renderSummaryInfo()}
); } }