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 / components / buttons / sidebar / CopyBtnSettings.tsx

CopyBtnSettings.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.28.0, at src/editor/components/buttons/sidebar/CopyBtnSettings.tsx

111 lines 3.5 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 { __ } from '@wordpress/i18n';
7 import classNames from 'classnames';
8 import { useThemeStore } from '../../../../state/theme';
9 import type { AttributesPropsAndSetter } from '../../../../types';
10 import { copyButtonTypes } from '../copy/CopyButton';
11
12 export const CopyBtnSettings = ({
13 attributes,
14 setAttributes,
15 }: AttributesPropsAndSetter) => {
16 const { updateThemeHistory } = useThemeStore();
17 return (
18 <BaseControl id="code-block-pro-show-copy-button">
19 <CheckboxControl
20 data-cy="copy-button"
21 label={__('Copy Button', 'code-block-pro')}
22 help={__('Adds a button to copy the code', 'code-block-pro')}
23 checked={attributes.copyButton}
24 onChange={(copyButton) => {
25 setAttributes({ copyButton });
26 updateThemeHistory({ copyButton });
27 }}
28 />
29 {attributes.copyButton && (
30 <div className="flex gap-2">
31 {Object.entries(copyButtonTypes).map(([slug, data]) => {
32 const { Component } = data;
33 const {
34 copyButtonType,
35 bgColor: backgroundColor,
36 textColor: color,
37 } = attributes;
38 const current = copyButtonType === slug;
39 return (
40 <div key={slug} style={{ backgroundColor }}>
41 <button
42 id={`code-block-pro-copy-button-${slug}`}
43 type="button"
44 onClick={() => {
45 setAttributes({ copyButtonType: slug });
46 updateThemeHistory({
47 copyButtonType: slug,
48 });
49 }}
50 style={{ color }}
51 aria-current={current}
52 className={classNames(
53 'sidebar-copy-button relative border-0 flex items-start w-full text-left outline-none cursor-pointer no-underline ring-offset-2 ring-offset-white focus:shadow-none ring-wp-theme-500 focus:ring-wp overflow-x-auto top-0 right-0 left-auto bg-transparent border-none transition-opacity duration-200 ease-in-out leading-none z-10 p-1 opacity-90',
54 {
55 'ring-wp': current,
56 },
57 )}
58 >
59 <span className="sr-only">{data.label}</span>
60 <span className="pointer-events-none w-full">
61 <Component color={color} />
62 </span>
63 </button>
64 </div>
65 );
66 })}
67 </div>
68 )}
69 {attributes.copyButton && (
70 <div style={{ marginTop: '1rem' }}>
71 <TextControl
72 id="code-block-pro-copy-button-text"
73 autoComplete="off"
74 label={__('Button label', 'code-block-pro')}
75 placeholder={__('Copy', 'code-block-pro')}
76 onChange={(copyButtonString) => {
77 setAttributes({ copyButtonString });
78 }}
79 value={attributes.copyButtonString ?? ''}
80 />
81 {attributes.copyButtonType === 'textSimple' && (
82 <TextControl
83 id="code-block-pro-copy-button-text-copied"
84 autoComplete="off"
85 label={__('Copied Text', 'code-block-pro')}
86 placeholder={__('Copied!', 'code-block-pro')}
87 onChange={(copyButtonStringCopied) => {
88 setAttributes({ copyButtonStringCopied });
89 }}
90 value={attributes.copyButtonStringCopied ?? ''}
91 help={__('Text briefly shown after the code is copied')}
92 />
93 )}
94 <CheckboxControl
95 label={__('Use Textarea', 'code-block-pro')}
96 help={__(
97 'Use a <textarea> to to store the code, otherwise a `data-code` attribute',
98 'code-block-pro',
99 )}
100 checked={attributes.copyButtonUseTextarea}
101 onChange={(copyButtonUseTextarea) => {
102 setAttributes({ copyButtonUseTextarea });
103 updateThemeHistory({ copyButtonUseTextarea });
104 }}
105 />
106 </div>
107 )}
108 </BaseControl>
109 );
110 };
111