From 22b9f5cb5867bae89830c33c168021de70cfb5cc Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Thu, 5 Oct 2023 17:32:05 +0530 Subject: [PATCH] feat: Added "Highlight" option to Super formatting toolbars --- .../Components/Icon/IconNameToSvgMapping.tsx | 1 + .../FloatingTextFormatToolbarPlugin.tsx | 229 ++++++++++-------- .../ToolbarPlugins/MobileToolbarPlugin.tsx | 11 +- .../useSelectedTextFormatInfo.ts | 3 + 4 files changed, 148 insertions(+), 96 deletions(-) diff --git a/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx b/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx index 836d3e6c2..8eed74b8a 100644 --- a/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx +++ b/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx @@ -87,6 +87,7 @@ export const IconNameToSvgMapping = { diamond: icons.DiamondIcon, download: icons.DownloadIcon, drag: icons.DragIcon, + draw: icons.DrawIcon, editor: icons.EditorIcon, email: icons.EmailIcon, evernote: icons.EvernoteIcon, diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/FloatingTextFormatToolbarPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/FloatingTextFormatToolbarPlugin.tsx index 7b9b0e8eb..723a394a3 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/FloatingTextFormatToolbarPlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/FloatingTextFormatToolbarPlugin.tsx @@ -38,6 +38,7 @@ import { SubscriptIcon, ListBulleted, ListNumbered, + DrawIcon, } from '@standardnotes/icons' import { IconComponent } from '../../Lexical/Theme/IconComponent' import { classNames } from '@standardnotes/snjs' @@ -49,6 +50,7 @@ import LinkTextEditor, { $isLinkTextNode } from '../LinkEditor/LinkTextEditor' import { URL_REGEX } from '@/Constants/Constants' import { useSelectedTextFormatInfo } from './useSelectedTextFormatInfo' import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery' +import StyledTooltip from '@/Components/StyledTooltip/StyledTooltip' const IconSize = 15 @@ -84,6 +86,7 @@ function TextFormatFloatingToolbar({ isSuperscript, isBulletedList, isNumberedList, + isHighlighted, }: { editor: LexicalEditor anchorElem: HTMLElement @@ -100,6 +103,7 @@ function TextFormatFloatingToolbar({ isUnderline: boolean isBulletedList: boolean isNumberedList: boolean + isHighlighted: boolean }) { const toolbarRef = useRef(null) @@ -312,7 +316,7 @@ function TextFormatFloatingToolbar({ return (
{isLinkText && !isAutoLink && ( <> @@ -338,100 +342,133 @@ function TextFormatFloatingToolbar({ )} {isText && (
- { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold') - }} - aria-label="Format text as bold" - > - - - - - { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic') - }} - active={isItalic} - aria-label="Format text as italics" - > - - - - - { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline') - }} - active={isUnderline} - aria-label="Format text to underlined" - > - - - - - { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough') - }} - active={isStrikethrough} - aria-label="Format text with a strikethrough" - > - - - - - { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'subscript') - }} - active={isSubscript} - title="Subscript" - aria-label="Format Subscript" - > - - - - - { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'superscript') - }} - active={isSuperscript} - title="Superscript" - aria-label="Format Superscript" - > - - - - - { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code') - }} - active={isCode} - aria-label="Insert code block" - > - - - - - - - - - - - - - - - - - - - + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold') + }} + aria-label="Format text as bold" + > + + + + + + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic') + }} + active={isItalic} + aria-label="Format text as italics" + > + + + + + + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline') + }} + active={isUnderline} + aria-label="Format text to underlined" + > + + + + + + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough') + }} + active={isStrikethrough} + aria-label="Format text with a strikethrough" + > + + + + + + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'subscript') + }} + active={isSubscript} + title="Subscript" + aria-label="Format Subscript" + > + + + + + + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'superscript') + }} + active={isSuperscript} + title="Superscript" + aria-label="Format Superscript" + > + + + + + + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code') + }} + active={isCode} + aria-label="Insert code block" + > + + + + + + + { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'highlight') + }} + active={isHighlighted} + aria-label="Highlight text" + > + + + + + + + + + + + + + + + + + + + + + + + + + +
)}
@@ -451,6 +488,7 @@ function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLEle isSuperscript, isUnderline, isCode, + isHighlighted, blockType, } = useSelectedTextFormatInfo() @@ -479,6 +517,7 @@ function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLEle isSuperscript={isSuperscript} isUnderline={isUnderline} isCode={isCode} + isHighlighted={isHighlighted} isBulletedList={blockType === 'bullet'} isNumberedList={blockType === 'number'} />, diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/MobileToolbarPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/MobileToolbarPlugin.tsx index 47e53796f..11396e8b9 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/MobileToolbarPlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/MobileToolbarPlugin.tsx @@ -77,7 +77,7 @@ const MobileToolbarPlugin = () => { } }, [editor]) - const { isBold, isItalic, isUnderline, isSubscript, isSuperscript, isStrikethrough, blockType } = + const { isBold, isItalic, isUnderline, isSubscript, isSuperscript, isStrikethrough, blockType, isHighlighted } = useSelectedTextFormatInfo() const [isSelectionLink, setIsSelectionLink] = useState(false) @@ -153,6 +153,14 @@ const MobileToolbarPlugin = () => { }, active: isUnderline, }, + { + name: 'Highlight', + iconName: 'draw', + onSelect: () => { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'highlight') + }, + active: isHighlighted, + }, { name: 'Strikethrough', iconName: 'strikethrough', @@ -223,6 +231,7 @@ const MobileToolbarPlugin = () => { editor, insertLink, isBold, + isHighlighted, isItalic, isSelectionLink, isStrikethrough, diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/useSelectedTextFormatInfo.ts b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/useSelectedTextFormatInfo.ts index 15ed7a834..e209a4da9 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/useSelectedTextFormatInfo.ts +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugins/useSelectedTextFormatInfo.ts @@ -41,6 +41,7 @@ export function useSelectedTextFormatInfo() { const [isBold, setIsBold] = useState(false) const [isItalic, setIsItalic] = useState(false) const [isUnderline, setIsUnderline] = useState(false) + const [isHighlighted, setIsHighlighted] = useState(false) const [isStrikethrough, setIsStrikethrough] = useState(false) const [isSubscript, setIsSubscript] = useState(false) const [isSuperscript, setIsSuperscript] = useState(false) @@ -108,6 +109,7 @@ export function useSelectedTextFormatInfo() { setIsSubscript(selection.hasFormat('subscript')) setIsSuperscript(selection.hasFormat('superscript')) setIsCode(selection.hasFormat('code')) + setIsHighlighted(selection.hasFormat('highlight')) // Update links const parent = node.getParent() @@ -171,6 +173,7 @@ export function useSelectedTextFormatInfo() { isStrikethrough, isSubscript, isSuperscript, + isHighlighted, isCode, blockType, }