PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.27.6
Code Block Pro – Beautiful Syntax Highlighting v1.27.6
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.27.6, at src/editor/components/seemore/RoundCenter.tsx

91 lines 3.1 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 {
10 bgColor,
11 textColor,
12 seeMoreString,
13 context,
14 footerType,
15 seeMoreCollapse,
16 seeMoreCollapseString,
17 } = attributes;
18 let bgTop, color, bg;
19 if (bgColor?.startsWith('var(')) {
20 bgTop = findBackgroundColor(attributes) ?? bgColor;
21 bg = bgTop;
22 color = findTextColor(attributes) ?? textColor;
23 } else {
24 const bgC = colord(bgColor as AnyColor);
25 const textC = colord(textColor as AnyColor);
26 color = bgC.isDark()
27 ? textC.lighten(0.15).toHex()
28 : textC.darken(0.15).toHex();
29 bg = bgC.isDark() ? bgC.lighten(0.1).toHex() : bgC.darken(0.1).toHex();
30 bgTop = bgC.toHex();
31 }
32 const hasFooter = footerType !== 'none';
33 const inEditor = context === 'editor';
34 const seeMore = seeMoreString || __('Expand', 'code-block-pro');
35
36 return (
37 <div
38 className="cbp-see-more-container"
39 // If the user opted to collapse, store strings
40 data-see-more-collapse-string={
41 seeMoreCollapse
42 ? seeMoreCollapseString || __('Collapse', 'code-block-pro')
43 : undefined
44 }
45 data-see-more-string={seeMoreCollapse ? seeMore : undefined}
46 style={{
47 display: context === 'front' ? 'none' : 'flex',
48 flexDirection: 'column',
49 alignItems: 'center',
50 width: '100%',
51 fontSize: '12px',
52 lineHeight: '1',
53 position: 'relative',
54 paddingTop: hasFooter ? 0 : '4px',
55 marginBottom: hasFooter || inEditor ? 0 : '-16px',
56 height: hasFooter && !inEditor ? 0 : '32px',
57 }}>
58 {/* bg 50% height at top */}
59 {!hasFooter && (
60 <div
61 style={{
62 backgroundColor: bgTop,
63 height: '50%',
64 position: 'absolute',
65 top: 0,
66 left: 0,
67 right: 0,
68 }}
69 aria-hidden="true"
70 />
71 )}
72 {/* span is used to avoid theme button styling */}
73 <span
74 role={inEditor ? 'presentation' : 'button'}
75 tabIndex={inEditor ? -1 : 0}
76 className="cbp-see-more-simple-btn cbp-see-more-simple-btn-hover"
77 style={{
78 color,
79 backgroundColor: bg,
80 padding: '6px 14px',
81 cursor: 'default',
82 position: 'relative',
83 borderRadius: '6px',
84 transform: hasFooter ? 'translateY(-50%)' : undefined,
85 }}>
86 {seeMore}
87 </span>
88 </div>
89 );
90 };
91