Skip to content

Commit 8379af6

Browse files
authored
Merge pull request #4135 from udecode/md/suggestion
Add static version suggestion leaf
2 parents fbd6ba2 + d1c3774 commit 8379af6

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

apps/www/content/docs/en/components/changelog.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Use the [CLI](https://platejs.org/docs/components/cli) to install the latest ver
1313
### March 2 #20.2
1414

1515
- `block-suggestion`: fix styles
16+
- `suggestion-leaf-static`: add static versions
1617

1718
### March 1 #20.1
1819

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
3+
import { cn } from '@udecode/cn';
4+
import { type SlateLeafProps, SlateLeaf } from '@udecode/plate';
5+
import {
6+
type TSuggestionText,
7+
BaseSuggestionPlugin,
8+
} from '@udecode/plate-suggestion';
9+
import { useEditorPlugin } from '@udecode/plate/react';
10+
11+
export function SuggestionLeafStatic(props: SlateLeafProps) {
12+
const { children, className, leaf } = props;
13+
14+
const { api } = useEditorPlugin(BaseSuggestionPlugin);
15+
16+
const dataList = api.suggestion.dataList(leaf as TSuggestionText);
17+
18+
const hasRemove = dataList.some((data) => data.type === 'remove');
19+
20+
const diffOperation = {
21+
type: hasRemove ? 'delete' : 'insert',
22+
} as const;
23+
24+
const Component = (
25+
{
26+
delete: 'del',
27+
insert: 'ins',
28+
update: 'span',
29+
} as const
30+
)[diffOperation.type];
31+
32+
return (
33+
<SlateLeaf
34+
{...props}
35+
as={Component}
36+
className={cn(
37+
'border-b-2 border-b-brand/[.24] bg-brand/[.08] text-brand/80 no-underline transition-colors duration-200',
38+
hasRemove &&
39+
'border-b-gray-300 bg-gray-300/25 text-gray-400 line-through',
40+
className
41+
)}
42+
>
43+
{children}
44+
</SlateLeaf>
45+
);
46+
}

apps/www/src/registry/registry-ui.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,10 @@ export const uiNodes: Registry['items'] = [
10991099
docs: [{ route: '/docs/suggestion' }],
11001100
examples: ['comments-demo', 'comments-pro'],
11011101
},
1102-
files: [{ path: 'plate-ui/suggestion-leaf.tsx', type: 'registry:ui' }],
1102+
files: [
1103+
{ path: 'plate-ui/suggestion-leaf.tsx', type: 'registry:ui' },
1104+
{ path: 'plate-ui/suggestion-leaf-static.tsx', type: 'registry:ui' },
1105+
],
11031106
name: 'suggestion-leaf',
11041107
registryDependencies: ['suggestion-plugin'],
11051108
type: 'registry:ui',

0 commit comments

Comments
 (0)