diff --git a/docs/package.json b/docs/package.json index 6c48cd1..6775ea3 100644 --- a/docs/package.json +++ b/docs/package.json @@ -11,6 +11,7 @@ "dependencies": { "@emotion/cache": "^11.14.0", "@emotion/styled": "^11.14.0", + "@mdi/js": "^7.4.47", "@mdi/react": "^1.6.1", "@mui/material": "^6.3.0", "@mui/material-nextjs": "^6.3.0", diff --git a/docs/src/components/PlainTextSelect.tsx b/docs/src/components/PlainTextSelect.tsx new file mode 100644 index 0000000..d8cb59c --- /dev/null +++ b/docs/src/components/PlainTextSelect.tsx @@ -0,0 +1,48 @@ +import { mdiMenuDown } from "@mdi/js" +import { Icon } from "@mdi/react" +import { ButtonBase, ClickAwayListener, Menu, MenuItem, MenuList } from "@mui/material" +import cn from "clsx" +import React, { useState } from "react" + +import useMenuTrigger from "@/hooks/useMenuTrigger" + +interface PlainTextSelectProps { + className?: string + items: T[] + renderLabel: (value: T | null) => string + children: (value: T) => React.ReactNode +} + +export default function PlainTextSelect( + { className, items, renderLabel, children }: PlainTextSelectProps +) { + const [value, setValue] = useState(null) + const { anchor, open, handleClick, handleClose } = useMenuTrigger() + const handleMenuClick = (data: T | null) => { + setValue(data) + handleClose() + } + return ( + <> + + {renderLabel(value)} + + + + + + handleMenuClick(null)}>None + {items.map((item, index) => ( + handleMenuClick(item)}> + {children(item)} + + ))} + + + + + ) +} diff --git a/docs/src/components/editor-toolbars/FontFamily.tsx b/docs/src/components/editor-toolbars/FontFamily.tsx index b239595..3c40d7b 100644 --- a/docs/src/components/editor-toolbars/FontFamily.tsx +++ b/docs/src/components/editor-toolbars/FontFamily.tsx @@ -1,17 +1,15 @@ -import { MenuItem, Select } from "@mui/material" +import PlainTextSelect from "@/components/PlainTextSelect" const fonts = ["Inter", "Roboto", "sans-serif", "serif", "monospace", "cursive", "Arial", "Helvetica", "fantasy"] export default function FontFamily() { return ( - - className="w-[140px]" - size="small" - displayEmpty - renderValue={value => value || "Font Family"} + value || "Font Family"} > - None - {fonts.map(font => {font})} - + {font => font} + ) } diff --git a/docs/src/components/editor-toolbars/FontSize.tsx b/docs/src/components/editor-toolbars/FontSize.tsx new file mode 100644 index 0000000..a32dcdb --- /dev/null +++ b/docs/src/components/editor-toolbars/FontSize.tsx @@ -0,0 +1,16 @@ +"use client" +import PlainTextSelect from "@/components/PlainTextSelect" + +const sizes = [12, 14, 15, 16, 17, 18, 20, 22, 24, 26].slice(6) + +export default function FontSize() { + return ( + value ? value + " px" : "Font Size"} + > + {size => {size} px} + + ) +} diff --git a/docs/src/components/page-index/ToolbarRich.tsx b/docs/src/components/page-index/ToolbarRich.tsx index 97c5d32..9b93e29 100644 --- a/docs/src/components/page-index/ToolbarRich.tsx +++ b/docs/src/components/page-index/ToolbarRich.tsx @@ -1,15 +1,17 @@ "use client" +import "@/styles/toolbars.css" + import cn from "clsx" -import FontFamily from "@/components/editor-toolbars/FontFamily" import Hr from "@/components/Hr" +import FontFamily from "../editor-toolbars/FontFamily" +import FontSize from "../editor-toolbars/FontSize" import FormatBrush from "../editor-toolbars/FormatBrush" import FormatClear from "../editor-toolbars/FormatClear" import Redo from "../editor-toolbars/Redo" import Undo from "../editor-toolbars/Undo" -// TODO fix tailwindcss dark mode export default function ToolbarRich() { return ( <> @@ -30,6 +32,7 @@ export default function ToolbarRich() {
+
diff --git a/docs/src/content/en/index.mdx b/docs/src/content/en/index.mdx index c3b8133..705485c 100644 --- a/docs/src/content/en/index.mdx +++ b/docs/src/content/en/index.mdx @@ -2,10 +2,17 @@ title: "Home page" --- import "@/components/page-index/index.css" + import Heading from "@/components/page-index/Heading" +import TiptapEditor from "@/components/page-index/TiptapEditor" +import ToolbarRich from "@/components/page-index/ToolbarRich" - + ```bash pnpm add @tiptiz/editor-icons -``` \ No newline at end of file +``` + + + + diff --git a/docs/src/hooks/useMenuTrigger.ts b/docs/src/hooks/useMenuTrigger.ts new file mode 100644 index 0000000..aa0cf48 --- /dev/null +++ b/docs/src/hooks/useMenuTrigger.ts @@ -0,0 +1,20 @@ +import type React from "react" + +import { useState } from "react" + +export default function useMenuTrigger() { + const [anchor, setAnchor] = useState(null) + const open = Boolean(anchor) + + const handleClick = (e: React.MouseEvent) => { + setAnchor(e.currentTarget) + } + const handleClose = () => setAnchor(null) + + return { + anchor, + open, + handleClick, + handleClose + } +} diff --git a/docs/src/styles/toolbars.css b/docs/src/styles/toolbars.css new file mode 100644 index 0000000..17cc467 --- /dev/null +++ b/docs/src/styles/toolbars.css @@ -0,0 +1,7 @@ +button.bar-menu-selector { + text-transform: initial; + justify-content: space-between; +} +.bar-menu-selector > svg { + transition: 0.4s transform; +} diff --git a/docs/tailwind.config.ts b/docs/tailwind.config.ts index d2e52af..6ddaed7 100644 --- a/docs/tailwind.config.ts +++ b/docs/tailwind.config.ts @@ -6,5 +6,6 @@ export default { "./src/components/**/*.{js,ts,jsx,tsx,mdx}", "./src/app/**/*.{js,ts,jsx,tsx,mdx}" ], - darkMode: ["variant", "dark (&:where(.dark *))"] + darkMode: ["variant", "dark (&:where(.dark *))"], + important: true } satisfies Config diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 63c4613..975ffcd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -99,6 +99,9 @@ importers: '@emotion/styled': specifier: ^11.14.0 version: 11.14.0(@emotion/react@11.14.0(@types/react@19.0.2)(react@19.0.0))(@types/react@19.0.2)(react@19.0.0) + '@mdi/js': + specifier: ^7.4.47 + version: 7.4.47 '@mdi/react': specifier: ^1.6.1 version: 1.6.1