| 1 |
import { BaseControl } from '@wordpress/components'; |
| 2 |
import { sprintf, __ } from '@wordpress/i18n'; |
| 3 |
import { Lang, Theme } from 'shiki'; |
| 4 |
import defaultThemes from '../../defaultThemes.json'; |
| 5 |
import { ThemePreview } from '../components/ThemePreview'; |
| 6 |
|
| 7 |
type ThemeSelectProps = { |
| 8 |
theme: Theme; |
| 9 |
language: Lang; |
| 10 |
code: string; |
| 11 |
fontSize: string; |
| 12 |
lineHeight: string; |
| 13 |
fontFamily: string; |
| 14 |
onClick: (slug: Theme) => void; |
| 15 |
}; |
| 16 |
export const ThemeSelect = ({ |
| 17 |
theme, |
| 18 |
language, |
| 19 |
code, |
| 20 |
fontSize, |
| 21 |
lineHeight, |
| 22 |
fontFamily, |
| 23 |
onClick, |
| 24 |
}: ThemeSelectProps) => { |
| 25 |
return ( |
| 26 |
<div className="code-block-pro-editor"> |
| 27 |
{Object.entries(defaultThemes).map(([slug, name]) => ( |
| 28 |
<BaseControl |
| 29 |
id={`code-block-pro-theme-${slug}`} |
| 30 |
label={ |
| 31 |
theme === slug |
| 32 |
? sprintf( |
| 33 |
__('%s (current)', 'code-block-pro'), |
| 34 |
name, |
| 35 |
) |
| 36 |
: name |
| 37 |
} |
| 38 |
key={slug}> |
| 39 |
<ThemePreview |
| 40 |
id={`code-block-pro-theme-${slug}`} |
| 41 |
theme={slug as Theme} |
| 42 |
lang={language} |
| 43 |
fontSize={fontSize} |
| 44 |
lineHeight={lineHeight} |
| 45 |
fontFamily={fontFamily} |
| 46 |
onClick={() => { |
| 47 |
onClick(slug as Theme); |
| 48 |
}} |
| 49 |
code={code} |
| 50 |
/> |
| 51 |
</BaseControl> |
| 52 |
))} |
| 53 |
</div> |
| 54 |
); |
| 55 |
}; |
| 56 |
|