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, lineWrapping: true,
extraKeys: { extraKeys: {
Enter: 'newlineAndIndentContinueMarkdownList', Enter: 'newlineAndIndentContinueMarkdownList',
// Leaving this commented for now Tab: false,
// Tab: false, 'Shift-Tab': false,
// 'Shift-Tab': false,
}, },
readOnly: false, readOnly: false,
smartIndent: false, smartIndent: false,

View File

@ -68,6 +68,7 @@ export const EditorLayout = ({ children, isExpandMode, error, previewContent, on
bottom={0} bottom={0}
zIndex={4} zIndex={4}
justifyContent="center" justifyContent="center"
onClick={onCollapse}
> >
<Box <Box
id="wysiwyg-expand" id="wysiwyg-expand"
@ -77,6 +78,7 @@ export const EditorLayout = ({ children, isExpandMode, error, previewContent, on
overflow="hidden" overflow="hidden"
width="70%" width="70%"
height="70%" height="70%"
onClick={e => e.stopPropagation()}
> >
<Flex height="100%" alignItems="flex-start"> <Flex height="100%" alignItems="flex-start">
<BoxWithBorder flex="1" height="100%"> <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 Expand from '@strapi/icons/Expand';
import { ExpandButton } from './WysiwygStyles'; import { ExpandButton } from './WysiwygStyles';
const WysiwygFooter = ({ isPreviewMode, onToggleExpand }) => { const WysiwygFooter = ({ onToggleExpand }) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
return ( return (
<Box padding={2} background="neutral100" hasRadius> <Box padding={2} background="neutral100" hasRadius>
<Flex justifyContent="flex-end" alignItems="flex-end"> <Flex justifyContent="flex-end" alignItems="flex-end">
<ExpandButton id="expand" disabled={isPreviewMode} onClick={onToggleExpand}> <ExpandButton id="expand" onClick={onToggleExpand}>
<Typography> <Typography>
{formatMessage({ {formatMessage({
id: 'components.WysiwygBottomControls.fullscreen', id: 'components.WysiwygBottomControls.fullscreen',
@ -29,12 +29,10 @@ const WysiwygFooter = ({ isPreviewMode, onToggleExpand }) => {
WysiwygFooter.defaultProps = { WysiwygFooter.defaultProps = {
onToggleExpand: () => {}, onToggleExpand: () => {},
isPreviewMode: false,
}; };
WysiwygFooter.propTypes = { WysiwygFooter.propTypes = {
onToggleExpand: PropTypes.func, onToggleExpand: PropTypes.func,
isPreviewMode: PropTypes.bool,
}; };
export default WysiwygFooter; export default WysiwygFooter;

View File

@ -1,6 +1,7 @@
import React, { useRef, useState } from 'react'; import React, { useRef, useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { FocusTrap } from '@strapi/design-system/FocusTrap';
import { Box } from '@strapi/design-system/Box'; import { Box } from '@strapi/design-system/Box';
import { Button } from '@strapi/design-system/Button'; import { Button } from '@strapi/design-system/Button';
import { IconButtonGroup } from '@strapi/design-system/IconButton'; import { IconButtonGroup } from '@strapi/design-system/IconButton';
@ -41,7 +42,9 @@ const WysiwygNav = ({
}); });
const buttonMoreRef = useRef(); const buttonMoreRef = useRef();
const handleTogglePopover = () => setVisiblePopover(prev => !prev); const handleTogglePopover = () => {
setVisiblePopover(prev => !prev);
};
if (isPreviewMode) { if (isPreviewMode) {
return ( return (
@ -81,10 +84,10 @@ const WysiwygNav = ({
/> />
</MainButtons> </MainButtons>
<MoreButton disabled ref={buttonMoreRef} id="more" label="More" icon={<More />} /> <MoreButton disabled id="more" label="More" icon={<More />} />
</Flex> </Flex>
<Button onClick={onTogglePreviewMode} variant="tertiary" size="L" id="preview"> <Button onClick={onTogglePreviewMode} variant="tertiary" id="preview">
{formatMessage({ {formatMessage({
id: 'components.Wysiwyg.ToggleMode.markdown-mode', id: 'components.Wysiwyg.ToggleMode.markdown-mode',
defaultMessage: 'Markdown mode', defaultMessage: 'Markdown mode',
@ -146,6 +149,7 @@ const WysiwygNav = ({
/> />
{visiblePopover && ( {visiblePopover && (
<Popover centered source={buttonMoreRef} spacing={4} id="popover"> <Popover centered source={buttonMoreRef} spacing={4} id="popover">
<FocusTrap onEscape={handleTogglePopover}>
<Flex> <Flex>
<IconButtonGroupMargin> <IconButtonGroupMargin>
<CustomIconButton <CustomIconButton
@ -205,6 +209,7 @@ const WysiwygNav = ({
/> />
</IconButtonGroup> </IconButtonGroup>
</Flex> </Flex>
</FocusTrap>
</Popover> </Popover>
)} )}
</Flex> </Flex>

View File

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