-
Notifications
You must be signed in to change notification settings - Fork 126
/
ErrorRenderer.tsx
61 lines (58 loc) · 1.7 KB
/
ErrorRenderer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-disable react/display-name */
import React from 'react';
import { TooltipPosition, ValidationTooltip } from './ValidationTooltip';
import { RenderErrorMessage } from './ValidationWrapperInternal';
export function tooltip(pos: TooltipPosition): RenderErrorMessage {
return (control, hasError, validation) => {
return (
<ValidationTooltip
pos={pos}
error={hasError}
render={() => {
if (!validation || !validation.message) {
return null;
}
return (validation && validation.message) || '';
}}
>
{control}
</ValidationTooltip>
);
};
}
export function text(pos: 'bottom' | 'right' = 'right'): RenderErrorMessage {
if (pos === 'right') {
return (control, _hasError, validation) => {
return (
<span style={{ display: 'inline-block' }}>
{control}
<span data-validation-message="text" style={{ marginLeft: '10px', color: '#d43517' }}>
{(validation && validation.message) || ''}
</span>
</span>
);
};
}
return (control, _hasError, validation) => {
return (
<span style={{ position: 'relative', display: 'inline-block' }}>
{control}
<span style={{ position: 'absolute', bottom: 0, left: 0, height: 0 }}>
<span
data-validation-message="text"
style={{
color: '#d43517',
overflow: 'visible',
whiteSpace: 'nowrap',
position: 'absolute',
top: '2px',
left: 0,
}}
>
{(validation && validation.message) || ''}
</span>
</span>
</span>
);
};
}