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