PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.27.4
Code Block Pro – Beautiful Syntax Highlighting v1.27.4
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 / HeaderSelect.tsx

HeaderSelect.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.27.4, at src/editor/components/HeaderSelect.tsx

111 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { BaseControl } from '@wordpress/components';
2 import { sprintf, __ } from '@wordpress/i18n';
3 import { Attributes } from '../../types';
4 import { Headlights } from './headers/Headlights';
5 import { HeadlightsMuted } from './headers/HeadlightsMuted';
6 import { HeadlightsMutedAlt } from './headers/HeadlightsMutedAlt';
7 import { PillString } from './headers/PillString';
8 import { SimpleString } from './headers/SimpleString';
9 import { StringSmall } from './headers/StringSmall';
10 import { UnsupportedTheme } from './misc/Unsupported';
11
12 type HeaderSelectProps = {
13 attributes: Attributes;
14 onClick: (slug: string) => void;
15 };
16
17 const unsupportedWithCssVars = ['headlightsMutedAlt'];
18
19 export const HeaderSelect = ({ attributes, onClick }: HeaderSelectProps) => {
20 const { headerType, ...attributesWithoutHeaderType }: Attributes =
21 attributes;
22 const { bgColor } = attributes;
23 const types = {
24 none: __('None', 'code-block-pro'),
25 headlights: __('Headlights', 'code-block-pro'),
26 headlightsMuted: __('Headlights muted', 'code-block-pro'),
27 headlightsMutedAlt: __('Headlights muted alt', 'code-block-pro'),
28 simpleString: __('Simple string', 'code-block-pro'),
29 stringSmall: __('String muted', 'code-block-pro'),
30 pillString: __('Pill string', 'code-block-pro'),
31 };
32 const isUnsupported = bgColor?.startsWith('var(');
33
34 return (
35 <div className="code-block-pro-editor">
36 {Object.entries(types).map(([slug, type]) => (
37 <BaseControl
38 id={`code-block-pro-header-${slug}`}
39 label={
40 headerType === slug
41 ? sprintf(
42 __('%s (current)', 'code-block-pro'),
43 type,
44 )
45 : type
46 }
47 help={
48 ['simpleString', 'pillString', 'stringSmall'].includes(
49 slug,
50 )
51 ? // Settings refers to the panel that can be expanded
52 __(
53 'Set the text at the top of this panel.',
54 'code-block-pro',
55 )
56 : undefined
57 }
58 key={slug}>
59 <button
60 id={`code-block-pro-header-${slug}`}
61 type="button"
62 onClick={() => onClick(slug)}
63 className="p-0 border flex items-start w-full text-left outline-none cursor-pointer no-underline ring-offset-2 ring-offset-white focus:shadow-none focus:ring-wp overflow-x-auto">
64 <span className="pointer-events-none w-full">
65 <HeaderType
66 headerType={slug}
67 {...attributesWithoutHeaderType}
68 />
69 <span
70 className="block w-full h-8"
71 style={{ backgroundColor: bgColor }}
72 />
73 </span>
74 </button>
75 {isUnsupported && unsupportedWithCssVars.includes(slug) && (
76 <UnsupportedTheme />
77 )}
78 </BaseControl>
79 ))}
80 </div>
81 );
82 };
83
84 export const HeaderType = (attributes: Attributes) => {
85 const { headerType, bgColor } = attributes;
86 const isACustomTheme = bgColor?.startsWith('var(');
87 if (isACustomTheme && unsupportedWithCssVars.includes(headerType ?? '')) {
88 return null;
89 }
90
91 if (headerType === 'headlights') {
92 return <Headlights {...attributes} />;
93 }
94 if (headerType === 'headlightsMuted') {
95 return <HeadlightsMuted {...attributes} />;
96 }
97 if (headerType === 'headlightsMutedAlt') {
98 return <HeadlightsMutedAlt {...attributes} />;
99 }
100 if (headerType === 'simpleString') {
101 return <SimpleString {...attributes} />;
102 }
103 if (headerType === 'stringSmall') {
104 return <StringSmall {...attributes} />;
105 }
106 if (headerType === 'pillString') {
107 return <PillString {...attributes} />;
108 }
109 return null;
110 };
111