PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Draft / components / SelectedText.jsx

SelectedText.jsx in Extendify 3.1.5, at src/Draft/components/SelectedText.jsx

62 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useSelectedText } from '@draft/hooks/useSelectedText';
2 import { store as blockEditorStore } from '@wordpress/block-editor';
3 import { Button } from '@wordpress/components';
4 import { useDispatch } from '@wordpress/data';
5 import { useEffect, useState } from '@wordpress/element';
6 import { __, isRTL } from '@wordpress/i18n';
7 import { Icon, pencil, trash } from '@wordpress/icons';
8
9 export const SelectedText = ({ loading }) => {
10 const [text, setText] = useState();
11 const { clearSelectedBlock } = useDispatch(blockEditorStore);
12 const { selectedText } = useSelectedText();
13
14 useEffect(() => {
15 setText(selectedText);
16 }, [setText, selectedText]);
17
18 if (!text) return;
19
20 const truncatedText = () => {
21 const preformat = text.split(' ');
22
23 if (preformat.length <= 20) return text;
24
25 return `${text.split(' ', 14).join(' ')}... ${text.slice(
26 text.lastIndexOf(' ') - 14,
27 )}`;
28 };
29
30 return (
31 <div
32 className="mb-4 flex space-x-2 overflow-hidden rounded-xs border-none bg-gray-100 p-3"
33 data-test="existing-text-container"
34 >
35 <div>
36 <Icon icon={pencil} className="fill-current" />
37 </div>
38 <div>
39 <div
40 className="mb-1 hyphens-auto text-pretty text-gray-800"
41 dangerouslySetInnerHTML={{
42 __html: truncatedText(),
43 }}
44 />
45 <div className="mt-3 flex w-full justify-end">
46 <Button
47 size="compact"
48 onClick={clearSelectedBlock}
49 disabled={loading}
50 icon={trash}
51 iconPosition={isRTL() ? 'right' : 'left'}
52 className="relative flex-row-reverse rounded-sm bg-gray-300 text-gray-800 hover:bg-gray-400"
53 data-test="remove-selection"
54 >
55 {__('Remove selection', 'extendify-local')}
56 </Button>
57 </div>
58 </div>
59 </div>
60 );
61 };
62