PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.1.0
Code Block Pro – Beautiful Syntax Highlighting v1.1.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.1.0, at src/editor/controls/Sidebar.tsx

91 lines 3.7 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 { sprintf, __ } from '@wordpress/i18n';
9 import { Theme } from 'shiki';
10 import defaultLanguages from '../../defaultLanguages.json';
11 import defaultThemes from '../../defaultThemes.json';
12 import { useLanguage } from '../../hooks/useLanguage';
13 import { useGlobalStore } from '../../state/global';
14 import { useThemeStore } from '../../state/theme';
15 import { AttributesPropsAndSetter } from '../../types';
16 import { Notice } from '../components/Notice';
17 import { ThemePreview } from '../components/ThemePreview';
18
19 export const SidebarControls = ({
20 attributes,
21 setAttributes,
22 }: AttributesPropsAndSetter) => {
23 const [language, setLanguage] = useLanguage({ attributes, setAttributes });
24 const { setPreviousTheme } = 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-settings">
34 <SelectControl
35 label={__('Language', 'code-block-pro')}
36 value={language}
37 onChange={setLanguage}
38 options={defaultLanguages.map((value) => ({
39 label: value,
40 value,
41 }))}
42 />
43 <CheckboxControl
44 label={__('Copy Button', 'code-block-pro')}
45 help={__(
46 'If checked, users will be able to copy your code snippet to their clipboard.',
47 'code-block-pro',
48 )}
49 checked={attributes.copyButton}
50 onChange={(value) => {
51 setPreviousSettings({ copyButton: value });
52 setAttributes({ copyButton: value });
53 }}
54 />
55 </BaseControl>
56 <Notice />
57 </div>
58 </PanelBody>
59 <PanelBody
60 title={__('Themes', 'code-block-pro')}
61 initialOpen={false}>
62 <div className="code-block-pro-editor">
63 {Object.entries(defaultThemes).map(([slug, name]) => (
64 <BaseControl
65 id={`code-block-pro-theme-${slug}`}
66 label={
67 attributes.theme === slug
68 ? sprintf(
69 __('%s (current)', 'code-block-pro'),
70 name,
71 )
72 : name
73 }
74 key={slug}>
75 <ThemePreview
76 theme={slug as Theme}
77 lang={language}
78 onClick={() => {
79 setAttributes({ theme: slug as Theme });
80 setPreviousTheme(slug as Theme);
81 }}
82 code={attributes.code}
83 />
84 </BaseControl>
85 ))}
86 </div>
87 </PanelBody>
88 </InspectorControls>
89 );
90 };
91