({
language: _language = DEFAULT_LANGUAGE,
transparentBackground = false,
paddingSize = 'l',
fontSize = 's',
isCopyable = false,
copyAriaLabel,
whiteSpace = 'pre-wrap',
children,
className,
overflowHeight,
isVirtualized: _isVirtualized,
lineNumbers = false,
'aria-label': ariaLabel,
...rest
})
| 123 | } & VirtualizedOptionProps; |
| 124 | |
| 125 | export const EuiCodeBlock: FunctionComponent<EuiCodeBlockProps> = ({ |
| 126 | language: _language = DEFAULT_LANGUAGE, |
| 127 | transparentBackground = false, |
| 128 | paddingSize = 'l', |
| 129 | fontSize = 's', |
| 130 | isCopyable = false, |
| 131 | copyAriaLabel, |
| 132 | whiteSpace = 'pre-wrap', |
| 133 | children, |
| 134 | className, |
| 135 | overflowHeight, |
| 136 | isVirtualized: _isVirtualized, |
| 137 | lineNumbers = false, |
| 138 | 'aria-label': ariaLabel, |
| 139 | ...rest |
| 140 | }) => { |
| 141 | const euiTheme = useEuiTheme(); |
| 142 | const language = useMemo( |
| 143 | () => checkSupportedLanguage(_language), |
| 144 | [_language] |
| 145 | ); |
| 146 | |
| 147 | const lineNumbersConfig = useMemo(() => { |
| 148 | const config = typeof lineNumbers === 'object' ? lineNumbers : {}; |
| 149 | return lineNumbers |
| 150 | ? { start: 1, show: true, ...config } |
| 151 | : { start: 1, show: false }; |
| 152 | }, [lineNumbers]); |
| 153 | |
| 154 | // Used by `FixedSizeList` when `isVirtualized=true` or `children` is parsable |
| 155 | const data: RefractorNode[] = useMemo(() => { |
| 156 | if (typeof children !== 'string') { |
| 157 | return []; |
| 158 | } |
| 159 | return highlightByLine(children, language, lineNumbersConfig, euiTheme); |
| 160 | }, [children, language, lineNumbersConfig, euiTheme]); |
| 161 | |
| 162 | // Used by `pre` when `isVirtualized=false` or `children` is not parsable |
| 163 | const content = useMemo( |
| 164 | () => getHtmlContent(data, children), |
| 165 | [data, children] |
| 166 | ); |
| 167 | |
| 168 | const isVirtualized = useMemo( |
| 169 | () => !!(_isVirtualized && Array.isArray(data)), |
| 170 | [_isVirtualized, data] |
| 171 | ); |
| 172 | |
| 173 | const { innerTextRef, copyButton } = useCopy({ |
| 174 | copyAriaLabel, |
| 175 | isCopyable, |
| 176 | isVirtualized, |
| 177 | children, |
| 178 | }); |
| 179 | |
| 180 | const { setWrapperRef, tabIndex, overflowHeightStyles } = useOverflow({ |
| 181 | overflowHeight, |
| 182 | }); |
nothing calls this directly
no test coverage detected
searching dependent graphs…