PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.18.0
Code Block Pro – Beautiful Syntax Highlighting v1.18.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 / seemore / RoundCenter.tsx

RoundCenter.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.18.0, at src/editor/components/seemore/RoundCenter.tsx

76 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { colord, AnyColor } from 'colord';
3 import { Attributes } from '../../../types';
4 import { findBackgroundColor, findTextColor } from '../../../util/colors';
5
6 export const RoundCenter = (
7 attributes: Partial<Attributes> & { context?: string },
8 ) => {
9 const { bgColor, textColor, seeMoreString, context, footerType } =
10 attributes;
11 let bgTop, color, bg;
12 if (bgColor?.startsWith('var(')) {
13 bgTop = findBackgroundColor(attributes) ?? bgColor;
14 bg = bgTop;
15 color = findTextColor(attributes) ?? textColor;
16 } else {
17 const bgC = colord(bgColor as AnyColor);
18 const textC = colord(textColor as AnyColor);
19 color = bgC.isDark()
20 ? textC.lighten(0.15).toHex()
21 : textC.darken(0.15).toHex();
22 bg = bgC.isDark() ? bgC.lighten(0.1).toHex() : bgC.darken(0.1).toHex();
23 bgTop = bgC.toHex();
24 }
25 const hasFooter = footerType !== 'none';
26 const inEditor = context === 'editor';
27
28 return (
29 <div
30 className="cbp-see-more-container"
31 style={{
32 display: context === 'front' ? 'none' : 'flex',
33 flexDirection: 'column',
34 alignItems: 'center',
35 width: '100%',
36 fontSize: '12px',
37 lineHeight: '1',
38 position: 'relative',
39 paddingTop: hasFooter ? 0 : '4px',
40 marginBottom: hasFooter || inEditor ? 0 : '-16px',
41 height: hasFooter && !inEditor ? 0 : '32px',
42 }}>
43 {/* bg 50% height at top */}
44 {!hasFooter && (
45 <div
46 style={{
47 backgroundColor: bgTop,
48 height: '50%',
49 position: 'absolute',
50 top: 0,
51 left: 0,
52 right: 0,
53 }}
54 aria-hidden="true"
55 />
56 )}
57 {/* span is used to avoid theme button styling */}
58 <span
59 role={inEditor ? 'presentation' : 'button'}
60 tabIndex={inEditor ? -1 : 0}
61 className="cbp-see-more-simple-btn cbp-see-more-simple-btn-hover"
62 style={{
63 color,
64 backgroundColor: bg,
65 padding: '6px 14px',
66 cursor: 'default',
67 position: 'relative',
68 borderRadius: '6px',
69 transform: hasFooter ? 'translateY(-50%)' : undefined,
70 }}>
71 {seeMoreString || __('Expand', 'code-block-pro')}
72 </span>
73 </div>
74 );
75 };
76