切换按钮以更改列表类型
一个用于切换不同列表类型(如无序列表、有序列表和任务列表)的按钮。
安装
您可以通过 Tiptap CLI (适用于 Vite 或 Next.js) 添加组件。
npx @tiptap/cli add list-button手动集成
对于 Vite 或 Next.js 以外的框架,可以手动从 [https://github.com/ueberdosis/tiptap-ui-components/tree/main/apps/web/src/components/tiptap-ui/list-button) 添加组件。
导入样式
此组件需要您导入我们的样式,这些样式已添加到 styles/keyframe-animation.scss 和 styles/_variables.scss 中。
用法
import { EditorContent, EditorContext, useEditor } from '@tiptap/react'
import { StarterKit } from '@tiptap/starter-kit'
import { TaskList } from '@tiptap/extension-task-list'
import { TaskItem } from '@tiptap/extension-task-item'
import { ListButton } from '@/components/tiptap-ui/list-button'
import '@/components/tiptap-node/code-block-node/code-block-node.scss'
import '@/components/tiptap-node/list-node/list-node.scss'
import '@/components/tiptap-node/paragraph-node/paragraph-node.scss'
export default function MyEditor() {
const editor = useEditor({
immediatelyRender: false,
extensions: [StarterKit, TaskList, TaskItem.configure({ nested: true })],
content: `
<ul>
<li>
<strong>粗体</strong> 用于强调,使用 <code>**</code> 或 <code>⌘+B</code> 或 <code>B</code> 按钮。
</li>
<li>
<em>斜体</em> 用于细微的区别,使用 <code>*</code> 或 <code>⌘+I</code> 或 <code>I</code> 按钮。
</li>
<li>
<s>删除线</s> 用于显示修订,使用 <code>~~</code> 或 <code>~~S~~</code> 按钮。
</li>
</ul>
<ul data-type="taskList">
<li data-type="taskItem" data-checked="true">
<div>测试模板</div>
</li>
<li data-type="taskItem" data-checked="false">
<div>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://tiptap.dev/pricing">创建账户</a>
</div>
</li>
<li data-type="taskItem" data-checked="false">
<div>下载免费模板</div>
</li>
</ul>
`,
})
return (
<EditorContext.Provider value={{ editor }}>
<div className="tiptap-button-group" data-orientation="horizontal">
<ListButton type="bulletList" />
<ListButton type="orderedList" />
<ListButton type="taskList" />
</div>
<EditorContent editor={editor} role="presentation" />
</EditorContext.Provider>
)
}属性
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| editor | Editor | null | null | Tiptap 编辑器实例 |
| type | 'bulletList' | 'orderedList' | 'taskList' | 必需 | 要切换的列表类型 |
| hideWhenUnavailable | boolean | false | 当不可用时,按钮是否应隐藏 |
| text | string | - | 显示在图标旁边的文本 |
需求
使用的参考组件
use-tiptap-editor(hook)tiptap-utils(lib)button(primitive)list-icon(icon)list-todo-icon(icon)list-ordered-icon(icon)
开源功能
@tiptap/extension-task-list@tiptap/extension-task-item