Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit c207875

Browse files
committed
🛠 Added style
1 parent 6431682 commit c207875

File tree

3 files changed

+156
-63
lines changed

3 files changed

+156
-63
lines changed

admin/src/components/Wysiwyg/index.js

100644100755
Lines changed: 99 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,100 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { isEmpty } from 'lodash';
4-
import { Label, InputDescription, InputErrors } from 'strapi-helper-plugin';
4+
import { LabelIconWrapper } from 'strapi-helper-plugin';
55
import Editor from '../editorjs';
66

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';
1611

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+
}
4668

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: {},
5079
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,
5388
};
5489

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,
5798
inputDescription: PropTypes.oneOfType([
5899
PropTypes.string,
59100
PropTypes.func,
@@ -62,6 +103,7 @@ Wysiwyg.propTypes = {
62103
params: PropTypes.object,
63104
}),
64105
]),
106+
inputStyle: PropTypes.object,
65107
label: PropTypes.oneOfType([
66108
PropTypes.string,
67109
PropTypes.func,
@@ -70,10 +112,19 @@ Wysiwyg.propTypes = {
70112
params: PropTypes.object,
71113
}),
72114
]),
115+
labelIcon: PropTypes.shape({
116+
icon: PropTypes.node.isRequired,
117+
title: PropTypes.string,
118+
}),
73119
name: PropTypes.string.isRequired,
74-
noErrorsDescription: PropTypes.bool,
120+
onBlur: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
75121
onChange: PropTypes.func.isRequired,
122+
placeholder: PropTypes.string,
123+
resetProps: PropTypes.bool,
124+
style: PropTypes.object,
125+
tabIndex: PropTypes.string,
126+
validations: PropTypes.object,
76127
value: PropTypes.string,
77128
};
78129

79-
export default Wysiwyg;
130+
export default WysiwygWithErrors;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import styled from 'styled-components';
2+
3+
const Wrapper = styled.div`
4+
padding-bottom: 2.8rem;
5+
font-size: 1.3rem;
6+
font-family: 'Lato';
7+
label {
8+
display: block;
9+
margin-bottom: 1rem;
10+
}
11+
&.bordered {
12+
.editorWrapper {
13+
border-color: red;
14+
}
15+
}
16+
> div + p {
17+
width: 100%;
18+
padding-top: 12px;
19+
font-size: 1.2rem;
20+
line-height: normal;
21+
white-space: nowrap;
22+
overflow: hidden;
23+
text-overflow: ellipsis;
24+
margin-bottom: -9px;
25+
}
26+
27+
div,
28+
pre,
29+
code {
30+
::-webkit-scrollbar {
31+
height: 5px;
32+
width: 5px;
33+
cursor: default;
34+
}
35+
}
36+
`;
37+
38+
export default Wrapper;

admin/src/components/editorjs/index.js

100644100755
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,25 @@ const Editor = ({ onChange, name, value }) => {
3939

4040
return (
4141
<>
42-
<EditorJs
43-
data={JSON.parse(value)}
44-
onReady={(api) => {
45-
if(value) {
46-
api.blocks.render(JSON.parse(value))
47-
}
48-
document.querySelector('[data-tool="image"]').remove()
49-
}}
50-
onChange={(api, newData) => {
51-
onChange({ target: { name, value: JSON.stringify(newData) } })}
52-
}
53-
tools={{...EditorTools, ...customImageTool}}
54-
instanceRef={instance => setEditorInstance(instance)}
55-
style={{border: `1px solid red`}}
56-
/>
42+
<div style={{ border: `1px solid rgb(227, 233, 243)`, borderRadius: `2px` }}>
43+
<EditorJs
44+
// data={JSON.parse(value)}
45+
// enableReInitialize={true}
46+
onReady={(api) => {
47+
if(value && JSON.parse(value).blocks.length) {
48+
api.blocks.render(JSON.parse(value))
49+
}
50+
document.querySelector('[data-tool="image"]').remove()
51+
}}
52+
onChange={(api, newData) => {
53+
if (newData.blocks.length) {
54+
onChange({target: {name, value: JSON.stringify(newData)}})
55+
}
56+
}}
57+
tools={{...EditorTools, ...customImageTool}}
58+
instanceRef={instance => setEditorInstance(instance)}
59+
/>
60+
</div>
5761
<MediaLibComponent
5862
toggle={mediaLibToggleFunc}
5963
isOpen={isMediaLibOpen}

0 commit comments

Comments
 (0)