| 1 |
import { BaseControl } from '@wordpress/components'; |
| 2 |
import { sprintf, __ } from '@wordpress/i18n'; |
| 3 |
import { Attributes } from '../../types'; |
| 4 |
import { HeaderType } from './HeaderType'; |
| 5 |
|
| 6 |
type HeaderSelectProps = { |
| 7 |
attributes: Attributes; |
| 8 |
onClick: (slug: string) => void; |
| 9 |
}; |
| 10 |
export const HeaderSelect = ({ attributes, onClick }: HeaderSelectProps) => { |
| 11 |
const { headerType, bgColor } = attributes; |
| 12 |
const types = { |
| 13 |
'': __('None', 'code-block-pro'), |
| 14 |
headlights: __('Headlights', 'code-block-pro'), |
| 15 |
}; |
| 16 |
return ( |
| 17 |
<div className="code-block-pro-editor"> |
| 18 |
{Object.entries(types).map(([slug, type]) => ( |
| 19 |
<BaseControl |
| 20 |
id={`code-block-pro-header-${slug}`} |
| 21 |
label={ |
| 22 |
headerType === slug |
| 23 |
? sprintf( |
| 24 |
__('%s (current)', 'code-block-pro'), |
| 25 |
type, |
| 26 |
) |
| 27 |
: type |
| 28 |
} |
| 29 |
key={slug}> |
| 30 |
<button |
| 31 |
id={`code-block-pro-header-${slug}`} |
| 32 |
type="button" |
| 33 |
onClick={() => onClick(slug)} |
| 34 |
className="p-0 border flex items-start w-full text-left outline-none cursor-pointer no-underline ring-offset-2 ring-offset-white focus:shadow-none focus:ring-wp overflow-x-scroll"> |
| 35 |
<span className="pointer-events-none w-full"> |
| 36 |
<HeaderType headerType={slug} bgColor={bgColor} /> |
| 37 |
<span |
| 38 |
className="block w-full h-8" |
| 39 |
style={{ backgroundColor: bgColor }} |
| 40 |
/> |
| 41 |
</span> |
| 42 |
</button> |
| 43 |
</BaseControl> |
| 44 |
))} |
| 45 |
</div> |
| 46 |
); |
| 47 |
}; |
| 48 |
|