Skip to content

Commit

Permalink
feat: support drupal wrapper and label css classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Feb 4, 2020
1 parent 3227395 commit b2440c8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/WebformElementWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,31 @@ export function isElementHidden(states: WebformSettings['states']): boolean {
return states.invisible === true || states.visible === false
}

function classNames(list: Array<undefined | false | string>) {
const className = list.filter(item => typeof item === 'string').join(' ')

return className.length > 0 ? className : undefined
}

const ElementWrapper: React.FC<Props> = ({ children, settings, error, labelFor, labelClassName, ...props }) => {
const { states, attributes } = settings

const wrapperClassNames = classNames(['form-group', error != null && 'is-invalid', props.className, attributes.wrapper_class])
// todo: pass required prop here and add css class 'required' etc. to label.
const labelClassNames = classNames([labelClassName, attributes.label_class])

if (states && isElementHidden(states)) {
return <></>
}

const label = (
<label style={getTileStyle(attributes)} className={labelClassName} htmlFor={labelFor}>
<label style={getTileStyle(attributes)} className={labelClassNames} htmlFor={labelFor}>
{attributes.title}
</label>
)

const classNames = ['form-group', error != null && 'is-invalid', props.className].filter(item => typeof item === 'string').join(' ')

return (
<div {...props} className={classNames}>
<div {...props} className={wrapperClassNames}>
{getTitleDisplay(attributes) === 'before' && label}

{children}
Expand Down

0 comments on commit b2440c8

Please sign in to comment.