forked from rocicorp/replicache-yjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
12,202 additions
and
4,681 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
.divider { | ||
background-color: rgba(#fff, 0.25); | ||
height: 1.25rem; | ||
margin-left: 0.5rem; | ||
margin-right: 0.75rem; | ||
width: 1px; | ||
} |
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,151 @@ | ||
"use client"; | ||
import "./MenuBar.css"; | ||
|
||
import React, { Fragment } from "react"; | ||
import { Editor } from "@tiptap/core"; | ||
|
||
import MenuItem from "./MenuItem"; | ||
|
||
export type Item = { | ||
icon?: string | undefined; | ||
title?: string | undefined; | ||
action?: () => boolean | undefined; | ||
isActive?: () => boolean | undefined; | ||
type?: "divider" | undefined; | ||
}; | ||
|
||
export function MenuBar({ editor }: { editor: Editor }) { | ||
const items: Item[] = [ | ||
{ | ||
icon: "bold", | ||
title: "Bold", | ||
action: () => editor.chain().focus().toggleBold().run(), | ||
isActive: () => editor.isActive("bold"), | ||
}, | ||
{ | ||
icon: "italic", | ||
title: "Italic", | ||
action: () => editor.chain().focus().toggleItalic().run(), | ||
isActive: () => editor.isActive("italic"), | ||
}, | ||
{ | ||
icon: "strikethrough", | ||
title: "Strike", | ||
action: () => editor.chain().focus().toggleStrike().run(), | ||
isActive: () => editor.isActive("strike"), | ||
}, | ||
{ | ||
icon: "code-view", | ||
title: "Code", | ||
action: () => editor.chain().focus().toggleCode().run(), | ||
isActive: () => editor.isActive("code"), | ||
}, | ||
{ | ||
icon: "mark-pen-line", | ||
title: "Highlight", | ||
action: () => editor.chain().focus().toggleHighlight().run(), | ||
isActive: () => editor.isActive("highlight"), | ||
}, | ||
{ | ||
type: "divider", | ||
}, | ||
{ | ||
icon: "h-1", | ||
title: "Heading 1", | ||
action: () => editor.chain().focus().toggleHeading({ level: 1 }).run(), | ||
isActive: () => editor.isActive("heading", { level: 1 }), | ||
}, | ||
{ | ||
icon: "h-2", | ||
title: "Heading 2", | ||
action: () => editor.chain().focus().toggleHeading({ level: 2 }).run(), | ||
isActive: () => editor.isActive("heading", { level: 2 }), | ||
}, | ||
{ | ||
icon: "paragraph", | ||
title: "Paragraph", | ||
action: () => editor.chain().focus().setParagraph().run(), | ||
isActive: () => editor.isActive("paragraph"), | ||
}, | ||
{ | ||
icon: "list-unordered", | ||
title: "Bullet List", | ||
action: () => editor.chain().focus().toggleBulletList().run(), | ||
isActive: () => editor.isActive("bulletList"), | ||
}, | ||
{ | ||
icon: "list-ordered", | ||
title: "Ordered List", | ||
action: () => editor.chain().focus().toggleOrderedList().run(), | ||
isActive: () => editor.isActive("orderedList"), | ||
}, | ||
{ | ||
icon: "list-check-2", | ||
title: "Task List", | ||
action: () => editor.chain().focus().toggleTaskList().run(), | ||
isActive: () => editor.isActive("taskList"), | ||
}, | ||
{ | ||
icon: "code-box-line", | ||
title: "Code Block", | ||
action: () => editor.chain().focus().toggleCodeBlock().run(), | ||
isActive: () => editor.isActive("codeBlock"), | ||
}, | ||
{ | ||
type: "divider", | ||
}, | ||
{ | ||
icon: "double-quotes-l", | ||
title: "Blockquote", | ||
action: () => editor.chain().focus().toggleBlockquote().run(), | ||
isActive: () => editor.isActive("blockquote"), | ||
}, | ||
{ | ||
icon: "separator", | ||
title: "Horizontal Rule", | ||
action: () => editor.chain().focus().setHorizontalRule().run(), | ||
}, | ||
{ | ||
type: "divider", | ||
}, | ||
{ | ||
icon: "text-wrap", | ||
title: "Hard Break", | ||
action: () => editor.chain().focus().setHardBreak().run(), | ||
}, | ||
{ | ||
icon: "format-clear", | ||
title: "Clear Format", | ||
action: () => editor.chain().focus().clearNodes().unsetAllMarks().run(), | ||
}, | ||
{ | ||
type: "divider", | ||
}, | ||
{ | ||
icon: "arrow-go-back-line", | ||
title: "Undo", | ||
action: () => editor.chain().focus().undo().run(), | ||
}, | ||
{ | ||
icon: "arrow-go-forward-line", | ||
title: "Redo", | ||
action: () => editor.chain().focus().redo().run(), | ||
}, | ||
]; | ||
|
||
return ( | ||
<div className="editor__header"> | ||
{items.map((item, index) => ( | ||
<Fragment key={index}> | ||
{item.type === "divider" ? ( | ||
<div className="divider" /> | ||
) : ( | ||
<MenuItem {...item} /> | ||
)} | ||
</Fragment> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default MenuBar; |
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,22 @@ | ||
.menu-item { | ||
background-color: transparent; | ||
border: none; | ||
border-radius: 0.4rem; | ||
color: #fff; | ||
cursor: pointer; | ||
height: 1.75rem; | ||
margin-right: 0.25rem; | ||
padding: 0.25rem; | ||
width: 1.75rem; | ||
} | ||
|
||
.menu-item svg { | ||
fill: currentColor; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
.menu-item:hover, | ||
.menu-item.is-active { | ||
background-color: #303030; | ||
} |
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,21 @@ | ||
"use client"; | ||
import "./MenuItem.css"; | ||
|
||
import React from "react"; | ||
|
||
import { Item } from "./MenuBar"; | ||
export function MenuItem({ icon, title, action, isActive }: Item) { | ||
return ( | ||
<button | ||
className={`menu-item${isActive && isActive() ? " is-active" : ""}`} | ||
onClick={action} | ||
title={title} | ||
> | ||
<svg className="remix"> | ||
<use xlinkHref={`/remixicon.symbol.svg#ri-${icon}`} /> | ||
</svg> | ||
</button> | ||
); | ||
} | ||
|
||
export default MenuItem; |
Oops, something went wrong.