| 1 |
import { RichText, useBlockProps as blockProps } from '@wordpress/block-editor'; |
| 2 |
import classNames from 'classnames'; |
| 3 |
import { FooterType } from '../editor/components/FooterSelect'; |
| 4 |
import { HeaderType } from '../editor/components/HeaderSelect'; |
| 5 |
import { SeeMoreType } from '../editor/components/SeeMoreSelect'; |
| 6 |
import { Attributes } from '../types'; |
| 7 |
import { fontFamilyLong, maybeClamp } from '../util/fonts'; |
| 8 |
import { CopyButton } from './CopyButton'; |
| 9 |
import './style.css'; |
| 10 |
|
| 11 |
export const BlockOutput = ({ attributes }: { attributes: Attributes }) => ( |
| 12 |
<div |
| 13 |
{...blockProps.save({ |
| 14 |
className: classNames({ |
| 15 |
'padding-disabled': attributes.disablePadding, |
| 16 |
'padding-bottom-disabled': |
| 17 |
attributes?.footerType && attributes?.footerType !== 'none', |
| 18 |
'cbp-has-line-numbers': attributes.lineNumbers, |
| 19 |
'cbp-blur-enabled': attributes.enableBlurring, |
| 20 |
'cbp-unblur-on-hover': attributes.removeBlurOnHover, |
| 21 |
}), |
| 22 |
})} |
| 23 |
data-code-block-pro-font-family={attributes.fontFamily} |
| 24 |
style={ |
| 25 |
{ |
| 26 |
fontSize: maybeClamp( |
| 27 |
attributes.fontSize, |
| 28 |
attributes.clampFonts, |
| 29 |
), |
| 30 |
// Tiny check to avoid block invalidation error |
| 31 |
fontFamily: fontFamilyLong(attributes.fontFamily), |
| 32 |
'--cbp-line-number-color': attributes?.lineNumbers |
| 33 |
? attributes.textColor |
| 34 |
: undefined, |
| 35 |
'--cbp-line-number-start': |
| 36 |
Number(attributes?.startingLineNumber) > 1 |
| 37 |
? attributes.startingLineNumber |
| 38 |
: undefined, |
| 39 |
'--cbp-line-number-width': attributes.lineNumbersWidth |
| 40 |
? `${attributes.lineNumbersWidth}px` |
| 41 |
: undefined, |
| 42 |
'--cbp-line-highlight-color': attributes?.enableHighlighting |
| 43 |
? attributes.lineHighlightColor |
| 44 |
: undefined, |
| 45 |
lineHeight: maybeClamp( |
| 46 |
attributes.lineHeight, |
| 47 |
attributes.clampFonts, |
| 48 |
), |
| 49 |
} as React.CSSProperties |
| 50 |
}> |
| 51 |
{attributes.code?.length > 0 ? ( |
| 52 |
<> |
| 53 |
<HeaderType {...attributes} /> |
| 54 |
{attributes.copyButton && ( |
| 55 |
<CopyButton attributes={attributes} /> |
| 56 |
)} |
| 57 |
<RichText.Content value={attributes.codeHTML} /> |
| 58 |
<FooterType {...attributes} /> |
| 59 |
<SeeMoreType {...attributes} /> |
| 60 |
</> |
| 61 |
) : null} |
| 62 |
</div> |
| 63 |
); |
| 64 |
|