uniforms-react-semantic
Version:
Semantic React UI components for uniforms.
32 lines (27 loc) • 919 B
JavaScript
/**
* Created by cesar on 13/9/17.
*/
import React, {Component} from 'react'
import ErrorLabel from "./ErrorLabel";
import {Label} from "semantic-ui-react";
const Wrapper = ({error, showInlineError, id, errorMessage, label, ...props}) => {
let headLabel, insideLabel
if (label && typeof label === 'string') {
headLabel = <label htmlFor={id}>{label}</label>
}
if (React.isValidElement(label)) {
insideLabel = label
}
const children = React.Children.map(props.children, child => {
return React.cloneElement(child, {
label: insideLabel
})
})
if (!headLabel && !error && !showInlineError) return children
return <div className={`${error ? 'error' : ''}`}>
{headLabel}
{children}
{!!(error && showInlineError) && <ErrorLabel style={{display: 'table'}} content={errorMessage}/>}
</div>
}
export default Wrapper