1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { isEmpty } from 'lodash' ;
4
- import { Label , InputDescription , InputErrors } from 'strapi-helper-plugin' ;
4
+ import { LabelIconWrapper } from 'strapi-helper-plugin' ;
5
5
import Editor from '../editorjs' ;
6
6
7
- const Wysiwyg = ( {
8
- inputDescription,
9
- errors,
10
- label,
11
- name,
12
- noErrorsDescription,
13
- onChange,
14
- value,
15
- } ) => {
7
+ import cn from 'classnames' ;
8
+ import { Description , ErrorMessage , Label } from '@buffetjs/styles' ;
9
+ import { Error } from '@buffetjs/core' ;
10
+ import Wrapper from './wrapper' ;
16
11
17
- return (
18
- < div
19
- style = { {
20
- marginBottom : '1.6rem' ,
21
- fontSize : '1.3rem' ,
22
- fontFamily : 'Lato' ,
23
- } }
24
- >
25
- < Label
26
- htmlFor = { name }
27
- message = { label }
28
- style = { { marginBottom : 10 } }
29
- />
30
- < Editor
31
- name = { name }
32
- onChange = { onChange }
33
- value = { value }
34
- />
35
- < InputDescription
36
- message = { inputDescription }
37
- style = { ! isEmpty ( inputDescription ) ? { marginTop : '1.4rem' } : { } }
38
- />
39
- < InputErrors
40
- errors = { ( ! noErrorsDescription && errors ) || [ ] }
41
- name = { name }
42
- />
43
- </ div >
44
- ) ;
45
- } ;
12
+ // eslint-disable-next-line react/prefer-stateless-function
13
+ class WysiwygWithErrors extends React . Component {
14
+ render ( ) {
15
+ const {
16
+ autoFocus,
17
+ className,
18
+ deactivateErrorHighlight,
19
+ disabled,
20
+ error : inputError ,
21
+ inputClassName,
22
+ inputDescription,
23
+ inputStyle,
24
+ label,
25
+ labelIcon,
26
+ name,
27
+ onBlur : handleBlur ,
28
+ onChange,
29
+ placeholder,
30
+ resetProps,
31
+ style,
32
+ tabIndex,
33
+ validations,
34
+ value,
35
+ ...rest
36
+ } = this . props ;
37
+
38
+ return (
39
+ < Error inputError = { inputError } name = { name } type = "text" validations = { validations } >
40
+ { ( { canCheck, onBlur, error, dispatch } ) => {
41
+ const hasError = Boolean ( error ) ;
42
+
43
+ return (
44
+ < Wrapper
45
+ className = { `${ cn ( ! isEmpty ( className ) && className ) } ${ hasError ? 'bordered' : '' } ` }
46
+ style = { style }
47
+ >
48
+ < Label htmlFor = { name } >
49
+ < span > { label } </ span >
50
+ { labelIcon && (
51
+ < LabelIconWrapper title = { labelIcon . title } > { labelIcon . icon } </ LabelIconWrapper >
52
+ ) }
53
+ </ Label >
54
+ < Editor
55
+ name = { name }
56
+ onChange = { onChange }
57
+ value = { value }
58
+ />
59
+ { ! hasError && inputDescription && < Description > { inputDescription } </ Description > }
60
+ { hasError && < ErrorMessage > { error } </ ErrorMessage > }
61
+ </ Wrapper >
62
+ ) ;
63
+ } }
64
+ </ Error >
65
+ ) ;
66
+ }
67
+ }
46
68
47
- Wysiwyg . defaultProps = {
48
- errors : [ ] ,
49
- inputDescription : null ,
69
+ WysiwygWithErrors . defaultProps = {
70
+ autoFocus : false ,
71
+ className : '' ,
72
+ deactivateErrorHighlight : false ,
73
+ didCheckErrors : false ,
74
+ disabled : false ,
75
+ error : null ,
76
+ inputClassName : '' ,
77
+ inputDescription : '' ,
78
+ inputStyle : { } ,
50
79
label : '' ,
51
- noErrorsDescription : false ,
52
- value : '' ,
80
+ labelIcon : null ,
81
+ onBlur : false ,
82
+ placeholder : '' ,
83
+ resetProps : false ,
84
+ style : { } ,
85
+ tabIndex : '0' ,
86
+ validations : { } ,
87
+ value : null ,
53
88
} ;
54
89
55
- Wysiwyg . propTypes = {
56
- errors : PropTypes . array ,
90
+ WysiwygWithErrors . propTypes = {
91
+ autoFocus : PropTypes . bool ,
92
+ className : PropTypes . string ,
93
+ deactivateErrorHighlight : PropTypes . bool ,
94
+ didCheckErrors : PropTypes . bool ,
95
+ disabled : PropTypes . bool ,
96
+ error : PropTypes . string ,
97
+ inputClassName : PropTypes . string ,
57
98
inputDescription : PropTypes . oneOfType ( [
58
99
PropTypes . string ,
59
100
PropTypes . func ,
@@ -62,6 +103,7 @@ Wysiwyg.propTypes = {
62
103
params : PropTypes . object ,
63
104
} ) ,
64
105
] ) ,
106
+ inputStyle : PropTypes . object ,
65
107
label : PropTypes . oneOfType ( [
66
108
PropTypes . string ,
67
109
PropTypes . func ,
@@ -70,10 +112,19 @@ Wysiwyg.propTypes = {
70
112
params : PropTypes . object ,
71
113
} ) ,
72
114
] ) ,
115
+ labelIcon : PropTypes . shape ( {
116
+ icon : PropTypes . node . isRequired ,
117
+ title : PropTypes . string ,
118
+ } ) ,
73
119
name : PropTypes . string . isRequired ,
74
- noErrorsDescription : PropTypes . bool ,
120
+ onBlur : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . func ] ) ,
75
121
onChange : PropTypes . func . isRequired ,
122
+ placeholder : PropTypes . string ,
123
+ resetProps : PropTypes . bool ,
124
+ style : PropTypes . object ,
125
+ tabIndex : PropTypes . string ,
126
+ validations : PropTypes . object ,
76
127
value : PropTypes . string ,
77
128
} ;
78
129
79
- export default Wysiwyg ;
130
+ export default WysiwygWithErrors ;
0 commit comments