import React from 'react'; import Html from "../../helper/Html"; import { Value as StyledValue } from "../../../primitives/Summary"; type Props = { value: any node: any } export default function Value({ value, node }: Props) { if (Number(value) === value && value % 1 !== 0) { // eslint-disable-next-line no-param-reassign value = Math.round(value); } if (!node.optional && [null, undefined, ""].includes(value)) { return * Må fylles ut; } if (node.options) { let values; if (typeof value === "object") { values = Object.keys(value).filter((key) => value[key]); } else { values = [value]; } // Map the values to option heading/text for the option values = values.map((val) => { const option = (node.options || []).find( ({ value: optionValue }: any) => optionValue === val ) || {}; return option.heading || option.text || val; }); if (!node.optional && !values.length) { return * Må fylles ut; } else if (!values.length) { return Ingen valgt; } const commaSeparated = values.slice(0, -1); const lastOne = values.slice(-1)[0]; // If only one value selected if (!commaSeparated.length) { return ( {lastOne} ); } // If more than one selected return ( {commaSeparated.join(", ")} og {lastOne}. ); } return ( {value} {node.unit ? : null} ); }