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 / BlurControl.tsx

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

81 lines 3.0 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 BlurControl = ({
12 attributes,
13 setAttributes,
14 }: AttributesPropsAndSetter) => {
15 const inputRef = useRef<HTMLInputElement>(null);
16 useEffect(() => {
17 try {
18 parseStringArrayWithSingleNestedArray(attributes.lineBlurs);
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.lineBlurs]);
29
30 return (
31 <BaseControl id="code-block-pro-show-blurring">
32 <CheckboxControl
33 data-cy="enable-blur"
34 label={__('Enable blur emphesis', 'code-block-pro')}
35 help={__(
36 'Blur surrounding code to focus on specific lines.',
37 'code-block-pro',
38 )}
39 checked={attributes.enableBlurring ?? false}
40 onChange={(enableBlurring) => {
41 setAttributes({ enableBlurring });
42 }}
43 />
44 {attributes.enableBlurring && (
45 <BaseControl id="code-block-pro-show-blurred-lines">
46 <div ref={inputRef}>
47 <TextControl
48 id="code-block-pro-show-blurred-lines"
49 spellCheck={false}
50 autoComplete="off"
51 label={__(
52 'Focus on the following',
53 'code-block-pro',
54 )}
55 help={sprintf(
56 __(
57 'Try %1$s or %2$s for a range.',
58 'code-block-pro',
59 ),
60 '1,5',
61 '1,[3,5]',
62 )}
63 onChange={(lineBlurs) => {
64 setAttributes({ lineBlurs });
65 }}
66 value={attributes?.lineBlurs ?? ''}
67 />
68 </div>
69 <CheckboxControl
70 label={__('Remove blur on hover', 'code-block-pro')}
71 checked={attributes.removeBlurOnHover ?? false}
72 onChange={(removeBlurOnHover) => {
73 setAttributes({ removeBlurOnHover });
74 }}
75 />
76 </BaseControl>
77 )}
78 </BaseControl>
79 );
80 };
81