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
Show file tree
Hide file tree
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
Next Next commit
added superscript and subscript buttons in playground
  • Loading branch information
animeshk874 committed Apr 24, 2022
commit 64be4ee6f5f10693e95b5212b95fd245327e0783
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions packages/lexical-playground/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ i.strikethrough {
background-image: url(images/icons/type-strikethrough.svg);
}

i.subscript {
background-image: url(images/icons/type-subscript.svg);
}

i.superscript {
background-image: url(images/icons/type-superscript.svg);
}

i.link {
background-image: url(images/icons/link.svg);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/lexical-playground/src/plugins/ToolbarPlugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ export default function ToolbarPlugin(): 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);
const [canUndo, setCanUndo] = useState(false);
const [canRedo, setCanRedo] = useState(false);
Expand All @@ -767,6 +769,8 @@ export default function ToolbarPlugin(): 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'));
setIsRTL($isParentElementRTL(selection));

Expand Down Expand Up @@ -1016,6 +1020,24 @@ export default function ToolbarPlugin(): React$Node {
aria-label="Format Strikethrough">
<i className="format strikethrough" />
</button>
<button
onClick={() => {
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'subscript');
}}
className={'toolbar-item spaced ' + (isSubscript ? 'active' : '')}
title="Subscript"
aria-label="Format Subscript">
<i className="format subscript" />
</button>
<button
onClick={() => {
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'superscript');
}}
className={'toolbar-item spaced ' + (isSuperscript ? 'active' : '')}
title="Superscript"
aria-label="Format Superscript">
<i className="format superscript" />
</button>
<button
onClick={() => {
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
.PlaygroundEditorTheme__textUnderlineStrikethrough {
text-decoration: underline line-through;
}
.PlaygroundEditorTheme__textSubscript {
font-size: 12px;
vertical-align: sub !important;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this necessary? I'm mostly just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case both sub and sup buttons are clicked, this will make sure that sub gets the priority. That's how it's handled here

}
.PlaygroundEditorTheme__textSuperscript {
font-size: 12px;
vertical-align: super;
}
.PlaygroundEditorTheme__textCode {
background-color: rgb(240, 242, 245);
padding: 1px 0.25rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const theme: EditorThemeClasses = {
code: 'PlaygroundEditorTheme__textCode',
italic: 'PlaygroundEditorTheme__textItalic',
strikethrough: 'PlaygroundEditorTheme__textStrikethrough',
subscript: 'PlaygroundEditorTheme__textSubscript',
superscript: 'PlaygroundEditorTheme__textSuperscript',
underline: 'PlaygroundEditorTheme__textUnderline',
underlineStrikethrough: 'PlaygroundEditorTheme__textUnderlineStrikethrough',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/lexical/Lexical.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ type TextNodeThemeClasses = {
underlineStrikethrough?: EditorThemeClassName;
italic?: EditorThemeClassName;
code?: EditorThemeClassName;
subscript?: EditorThemeClassName;
superscript?: EditorThemeClassName;
};
export type EditorThemeClasses = {
ltr?: EditorThemeClassName;
Expand Down
2 changes: 2 additions & 0 deletions packages/lexical/flow/Lexical.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ type TextNodeThemeClasses = {
underlineStrikethrough?: EditorThemeClassName,
italic?: EditorThemeClassName,
code?: EditorThemeClassName,
subscript?: EditorThemeClassName,
superscript?: EditorThemeClassName,
};
export type EditorThemeClasses = {
ltr?: EditorThemeClassName,
Expand Down