-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathaware-builder-component.tsx
More file actions
30 lines (27 loc) · 980 Bytes
/
aware-builder-component.tsx
File metadata and controls
30 lines (27 loc) · 980 Bytes
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
import { Builder, builder, BuilderComponent } from '@builder.io/react';
import { BuilderPageProps } from '@builder.io/react/src/components/builder-page.component';
import '@builder.io/widgets';
import React from 'react';
import Link from '../atoms/link';
import { useCartCount, useAddItemToCart } from 'gatsby-theme-shopify-manager/src';
const apiKey = process.env.GATSBY_BUILDER_API_KEY;
builder.init(apiKey!);
Builder.isStatic = true;
const AwareBuilderComponent: React.FC<Partial<BuilderPageProps>> = props => {
const cartCount = useCartCount();
const addItem = useAddItemToCart();
return (
<BuilderComponent
renderLink={props => {
const internal = props.target !== '_blank' && /^\/(?!\/)/.test(props.href!);
if (internal) {
return <Link url={props.href!} {...props} />;
}
return <a {...props} />;
}}
context={{ cartCount, addItem }}
{...props}
/>
);
};
export default AwareBuilderComponent;