MCPcopy Create free account
hub / github.com/elastic/eui / EuiCodeBlock

Function EuiCodeBlock

packages/eui/src/components/code/code_block.tsx:125–341  ·  view source on GitHub ↗
({
  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
})

Source from the content-addressed store, hash-verified

123} & VirtualizedOptionProps;
124
125export 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 });

Callers

nothing calls this directly

Calls 10

useEuiThemeFunction · 0.90
checkSupportedLanguageFunction · 0.90
highlightByLineFunction · 0.90
getHtmlContentFunction · 0.90
useCopyFunction · 0.90
useOverflowFunction · 0.90
useCombinedRefsFunction · 0.90
useFullScreenFunction · 0.90
useEuiMemoizedStylesFunction · 0.90
useEuiI18nFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…