| 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 |
|