forked from layer5io/layer5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot-wrapper.js
More file actions
55 lines (52 loc) · 1.42 KB
/
root-wrapper.js
File metadata and controls
55 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";
import { MDXProvider } from "@mdx-js/react";
import Code from "./src/components/CodeBlock";
import CTA_ImageOnly from "./src/components/Call-To-Actions/CTA_ImageOnly";
import CTA_FullWidth from "./src/components/Call-To-Actions/CTA_FullWidth";
import CTA_Bottom from "./src/components/Call-To-Actions/CTA_Bottom";
import { ContextWrapper } from "./context-wrapper";
// Custom image component for better CLS scores
const OptimizedImage = props => {
return (
<div style={{ width: "100%", height: "auto" }}>
<img
{...props}
width={props.width || "100%"}
height={props.height || "auto"}
style={{
objectFit: props.objectFit || "contain",
margin: "20px 0px",
...props.style
}}
loading="lazy"
alt={props.alt || "Blog content image"}
/>
</div>
);
};
const components = {
pre: ({ children: { props } }) => {
if (props.mdxType === "code") {
return (
<Code
codeString={props.children.trim()}
language={
props.className && props.className.replace("language-", "")
}
{...props}
/>
);
}
},
img: OptimizedImage,
CTA_ImageOnly,
CTA_FullWidth,
CTA_Bottom
};
export const wrapRootElement = ({ element }) => (
<ContextWrapper>
<MDXProvider components={components}>
{element}
</MDXProvider>
</ContextWrapper>
);