import * as React from "react"; import { ConditionLevelEffectLookup } from "@dndbeyond/character-rules-engine/es"; import SlotManager from "../SlotManager"; import { ThemeButton } from "../common/Button"; interface Props { conditionName: string; levels: Array; levelEffectLookup: ConditionLevelEffectLookup | null; levelOverrides: Record; activeLevel: number | null; isInteractive: boolean; onLevelChange: (value: number | null) => void; } export default class ConditionLevelsTable extends React.PureComponent { static defaultProps = { activeLevel: null, isInteractive: false, onLevelChange: null, levelOverrides: {}, levelEffectLookup: null, }; handleLevelChange = (level: number | null, used: number): void => { const { onLevelChange, activeLevel } = this.props; let value: number | null = level; if (level !== null && activeLevel === level) { value = level > 1 ? level - 1 : null; } if (onLevelChange) { onLevelChange(value); } }; renderEffect = (level: number): string => { const { levelEffectLookup, levelOverrides } = this.props; if (levelOverrides.hasOwnProperty(level)) { return levelOverrides[level]; } let effect: string = ""; if (levelEffectLookup !== null && levelEffectLookup.hasOwnProperty(level)) { effect = levelEffectLookup[level]; } return effect; }; render() { const { conditionName, levels, activeLevel, isInteractive } = this.props; return (
{levels.map((level, idx) => { let isActive: boolean = level === activeLevel; let isImplied: boolean = activeLevel !== null && level < activeLevel; let classNames: Array = [ "ct-condition-levels-table__table-slot", ]; if (isActive) { classNames.push( "ct-condition-levels-table__table-slot--active" ); } if (isImplied) { classNames.push( "ct-condition-levels-table__table-slot--implied" ); } if (isInteractive) { classNames.push( "ct-condition-levels-table__table-slot--interactive" ); } return ( ); })}
Applied Level Effect
{level} {this.renderEffect(level)}
{isInteractive && activeLevel !== null && (
Remove All {conditionName}
)}
); } }