Skip to content

Commit

Permalink
feat: add counter to notepad
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Feb 24, 2024
1 parent b143e46 commit 2424523
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 3 deletions.
226 changes: 224 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"react-dom": "^18.2.0",
"react-icons": "4.11.0",
"react-wrap-balancer": "1.1.0",
"word-counting": "1.1.4",
"zustand": "4.4.3"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions src/components/toolbox/notepad/notepad.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@
outline: none;
scroll-padding-bottom: 12px;
}

.counter {
margin-top: 8px;
font-size: var(--font-sm);
color: var(--color-foreground-subtle);
text-align: center;
}
7 changes: 7 additions & 0 deletions src/components/toolbox/notepad/notepad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface NotepadProps {
export function Notepad({ onClose, show }: NotepadProps) {
const note = useNoteStore(state => state.note);
const write = useNoteStore(state => state.write);
const words = useNoteStore(state => state.words());
const characters = useNoteStore(state => state.characters());

return (
<Modal show={show} wide onClose={onClose}>
Expand All @@ -24,6 +26,11 @@ export function Notepad({ onClose, show }: NotepadProps) {
value={note}
onChange={e => write(e.target.value)}
/>

<p className={styles.counter}>
{characters} character{characters !== 1 && 's'}{words} word
{words !== 1 && 's'}
</p>
</Modal>
);
}
10 changes: 10 additions & 0 deletions src/helpers/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import wordsCounter from 'word-counting';

export function count(_string: string) {
const string = _string.trim();

return {
characters: string.replace(/\s/g, '').length,
words: wordsCounter(string).wordsCount,
};
}
Loading

0 comments on commit 2424523

Please sign in to comment.