From a80289db57c1b002edd586b323444d3a474587ad Mon Sep 17 00:00:00 2001 From: MAZE Date: Fri, 30 Aug 2024 15:24:39 +0330 Subject: [PATCH] feat: add notepad tool --- .../tools/notepad/button/button.module.css | 45 +++++++++++++ .../tools/notepad/button/button.tsx | 36 ++++++++++ src/components/tools/notepad/button/index.ts | 1 + src/components/tools/notepad/index.ts | 1 + .../tools/notepad/notepad.module.css | 44 +++++++++++++ src/components/tools/notepad/notepad.tsx | 66 +++++++++++++++++++ src/pages/tools/notepad.astro | 19 ++++++ 7 files changed, 212 insertions(+) create mode 100644 src/components/tools/notepad/button/button.module.css create mode 100644 src/components/tools/notepad/button/button.tsx create mode 100644 src/components/tools/notepad/button/index.ts create mode 100644 src/components/tools/notepad/index.ts create mode 100644 src/components/tools/notepad/notepad.module.css create mode 100644 src/components/tools/notepad/notepad.tsx create mode 100644 src/pages/tools/notepad.astro diff --git a/src/components/tools/notepad/button/button.module.css b/src/components/tools/notepad/button/button.module.css new file mode 100644 index 0000000..4a4e756 --- /dev/null +++ b/src/components/tools/notepad/button/button.module.css @@ -0,0 +1,45 @@ +.button { + display: flex; + align-items: center; + justify-content: center; + width: 30px; + height: 30px; + font-size: var(--font-sm); + color: var(--color-foreground); + cursor: pointer; + background-color: var(--color-neutral-100); + border: 1px solid var(--color-neutral-200); + border-radius: 4px; + outline: none; + transition: 0.2s; + transition-property: border-color, color, background-color; + + &:focus-visible { + outline: 2px solid var(--color-neutral-400); + outline-offset: 2px; + } + + &.critical { + color: #f43f5e; + border-color: #f43f5e; + + &:hover { + background-color: rgb(244 63 94 / 10%); + } + } + + &.recommended { + font-size: var(--font-xsm); + color: #22c55e; + border-color: #22c55e; + + &:hover { + background-color: rgb(34 197 94 / 10%); + } + } + + &:hover, + &:focus-visible { + background-color: var(--color-neutral-200); + } +} diff --git a/src/components/tools/notepad/button/button.tsx b/src/components/tools/notepad/button/button.tsx new file mode 100644 index 0000000..d3da910 --- /dev/null +++ b/src/components/tools/notepad/button/button.tsx @@ -0,0 +1,36 @@ +import { Tooltip } from '@/components/tooltip'; + +import { cn } from '@/helpers/styles'; + +import styles from './button.module.css'; + +interface ButtonProps { + critical?: boolean; + icon: React.ReactElement; + onClick: () => void; + recommended?: boolean; + tooltip: string; +} + +export function Button({ + critical, + icon, + onClick, + recommended, + tooltip, +}: ButtonProps) { + return ( + + + + ); +} diff --git a/src/components/tools/notepad/button/index.ts b/src/components/tools/notepad/button/index.ts new file mode 100644 index 0000000..a039b75 --- /dev/null +++ b/src/components/tools/notepad/button/index.ts @@ -0,0 +1 @@ +export { Button } from './button'; diff --git a/src/components/tools/notepad/index.ts b/src/components/tools/notepad/index.ts new file mode 100644 index 0000000..8a3fad5 --- /dev/null +++ b/src/components/tools/notepad/index.ts @@ -0,0 +1 @@ +export { Notepad } from './notepad'; diff --git a/src/components/tools/notepad/notepad.module.css b/src/components/tools/notepad/notepad.module.css new file mode 100644 index 0000000..2dadc40 --- /dev/null +++ b/src/components/tools/notepad/notepad.module.css @@ -0,0 +1,44 @@ +.header { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 8px; + + & .label { + font-size: var(--font-sm); + font-weight: 500; + color: var(--color-foreground-subtle); + } + + & .buttons { + display: flex; + column-gap: 4px; + align-items: center; + } +} + +.textarea { + width: 100%; + height: 350px; + padding: 12px; + line-height: 1.6; + color: var(--color-foreground-subtle); + resize: none; + background-color: var(--color-neutral-50); + border: 1px solid var(--color-neutral-200); + border-radius: 4px; + outline: none; + scroll-padding-bottom: 12px; + + &:focus-visible { + outline: 2px solid var(--color-neutral-400); + outline-offset: 2px; + } +} + +.counter { + margin-top: 8px; + font-size: var(--font-xsm); + color: var(--color-foreground-subtle); + text-align: center; +} diff --git a/src/components/tools/notepad/notepad.tsx b/src/components/tools/notepad/notepad.tsx new file mode 100644 index 0000000..9ca334e --- /dev/null +++ b/src/components/tools/notepad/notepad.tsx @@ -0,0 +1,66 @@ +import { BiTrash } from 'react-icons/bi/index'; +import { LuCopy, LuDownload } from 'react-icons/lu/index'; +import { FaCheck } from 'react-icons/fa6/index'; +import { FaUndo } from 'react-icons/fa/index'; + +import { Button } from './button'; + +import { useNoteStore } from '@/stores/note'; +import { useCopy } from '@/hooks/use-copy'; +import { download } from '@/helpers/download'; + +import styles from './notepad.module.css'; +import { Container } from '@/components/container'; + +export function Notepad() { + const note = useNoteStore(state => state.note); + const history = useNoteStore(state => state.history); + const write = useNoteStore(state => state.write); + const words = useNoteStore(state => state.words()); + const characters = useNoteStore(state => state.characters()); + const clear = useNoteStore(state => state.clear); + const restore = useNoteStore(state => state.restore); + + const { copy, copying } = useCopy(); + + return ( + +
+

Your Note

+
+
+
+ +