Skip to content

Commit

Permalink
Make validation error class customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZoker committed Jan 20, 2021
1 parent 7046332 commit e308a00
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/vanilla/Styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- array.table.label → id for the label in the header
- array.table.button → id for the add button
- array.table.validation → id for the validation field
- array.table.validation.error → id for the validation error field
- array.validation.error → id for the validation column if activated
### GroupRenderer
#### Hardcoded ClassNames
Expand All @@ -50,6 +51,8 @@
#### Ids
- control → id for the whole control
- control.label → id for the label of control
- control.validation → id for the validation of control
- control.validation.error → id for the validation error of control
- input.description → id for the description of control

## Example of styling id contributions
Expand Down
2 changes: 1 addition & 1 deletion packages/vanilla/src/complex/TableArrayControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TableArrayControl extends React.Component<ArrayControlProps & VanillaRende
const labelObject = createLabelDescriptionFrom(controlElement, schema);
const isValid = errors.length === 0;
const divClassNames = [validationClass]
.concat(isValid ? '' : ' validation_error')
.concat(isValid ? '' : getStyleAsClassName('array.table.validation.error'))
.join(' ');
const labelText = isPlainLabel(label) ? label : label.default;

Expand Down
2 changes: 1 addition & 1 deletion packages/vanilla/src/controls/InputControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class InputControl extends Control<
const isValid = errors.length === 0;

const divClassNames = [classNames.validation]
.concat(isValid ? classNames.description : 'validation_error')
.concat(isValid ? classNames.description : classNames.validationError)
.join(' ');

const appliedUiSchemaOptions = merge({}, config, uischema.options);
Expand Down
8 changes: 8 additions & 0 deletions packages/vanilla/src/styles/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const vanillaStyles: StyleDef[] = [
name: 'control.select',
classNames: ['select']
},
{
name: 'control.validation.error',
classNames: ['validation_error']
},
{
name: 'control.validation',
classNames: ['validation']
Expand Down Expand Up @@ -97,6 +101,10 @@ export const vanillaStyles: StyleDef[] = [
name: 'vertical.layout',
classNames: ['vertical-layout']
},
{
name: 'array.table.validation.error',
classNames: ['validation_error']
},
{
name: 'array.table.validation',
classNames: ['validation']
Expand Down
8 changes: 6 additions & 2 deletions packages/vanilla/src/util/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const addVanillaControlProps = <P extends StatePropsOfControl>(
const labelClass = getStyleAsClassName(state)('control.label');
const descriptionClassName = getStyleAsClassName(state)('input.description');
const validationClassName = getStyleAsClassName(state)('control.validation');
const validationErrorClassName = getStyleAsClassName(state)('control.validation.error');
const inputClassName = ['validate'].concat(isValid ? 'valid' : 'invalid');

return {
Expand All @@ -83,7 +84,8 @@ export const addVanillaControlProps = <P extends StatePropsOfControl>(
input: inputClassName.join(' '),
label: labelClass,
description: descriptionClassName,
validation: validationClassName
validation: validationClassName,
validationError: validationErrorClassName
}
};
};
Expand All @@ -106,6 +108,7 @@ export const withVanillaControlProps = (Component: ComponentType<any>) => (props
const labelClass = findStyleAsClassName(contextStyles)('control.label');
const descriptionClassName = findStyleAsClassName(contextStyles)('input.description');
const validationClassName = findStyleAsClassName(contextStyles)('control.validation');
const validationErrorClassName = findStyleAsClassName(contextStyles)('control.validation.error');
const inputClassName = ['validate'].concat(isValid ? 'valid' : 'invalid');
return (
<Component
Expand All @@ -117,7 +120,8 @@ export const withVanillaControlProps = (Component: ComponentType<any>) => (props
input: inputClassName.join(' '),
label: labelClass,
description: descriptionClassName,
validation: validationClassName
validation: validationClassName,
validationError: validationErrorClassName
}}
/>
);
Expand Down

0 comments on commit e308a00

Please sign in to comment.