Skip to content

Commit b617ca3

Browse files
authored
Merge pull request #853 from rvsia/blueprintWarning
feat(blueprint): implement warning intent
2 parents 4dded57 + 8ef463d commit b617ca3

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/blueprint-component-mapper/src/files/form-group.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ export const FormGroupInternal = ({
2222
}) => {
2323
const { required } = useContext(BlueprintContext);
2424

25-
const { error, touched } = meta;
25+
const { error, touched, warning } = meta;
2626
const showError = (validateOnMount || touched) && error;
27+
const showWarning = (validateOnMount || touched) && warning;
2728

28-
const text = showError ? error : helperText || description;
29+
const text = showError || showWarning || helperText || description;
2930

30-
const intent = showError && error && { intent: Intent.DANGER };
31+
const intent = (showError && { intent: Intent.DANGER }) || (showWarning && { intent: Intent.WARNING });
3132
const labelInfo = !hideLabel && isRequired && { labelInfo: required };
3233

3334
return (

packages/blueprint-component-mapper/src/tests/components.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3+
import { act } from 'react-dom/test-utils';
34

45
import FormRenderer, { componentTypes } from '@data-driven-forms/react-form-renderer';
56
import FormTemplate from '../files/form-template';
@@ -107,6 +108,29 @@ describe('formFields generated tests', () => {
107108
expect(wrapper.find('.bp3-intent-danger').length).toBeGreaterThanOrEqual(1);
108109
});
109110

111+
it('renders with warning', async () => {
112+
const errorField = {
113+
...field,
114+
validate: [{ type: validatorTypes.REQUIRED, warning: true }],
115+
useWarnings: true,
116+
validateOnMount: true
117+
};
118+
let wrapper;
119+
120+
await act(async () => {
121+
wrapper = mount(<RendererWrapper schema={{ fields: [errorField] }} />);
122+
});
123+
wrapper.update();
124+
125+
expect(
126+
wrapper
127+
.find('.bp3-form-helper-text')
128+
.last()
129+
.text()
130+
).toEqual(errorText);
131+
expect(wrapper.find('.bp3-intent-warning').length).toBeGreaterThanOrEqual(1);
132+
});
133+
110134
it('renders with helperText', () => {
111135
const helpertextField = {
112136
...field,

0 commit comments

Comments
 (0)