-
Notifications
You must be signed in to change notification settings - Fork 396
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
Adiciona contador de caracteres em tempo real no campo de postagem #1813
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import byteMDLocale from 'bytemd/locales/pt_BR.json'; | |
import 'katex/dist/katex.css'; | ||
import { useEffect, useMemo, useRef, useState } from 'react'; | ||
|
||
import { Box, EditorColors, EditorStyles, useTheme } from '@/TabNewsUI'; | ||
import { Box, EditorColors, EditorStyles, Text, useTheme } from '@/TabNewsUI'; | ||
|
||
import { anchorHeadersPlugin } from './plugins/anchor-headers'; | ||
import { copyCodeToClipboardPlugin } from './plugins/copy-code-to-clipboard'; | ||
|
@@ -82,8 +82,23 @@ export default function Viewer({ value: _value, areLinksTrusted, clobberPrefix, | |
); | ||
} | ||
|
||
export function CharacterCounter({ text, maxLength }) { | ||
const characterCount = useMemo(() => text.length, [text]); | ||
return ( | ||
<Text | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
fontSize: '14px', | ||
color: characterCount > maxLength ? 'danger.fg' : undefined, | ||
}}> | ||
{characterCount}/{maxLength} | ||
</Text> | ||
); | ||
} | ||
|
||
// Editor is not part of Primer, so error messages and styling need to be created manually | ||
export function Editor({ isValid, onKeyDown, compact, areLinksTrusted, clobberPrefix, ...props }) { | ||
export function Editor({ isValid, onKeyDown, compact, areLinksTrusted, clobberPrefix, maxLength, value, ...props }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agora precisa voltar a passar Mas, ao invés disso, que tal adicionar o contador diretamente lá no Seria só modificar ali no trecho que começa com |
||
clobberPrefix = clobberPrefix?.toLowerCase(); | ||
const bytemdPluginList = usePlugins({ areLinksTrusted, clobberPrefix }); | ||
const editorMode = 'split'; // 'tab' | ||
|
@@ -114,6 +129,7 @@ export function Editor({ isValid, onKeyDown, compact, areLinksTrusted, clobberPr | |
/> | ||
<EditorStyles compact={compact} mode={editorMode} /> | ||
<EditorColors /> | ||
<CharacterCounter text={value} maxLength={maxLength} /> | ||
</Box> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisa do
useMemo
aqui?