| 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 SimpleString = (attributes: Attributes) => { |
| 7 |
const { language, bgColor, textColor, headerString } = attributes; |
| 8 |
const bgC = colord(bgColor as AnyColor); |
| 9 |
let bg = bgC.isDark() ? bgC.lighten(0.05).toHex() : bgC.darken(0.05).toHex(); |
| 10 |
const textC = colord(textColor as AnyColor); |
| 11 |
let text = textC.isDark() |
| 12 |
? textC.lighten(0.05).toHex() |
| 13 |
: textC.darken(0.05).toHex(); |
| 14 |
|
| 15 |
if (bgColor?.startsWith('var(')) { |
| 16 |
bg = findBackgroundColor(attributes) ?? bgColor; |
| 17 |
} |
| 18 |
if (textColor?.startsWith('var(')) { |
| 19 |
text = findTextColor(attributes) ?? textColor; |
| 20 |
} |
| 21 |
return ( |
| 22 |
<span |
| 23 |
style={{ |
| 24 |
display: 'flex', |
| 25 |
alignItems: 'center', |
| 26 |
padding: '10px 0px 10px 16px', |
| 27 |
marginBottom: '-2px', |
| 28 |
width: '100%', |
| 29 |
textAlign: 'left', |
| 30 |
backgroundColor: bg, |
| 31 |
color: text, |
| 32 |
}} |
| 33 |
> |
| 34 |
{headerString || languages[language as Lang]} |
| 35 |
</span> |
| 36 |
); |
| 37 |
}; |
| 38 |
|