/** * Component for render bold label and cursive value * * @author Brauer Ilya * @date 2021-01-19 */ import * as React from 'react'; import * as styles from './labelValue.m.scss'; import {joinClassNames} from '../../utils/joinClassNames'; import {Tooltip} from '../../component'; import {PLACEMENT} from '../../constants'; export interface ILabelValueProps { label: React.ReactNode; value: React.ReactNode; labelTooltip?: string; valueTooltip?: string; labelCanCollapsed?: boolean; valueCanCollapsed?: boolean; hasAsterisk?: boolean; hasColon?: boolean; type?: 'value' | 'info' | 'primary'; isValueItalic?: boolean; isSpaceBetween?: boolean; isCenterPosition?: boolean; labelWidth?: number; labelAlign?: 'left' | 'center' | 'right'; labelWeight?: number; isWhiteColor?: boolean; isWrap?: boolean; verticalAlign?: 'top' | 'center'; } type DefaultPropsKeys = 'hasAsterisk' | 'hasColon' | 'type' | 'labelCanCollapsed' | 'valueCanCollapsed' | 'isValueItalic' | 'isSpaceBetween' | 'isCenterPosition' | 'labelAlign' | 'labelWeight' | 'isWhiteColor' | 'isWrap' | 'verticalAlign'; type DefaultProps = Required>; export class LabelValue extends React.PureComponent { static defaultProps: DefaultProps = { hasAsterisk: false, hasColon: true, type: 'info', valueCanCollapsed: true, labelCanCollapsed: true, isValueItalic: false, isSpaceBetween: false, isCenterPosition: false, labelAlign: 'left', labelWeight: 600, isWhiteColor: false, isWrap: false, verticalAlign: 'center' }; renderLabel = () => { const labelContainer = joinClassNames( styles.labelContainer, [styles.canCollapsed, this.props.labelCanCollapsed === true], [styles.alignLeft, this.props.labelAlign === 'left'], [styles.alignCenter, this.props.labelAlign === 'center'], [styles.alignRight, this.props.labelAlign === 'right'], ); const {labelWidth, labelWeight} = this.props; let labelStyle = {}; if (labelWidth) { labelStyle = Object.assign(labelStyle, { width: `${labelWidth}%`, flexShrink: 0 }); } if (labelWeight) { labelStyle = Object.assign(labelStyle, { fontWeight: labelWeight }); } return (
{this.props.label}
{this.props.hasColon && (
:
)} {this.props.hasAsterisk && (
*
)}
); }; override render () { const containerHasCollapsedChild = this.props.valueCanCollapsed === true || this.props.labelCanCollapsed === true; const container = joinClassNames(styles.container, [styles.typeValue, this.props.type === 'value'], [styles.typeInfo, this.props.type === 'info'], [styles.typePrimary, this.props.type === 'primary'], [styles.containerHasCollapsedChild, containerHasCollapsedChild], [styles.spaceBetween, this.props.isSpaceBetween === true], [styles.center, this.props.isCenterPosition === true], [styles.isWhiteColor, this.props.isWhiteColor === true], [styles.isWrap, this.props.isWrap === true], [styles.verticalAlignCenter, this.props.verticalAlign === 'center'], [styles.verticalAlignTop, this.props.verticalAlign === 'top'], ); const value = joinClassNames(styles.value, [styles.canCollapsed, this.props.valueCanCollapsed === true], [styles.isValueItalic, this.props.isValueItalic === true] ); return (
{ this.props.labelCanCollapsed ? ( {this.renderLabel()} ) : ( this.renderLabel() ) } { this.props.valueCanCollapsed ? (
{this.props.value}
) : (
{this.props.value}
) }
); } }