-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(richtext-lexical): add new paragraph button below the editor (#1…
- Loading branch information
Showing
6 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/richtext-lexical/src/lexical/plugins/InsertParagraphAtEnd/index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@import '../../../scss/styles'; | ||
|
||
@layer payload-default { | ||
.rich-text-lexical--show-gutter { | ||
.insert-paragraph-at-end { | ||
padding: 4px 0px 2px 40px; | ||
} | ||
} | ||
.insert-paragraph-at-end { | ||
height: 24px; | ||
margin-top: -16px; | ||
width: 100%; | ||
z-index: 2; | ||
position: relative; | ||
padding: 4px 0px 2px 0px; | ||
|
||
&-inside { | ||
width: 100%; | ||
height: 100%; | ||
background-color: transparent; | ||
transition: background-color 0.1s ease-in-out; | ||
display: flex; | ||
justify-content: center; | ||
border-radius: $style-radius-s; | ||
color: var(--theme-elevation-500); | ||
|
||
span { | ||
display: none; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
} | ||
|
||
&:hover { | ||
cursor: pointer; | ||
|
||
.insert-paragraph-at-end-inside { | ||
background-color: var(--theme-elevation-100); | ||
|
||
span { | ||
display: flex; | ||
} | ||
} | ||
} | ||
} | ||
|
||
html[data-theme='dark'] { | ||
.insert-paragraph-at-end:hover { | ||
.insert-paragraph-at-end-inside { | ||
background-color: var(--theme-elevation-50); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/richtext-lexical/src/lexical/plugins/InsertParagraphAtEnd/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
/* eslint-disable jsx-a11y/click-events-have-key-events */ | ||
'use client' | ||
|
||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' | ||
import { $createParagraphNode, $getRoot } from 'lexical' | ||
import React from 'react' | ||
|
||
import './index.scss' | ||
import { useEditorConfigContext } from '../../config/client/EditorConfigProvider.js' | ||
const baseClass = 'insert-paragraph-at-end' | ||
|
||
export const InsertParagraphAtEndPlugin: React.FC = () => { | ||
const [editor] = useLexicalComposerContext() | ||
const { editorConfig } = useEditorConfigContext() | ||
|
||
if (editorConfig?.admin?.hideInsertParagraphAtEnd) { | ||
return null | ||
} | ||
|
||
const onClick = () => { | ||
editor.update(() => { | ||
const paragraphNode = $createParagraphNode() | ||
$getRoot().append(paragraphNode) | ||
paragraphNode.select() | ||
}) | ||
} | ||
|
||
return ( | ||
<div aria-label="Insert Paragraph" className={baseClass} onClick={onClick}> | ||
<div className={`${baseClass}-inside`}> | ||
<span>+</span> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters