Skip to content

Commit 9e101be

Browse files
authored
Merge branch 'KelvinTegelaar:dev' into dev
2 parents 4854132 + 45ef541 commit 9e101be

File tree

4 files changed

+124
-71
lines changed

4 files changed

+124
-71
lines changed

src/components/forms/RFFComponents.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
CFormSwitch,
88
CFormTextarea,
99
CSpinner,
10+
CTooltip,
1011
} from '@coreui/react'
1112
import Select from 'react-select'
1213
import AsyncSelect from 'react-select/async'
@@ -75,9 +76,14 @@ RFFCFormCheck.propTypes = {
7576
...sharedPropTypes,
7677
}
7778

79+
function ConditionWrapper({ condition, wrapper, children }) {
80+
return condition ? wrapper(children) : children
81+
}
82+
7883
export const RFFCFormSwitch = ({
7984
name,
8085
label,
86+
helpText,
8187
sublabel,
8288
className = 'mb-3',
8389
validate,
@@ -86,26 +92,36 @@ export const RFFCFormSwitch = ({
8692
return (
8793
<Field name={name} type="checkbox" validate={validate}>
8894
{({ meta, input }) => (
89-
<div className={className}>
90-
<CFormSwitch
91-
{...input}
92-
// @todo revisit this, only shows green when checked
93-
valid={!meta.error && meta.touched && validate}
94-
invalid={meta.error && meta.touched && validate}
95-
disabled={disabled}
96-
id={name}
97-
label={label}
98-
/>
99-
{input.value && <RFFCFormFeedback meta={meta} />}
100-
<sub>{sublabel}</sub>
101-
</div>
95+
<ConditionWrapper
96+
condition={helpText}
97+
wrapper={(children) => (
98+
<CTooltip placement="left" content={helpText}>
99+
{children}
100+
</CTooltip>
101+
)}
102+
>
103+
<div className={className}>
104+
<CFormSwitch
105+
{...input}
106+
// @todo revisit this, only shows green when checked
107+
valid={!meta.error && meta.touched && validate}
108+
invalid={meta.error && meta.touched && validate}
109+
disabled={disabled}
110+
id={name}
111+
label={label}
112+
/>
113+
{input.value && <RFFCFormFeedback meta={meta} />}
114+
<sub>{sublabel}</sub>
115+
</div>
116+
</ConditionWrapper>
102117
)}
103118
</Field>
104119
)
105120
}
106121

107122
RFFCFormSwitch.propTypes = {
108123
...sharedPropTypes,
124+
helpText: PropTypes.string,
109125
}
110126

111127
export const RFFCFormInput = ({

0 commit comments

Comments
 (0)