Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added superscript and subscript buttons in playground #1945

Merged
merged 14 commits into from
May 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added sup and sub buttons in floating toolbar
  • Loading branch information
animeshk874 committed Apr 24, 2022
commit a204cfd030c5de4628f5b5aeee311b10a31cb9b4
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ function FloatingCharacterStylesEditor({
isUnderline,
isCode,
isStrikethrough,
isSubscript,
isSuperscript,
}: {
editor: LexicalEditor,
isBold: boolean,
isCode: boolean,
isItalic: boolean,
isLink: boolean,
isStrikethrough: boolean,
isSubscript: boolean,
isSuperscript: boolean,
isUnderline: boolean,
}): React$Node {
const popupCharStylesEditorRef = useRef<HTMLElement | null>(null);
Expand Down Expand Up @@ -157,6 +161,24 @@ function FloatingCharacterStylesEditor({
aria-label="Format Strikethrough">
<i className="format strikethrough" />
</button>
<button
onClick={() => {
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'subscript');
}}
className={'popup-item spaced ' + (isSubscript ? 'active' : '')}
title="Subscript"
aria-label="Format Subscript">
<i className="format subscript" />
</button>
<button
onClick={() => {
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'superscript');
}}
className={'popup-item spaced ' + (isSuperscript ? 'active' : '')}
title="Superscript"
aria-label="Format Superscript">
<i className="format superscript" />
</button>
<button
onClick={() => {
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code');
Expand Down Expand Up @@ -198,6 +220,8 @@ function useCharacterStylesPopup(editor: LexicalEditor): React$Node {
const [isItalic, setIsItalic] = useState(false);
const [isUnderline, setIsUnderline] = useState(false);
const [isStrikethrough, setIsStrikethrough] = useState(false);
const [isSubscript, setIsSubscript] = useState(false);
const [isSuperscript, setIsSuperscript] = useState(false);
const [isCode, setIsCode] = useState(false);

useEffect(() => {
Expand All @@ -216,6 +240,8 @@ function useCharacterStylesPopup(editor: LexicalEditor): React$Node {
setIsItalic(selection.hasFormat('italic'));
setIsUnderline(selection.hasFormat('underline'));
setIsStrikethrough(selection.hasFormat('strikethrough'));
setIsSubscript(selection.hasFormat('subscript'));
setIsSuperscript(selection.hasFormat('superscript'));
setIsCode(selection.hasFormat('code'));

// Update links
Expand Down Expand Up @@ -249,6 +275,8 @@ function useCharacterStylesPopup(editor: LexicalEditor): React$Node {
isBold={isBold}
isItalic={isItalic}
isStrikethrough={isStrikethrough}
isSubscript={isSubscript}
isSuperscript={isSuperscript}
isUnderline={isUnderline}
isCode={isCode}
/>,
Expand Down