PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.28.0
Code Block Pro – Beautiful Syntax Highlighting v1.28.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.28.0, at src/editor/controls/BlurControl.tsx

75 lines 2.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 type { 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={__('Line blurring', '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={__('Focus on the following', 'code-block-pro')}
52 help={sprintf(
53 __('Try %1$s or %2$s for a range.', 'code-block-pro'),
54 '1,5',
55 '1,[3,5]',
56 )}
57 onChange={(lineBlurs) => {
58 setAttributes({ lineBlurs });
59 }}
60 value={attributes?.lineBlurs ?? ''}
61 />
62 </div>
63 <CheckboxControl
64 label={__('Remove blur on hover', 'code-block-pro')}
65 checked={attributes.removeBlurOnHover ?? false}
66 onChange={(removeBlurOnHover) => {
67 setAttributes({ removeBlurOnHover });
68 }}
69 />
70 </BaseControl>
71 )}
72 </BaseControl>
73 );
74 };
75