PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.3.0
Code Block Pro – Beautiful Syntax Highlighting v1.3.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 / Sidebar.tsx

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

108 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { InspectorControls } from '@wordpress/block-editor';
2 import {
3 PanelBody,
4 BaseControl,
5 SelectControl,
6 CheckboxControl,
7 } from '@wordpress/components';
8 import { __ } from '@wordpress/i18n';
9 import { Theme } from 'shiki';
10 import { useLanguage } from '../../hooks/useLanguage';
11 import { useGlobalStore } from '../../state/global';
12 import { useThemeStore } from '../../state/theme';
13 import { AttributesPropsAndSetter } from '../../types';
14 import { languages } from '../../util/languages';
15 import { FontSizeSelect, FontLineHeightSelect } from '../components/FontSelect';
16 import { Notice } from '../components/Notice';
17 import { ThemeSelect } from '../components/ThemeSelect';
18
19 export const SidebarControls = ({
20 attributes,
21 setAttributes,
22 }: AttributesPropsAndSetter) => {
23 const [language, setLanguage] = useLanguage({ attributes, setAttributes });
24 const { updateThemeHistory } = useThemeStore();
25 const { setPreviousSettings } = useGlobalStore();
26
27 return (
28 <InspectorControls>
29 <PanelBody
30 title={__('Settings', 'code-block-pro')}
31 initialOpen={true}>
32 <div className="code-block-pro-editor">
33 <BaseControl id="code-block-pro-language">
34 <SelectControl
35 id="code-block-pro-language"
36 label={__('Code Language', 'code-block-pro')}
37 data-cy-cbp="language-select"
38 value={language}
39 onChange={setLanguage}
40 options={Object.entries(languages).map(
41 ([value, label]) => ({
42 label,
43 value,
44 }),
45 )}
46 />
47 </BaseControl>
48 <Notice />
49 </div>
50 </PanelBody>
51 <PanelBody
52 title={__('Styling', 'code-block-pro')}
53 initialOpen={false}>
54 <div className="code-block-pro-editor">
55 <h2 className="m-0">{__('Font Size', 'code-block-pro')}</h2>
56 <FontSizeSelect
57 value={attributes.fontSize}
58 onChange={(fontSize) => {
59 setAttributes({ fontSize });
60 updateThemeHistory({ ...attributes, fontSize });
61 }}
62 />
63 <h2 className="m-0">
64 {__('Line Height', 'code-block-pro')}
65 </h2>
66 <FontLineHeightSelect
67 value={attributes.lineHeight}
68 onChange={(lineHeight) => {
69 setAttributes({ lineHeight });
70 updateThemeHistory({
71 ...attributes,
72 lineHeight,
73 });
74 }}
75 />
76 </div>
77 </PanelBody>
78 <PanelBody
79 title={__('Themes', 'code-block-pro')}
80 initialOpen={false}>
81 <ThemeSelect
82 {...attributes}
83 onClick={(slug: Theme) => {
84 setAttributes({ theme: slug });
85 updateThemeHistory({ ...attributes, theme: slug });
86 }}
87 />
88 </PanelBody>
89 <PanelBody
90 title={__('Extra Settings', 'code-block-pro')}
91 initialOpen={false}>
92 <CheckboxControl
93 label={__('Copy Button', 'code-block-pro')}
94 help={__(
95 'If checked, users will be able to copy your code snippet to their clipboard.',
96 'code-block-pro',
97 )}
98 checked={attributes.copyButton}
99 onChange={(value) => {
100 setPreviousSettings({ copyButton: value });
101 setAttributes({ copyButton: value });
102 }}
103 />
104 </PanelBody>
105 </InspectorControls>
106 );
107 };
108