Example: list-custom-checkbox
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import './custom-list.css'
import {
createEditor,
type NodeJSON,
} from 'prosekit/core'
import { ProseKit } from 'prosekit/react'
import { useMemo } from 'react'
import { defineExtension } from './extension'
import Toolbar from './toolbar'
export default function Editor() {
const editor = useMemo(() => {
return createEditor({ extension: defineExtension(), defaultContent })
}, [])
return (
<ProseKit editor={editor}>
<div className="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-white dark:bg-gray-950 color-black dark:color-white" data-custom-list-css-enabled>
<Toolbar />
<div className="relative w-full flex-1 box-border overflow-y-scroll">
<div ref={editor.mount} className="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
</div>
</div>
</ProseKit>
)
}
const defaultContent: NodeJSON = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{ type: 'text', text: 'Custom list checkbox design and strikethrough for completed tasks. Please check ' },
{ type: 'text', text: 'custom-list.css', marks: [{ type: 'code' }] },
{ type: 'text', text: ' for the styles.' },
],
},
{
type: 'list',
attrs: { kind: 'task', checked: true },
content: [
{ type: 'paragraph', content: [{ type: 'text', text: 'Completed Task' }] },
],
},
{
type: 'list',
attrs: { kind: 'task', checked: false },
content: [
{ type: 'paragraph', content: [{ type: 'text', text: 'Incomplete Task' }] },
],
},
],
}
import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
export function defineExtension() {
return union(defineBasicExtension())
}
export type EditorExtension = ReturnType<typeof defineExtension>
import type { Editor } from 'prosekit/core'
import { useEditorDerivedValue } from 'prosekit/react'
import Button from './button'
import type { EditorExtension } from './extension'
function getToolbarItems(editor: Editor<EditorExtension>) {
return {
bullet: {
isActive: editor.nodes.list.isActive({ kind: 'bullet' }),
canExec: editor.commands.toggleList.canExec({ kind: 'bullet' }),
command: () => editor.commands.toggleList({ kind: 'bullet' }),
},
ordered: {
isActive: editor.nodes.list.isActive({ kind: 'ordered' }),
canExec: editor.commands.toggleList.canExec({ kind: 'ordered' }),
command: () => editor.commands.toggleList({ kind: 'ordered' }),
},
task: {
isActive: editor.nodes.list.isActive({ kind: 'task' }),
canExec: editor.commands.toggleList.canExec({ kind: 'task' }),
command: () => editor.commands.toggleList({ kind: 'task' }),
},
toggle: {
isActive: editor.nodes.list.isActive({ kind: 'toggle' }),
canExec: editor.commands.toggleList.canExec({ kind: 'toggle' }),
command: () => editor.commands.toggleList({ kind: 'toggle' }),
},
}
}
export default function Toolbar() {
const items = useEditorDerivedValue(getToolbarItems)
return (
<div className="z-2 box-border border-gray-200 dark:border-gray-800 border-solid border-l-0 border-r-0 border-t-0 border-b flex flex-wrap gap-1 p-2 items-center">
<Button
pressed={items.bullet.isActive}
disabled={!items.bullet.canExec}
onClick={items.bullet.command}
>
<div className="i-lucide-list size-5 block" />
</Button>
<Button
pressed={items.ordered.isActive}
disabled={!items.ordered.canExec}
onClick={items.ordered.command}
>
<div className="i-lucide-list-ordered size-5 block" />
</Button>
<Button
pressed={items.task.isActive}
disabled={!items.task.canExec}
onClick={items.task.command}
>
<div className="i-lucide-list-checks size-5 block" />
</Button>
<Button
pressed={items.toggle.isActive}
disabled={!items.toggle.canExec}
onClick={items.toggle.command}
>
<div className="i-lucide-list-collapse size-5 block" />
</Button>
</div>
)
}
div[data-custom-list-css-enabled] .ProseMirror .prosemirror-flat-list[data-list-kind="task"] {
& > .list-marker label {
box-sizing: border-box;
display: flex;
position: relative;
left: calc(var(--spacing) * -0.5);
align-items: center;
cursor: pointer;
transition: transform 0.15s ease-in-out;
&:hover {
transform: scale(1.1);
}
&::after {
position: absolute;
width: calc(var(--spacing) * 5);
height: calc(var(--spacing) * 5);
content: "";
color: var(--color-white);
opacity: 0;
}
/* https://api.iconify.design/lucide.css?icons=check */
&::after {
display: inline-block;
background-color: currentColor;
-webkit-mask-image: var(--svg);
mask-image: var(--svg);
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
-webkit-mask-size: 100% 100%;
mask-size: 100% 100%;
--svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='none' stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M20 6L9 17l-5-5'/%3E%3C/svg%3E");
}
& input {
box-sizing: border-box;
appearance: none;
width: calc(var(--spacing) * 5);
height: calc(var(--spacing) * 5);
margin: 0;
border-width: 1px;
border-style: solid;
border-radius: var(--radius-md);
border-color: color-mix(in srgb, var(--color-gray-300) 50%, transparent);
box-shadow: var(--shadow-sm);
cursor: pointer;
transition: all 0.15s ease-in-out;
&:hover {
box-shadow: var(--shadow-md);
}
&:checked {
border-color: var(--color-red-500);
background-color: var(--color-red-500);
}
}
}
&[data-list-checked] > .list-marker label {
&::after {
opacity: 1;
}
}
&[data-list-checked] {
color: var(--color-gray-400);
text-decoration: line-through;
text-decoration-color: var(--color-gray-400);
}
}
import {
TooltipContent,
TooltipRoot,
TooltipTrigger,
} from 'prosekit/react/tooltip'
import type { ReactNode } from 'react'
export default function Button({
pressed,
disabled,
onClick,
tooltip,
children,
}: {
pressed?: boolean
disabled?: boolean
onClick?: VoidFunction
tooltip?: string
children: ReactNode
}) {
return (
<TooltipRoot>
<TooltipTrigger className="block">
<button
data-state={pressed ? 'on' : 'off'}
disabled={disabled}
onClick={() => onClick?.()}
onMouseDown={(event) => event.preventDefault()}
className="outline-unset focus-visible:outline-unset flex items-center justify-center rounded-md p-2 font-medium transition focus-visible:ring-2 text-sm focus-visible:ring-gray-900 dark:focus-visible:ring-gray-300 disabled:pointer-events-none min-w-9 min-h-9 text-gray-900 dark:text-gray-50 disabled:text-gray-900/50 dark:disabled:text-gray-50/50 bg-transparent hover:bg-gray-100 dark:hover:bg-gray-800 data-[state=on]:bg-gray-200 dark:data-[state=on]:bg-gray-700"
>
{children}
{tooltip ? <span className="sr-only">{tooltip}</span> : null}
</button>
</TooltipTrigger>
{tooltip
? (
<TooltipContent className="z-50 overflow-hidden rounded-md border border-solid bg-gray-900 dark:bg-gray-50 px-3 py-1.5 text-xs text-gray-50 dark:text-gray-900 shadow-xs [&:not([data-state])]:hidden will-change-transform data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 data-[state=open]:animate-duration-150 data-[state=closed]:animate-duration-200 data-[side=bottom]:slide-in-from-top-2 data-[side=bottom]:slide-out-to-top-2 data-[side=left]:slide-in-from-right-2 data-[side=left]:slide-out-to-right-2 data-[side=right]:slide-in-from-left-2 data-[side=right]:slide-out-to-left-2 data-[side=top]:slide-in-from-bottom-2 data-[side=top]:slide-out-to-bottom-2">
{tooltip}
</TooltipContent>
)
: null}
</TooltipRoot>
)
}