Skip to content

Commit

Permalink
feat: add valid class to classNames utility
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 14, 2020
1 parent bd67de2 commit cf19610
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const cn = classNames(res, {
untested: 'is-untested', // will only be applied if the provided field did not run yet
tested: 'some-tested-class', // will only be applied if the provided field did run
invalid: 'my_invalid_class', // will only be applied if the provided field ran at least once and has an errror
valid: 'my_valid_class', // will only be applied if the provided field ran at least once does not have errors or warnings
warning: 'my_warning_class', // will only be applied if the provided field ran at least once and has a warning
});

Expand Down
2 changes: 2 additions & 0 deletions packages/vest/src/utilities/classNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const classNames = (res, classes = {}) => {
selectors.untested = key => !selectors.tested(key);
selectors.invalid = key => selectors.tested(key) && res.hasErrors(key);
selectors.warning = key => selectors.tested(key) && res.hasWarnings(key);
selectors.valid = key =>
selectors.tested(key) && !res.hasWarnings(key) && !res.hasErrors(key);

return key => {
const classesArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/vest/src/utilities/tests/classNames.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('Utility: classNames', () => {
invalid: 'invalid_string',
tested: 'tested_string',
untested: 'untested_string',
valid: 'valid_string',
warning: 'warning_string',
});

Expand All @@ -54,7 +55,7 @@ describe('Utility: classNames', () => {
'tested_string warning_string'.split(' ').sort()
);
expect(genClass('field_4').split(' ').sort()).toEqual(
'tested_string'.split(' ').sort()
'tested_string valid_string'.split(' ').sort()
);

expect(genClass('field_5').split(' ').sort()).toEqual(
Expand Down

0 comments on commit cf19610

Please sign in to comment.