-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuseAmplifyKit.ts
52 lines (49 loc) · 1.79 KB
/
useAmplifyKit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { useMemo } from 'react';
import { RichText } from 'src/molecules/RichTextEditor';
import {
ImageExtensionFnProps,
RichTextEditorFeatures,
} from 'src/molecules/RichTextEditor/RichTextEditor.types';
interface AmplifyKitProps extends ImageExtensionFnProps {
features?: RichTextEditorFeatures[];
placeholder?: string;
}
/* c8 ignore start */
export const useAmplifyKit = ({
features,
placeholder,
onImageUpload,
onImageRead,
}: AmplifyKitProps) => {
// This hooks is where we can use the features API we made to turn off extensions in the new configure API
// Currently its only turning off the image extension since its the only one that needs to be turned off for the moment
// The new compound component structure also lets users circumvent this if they need more control
return useMemo(
() =>
RichText.Kit.configure({
placeholder: placeholder ? { placeholder } : undefined,
link: features?.includes(RichTextEditorFeatures.LINKS) ? {} : false,
table: features?.includes(RichTextEditorFeatures.TABLE) ? {} : false,
textAlign: features?.includes(RichTextEditorFeatures.ALIGNMENT)
? {}
: false,
bulletList: features?.includes(RichTextEditorFeatures.LISTS)
? {}
: false,
orderedList: features?.includes(RichTextEditorFeatures.LISTS)
? {}
: false,
codeBlockLowlight: features?.includes(RichTextEditorFeatures.CODE)
? {}
: false,
image: features?.includes(RichTextEditorFeatures.IMAGES)
? { onImageUpload, onImageRead }
: false,
heading: features?.includes(RichTextEditorFeatures.HEADERS)
? {}
: false,
}),
[placeholder, features, onImageUpload, onImageRead]
);
};
/* c8 ignore stop */