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