import React from "react"; import { CLASSPREFIX as eccgui } from "../../configuration/constants"; import PropertyName from "./PropertyName"; import PropertyValue from "./PropertyValue"; export interface PropertyValuePairProps extends React.HTMLAttributes { /** * Add a bit white space to the bottom of the element. */ hasSpacing?: boolean; /** * Add a horizontal rule to the bottom of the element. */ hasDivider?: boolean; /** * Forward the `nowrap` option to it `PropertyName` and `PropertyValue` children. */ nowrap?: boolean; /** * Only use one single column and put property label and value below each other. */ singleColumn?: boolean; } /** * Parent container to group one `PropertyName` and one or more `PropertyValues`. * Even if only one `PropertyValuePair` is used it need to be wrapped into an `PropertyValueList` container. */ export const PropertyValuePair = ({ children, className = "", nowrap, hasSpacing = false, hasDivider = false, singleColumn = false, ...otherProps }: PropertyValuePairProps) => { const alteredChildren = nowrap ? React.Children.map(children, (child) => { const originalChild = child as React.ReactElement; if (originalChild.type && (originalChild.type === PropertyName || originalChild.type === PropertyValue)) { return React.cloneElement(originalChild, { nowrap: true }); } return child; }) : children; return (
{alteredChildren}
); }; export default PropertyValuePair;