import { BaseControl, ExternalLink } from '@wordpress/components'; import { applyFilters } from '@wordpress/hooks'; import { sprintf, __ } from '@wordpress/i18n'; import { Theme } from 'shiki'; import defaultThemes from '../../defaultThemes.json'; import { useSettingsStore } from '../../state/settings'; import { Lang } from '../../types'; import { getPriorityThemes } from '../../util/themes'; import { ThemePreview } from '../components/ThemePreview'; type ThemeSelectProps = { theme: Theme; language: Lang; code: string; fontSize: string; lineHeight: string; fontFamily: string; search: string; clampFonts: boolean; onClick: (slug: Theme) => void; }; export const ThemeSelect = (props: ThemeSelectProps) => { const { hiddenThemes } = useSettingsStore(); const themes = applyFilters( 'blocks.codeBlockPro.themes', defaultThemes, ) as Record; const themesSorted = Object.entries(themes) .filter(([slug]) => !hiddenThemes.includes(slug)) .filter(([slug]) => slug.includes(props.search.toLocaleLowerCase())) .map(([slug, { name, priority }]) => ({ name, slug, priority })) .sort((a, b) => (a.priority === b.priority ? 0 : a.priority ? -1 : 1)); const priorityThemes = getPriorityThemes(); return (
{props.search?.length > 0 ? ( {priorityThemes?.length > 0 ? null : (
{__( 'Get 25+ more themes here', 'code-block-pro', )}
)}
) : null} {themesSorted.slice(0, 9).map(({ name, slug }) => ( ))} {props.search?.length > 0 ? null : ( {priorityThemes?.length > 0 ? null : (
{__( 'Get 25+ more themes here', 'code-block-pro', )}
)}
)} {themesSorted.slice(9).map(({ name, slug }) => ( ))} {props.search?.length > 0 ? null : ( {priorityThemes?.length > 0 ? null : (
{__( 'Get 25+ more themes here', 'code-block-pro', )}
)}
)}
); }; const ThemeItem = ({ slug, name, theme, language, code, fontSize, lineHeight, fontFamily, clampFonts, onClick, }: { slug: string; name: string } & ThemeSelectProps) => ( { onClick(slug as Theme); }} code={code} /> );