Skip to content

Commit 5ac5620

Browse files
authored
Merge pull request #855 from rvsia/carbonWarning
feat(carbon): add warning support
2 parents 17eda81 + 25533cb commit 5ac5620

File tree

13 files changed

+86
-29
lines changed

13 files changed

+86
-29
lines changed

packages/carbon-component-mapper/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
3131
"@babel/preset-env": "^7.1.6",
3232
"@babel/preset-react": "^7.0.0",
33-
"@carbon/icons-react": "^10.18.0",
33+
"@carbon/icons-react": "^10.19.0",
3434
"@semantic-release/git": "^7.0.5",
3535
"@semantic-release/npm": "^5.1.1",
3636
"@types/carbon-components-react": "^7.10.9",
@@ -39,8 +39,8 @@
3939
"babel-jest": "^23.6.0",
4040
"babel-loader": "^8.0.4",
4141
"babel-plugin-lodash": "^3.3.4",
42-
"carbon-components": "^10.20.0",
43-
"carbon-components-react": "^7.20.0",
42+
"carbon-components": "^10.22.0",
43+
"carbon-components-react": "^7.22.0",
4444
"carbon-icons": "^7.0.7",
4545
"clsx": "^1.1.1",
4646
"css-loader": "^1.0.1",

packages/carbon-component-mapper/src/common/helper-text-block.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import PropTypes from 'prop-types';
33

44
import './helper-text-block.scss';
55

6-
const HelperTextBlock = ({ helperText, errorText }) => {
6+
const HelperTextBlock = ({ helperText, errorText, warnText }) => {
77
if (errorText) {
88
return <div className="bx--form-requirement ddorg__carbon-error-helper-text">{errorText}</div>;
99
}
1010

11+
if (warnText) {
12+
return <div className="bx--form-requirement ddorg__carbon-warning-helper-text">{warnText}</div>;
13+
}
14+
1115
if (helperText) {
1216
return <div className="bx--form__helper-text">{helperText}</div>;
1317
}
@@ -17,7 +21,8 @@ const HelperTextBlock = ({ helperText, errorText }) => {
1721

1822
HelperTextBlock.propTypes = {
1923
helperText: PropTypes.node,
20-
errorText: PropTypes.node
24+
errorText: PropTypes.node,
25+
warnText: PropTypes.node
2126
};
2227

2328
export default HelperTextBlock;

packages/carbon-component-mapper/src/files/checkbox.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ const SingleCheckbox = (props) => {
3333

3434
const invalid = (meta.touched || validateOnMount) && meta.error;
3535

36+
const warnText = (meta.touched || validateOnMount) && meta.warning;
37+
3638
return (
3739
<div {...WrapperProps}>
3840
<CarbonCheckbox {...input} id={input.name} {...rest} />
39-
<HelperTextBlock helperText={helperText} errorText={invalid} />
41+
<HelperTextBlock helperText={helperText} errorText={invalid} warnText={warnText} />
4042
</div>
4143
);
4244
};

packages/carbon-component-mapper/src/files/date-picker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ const DatePicker = (props) => {
1111
const { input, datePickerType, meta, DatePickerProps, validateOnMount, helperText, WrapperProps, ...rest } = useFieldApi(prepareProps(props));
1212

1313
const invalid = (meta.touched || validateOnMount) && meta.error;
14+
const warnText = (meta.touched || validateOnMount) && meta.warning;
1415

1516
return (
1617
<div {...WrapperProps}>
1718
<CarbonDatePicker {...input} datePickerType={datePickerType} {...DatePickerProps}>
1819
<DatePickerInput id={input.name} invalid={Boolean(invalid)} invalidText={invalid ? invalid : ''} {...rest} />
1920
</CarbonDatePicker>
20-
<HelperTextBlock helperText={!invalid && helperText} />
21+
<HelperTextBlock helperText={!invalid && helperText} warnText={warnText} />
2122
</div>
2223
);
2324
};

packages/carbon-component-mapper/src/files/radio.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const Radio = (props) => {
1313
);
1414

1515
const invalid = (meta.touched || validateOnMount) && meta.error;
16+
const warnText = (meta.touched || validateOnMount) && meta.warning;
1617

1718
return (
1819
<FormGroup legendText={labelText} {...FormGroupProps}>
@@ -21,7 +22,7 @@ const Radio = (props) => {
2122
<RadioButton key={option.value} disabled={disabled} labelText={option.label} value={option.value} {...option} />
2223
))}
2324
</RadioButtonGroup>
24-
<HelperTextBlock helperText={helperText} errorText={invalid} />
25+
<HelperTextBlock helperText={helperText} errorText={invalid} warnText={warnText} />
2526
</FormGroup>
2627
);
2728
};

packages/carbon-component-mapper/src/files/select.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ ClearedSelect.propTypes = {
166166
};
167167

