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 / Toolbar.tsx

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

72 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { BlockControls } from '@wordpress/block-editor';
2 import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
3 import { applyFilters } from '@wordpress/hooks';
4 import { __ } from '@wordpress/i18n';
5 import defaultThemes from '../../defaultThemes.json';
6 import { useCanEditHTML } from '../../hooks/useCanEditHTML';
7 import { useLanguage } from '../../hooks/useLanguage';
8 import { useGlobalStore } from '../../state/global';
9 import type { AttributesPropsAndSetter, ThemeOption } from '../../types';
10 import { languages } from '../../util/languages';
11
12 export const ToolbarControls = ({
13 attributes,
14 setAttributes,
15 }: AttributesPropsAndSetter) => {
16 const [language] = useLanguage({ attributes, setAttributes });
17 const { theme, bgColor, textColor } = attributes;
18 const themes = applyFilters(
19 'blocks.codeBlockPro.themes',
20 defaultThemes,
21 ) as ThemeOption;
22 const { setBringAttentionToPanel } = useGlobalStore();
23 const canEdit = useCanEditHTML();
24
25 if (canEdit === undefined) return null;
26
27 return (
28 <BlockControls>
29 <ToolbarGroup className="code-block-pro-editor">
30 <ToolbarButton
31 icon={() =>
32 (languages[language] ?? language)?.replace(
33 'ANSI',
34 'ANSI (experimental)',
35 )
36 }
37 onClick={() => setBringAttentionToPanel('language-select')}
38 label={__('Press to open sidebar panel', 'code-block-pro')}
39 style={{ width: 'auto' }}
40 />
41 </ToolbarGroup>
42 {themes[theme]?.name && (
43 <ToolbarGroup className="code-block-pro-editor">
44 <ToolbarButton
45 icon={() => themes[theme]?.name}
46 onClick={() => setBringAttentionToPanel('theme-select')}
47 label={__('Press to open sidebar panel', 'code-block-pro')}
48 style={{ width: 'auto' }}
49 >
50 <span className="flex mx-2">
51 <span
52 style={{
53 backgroundColor:
54 themes[theme]?.styles?.['color-background'] ?? bgColor,
55 }}
56 className="w-3 h-3 border border-gray-400 border-solid border-1 rounded-full inline-block"
57 />
58 <span
59 style={{
60 backgroundColor:
61 themes[theme]?.styles?.['color-text'] ?? textColor,
62 }}
63 className="w-3 h-3 border border-gray-400 border-solid border-1 rounded-full inline-block transform -translate-x-1"
64 />
65 </span>
66 </ToolbarButton>
67 </ToolbarGroup>
68 )}
69 </BlockControls>
70 );
71 };
72