import * as React from 'react'; import { themr, ThemedComponentClass } from '@friendsofreactjs/react-css-themr'; import { createUniqueIDFactory } from '@shopify/javascript-utilities/other'; import { classNames } from '@shopify/react-utilities/styles'; import { wrapWithComponent } from '../../utilities'; import { FORM_LAYOUT } from '../ThemeIdentifiers'; import Item from './Item'; import * as baseTheme from './FormLayout.scss'; export interface Props { children?: React.ReactNode; condensed?: boolean; componentTitle?: string; helpText?: React.ReactNode; componentStyle?: React.CSSProperties; theme?: any; } const getUniqueID = createUniqueIDFactory('FormLayoutGroup'); class Group extends React.PureComponent { render() { const { children, condensed = false, componentTitle, helpText, componentStyle, theme } = this.props; const className = classNames( condensed && theme.condensed ); const id = getUniqueID(); let helpTextElement = null; let helpTextID: undefined | string; let titleElement = null; let titleID: undefined | string; if (helpText) { helpTextID = `${id}HelpText`; helpTextElement =
{helpText}
; } if (componentTitle) { titleID = `${id}Title`; titleElement =
{componentTitle}
; } const itemsMarkup = React.Children.map(children, child => wrapWithComponent(child, Item)); return (
{titleElement}
{itemsMarkup}
{helpTextElement}
); } } export default themr(FORM_LAYOUT, baseTheme)(Group) as ThemedComponentClass;