Skip to content

Commit 8ea1dbd

Browse files
committed
chore: Bump package version to 1.0.215 and enhance Tiptap component
- Update package version in package.json to 1.0.215 - Add autoFocus prop to Tiptap component for improved user experience - Implement placeholder support in Tiptap stories - Refactor Tiptap component to streamline editor handling and focus management - Add CSS styles for empty editor state placeholders in tailwind.css
1 parent 8931e68 commit 8ea1dbd

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.214",
3+
"version": "1.0.215",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

src/Components/Inputs/Tiptap/index.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Editor } from "@tiptap/core";
21
import { EditorContent, useEditor } from "@tiptap/react";
32
import { useMobile } from "Hooks/useMediaQuery";
43
import classNames from "classnames";
@@ -21,6 +20,7 @@ import { TiptapProps, TiptapRef } from "./types";
2120

2221
const Tiptap: ForwardRefRenderFunction<TiptapRef, TiptapProps> = (
2322
{
23+
autoFocus = true,
2424
editorContent,
2525
onUpdate,
2626
actions,
@@ -37,7 +37,6 @@ const Tiptap: ForwardRefRenderFunction<TiptapRef, TiptapProps> = (
3737
},
3838
ref
3939
) => {
40-
const [editorRef, setEditorRef] = useState<Editor | null>(null);
4140
const isMobile = useMobile();
4241
const [textSelected, setTextSelected] = useState<string>("");
4342

@@ -80,25 +79,40 @@ const Tiptap: ForwardRefRenderFunction<TiptapRef, TiptapProps> = (
8079

8180
const editor = useEditor(useEditorConfig);
8281

83-
useImperativeHandle(ref, () => {
84-
return {
82+
useEffect(() => {
83+
if (autoFocus && editor) {
84+
editor.commands.focus();
85+
}
86+
}, [autoFocus, editor]);
87+
88+
useImperativeHandle(
89+
ref,
90+
() => ({
8591
clearContent: () => {
86-
editorRef?.commands.clearContent(true);
87-
},
92+
if (!editor) {
93+
return;
94+
}
8895

89-
getContents() {
90-
return editorRef?.getHTML();
96+
editor.commands.clearContent(true);
9197
},
92-
98+
getContents: () => editor?.getHTML() ?? "",
9399
setContent: (content: string) => {
94-
editorRef?.commands.setContent(content);
100+
if (!editor) {
101+
return;
102+
}
103+
104+
editor.commands.setContent(content);
95105
},
106+
setFocus: () => {
107+
if (!editor) {
108+
return;
109+
}
96110

97-
setFocus() {
98-
editorRef?.commands.focus("end");
111+
editor.commands.focus("end");
99112
}
100-
};
101-
}, [editorRef]);
113+
}),
114+
[editor]
115+
);
102116

103117
useEffect(() => {
104118
if (textSelected !== "clicked-outside" || !editor) {
@@ -112,10 +126,6 @@ const Tiptap: ForwardRefRenderFunction<TiptapRef, TiptapProps> = (
112126
setTextSelected("");
113127
}, [textSelected, isMobile, editor]);
114128

115-
if (!editorRef && editor) {
116-
setEditorRef(editor);
117-
}
118-
119129
if (!editor) {
120130
return null;
121131
}

src/Components/Inputs/Tiptap/tiptap.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const Default = () => {
6262
<div className='yl:w-full yl:md:w-[768px]'>
6363
<Tiptap
6464
ref={tiptapRef as RefObject<TiptapRef>}
65+
placeholder='Enter your content here...'
6566
label='Content'
6667
suggestions={suggestions}
6768
toolbarItems={toolbarItems}

src/Components/Inputs/Tiptap/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface ITiptapActions {
1818
}
1919

2020
export interface TiptapProps {
21+
autoFocus?: boolean;
2122
editorContent?: string;
2223
onUpdate?: (props: EditorEvents["update"]) => void;
2324
onAction?: (action: TiptapActionsEnum) => void;

src/tailwind.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,19 @@
4444
}
4545
}
4646
}
47+
48+
.tiptap p.is-editor-empty:first-child::before {
49+
color: var(--color-muted);
50+
content: attr(data-placeholder);
51+
float: left;
52+
height: 0;
53+
pointer-events: none;
54+
}
55+
56+
.tiptap p.is-empty::before {
57+
color: var(--color-muted);
58+
content: attr(data-placeholder);
59+
float: left;
60+
height: 0;
61+
pointer-events: none;
62+
}

0 commit comments

Comments
 (0)