PluginProbe
Extendify / 2.2.2
Extendify v2.2.2
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 2.2.2, at src/Draft/components/SelectedText.jsx

60 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { store as blockEditorStore } from '@wordpress/block-editor';
2 import { Button } from '@wordpress/components';
3 import { useDispatch } from '@wordpress/data';
4 import { useEffect, useState } from '@wordpress/element';
5 import { __, isRTL } from '@wordpress/i18n';
6 import { Icon, edit, trash } from '@wordpress/icons';
7 import { useSelectedText } from '@draft/hooks/useSelectedText';
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-sm border-none bg-gray-100 p-3"
33 data-test="existing-text-container">
34 <div>
35 <Icon icon={edit} className="fill-current" />
36 </div>
37 <div>
38 <div
39 className="mb-1 hyphens-auto text-pretty text-gray-800"
40 dangerouslySetInnerHTML={{
41 __html: truncatedText(),
42 }}
43 />
44 <div className="mt-3 flex w-full justify-end">
45 <Button
46 size="compact"
47 onClick={clearSelectedBlock}
48 disabled={loading}
49 icon={trash}
50 iconPosition={isRTL() ? 'right' : 'left'}
51 className="relative flex-row-reverse rounded bg-gray-300 text-gray-800 hover:bg-gray-400"
52 data-test="remove-selection">
53 {__('Remove selection', 'extendify-local')}
54 </Button>
55 </div>
56 </div>
57 </div>
58 );
59 };
60