-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from hunghg255/show-limit
- Loading branch information
Showing
4 changed files
with
63 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { Editor } from '@tiptap/core' | ||
import React, { useMemo } from 'react' | ||
import { useLocale } from '@/locales' | ||
|
||
interface IPropsCharactorCount { | ||
editor: Editor | ||
extensions: any | ||
} | ||
|
||
function CharactorCount({ editor, extensions }: IPropsCharactorCount) { | ||
const { t } = useLocale() | ||
|
||
const limit = useMemo(() => { | ||
return extensions?.find((extension: any) => extension.name === 'base-kit')?.options?.characterCount?.limit | ||
}, [extensions]) | ||
|
||
if (!limit) { | ||
return ( | ||
<div className="richtext-flex richtext-items-center richtext-justify-between richtext-p-3 richtext-border-t"> | ||
<div className="richtext-flex richtext-flex-col"> | ||
<div className="richtext-flex richtext-justify-end richtext-gap-3 richtext-text-sm"> | ||
<span> | ||
{(editor as any).storage.characterCount.characters()} | ||
{' '} | ||
{t('editor.characters')} | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div className="richtext-flex richtext-items-center richtext-justify-between richtext-p-3 richtext-border-t"> | ||
<div className="richtext-flex richtext-flex-col"> | ||
<div className="richtext-flex richtext-justify-end richtext-gap-3 richtext-text-sm"> | ||
<span> | ||
{editor.storage.characterCount.characters()} | ||
/ | ||
{limit} | ||
{' '} | ||
{t('editor.characters')} | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default CharactorCount |
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