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

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

80 lines 3.0 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 { SimpleString } from './headers/SimpleString';
8
9 type HeaderSelectProps = {
10 attributes: Attributes;
11 onClick: (slug: string) => void;
12 };
13 export const HeaderSelect = ({ attributes, onClick }: HeaderSelectProps) => {
14 const { headerType, bgColor } = attributes;
15 const types = {
16 none: __('None', 'code-block-pro'),
17 headlights: __('Headlights', 'code-block-pro'),
18 headlightsMuted: __('Headlights muted', 'code-block-pro'),
19 headlightsMutedAlt: __('Headlights muted alt', 'code-block-pro'),
20 simpleString: __('Simple string', 'code-block-pro'),
21 };
22
23 const attributesWithoutHeaderType = {
24 ...attributes,
25 } as Partial<Attributes>;
26 delete attributesWithoutHeaderType.headerType;
27
28 return (
29 <div className="code-block-pro-editor">
30 {Object.entries(types).map(([slug, type]) => (
31 <BaseControl
32 id={`code-block-pro-header-${slug}`}
33 label={
34 headerType === slug
35 ? sprintf(
36 __('%s (current)', 'code-block-pro'),
37 type,
38 )
39 : type
40 }
41 key={slug}>
42 <button
43 id={`code-block-pro-header-${slug}`}
44 type="button"
45 onClick={() => onClick(slug)}
46 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-scroll">
47 <span className="pointer-events-none w-full">
48 <HeaderType
49 headerType={slug}
50 {...attributesWithoutHeaderType}
51 />
52 <span
53 className="block w-full h-8"
54 style={{ backgroundColor: bgColor }}
55 />
56 </span>
57 </button>
58 </BaseControl>
59 ))}
60 </div>
61 );
62 };
63
64 export const HeaderType = (attributes: Partial<Attributes>) => {
65 const { headerType } = attributes;
66 if (headerType === 'headlights') {
67 return <Headlights {...attributes} />;
68 }
69 if (headerType === 'headlightsMuted') {
70 return <HeadlightsMuted {...attributes} />;
71 }
72 if (headerType === 'headlightsMutedAlt') {
73 return <HeadlightsMutedAlt {...attributes} />;
74 }
75 if (headerType === 'simpleString') {
76 return <SimpleString {...attributes} />;
77 }
78 return null;
79 };
80