168168
const Select = (props) => {
169-
const { isMulti, isSearchable, loadOptions, input, meta, validateOnMount, ...rest } = useFieldApi(prepareProps(props));
169+
const { isMulti, isSearchable, loadOptions, input, meta, validateOnMount, helperText, ...rest } = useFieldApi(prepareProps(props));
170170

171171
const [loadOptionsChangeCounter, setCounter] = useState(0);
172172

@@ -180,6 +180,7 @@ const Select = (props) => {
180180
const Component = isMulti && isSearchable ? ClearedMultiSelectFilterable : isMulti ? ClearedMultiSelect : ClearedSelect;
181181

182182
const invalidText = ((meta.touched || validateOnMount) && meta.error) || '';
183+
const text = ((meta.touched || validateOnMount) && meta.warning) || helperText;
183184

184185
return (
185186
<DataDrivenSelect
@@ -191,6 +192,7 @@ const Select = (props) => {
191192
invalidText={invalidText}
192193
loadOptionsChangeCounter={loadOptionsChangeCounter}
193194
originalOnChange={multiOnChange(input, rest.simpleValue)}
195+
helperText={text}
194196
/>
195197
);
196198
};

packages/carbon-component-mapper/src/files/slider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const Slider = (props) => {
1111
const { input, meta, isRequired, validateOnMount, helperText, WrapperProps, ...rest } = useFieldApi(prepareProps(props));
1212

1313
const invalid = (meta.touched || validateOnMount) && meta.error;
14+
const warnText = (meta.touched || validateOnMount) && meta.warning;
1415

1516
return (
1617
<div {...WrapperProps}>
@@ -25,7 +26,7 @@ const Slider = (props) => {
2526
required={isRequired}
2627
{...rest}
2728
/>
28-
<HelperTextBlock helperText={helperText} errorText={invalid} />
29+
<HelperTextBlock helperText={helperText} errorText={invalid} warnText={warnText} />
2930
</div>
3031
);
3132
};

packages/carbon-component-mapper/src/files/switch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ const Switch = (props) => {
1111
const { input, meta, onText, offText, validateOnMount, helperText, WrapperProps, ...rest } = useFieldApi(prepareProps(props));
1212

1313
const invalid = (meta.touched || validateOnMount) && meta.error;
14+
const warnText = (meta.touched || validateOnMount) && meta.warning;
1415

1516
return (
1617
<div {...WrapperProps}>
1718
<Toggle {...input} key={input.name} id={input.name} labelA={offText} labelB={onText} {...rest} />
18-
<HelperTextBlock helperText={helperText} errorText={invalid} />
19+
<HelperTextBlock helperText={helperText} errorText={invalid} warnText={warnText} />
1920
</div>
2021
);
2122
};

packages/carbon-component-mapper/src/files/text-field.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ const TextField = (props) => {
1010
const { input, meta, validateOnMount, ...rest } = useFieldApi(prepareProps(props));
1111

1212
const invalid = (meta.touched || validateOnMount) && meta.error;
13+
const warn = (meta.touched || validateOnMount) && meta.warning;
1314

14-
return <TextInput {...input} key={input.name} id={input.name} invalid={Boolean(invalid)} invalidText={invalid || ''} {...rest} />;
15+
return (
16+
<TextInput
17+
{...input}
18+
key={input.name}
19+
id={input.name}
20+
invalid={Boolean(invalid)}
21+
invalidText={invalid || ''}
22+
warn={Boolean(warn)}
23+
warnText={warn || ''}
24+
{...rest}
25+
/>
26+
);
1527
};
1628

1729
TextField.propTypes = {

packages/carbon-component-mapper/src/files/textarea.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { TextArea } from 'carbon-components-react';
77
import prepareProps from '../common/prepare-props';
88

99
const Textarea = (props) => {
10-
const { input, meta, validateOnMount, ...rest } = useFieldApi(prepareProps(props));
10+
const { input, meta, validateOnMount, helperText, ...rest } = useFieldApi(prepareProps(props));
1111

1212
const invalid = (meta.touched || validateOnMount) && meta.error;
13+
const text = ((meta.touched || validateOnMount) && meta.warning) || helperText;
1314

14-
return <TextArea {...input} key={input.name} id={input.name} invalid={Boolean(invalid)} invalidText={invalid || ''} {...rest} />;
15+
return <TextArea {...input} key={input.name} id={input.name} invalid={Boolean(invalid)} invalidText={invalid || ''} helperText={text} {...rest} />;
1516
};
1617

1718
Textarea.propTypes = {
@@ -20,7 +21,8 @@ Textarea.propTypes = {
2021
isRequired: PropTypes.bool,
2122
label: PropTypes.node,
2223
labelText: PropTypes.node,
23-
description: PropTypes.node
24+
description: PropTypes.node,
25+
helperText: PropTypes.node
2426
};
2527

2628
export default Textarea;

0 commit comments

Comments
 (0)