-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathHeadingElementContentEditable.tsx
55 lines (49 loc) · 1.7 KB
/
HeadingElementContentEditable.tsx
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
53
54
55
import { useAppDispatch } from 'app/store/storeHooks';
import { useEditable } from 'common/hooks/useEditable';
import { AutosizeTextarea } from 'features/nodes/components/sidePanel/builder/AutosizeTextarea';
import { HeadingElementContent } from 'features/nodes/components/sidePanel/builder/HeadingElementContent';
import { formElementHeadingDataChanged } from 'features/nodes/store/nodesSlice';
import type { HeadingElement } from 'features/nodes/types/workflow';
import { memo, useCallback, useRef } from 'react';
import { useTranslation } from 'react-i18next';
export const HeadingElementContentEditable = memo(({ el }: { el: HeadingElement }) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const { id, data } = el;
const { content } = data;
const ref = useRef<HTMLTextAreaElement>(null);
const onChange = useCallback(
(content: string) => {
dispatch(formElementHeadingDataChanged({ id, changes: { content } }));
},
[dispatch, id]
);
const editable = useEditable({
value: content,
defaultValue: '',
onChange,
inputRef: ref,
});
if (!editable.isEditing) {
return <HeadingElementContent content={editable.value} onDoubleClick={editable.startEditing} />;
}
return (
<AutosizeTextarea
ref={ref}
placeholder={t('workflows.builder.headingPlaceholder')}
{...editable.inputProps}
variant="outline"
overflowWrap="anywhere"
w="full"
minRows={1}
maxRows={10}
resize="none"
p={1}
px={2}
fontWeight="bold"
fontSize="2xl"
_focusVisible={{ borderRadius: 'base', h: 'unset' }}
/>
);
});
HeadingElementContentEditable.displayName = 'HeadingElementContentEditable';