Some UI fix for the WYSIWYG

Signed-off-by: HichamELBSI <elabbassih@gmail.com>
This commit is contained in:
HichamELBSI 2022-01-10 12:42:37 +01:00
parent a666e0a4b4
commit 54c80d9a87
5 changed files with 78 additions and 73 deletions

View File

@ -25,9 +25,8 @@ const Editor = ({
lineWrapping: true,
extraKeys: {
Enter: 'newlineAndIndentContinueMarkdownList',
// Leaving this commented for now
// Tab: false,
// 'Shift-Tab': false,
Tab: false,
'Shift-Tab': false,
},
readOnly: false,
smartIndent: false,

View File

@ -68,6 +68,7 @@ export const EditorLayout = ({ children, isExpandMode, error, previewContent, on
bottom={0}
zIndex={4}
justifyContent="center"
onClick={onCollapse}
>
<Box
id="wysiwyg-expand"
@ -77,6 +78,7 @@ export const EditorLayout = ({ children, isExpandMode, error, previewContent, on
overflow="hidden"
width="70%"
height="70%"
onClick={e => e.stopPropagation()}
>
<Flex height="100%" alignItems="flex-start">
<BoxWithBorder flex="1" height="100%">

View File

@ -7,13 +7,13 @@ import { Typography } from '@strapi/design-system/Typography';
import Expand from '@strapi/icons/Expand';
import { ExpandButton } from './WysiwygStyles';
const WysiwygFooter = ({ isPreviewMode, onToggleExpand }) => {
const WysiwygFooter = ({ onToggleExpand }) => {
const { formatMessage } = useIntl();
return (
<Box padding={2} background="neutral100" hasRadius>
<Flex justifyContent="flex-end" alignItems="flex-end">
<ExpandButton id="expand" disabled={isPreviewMode} onClick={onToggleExpand}>
<ExpandButton id="expand" onClick={onToggleExpand}>
<Typography>
{formatMessage({
id: 'components.WysiwygBottomControls.fullscreen',
@ -29,12 +29,10 @@ const WysiwygFooter = ({ isPreviewMode, onToggleExpand }) => {
WysiwygFooter.defaultProps = {
onToggleExpand: () => {},
isPreviewMode: false,
};
WysiwygFooter.propTypes = {
onToggleExpand: PropTypes.func,
isPreviewMode: PropTypes.bool,
};
export default WysiwygFooter;

View File

@ -1,6 +1,7 @@
import React, { useRef, useState } from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { FocusTrap } from '@strapi/design-system/FocusTrap';
import { Box } from '@strapi/design-system/Box';
import { Button } from '@strapi/design-system/Button';
import { IconButtonGroup } from '@strapi/design-system/IconButton';
@ -41,7 +42,9 @@ const WysiwygNav = ({
});
const buttonMoreRef = useRef();
const handleTogglePopover = () => setVisiblePopover(prev => !prev);
const handleTogglePopover = () => {
setVisiblePopover(prev => !prev);
};
if (isPreviewMode) {
return (
@ -81,10 +84,10 @@ const WysiwygNav = ({
/>
</MainButtons>
<MoreButton disabled ref={buttonMoreRef} id="more" label="More" icon={<More />} />
<MoreButton disabled id="more" label="More" icon={<More />} />
</Flex>
<Button onClick={onTogglePreviewMode} variant="tertiary" size="L" id="preview">
<Button onClick={onTogglePreviewMode} variant="tertiary" id="preview">
{formatMessage({
id: 'components.Wysiwyg.ToggleMode.markdown-mode',
defaultMessage: 'Markdown mode',
@ -146,65 +149,67 @@ const WysiwygNav = ({
/>
{visiblePopover && (
<Popover centered source={buttonMoreRef} spacing={4} id="popover">
<Flex>
<IconButtonGroupMargin>
<CustomIconButton
onClick={() => onActionClick('Strikethrough', editorRef, handleTogglePopover)}
id="Strikethrough"
label="Strikethrough"
name="Strikethrough"
icon={<Strikethrough />}
/>
<CustomIconButton
onClick={() => onActionClick('BulletList', editorRef, handleTogglePopover)}
id="BulletList"
label="BulletList"
name="BulletList"
icon={<BulletList />}
/>
<CustomIconButton
onClick={() => onActionClick('NumberList', editorRef, handleTogglePopover)}
id="NumberList"
label="NumberList"
name="NumberList"
icon={<NumberList />}
/>
</IconButtonGroupMargin>
<IconButtonGroup>
<CustomIconButton
onClick={() => onActionClick('Code', editorRef, handleTogglePopover)}
id="Code"
label="Code"
name="Code"
icon={<Code />}
/>
<CustomIconButton
onClick={() => {
handleTogglePopover();
onToggleMediaLib();
}}
id="Image"
label="Image"
name="Image"
icon={<Image />}
/>
<CustomLinkIconButton
onClick={() => onActionClick('Link', editorRef, handleTogglePopover)}
id="Link"
label="Link"
name="Link"
// eslint-disable-next-line jsx-a11y/anchor-is-valid
icon={<Link />}
/>
<CustomIconButton
onClick={() => onActionClick('Quote', editorRef, handleTogglePopover)}
id="Quote"
label="Quote"
name="Quote"
icon={<Quote />}
/>
</IconButtonGroup>
</Flex>
<FocusTrap onEscape={handleTogglePopover}>
<Flex>
<IconButtonGroupMargin>
<CustomIconButton
onClick={() => onActionClick('Strikethrough', editorRef, handleTogglePopover)}
id="Strikethrough"
label="Strikethrough"
name="Strikethrough"
icon={<Strikethrough />}
/>
<CustomIconButton
onClick={() => onActionClick('BulletList', editorRef, handleTogglePopover)}
id="BulletList"
label="BulletList"
name="BulletList"
icon={<BulletList />}
/>
<CustomIconButton
onClick={() => onActionClick('NumberList', editorRef, handleTogglePopover)}
id="NumberList"
label="NumberList"
name="NumberList"
icon={<NumberList />}
/>
</IconButtonGroupMargin>
<IconButtonGroup>
<CustomIconButton
onClick={() => onActionClick('Code', editorRef, handleTogglePopover)}
id="Code"
label="Code"
name="Code"
icon={<Code />}
/>
<CustomIconButton
onClick={() => {
handleTogglePopover();
onToggleMediaLib();
}}
id="Image"
label="Image"
name="Image"
icon={<Image />}
/>
<CustomLinkIconButton
onClick={() => onActionClick('Link', editorRef, handleTogglePopover)}
id="Link"
label="Link"
name="Link"
// eslint-disable-next-line jsx-a11y/anchor-is-valid
icon={<Link />}
/>
<CustomIconButton
onClick={() => onActionClick('Quote', editorRef, handleTogglePopover)}
id="Quote"
label="Quote"
name="Quote"
icon={<Quote />}
/>
</IconButtonGroup>
</Flex>
</FocusTrap>
</Popover>
)}
</Flex>

View File

@ -54,7 +54,10 @@ const Wysiwyg = ({
const handleToggleMediaLib = () => setMediaLibVisible(prev => !prev);
const handleTogglePreviewMode = () => setIsPreviewMode(prev => !prev);
const handleToggleExpand = () => setIsExpandMode(prev => !prev);
const handleToggleExpand = () => {
setIsPreviewMode(false);
setIsExpandMode(prev => !prev);
};
const handleActionClick = (value, currentEditorRef, togglePopover) => {
switch (value) {
@ -160,9 +163,7 @@ const Wysiwyg = ({
value={value}
/>
{!isExpandMode && (
<WysiwygFooter isPreviewMode={isPreviewMode} onToggleExpand={handleToggleExpand} />
)}
{!isExpandMode && <WysiwygFooter onToggleExpand={handleToggleExpand} />}
</EditorLayout>
<Hint description={description} name={name} error={error} />
</Stack>