import React from "react"; import { BackgroundCharacteristicContract } from "@dndbeyond/character-rules-engine/es"; import { ThemeButton } from "../common/Button"; interface Props { suggestions: Array; tableLabel: React.ReactNode; dieLabel: React.ReactNode; useButtonLabel: React.ReactNode; randomizeButtonLabel: React.ReactNode; onSuggestionUse?: ( idx: number, diceRoll: number, description: string | null ) => void; } export default class SuggestionTable extends React.PureComponent { static defaultProps = { useButtonLabel: "+ Add", randomizeButtonLabel: "Random", suggestions: [], }; handleSuggestionUse = ( idx: number, diceRoll: number, description: string | null ): void => { const { onSuggestionUse } = this.props; if (onSuggestionUse) { onSuggestionUse(idx, diceRoll, description); } }; handleRandomClick = (): void => { const { onSuggestionUse, suggestions } = this.props; if (onSuggestionUse) { let randomIdx: number = Math.floor(Math.random() * suggestions.length); let randomSuggestion: BackgroundCharacteristicContract = suggestions[randomIdx]; onSuggestionUse( randomIdx, randomSuggestion.diceRoll, randomSuggestion.description ); } }; render() { const { suggestions, dieLabel, tableLabel, useButtonLabel, randomizeButtonLabel, } = this.props; return (
{suggestions.map((suggestion, idx) => ( ))}
{dieLabel} {tableLabel} {randomizeButtonLabel}
{suggestion.diceRoll} {suggestion.description} {useButtonLabel}
); } }