PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.28.0
Code Block Pro – Beautiful Syntax Highlighting v1.28.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 / footers / SimpleStringStart.tsx

SimpleStringStart.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.28.0, at src/editor/components/footers/SimpleStringStart.tsx

90 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { type AnyColor, colord } from 'colord';
2 import type { Attributes, Lang } from '../../../types';
3 import { findBackgroundColor, findTextColor } from '../../../util/colors';
4 import { languages } from '../../../util/languages';
5
6 export const SimpleStringStart = (attributes: Attributes) => {
7 const {
8 language,
9 bgColor,
10 textColor,
11 footerString,
12 footerLink,
13 footerLinkTarget,
14 disablePadding,
15 } = attributes;
16 const textC = colord(textColor as AnyColor);
17 const text = textColor?.startsWith('var(')
18 ? (findTextColor(attributes) ?? textColor)
19 : textC.isDark()
20 ? textC.lighten(0.05).toHex()
21 : textC.darken(0.05).toHex();
22 return (
23 <span
24 style={{
25 display: 'flex',
26 alignItems: 'flex-end',
27 padding: disablePadding ? '10px 0 0 0' : '10px',
28 width: '100%',
29 justifyContent: 'flex-start',
30 backgroundColor: findBackgroundColor(attributes) ?? bgColor,
31 color: text,
32 fontSize: '12px',
33 lineHeight: '1',
34 position: 'relative',
35 }}
36 >
37 <Inner
38 text={footerString || languages[language as Lang]}
39 color={text}
40 link={footerLink}
41 linkTarget={footerLinkTarget}
42 />
43 </span>
44 );
45 };
46
47 const Inner = ({
48 text,
49 color,
50 link,
51 linkTarget,
52 }: {
53 text?: string;
54 color: string;
55 link?: string;
56 linkTarget?: boolean;
57 }) => {
58 if (!link) return <>{text}</>;
59 const style = {
60 color,
61 // attempt to reset the link to not inheret from theme
62 textDecoration: 'none',
63 fontWeight: 'normal',
64 border: 'none',
65 background: 'none',
66 borderRadius: '0',
67 padding: '0',
68 margin: '0',
69 };
70 if (linkTarget) {
71 return (
72 <a
73 className="cbp-footer-link"
74 href={link}
75 style={style}
76 target={'_blank'}
77 // Gutenberg required
78 rel={'noopener noreferrer'}
79 >
80 {text}
81 </a>
82 );
83 }
84 return (
85 <a className="cbp-footer-link" href={link} style={style}>
86 {text}
87 </a>
88 );
89 };
90