| 1 |
import { BaseControl } from '@wordpress/components'; |
| 2 |
import { sprintf, __ } from '@wordpress/i18n'; |
| 3 |
import { Attributes } from '../../types'; |
| 4 |
import { BlockLeft } from './seemore/BlockLeft'; |
| 5 |
import { BlockRight } from './seemore/BlockRight'; |
| 6 |
import { RoundCenter } from './seemore/RoundCenter'; |
| 7 |
|
| 8 |
type SeeMoreSelectProps = { |
| 9 |
attributes: Attributes; |
| 10 |
onClick: (slug: string) => void; |
| 11 |
}; |
| 12 |
export const SeeMoreSelect = ({ attributes, onClick }: SeeMoreSelectProps) => { |
| 13 |
const { |
| 14 |
seeMoreType, |
| 15 |
...attributesWithoutSeeMoreType |
| 16 |
}: Partial<Attributes> = attributes; |
| 17 |
const { bgColor } = attributes; |
| 18 |
const types = { |
| 19 |
none: __('None', 'code-block-pro'), |
| 20 |
roundCenter: __('See more center', 'code-block-pro'), |
| 21 |
blockLeft: __('See more left', 'code-block-pro'), |
| 22 |
blockRight: __('See more right', 'code-block-pro'), |
| 23 |
}; |
| 24 |
|
| 25 |
return ( |
| 26 |
<div className="code-block-pro-editor"> |
| 27 |
{Object.entries(types).map(([slug, type]) => ( |
| 28 |
<BaseControl |
| 29 |
id={`code-block-pro-see-more-${slug}`} |
| 30 |
label={ |
| 31 |
seeMoreType === slug || |
| 32 |
(!seeMoreType && slug === 'none') |
| 33 |
? sprintf( |
| 34 |
__('%s (current)', 'code-block-pro'), |
| 35 |
type, |
| 36 |
) |
| 37 |
: type |
| 38 |
} |
| 39 |
key={slug}> |
| 40 |
<button |
| 41 |
id={`code-block-pro-see-more-${slug}`} |
| 42 |
type="button" |
| 43 |
onClick={() => onClick(slug)} |
| 44 |
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"> |
| 45 |
<span className="pointer-events-none w-full"> |
| 46 |
<span |
| 47 |
className="block w-full h-8" |
| 48 |
style={{ backgroundColor: bgColor }} |
| 49 |
/> |
| 50 |
<SeeMoreType |
| 51 |
seeMoreType={slug} |
| 52 |
context="editor" |
| 53 |
{...attributesWithoutSeeMoreType} |
| 54 |
/> |
| 55 |
</span> |
| 56 |
</button> |
| 57 |
</BaseControl> |
| 58 |
))} |
| 59 |
</div> |
| 60 |
); |
| 61 |
}; |
| 62 |
|
| 63 |
export const SeeMoreType = ( |
| 64 |
props: Partial<Attributes> & { context?: string }, |
| 65 |
) => { |
| 66 |
const { seeMoreType, enableMaxHeight, context } = props; |
| 67 |
if (!enableMaxHeight) return null; |
| 68 |
if (seeMoreType === 'roundCenter') { |
| 69 |
return <RoundCenter {...props} context={context} />; |
| 70 |
} |
| 71 |
if (seeMoreType === 'blockLeft') { |
| 72 |
return <BlockLeft {...props} context={context} />; |
| 73 |
} |
| 74 |
if (seeMoreType === 'blockRight') { |
| 75 |
return <BlockRight {...props} context={context} />; |
| 76 |
} |
| 77 |
|
| 78 |
return null; |
| 79 |
}; |
| 80 |
|