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

SeeMoreSelect.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.27.2, at src/editor/components/SeeMoreSelect.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 { BlockLeft } from './seemore/BlockLeft';
5 import { BlockRight } from './seemore/BlockRight';
6 import { RoundCenter } from './seemore/RoundCenter';
7
8 type SeeMoreSelectProps = {
9 attributes: Attributes;
10 onClick: (slug: string) => void;
11 };
12 export const SeeMoreSelect = ({ attributes, onClick }: SeeMoreSelectProps) => {
13 const {
14 seeMoreType,
15 ...attributesWithoutSeeMoreType
16 }: Partial<Attributes> = attributes;
17 const { bgColor } = attributes;
18 const types = {
19 none: __('None', 'code-block-pro'),
20 roundCenter: __('See more center', 'code-block-pro'),
21 blockLeft: __('See more left', 'code-block-pro'),
22 blockRight: __('See more right', 'code-block-pro'),
23 };
24
25 return (
26 <div className="code-block-pro-editor">
27 {Object.entries(types).map(([slug, type]) => (
28 <BaseControl
29 id={`code-block-pro-see-more-${slug}`}
30 label={
31 seeMoreType === slug ||
32 (!seeMoreType && slug === 'none')
33 ? sprintf(
34 __('%s (current)', 'code-block-pro'),
35 type,
36 )
37 : type
38 }
39 key={slug}>
40 <button
41 id={`code-block-pro-see-more-${slug}`}
42 type="button"
43 onClick={() => onClick(slug)}
44 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">
45 <span className="pointer-events-none w-full">
46 <span
47 className="block w-full h-8"
48 style={{ backgroundColor: bgColor }}
49 />
50 <SeeMoreType
51 seeMoreType={slug}
52 context="editor"
53 {...attributesWithoutSeeMoreType}
54 />
55 </span>
56 </button>
57 </BaseControl>
58 ))}
59 </div>
60 );
61 };
62
63 export const SeeMoreType = (
64 props: Partial<Attributes> & { context?: string },
65 ) => {
66 const { seeMoreType, enableMaxHeight, context } = props;
67 if (!enableMaxHeight) return null;
68 if (seeMoreType === 'roundCenter') {
69 return <RoundCenter {...props} context={context} />;
70 }
71 if (seeMoreType === 'blockLeft') {
72 return <BlockLeft {...props} context={context} />;
73 }
74 if (seeMoreType === 'blockRight') {
75 return <BlockRight {...props} context={context} />;
76 }
77
78 return null;
79 };
80