| 1 |
import { BaseControl } from '@wordpress/components'; |
| 2 |
import { sprintf, __ } from '@wordpress/i18n'; |
| 3 |
import { Attributes } from '../../types'; |
| 4 |
import { SimpleStringEnd } from './footers/SimpleStringEnd'; |
| 5 |
|
| 6 |
type FooterSelectProps = { |
| 7 |
attributes: Attributes; |
| 8 |
onClick: (slug: string) => void; |
| 9 |
}; |
| 10 |
export const FooterSelect = ({ attributes, onClick }: FooterSelectProps) => { |
| 11 |
const { footerType, ...attributesWithoutFooterType }: Partial<Attributes> = |
| 12 |
attributes; |
| 13 |
const { bgColor } = attributes; |
| 14 |
const types = { |
| 15 |
none: __('None', 'code-block-pro'), |
| 16 |
simpleStringEnd: __('Simple string end', 'code-block-pro'), |
| 17 |
}; |
| 18 |
|
| 19 |
return ( |
| 20 |
<div className="code-block-pro-editor"> |
| 21 |
{Object.entries(types).map(([slug, type]) => ( |
| 22 |
<BaseControl |
| 23 |
id={`code-block-pro-footer-${slug}`} |
| 24 |
label={ |
| 25 |
footerType === slug |
| 26 |
? sprintf( |
| 27 |
__('%s (current)', 'code-block-pro'), |
| 28 |
type, |
| 29 |
) |
| 30 |
: type |
| 31 |
} |
| 32 |
help={ |
| 33 |
['simpleStringEnd'].includes(slug) |
| 34 |
? __('Update text in Settings', 'code-block-pro') |
| 35 |
: undefined |
| 36 |
} |
| 37 |
key={slug}> |
| 38 |
<button |
| 39 |
id={`code-block-pro-footer-${slug}`} |
| 40 |
type="button" |
| 41 |
onClick={() => onClick(slug)} |
| 42 |
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-auto"> |
| 43 |
<span className="pointer-events-none w-full"> |
| 44 |
<span |
| 45 |
className="block w-full h-8" |
| 46 |
style={{ backgroundColor: bgColor }} |
| 47 |
/> |
| 48 |
<FooterType |
| 49 |
footerType={slug} |
| 50 |
{...attributesWithoutFooterType} |
| 51 |
/> |
| 52 |
</span> |
| 53 |
</button> |
| 54 |
</BaseControl> |
| 55 |
))} |
| 56 |
</div> |
| 57 |
); |
| 58 |
}; |
| 59 |
|
| 60 |
export const FooterType = (attributes: Partial<Attributes>) => { |
| 61 |
const { footerType } = attributes; |
| 62 |
if (footerType === 'simpleStringEnd') { |
| 63 |
return <SimpleStringEnd {...attributes} />; |
| 64 |
} |
| 65 |
return null; |
| 66 |
}; |
| 67 |
|