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

Commit

Permalink
fix: include label for the rich text editor field
Browse files Browse the repository at this point in the history
Strapi V4 has its own design system, and the field label wasn't showing. I'm working on moving over to @strapi/design-system. This commit shows the label.
  • Loading branch information
jaskipper committed Feb 27, 2022
1 parent d83929a commit 73187d7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
39 changes: 27 additions & 12 deletions admin/src/components/Wysiwyg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import cn from 'classnames';
import { Description, ErrorMessage, Label } from "@buffetjs/styles";
import { Error } from "@buffetjs/core";
import Wrapper from './wrapper';
import { useIntl } from 'react-intl';
import { Box } from '@strapi/design-system/Box';
import { Typography } from '@strapi/design-system/Typography';


// eslint-disable-next-line react/prefer-stateless-function
class WysiwygWithErrors extends React.Component {
Expand All @@ -22,7 +26,10 @@ class WysiwygWithErrors extends React.Component {
inputDescription,
inputStyle,
label,
description,
intlLabel,
labelIcon,
required,
name,
onBlur: handleBlur,
onChange,
Expand All @@ -44,24 +51,32 @@ class WysiwygWithErrors extends React.Component {
>
{({ canCheck, onBlur, error, dispatch }) => {
const hasError = Boolean(error);
const { formatMessage } = useIntl();

return (

<Wrapper size={1} className={`${cn(!isEmpty(className) && className)} ${hasError ? 'bordered' : ''}`}
style={style}>
<Label htmlFor={name}>
<span>{label}</span>
{labelIcon && (
<LabelIconWrapper title={labelIcon.title}>
{labelIcon.icon}
</LabelIconWrapper>
<Wrapper size={1} className={`${cn(!isEmpty(className) && className)} ${hasError ? 'bordered' : ''}`} style={style}>

<Box>
<Typography variant="pi" fontWeight="bold">
{formatMessage(intlLabel)}
</Typography>
{required && (
<Typography variant="pi" fontWeight="bold" textColor="danger600">
*
</Typography>
)}
</Label>
</Box>
<Editor name={name} onChange={onChange} value={value} />
{!hasError && inputDescription && (
<Description>{inputDescription}</Description>
{error && (
<Typography variant="pi" textColor="danger600">
{formatMessage({ id: error, defaultMessage: error })}
</Typography>
)}
{description && (
<Typography variant="pi">{formatMessage(description)}</Typography>
)}
{hasError && <ErrorMessage>{error}</ErrorMessage>}

</Wrapper>
);
}}
Expand Down
7 changes: 3 additions & 4 deletions admin/src/components/Wysiwyg/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import styled from 'styled-components';
import { Box } from "@strapi/design-system/Box";

const Wrapper = styled(Box)`
padding-bottom: 2.8rem;
@media (min-width: 651px) {
.codex-editor--narrow .codex-editor__redactor {
margin-right: 0;
}
}
.codex-editor {
padding: 1rem;
font-size: 1rem;
font-family: "Lato";
}
*:focus-visible {
outline: none;
Expand Down Expand Up @@ -37,9 +40,6 @@ const Wrapper = styled(Box)`
font-size: .67em;
font-weight: bold;
}
padding-bottom: 2.8rem;
font-size: 1rem;
font-family: "Lato";
label {
display: block;
margin-bottom: 1rem;
Expand All @@ -59,7 +59,6 @@ const Wrapper = styled(Box)`
text-overflow: ellipsis;
margin-bottom: -9px;
}
div,
pre,
code {
Expand Down
2 changes: 1 addition & 1 deletion admin/src/components/editorjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Editor = ({ onChange, name, value }) => {

return (
<>
<div style={{ border: `1px solid rgb(227, 233, 243)`, borderRadius: `2px` }}>
<div style={{ border: `1px solid rgb(227, 233, 243)`, borderRadius: `2px`, marginTop: `4px` }}>
<EditorJs
// data={JSON.parse(value)}
// enableReInitialize={true}
Expand Down
4 changes: 4 additions & 0 deletions admin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default {
blockerComponentProps: {},
description: pluginDescription,
icon: pluginPkg.strapi.icon,
intlLabel: {
id: pluginId,
defaultMessage: pluginId
},
id: pluginId,
initializer: () => null,
injectedComponents: [],
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1714,11 +1714,6 @@ duplexer2@~0.1.0:
dependencies:
readable-stream "^2.0.2"

editorjs-alert@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/editorjs-alert/-/editorjs-alert-1.0.3.tgz#880890b7006f5f09f67d8bb8446aceb4769b66ce"
integrity sha512-YsKp0BBmswueE2zh0Lj2YflFA/9pvguHTSsy6uh00p3lattflW33ow4CSYD0JFe3y+TqqD8VoB/IlS7C9fKu0Q==

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
Expand Down

0 comments on commit 73187d7

Please sign in to comment.