PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.13.0
Code Block Pro – Beautiful Syntax Highlighting v1.13.0
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / src / editor / controls / HighlightingControl.tsx

HighlightingControl.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.13.0, at src/editor/controls/HighlightingControl.tsx

73 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 BaseControl,
3 CheckboxControl,
4 TextControl,
5 } from '@wordpress/components';
6 import { useEffect, useRef } from '@wordpress/element';
7 import { sprintf, __ } from '@wordpress/i18n';
8 import { AttributesPropsAndSetter } from '../../types';
9 import { parseStringArrayWithSingleNestedArray } from '../../util/arrayHelpers';
10
11 export const HighlightingControl = ({
12 attributes,
13 setAttributes,
14 }: AttributesPropsAndSetter) => {
15 const inputRef = useRef<HTMLInputElement>(null);
16 useEffect(() => {
17 try {
18 parseStringArrayWithSingleNestedArray(attributes.lineHighlights);
19 inputRef.current
20 ?.querySelector('input')
21 ?.classList.remove('cbp-input-error');
22 } catch (e) {
23 console.error(e);
24 inputRef.current
25 ?.querySelector('input')
26 ?.classList.add('cbp-input-error');
27 }
28 }, [attributes.lineHighlights]);
29 return (
30 <BaseControl id="code-block-pro-show-highlighting">
31 <CheckboxControl
32 data-cy="enable-highlighting"
33 label={__('Enable line highlighting', 'code-block-pro')}
34 help={__(
35 'Highlight individual lines to bring attention to specific code.',
36 'code-block-pro',
37 )}
38 checked={attributes.enableHighlighting ?? false}
39 onChange={(enableHighlighting) => {
40 setAttributes({ enableHighlighting });
41 }}
42 />
43 {attributes.enableHighlighting && (
44 <BaseControl id="code-block-pro-show-highlighted-lines">
45 <div ref={inputRef}>
46 <TextControl
47 id="code-block-pro-show-highlighted-lines"
48 spellCheck={false}
49 autoComplete="off"
50 label={__(
51 'Highlight the following',
52 'code-block-pro',
53 )}
54 help={sprintf(
55 __(
56 'Try %1$s or %2$s for a range.',
57 'code-block-pro',
58 ),
59 '1,5',
60 '1,[3,5]',
61 )}
62 onChange={(lineHighlights) => {
63 setAttributes({ lineHighlights });
64 }}
65 value={attributes?.lineHighlights ?? ''}
66 />
67 </div>
68 </BaseControl>
69 )}
70 </BaseControl>
71 );
72 };
73