@graphcommerce/docs 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +4 -0
- package/CHANGELOG.md +160 -0
- package/components/Layout/LayoutFull.tsx +85 -0
- package/components/Layout/Logo.tsx +19 -0
- package/components/Layout/graphcommerce.svg +34 -0
- package/components/Search.tsx +37 -0
- package/components/SearchForm.tsx +110 -0
- package/components/SidebarMenu/index.tsx +101 -0
- package/components/prism.css +274 -0
- package/components/rehype-prism-plus.css +49 -0
- package/components/theme.ts +410 -0
- package/content/framework/deployment.md +56 -0
- package/content/framework/environment-variables.md +61 -0
- package/content/framework/favicon.md +38 -0
- package/content/framework/graphcms.md +66 -0
- package/content/framework/icons.md +255 -0
- package/content/framework/readme.md +79 -0
- package/content/framework/seo.md +64 -0
- package/content/framework/static-file-serving.md +44 -0
- package/content/framework/static-generation.md +221 -0
- package/content/framework/theming.md +258 -0
- package/content/framework/translations.md +112 -0
- package/content/framework/troubleshooting.md +67 -0
- package/content/framework/typography.md +143 -0
- package/content/getting-started/create.md +152 -0
- package/content/getting-started/graphcms-component.md +240 -0
- package/content/getting-started/header.md +224 -0
- package/content/getting-started/pages.md +290 -0
- package/content/getting-started/readme.md +294 -0
- package/content/getting-started/start-building.md +160 -0
- package/content/getting-started/vscode.md +48 -0
- package/content/readme.md +124 -0
- package/content/roadmap.md +31 -0
- package/lib/DocumentIndexer.ts +59 -0
- package/lib/files.ts +168 -0
- package/lib/instantSearch.ts +26 -0
- package/lib/typesense/IndexerHandler.ts +47 -0
- package/lib/typesense/Leaves.ts +37 -0
- package/lib/typesense/SearchIndexer.ts +64 -0
- package/lib/typesense/batchInterable.ts +13 -0
- package/lib/typesense/createInstantSearchProps.ts +36 -0
- package/lib/typesense/typesenseClientConf.ts +23 -0
- package/lib/typesense/typesenseIndexerHandler.ts +23 -0
- package/next-env.d.ts +5 -0
- package/next.config.js +21 -0
- package/package.json +56 -0
- package/pages/[[...url]].tsx +391 -0
- package/pages/_app.tsx +26 -0
- package/pages/_document.tsx +22 -0
- package/pages/api/reindex.ts +4 -0
- package/pages/menu/[[...url]].tsx +69 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/favicon.svg +12 -0
- package/public/link.svg +4 -0
- package/public/manifest/favicon-192.png +0 -0
- package/public/manifest/favicon-512.png +0 -0
- package/public/manifest.webmanifest +20 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Typography
|
|
2
|
+
|
|
3
|
+
This guide provides information about using the Typography component and
|
|
4
|
+
customizing your GraphCommerce storefront's typography. If your looking to learn
|
|
5
|
+
about the `<Trans>` macro, head over to
|
|
6
|
+
[translations](../framework/translations.md).
|
|
7
|
+
|
|
8
|
+
## Using the typography component
|
|
9
|
+
|
|
10
|
+
The `<Typography>` component is used to render text on pages and in components:
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
<Typography variant='h1' component='h4'>
|
|
14
|
+
<Trans>This is the homepage</Trans>
|
|
15
|
+
</Typography>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Will output:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
<h4 class='MuiTypography-root MuiTypography-h1'>This is the homepage</h4>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
It's important to realize that the style of a typography component is
|
|
25
|
+
independent from the semantic underlying element. In the example above, the
|
|
26
|
+
variant prop is used to render a `<h4>` semantic element with h1 styling.
|
|
27
|
+
|
|
28
|
+
## Changing font styles and font sizes
|
|
29
|
+
|
|
30
|
+
Font styles are part of the global styles in /components/index.ts. Changes to
|
|
31
|
+
font-size and few other properties can be made here:
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
h1: {
|
|
35
|
+
...fontSize(28, 64),
|
|
36
|
+
fontWeight: 700,
|
|
37
|
+
fontVariationSettings: "'wght' 660",
|
|
38
|
+
lineHeight: 1.22,
|
|
39
|
+
},
|
|
40
|
+
h2: {
|
|
41
|
+
...fontSize(25, 40),
|
|
42
|
+
fontWeight: 700,
|
|
43
|
+
fontVariationSettings: "'wght' 630",
|
|
44
|
+
lineHeight: 1.35,
|
|
45
|
+
},
|
|
46
|
+
h3: {
|
|
47
|
+
...fontSize(22, 30),
|
|
48
|
+
fontWeight: 700,
|
|
49
|
+
fontVariationSettings: "'wght' 680",
|
|
50
|
+
lineHeight: 1.55,
|
|
51
|
+
},
|
|
52
|
+
...
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
In most other cases, styling within the context of a page or component is the
|
|
56
|
+
better solution. The sx prop is used to overwrite the styling of a Typography
|
|
57
|
+
component:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
<Typography
|
|
61
|
+
variant='h3'
|
|
62
|
+
component='div'
|
|
63
|
+
gutterBottom
|
|
64
|
+
sx={{
|
|
65
|
+
h3: (theme) => ({
|
|
66
|
+
color: theme.palette.primary.main,
|
|
67
|
+
}),
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
{product.name}
|
|
71
|
+
</Typography>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Responsive font sizes
|
|
75
|
+
|
|
76
|
+
The fontSize 'property' accepts an object with a font size for each breakpoint:
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
fontSize: {
|
|
80
|
+
lg: 50,
|
|
81
|
+
md: 40,
|
|
82
|
+
sm: 25,
|
|
83
|
+
xs: 15
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The GraphCommerce helper function `breakpointVal` does the same, but simplifies
|
|
88
|
+
the syntax by calculating the intermediate values (`fontSize` is a
|
|
89
|
+
simplification of `breakpointVal`):
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
// Example from /components/theme.ts
|
|
93
|
+
|
|
94
|
+
h1: {
|
|
95
|
+
...fontSize(28, 64),
|
|
96
|
+
fontWeight: 700,
|
|
97
|
+
fontVariationSettings: "'wght' 660",
|
|
98
|
+
lineHeight: 1.22,
|
|
99
|
+
},
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
To use breakpointVal in a component:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
sx={{
|
|
106
|
+
...breakpointVal('fontSize', 36, 82, theme.breakpoints.values),
|
|
107
|
+
}}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Adding a custom font
|
|
111
|
+
|
|
112
|
+
- In /pages/\_document.tsx, add your Google font `<link>` element as a child of
|
|
113
|
+
the `<Head>` component:
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
<Head>
|
|
117
|
+
...
|
|
118
|
+
<link rel='preconnect' href='https://fonts.googleapis.com' />
|
|
119
|
+
<link rel='preconnect' href='https://fonts.gstatic.com' crossOrigin='' />
|
|
120
|
+
<link
|
|
121
|
+
href='https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,700;1,400;1,600&display=swap'
|
|
122
|
+
rel='stylesheet'
|
|
123
|
+
/>
|
|
124
|
+
</Head>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- In /components/theme.ts, add the font to the global fontFamily, or to specific
|
|
128
|
+
font class like h1:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
typography: {
|
|
132
|
+
fontFamily:
|
|
133
|
+
'Open Sans,-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji',
|
|
134
|
+
// @see docs typography.md
|
|
135
|
+
h1: {
|
|
136
|
+
fontFamily: 'Open Sans',
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Next steps
|
|
140
|
+
|
|
141
|
+
- Learn more about the
|
|
142
|
+
[Typography component ↗](https://mui.com/components/typography/) in the MUI
|
|
143
|
+
documentation
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
---
|
|
2
|
+
menu: 1. Create a custom storefront
|
|
3
|
+
metaTitle: Create a custom storefront
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Create a GraphCommerce storefront
|
|
7
|
+
|
|
8
|
+
You're ready to create a GraphCommerce storefront. You want to set up your
|
|
9
|
+
development environment so that you can begin development.
|
|
10
|
+
|
|
11
|
+
In this tutorial, you'll create a GraphCommerce app locally to begin developing
|
|
12
|
+
a full-featured storefront. GraphCommerce is a front-end framework used for
|
|
13
|
+
building headless Magento e-commerce PWA's.
|
|
14
|
+
|
|
15
|
+
### What you'll learn
|
|
16
|
+
|
|
17
|
+
After you've finished this tutorial, you'll have accomplished the following:
|
|
18
|
+
|
|
19
|
+
- Set up your local development environment
|
|
20
|
+
- Generated a new project based on the magento-graphcms example
|
|
21
|
+
|
|
22
|
+
<figure>
|
|
23
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/fk82kF" />
|
|
24
|
+
<figcaption>GraphCommerce magento-graphcms example category page</figcaption>
|
|
25
|
+
</figure>
|
|
26
|
+
|
|
27
|
+
<figure>
|
|
28
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/Fs7XWK" />
|
|
29
|
+
<figcaption>GraphCommerce magento-graphcms example product page</figcaption>
|
|
30
|
+
</figure>
|
|
31
|
+
|
|
32
|
+
### Requirements
|
|
33
|
+
|
|
34
|
+
You've familiarized yourself with
|
|
35
|
+
[React ↗](https://reactjs.org/docs/getting-started.html),
|
|
36
|
+
[Next.js ↗](https://nextjs.org/docs/getting-started), and
|
|
37
|
+
[Mui ↗](https://mui.com/getting-started/installation/). GraphCommerce is a
|
|
38
|
+
front-end React framework that uses Next.js for server-side rendering.
|
|
39
|
+
|
|
40
|
+
### Install dependencies
|
|
41
|
+
|
|
42
|
+
If you want to test a GraphCommerce storefront using a pre-configured Magento
|
|
43
|
+
demo store and a pre-configured GraphCMS project with demo content, then you
|
|
44
|
+
need to only install the dependencies. This is the quickest approach.
|
|
45
|
+
|
|
46
|
+
- Install and use node 14: `nvm install 14 && nvm use 14`
|
|
47
|
+
- Install yarn: `npm install --global yarn`
|
|
48
|
+
|
|
49
|
+
## Step 1: Create a new GraphCommerce app
|
|
50
|
+
|
|
51
|
+
### Download the example
|
|
52
|
+
|
|
53
|
+
1. `git clone ... graphcommerce`
|
|
54
|
+
2. `mkdir my-project`
|
|
55
|
+
3. `cp -R graphcommerce/examples/magento-graphcms/. my-project`
|
|
56
|
+
4. `rm -rf graphcommerce`
|
|
57
|
+
5. `cd my-project`
|
|
58
|
+
6. `cp -R .env.example .env`
|
|
59
|
+
7. `rm CHANGELOG.md && touch CHANGELOG.md`
|
|
60
|
+
8. `rm -rf node_modules && rm -rf .next`
|
|
61
|
+
|
|
62
|
+
Edit /package.json. Delete `"scripts": {...}` and rename `scripts_local` to
|
|
63
|
+
`scripts`:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"name": "@my-company/my-project",
|
|
68
|
+
"scripts": {
|
|
69
|
+
...
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Step 2: Magento and GraphCMS API keys
|
|
75
|
+
|
|
76
|
+
> By default, the .env file is configured with API keys from a demo Magento
|
|
77
|
+
> store and a demo GraphCMS project. If you want to test your GraphCommerce app
|
|
78
|
+
> using the demo store, then you can start the development environment. Only
|
|
79
|
+
> proceed with the following steps if you want to develop a GraphCommerce
|
|
80
|
+
> storefront using your own Magento store and/or GraphCMS project.
|
|
81
|
+
|
|
82
|
+
### Requirements
|
|
83
|
+
|
|
84
|
+
To order to be able to connect your GraphCommerce app to your Magento backend
|
|
85
|
+
and/or GraphCMS project, you'll need:
|
|
86
|
+
|
|
87
|
+
- Magento 2.4.3 - Clean install, or a production or development environment
|
|
88
|
+
- GraphCMS - A GraphCMS project with the required schema.
|
|
89
|
+
[Clone the demo GraphCMS project](https://app.graphcms.com/clone/caddaa93cfa9436a9e76ae9c0F34d257)
|
|
90
|
+
as your starting point.
|
|
91
|
+
|
|
92
|
+
### Configuration
|
|
93
|
+
|
|
94
|
+
To connect your GraphCommerce app to your Magento backend and/or GraphCMS
|
|
95
|
+
project, you need to update variables in the /.env file. The .env file contains
|
|
96
|
+
useful information about your storefront.
|
|
97
|
+
|
|
98
|
+
`MAGENTO_ENDPOINT=""`
|
|
99
|
+
Magento 2 API url, located at `http://<magento2-server>/graphql`.
|
|
100
|
+
|
|
101
|
+
`IMAGE_DOMAINS=",media.graphcms.com"`
|
|
102
|
+
Comma-separated list of image domains. Add media.graphcms.com as default.
|
|
103
|
+
|
|
104
|
+
`GRAPHCMS_URL=""`
|
|
105
|
+
GraphCMS API url. Once logged in, copy it from Project Settings > Api Access >
|
|
106
|
+
Content API
|
|
107
|
+
|
|
108
|
+
`NEXT_PUBLIC_LOCALE_STORES='{"en": "en_US", "nl": "default"}'`
|
|
109
|
+
List of routes and store_codes. In the above example, adding URL suffix /nl/
|
|
110
|
+
would result in the storeview 'default' is loaded. GraphCommerce uses the
|
|
111
|
+
browser language to determine which storeview to load. A URL suffix will be
|
|
112
|
+
added as a result, with the exception of the first option in the list.
|
|
113
|
+
|
|
114
|
+
> If need to fetch a list of available store_codes, run `yarn dev` when you
|
|
115
|
+
> entered your `MAGENTO_ENDPOINT`. The app won't build, but the GraphQL explorer
|
|
116
|
+
> will start at `http://localhost:3000/api/graphql`. Enter the following query:
|
|
117
|
+
>
|
|
118
|
+
> ```graphql {3-4}
|
|
119
|
+
> query {
|
|
120
|
+
> availableStores {
|
|
121
|
+
> store_code
|
|
122
|
+
> store_name
|
|
123
|
+
> }
|
|
124
|
+
> }
|
|
125
|
+
> ```
|
|
126
|
+
|
|
127
|
+
### Remove unused PSP's
|
|
128
|
+
|
|
129
|
+
The example has Payment Service Providers integrated (Mollie, Braintree). Remove
|
|
130
|
+
the ones you don't want to use.
|
|
131
|
+
|
|
132
|
+
- Remove `"@graphcommerce/[psp]"` from package.json
|
|
133
|
+
- Remove all [psp] references from `pages/checkout/payment.tsx`
|
|
134
|
+
|
|
135
|
+
## Step 3: Start the development environment
|
|
136
|
+
|
|
137
|
+
- `yarn` Install the dependencies
|
|
138
|
+
- `yarn codegen` Converts all .graphql files to typescript files
|
|
139
|
+
- `yarn dev` Run the app
|
|
140
|
+
|
|
141
|
+
Visit the development environment running at http://localhost:3000
|
|
142
|
+
Visit the GraphQL Playground running at http://localhost:3000/api/graphql
|
|
143
|
+
|
|
144
|
+
> No success? Refer to [common build errors](../framework/troubleshooting.md)
|
|
145
|
+
|
|
146
|
+
## Next steps
|
|
147
|
+
|
|
148
|
+
- Learn how to [Set up Visual Studio Code](../getting-started/vscode.md) and
|
|
149
|
+
install usefull extensions for an optimal development experience
|
|
150
|
+
- [Start building a GraphCommerce custom storefront](../getting-started/start-building.md)
|
|
151
|
+
by customizing text and component styles, fetching data from server
|
|
152
|
+
components, and making changes to GraphQL queries.
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
---
|
|
2
|
+
menu: 5. Build a GraphCMS component
|
|
3
|
+
metaTitle: Build a GraphCMS component
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
> **Developer preview**
|
|
7
|
+
> This is a developer preview of GraphCommerce. The documentation will be
|
|
8
|
+
> updated as GraphCommerce introduces
|
|
9
|
+
> [new features and refines existing functionality](https://github.com/ho-nl/m2-pwa/releases).
|
|
10
|
+
|
|
11
|
+
# Build a GraphCMS component
|
|
12
|
+
|
|
13
|
+
Previously, you created a GraphCommerce app and started building a custom
|
|
14
|
+
header. You're now ready to build a GraphCMS component.
|
|
15
|
+
|
|
16
|
+
GraphCMS is the integrated Content Management System that is part of the
|
|
17
|
+
[magento-graphcms example](../getting-started/readme.md).
|
|
18
|
+
|
|
19
|
+
In this tutorial, you'll accomplish a series of tasks to add some specific
|
|
20
|
+
functionality to your app. The final result will be relatively simple, but
|
|
21
|
+
you'll learn where to find resources to build more complex features on your own.
|
|
22
|
+
|
|
23
|
+
### After you've finished this tutorial, you'll have accomplished the following:
|
|
24
|
+
|
|
25
|
+
- Create a Model in GraphCMS, called Banner
|
|
26
|
+
- Configure the Model's copy and image field
|
|
27
|
+
- Define the relationship between the Banner Model and Page Content field
|
|
28
|
+
- Write a GraphQL query fragment and add it to the page query
|
|
29
|
+
- Add the component to the page renderers
|
|
30
|
+
|
|
31
|
+
### Requirements
|
|
32
|
+
|
|
33
|
+
You've familiarized yourself with
|
|
34
|
+
[React ↗](https://reactjs.org/docs/getting-started.html),
|
|
35
|
+
[Next.js ↗](https://nextjs.org/docs/getting-started), and
|
|
36
|
+
[Mui ↗](https://mui.com/getting-started/installation/). GraphCommerce is a
|
|
37
|
+
frontend React framework that uses Next.js for server-side rendering.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
### Create the GraphCMS model
|
|
42
|
+
|
|
43
|
+
- Login to GraphCMS, navigate to the Schema and add a new Model called "Banner"
|
|
44
|
+
- Add a single line text field called "Identity" and configure the following:
|
|
45
|
+
|
|
46
|
+
<figure>
|
|
47
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/6UGrfK" />
|
|
48
|
+
<figcaption>Adding a Single line text field called "Identity"</figcaption>
|
|
49
|
+
</figure>
|
|
50
|
+
|
|
51
|
+
<figure>
|
|
52
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/TvNPoT" />
|
|
53
|
+
<figcaption>Configuring of the "Identity" field</figcaption>
|
|
54
|
+
</figure>
|
|
55
|
+
|
|
56
|
+
- Add an Asset field called "Image" and configure the following:
|
|
57
|
+
|
|
58
|
+
<figure>
|
|
59
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/OdkckP" />
|
|
60
|
+
<figcaption>Adding an Asset field called "Image"</figcaption>
|
|
61
|
+
</figure>
|
|
62
|
+
|
|
63
|
+
- Add a Rich text field called "Copy" and configure the following:
|
|
64
|
+
|
|
65
|
+
<figure>
|
|
66
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/C8nzzB" />
|
|
67
|
+
<figcaption>Adding a Rich text field called "Copy"</figcaption>
|
|
68
|
+
</figure>
|
|
69
|
+
|
|
70
|
+
<figure>
|
|
71
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/j9kydr" />
|
|
72
|
+
<figcaption>Configuring of the "Copy" field</figcaption>
|
|
73
|
+
</figure>
|
|
74
|
+
|
|
75
|
+
### Define relationship with Content field
|
|
76
|
+
|
|
77
|
+
To be able to use the newly created model to add banners to pages, define the
|
|
78
|
+
relationship between the Banner model and the Content field of the Page model.
|
|
79
|
+
|
|
80
|
+
- Navigate to the Page Schema. Edit the field called "Content"
|
|
81
|
+
- Click "Define relationship" (collapsed by default). Add the Banner model to
|
|
82
|
+
"Models to reference"
|
|
83
|
+
|
|
84
|
+
<figure>
|
|
85
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/Dc4axA" />
|
|
86
|
+
<figcaption>Adding the newly created Banner Model to "Models to reference"</figcaption>
|
|
87
|
+
</figure>
|
|
88
|
+
|
|
89
|
+
- Navigate to Content, edit the Homepage entry and add a new banner instance to
|
|
90
|
+
the homepage:
|
|
91
|
+
|
|
92
|
+
<figure>
|
|
93
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/lpa4x4" />
|
|
94
|
+
<figcaption>Adding a new banner to the Homepage content entry</figcaption>
|
|
95
|
+
</figure>
|
|
96
|
+
|
|
97
|
+
### Validate GraphQL Schema
|
|
98
|
+
|
|
99
|
+
- To validate the addition of the Banner model and the relation with the Page
|
|
100
|
+
model Content field, try out the following GraphQL query in your local GraphQL
|
|
101
|
+
endpoint (running at http://localhost:3000/api/graphql):
|
|
102
|
+
|
|
103
|
+
```graphql
|
|
104
|
+
query {
|
|
105
|
+
pages(where: { url: "page/home" }) {
|
|
106
|
+
title
|
|
107
|
+
content {
|
|
108
|
+
__typename
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Should output the following. Make note that 'Banner' is listed as a typename.
|
|
115
|
+
|
|
116
|
+
<figure>
|
|
117
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/G51mOD" />
|
|
118
|
+
<figcaption>Validation of the addition of "Banner" to the GraphQL Schema</figcaption>
|
|
119
|
+
</figure>
|
|
120
|
+
|
|
121
|
+
### Create the component query fragment
|
|
122
|
+
|
|
123
|
+
- Add a new file, /components/GraphCMS/Banner/Banner.graphql:
|
|
124
|
+
|
|
125
|
+
```graphql
|
|
126
|
+
fragment Banner on Banner {
|
|
127
|
+
image {
|
|
128
|
+
...Asset
|
|
129
|
+
}
|
|
130
|
+
copy {
|
|
131
|
+
raw
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- After saving the file, a new file Banner.gql.ts should be
|
|
137
|
+
[created automatically](../getting-started/readme.md#query-fragments). Take a
|
|
138
|
+
look at the file's contents. It should export the type `BannerFragment`.
|
|
139
|
+
|
|
140
|
+
### Add the query fragment to the page query fragments
|
|
141
|
+
|
|
142
|
+
- In /components/GraphCMS/RowRenderer.graphql, add the fragment:
|
|
143
|
+
|
|
144
|
+
```graphql
|
|
145
|
+
fragment RowRenderer on Page {
|
|
146
|
+
content {
|
|
147
|
+
__typename
|
|
148
|
+
... on Node {
|
|
149
|
+
id
|
|
150
|
+
}
|
|
151
|
+
...RowColumnOne
|
|
152
|
+
...RowColumnTwo
|
|
153
|
+
...RowColumnThree
|
|
154
|
+
...RowBlogContent
|
|
155
|
+
...RowHeroBanner
|
|
156
|
+
...RowSpecialBanner
|
|
157
|
+
...RowQuote
|
|
158
|
+
...RowButtonLinkList
|
|
159
|
+
...RowServiceOptions
|
|
160
|
+
...RowContentLinks
|
|
161
|
+
...RowProduct
|
|
162
|
+
...Banner
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Create the React component
|
|
168
|
+
|
|
169
|
+
- Add a new file, /components/GraphCMS/Banner/index.tsx:
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import { RichText } from '@graphcommerce/graphcms-ui'
|
|
173
|
+
import { BannerFragment } from './Banner.gql'
|
|
174
|
+
|
|
175
|
+
export function Banner(props: BannerFragment) {
|
|
176
|
+
const { copy, image } = props
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<div>
|
|
180
|
+
{image?.url}
|
|
181
|
+
<RichText
|
|
182
|
+
{...copy}
|
|
183
|
+
sxRenderer={{
|
|
184
|
+
paragraph: {
|
|
185
|
+
textAlign: 'center' as const,
|
|
186
|
+
},
|
|
187
|
+
'heading-one': (theme) => ({
|
|
188
|
+
color: theme.palette.primary.main,
|
|
189
|
+
}),
|
|
190
|
+
}}
|
|
191
|
+
/>
|
|
192
|
+
</div>
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Add the component to page components
|
|
198
|
+
|
|
199
|
+
- In /components/GraphCMS/RowRenderer.tsx, add to the imports:
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
import { Banner } from './Banner'
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
- In the same file, add banner:
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
const defaultRenderer: Partial<ContentTypeRenderer> = {
|
|
209
|
+
RowColumnOne,
|
|
210
|
+
RowColumnTwo,
|
|
211
|
+
RowColumnThree,
|
|
212
|
+
RowHeroBanner,
|
|
213
|
+
RowSpecialBanner,
|
|
214
|
+
RowQuote,
|
|
215
|
+
RowBlogContent,
|
|
216
|
+
RowButtonLinkList,
|
|
217
|
+
RowServiceOptions,
|
|
218
|
+
RowContentLinks,
|
|
219
|
+
RowProduct,
|
|
220
|
+
Banner,
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- If a Model entry had been added to the homepage content field, it should
|
|
225
|
+
render. Note that the order in which content of the content field is sorted,
|
|
226
|
+
matters:
|
|
227
|
+
|
|
228
|
+
<figure>
|
|
229
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/ONwNJD" />
|
|
230
|
+
<figcaption>An instance of the banner component rendering with content from GraphCMS</figcaption>
|
|
231
|
+
</figure>
|
|
232
|
+
|
|
233
|
+
<figure>
|
|
234
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/bMsi6A" />
|
|
235
|
+
<figcaption>Sort order matters</figcaption>
|
|
236
|
+
</figure>
|
|
237
|
+
|
|
238
|
+
## Next steps
|
|
239
|
+
|
|
240
|
+
- Explore the [GraphCommerce framework](../framework/readme.md)
|