Skip to content

Commit

Permalink
Merge pull request #3572 from udecode/todo
Browse files Browse the repository at this point in the history
Add todo to playground template
  • Loading branch information
felixfeng33 authored Sep 23, 2024
2 parents 177a05e + a4d0bbb commit 02e1b5f
Show file tree
Hide file tree
Showing 7 changed files with 4,463 additions and 3,494 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { withRef } from '@udecode/cn';
import {
useIndentTodoToolBarButton,
useIndentTodoToolBarButtonState,
} from '@udecode/plate-indent-list/react';
import { withRef } from '@udecode/react-utils';

import { Icons } from '@/components/icons';

Expand Down
7,877 changes: 4,384 additions & 3,493 deletions templates/plate-playground-template/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions templates/plate-playground-template/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
Search,
Settings,
Smile,
Square,
Strikethrough,
Subscript,
SunMedium,
Expand Down Expand Up @@ -162,6 +163,7 @@ const borderTop = (props: LucideProps) => (

export const Icons = {
add: Plus,
todo: Square,
chevronDown: ChevronDown,
alignCenter: AlignCenter,
alignJustify: AlignJustify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ import { HeadingElement } from '@/components/plate-ui/heading-element';
import { HighlightLeaf } from '@/components/plate-ui/highlight-leaf';
import { HrElement } from '@/components/plate-ui/hr-element';
import { ImageElement } from '@/components/plate-ui/image-element';
import {
TodoLi,
TodoMarker,
} from '@/components/plate-ui/indent-todo-marker-component';
import { KbdLeaf } from '@/components/plate-ui/kbd-leaf';
import { LinkElement } from '@/components/plate-ui/link-element';
import { LinkFloatingToolbar } from '@/components/plate-ui/link-floating-toolbar';
Expand Down Expand Up @@ -225,6 +229,15 @@ export const useMyEditor = () => {
...HEADING_LEVELS,
],
},
options: {
listStyleTypes: {
todo: {
liComponent: TodoLi,
markerComponent: TodoMarker,
type: 'todo',
},
},
},
}),
LineHeightPlugin.configure({
inject: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { OutdentToolbarButton } from '@/components/plate-ui/outdent-toolbar-butt
import { TableDropdownMenu } from '@/components/plate-ui/table-dropdown-menu';

import { ColorDropdownMenu } from './color-dropdown-menu';
import { IndentTodoToolbarButton } from './indent-todo-toolbar-button';
import { InsertDropdownMenu } from './insert-dropdown-menu';
import { MarkToolbarButton } from './mark-toolbar-button';
import { ModeDropdownMenu } from './mode-dropdown-menu';
Expand Down Expand Up @@ -102,6 +103,7 @@ export function FixedToolbarButtons() {

<IndentListToolbarButton nodeType={ListStyleType.Disc} />
<IndentListToolbarButton nodeType={ListStyleType.Decimal} />
<IndentTodoToolbarButton />

<OutdentToolbarButton />
<IndentToolbarButton />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { cn } from '@udecode/cn';
import {
useIndentTodoListElement,
useIndentTodoListElementState,
} from '@udecode/plate-indent-list/react';

import { Checkbox } from './checkbox';

import type { PlateRenderElementProps } from '@udecode/plate-common/react';

export const TodoMarker = ({
element,
}: Omit<PlateRenderElementProps, 'children'>) => {
const state = useIndentTodoListElementState({ element });
const { checkboxProps } = useIndentTodoListElement(state);

return (
<div contentEditable={false}>
<Checkbox
style={{ left: -24, position: 'absolute', top: 4 }}
{...checkboxProps}
/>
</div>
);
};

export const TodoLi = (props: PlateRenderElementProps) => {
const { children, element } = props;

return (
<span
className={cn(
(element.checked as boolean) && 'text-muted-foreground line-through'
)}
>
{children}
</span>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
useIndentTodoToolBarButton,
useIndentTodoToolBarButtonState,
} from '@udecode/plate-indent-list/react';
import { withRef } from '@udecode/cn';

import { Icons } from '@/components/icons';

import { ToolbarButton } from './toolbar';

export const IndentTodoToolbarButton = withRef<typeof ToolbarButton>(
(rest, ref) => {
const state = useIndentTodoToolBarButtonState({ nodeType: 'todo' });
const { props } = useIndentTodoToolBarButton(state);

return (
<ToolbarButton ref={ref} tooltip="Todo" {...props} {...rest}>
<Icons.todo />
</ToolbarButton>
);
}
);

0 comments on commit 02e1b5f

Please sign in to comment.