@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,221 @@
|
|
|
1
|
+
---
|
|
2
|
+
menu: Static Site Generation (SSG)
|
|
3
|
+
metaTitle: Static Site Generation with Nextjs ecommerce framework GraphCommerce
|
|
4
|
+
metaDescription:
|
|
5
|
+
'GraphCommerce is a nextjs Magento framework. GraphCommerce offers Static Site
|
|
6
|
+
Generation for Magento nextjs PWA out-of-the-box.'
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
> **Developer preview**
|
|
10
|
+
> This is a developer preview of GraphCommerce. The documentation will be
|
|
11
|
+
> updated as GraphCommerce introduces
|
|
12
|
+
> [new features and refines existing functionality](https://github.com/ho-nl/m2-pwa/releases).
|
|
13
|
+
|
|
14
|
+
# Static Site Generation (SSG) in GraphCommerce
|
|
15
|
+
|
|
16
|
+
Pages that export a function called getStaticProps, will pre-render at
|
|
17
|
+
build-time. `getStaticProps` generates HTML and JSON files, both of which can be
|
|
18
|
+
cached by a CDN for performance.
|
|
19
|
+
|
|
20
|
+
In the [magento-graphcms example](../getting-started/readme.md), getStaticProps
|
|
21
|
+
is used to pre-render **all pages**. Client-side rendering is used to display
|
|
22
|
+
user-specific content on pre-rendered pages at run-time.
|
|
23
|
+
|
|
24
|
+
For example, client-side rendering is used to display customer data on the
|
|
25
|
+
/account page:
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// Example from /pages/account/index.tsx
|
|
29
|
+
|
|
30
|
+
function AccountIndexPage() {
|
|
31
|
+
const { data, loading, error } = useQuery(AccountDashboardDocument, {
|
|
32
|
+
fetchPolicy: 'cache-and-network',
|
|
33
|
+
ssr: false,
|
|
34
|
+
})
|
|
35
|
+
const { data: config } = useQuery(StoreConfigDocument)
|
|
36
|
+
...
|
|
37
|
+
|
|
38
|
+
const customer = data?.customer
|
|
39
|
+
...
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
In the same file, `getStaticProps` runs the DefaultPageDocument query to fetch
|
|
44
|
+
the data needed to render the layout (header, footer, menu etc.)
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
// Example from /pages/account/index.tsx
|
|
48
|
+
|
|
49
|
+
export const getStaticProps: GetPageStaticProps = async ({ locale }) => {
|
|
50
|
+
...
|
|
51
|
+
|
|
52
|
+
const page = staticClient.query({
|
|
53
|
+
query: DefaultPageDocument,
|
|
54
|
+
variables: {
|
|
55
|
+
url: 'account',
|
|
56
|
+
rootCategory: (await conf).data.storeConfig?.root_category_uid ?? '',
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
props: {
|
|
62
|
+
...(await page).data,
|
|
63
|
+
up: { href: '/', title: 'Home' },
|
|
64
|
+
apolloState: await conf.then(() => client.cache.extract()),
|
|
65
|
+
},
|
|
66
|
+
revalidate: 60 * 20,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## getStaticPaths
|
|
72
|
+
|
|
73
|
+
Pages that have dynamic routes need a list of paths to be statically generated.
|
|
74
|
+
All paths specified by a function called `getStaticPaths` will be statically
|
|
75
|
+
pre-rendered at build-time.
|
|
76
|
+
|
|
77
|
+
For example, `getStaticPaths` runs the ProductStaticPaths query to fetch a list
|
|
78
|
+
of all configurable product paths:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
// Example from /pages/product/configurable/[url].tsx
|
|
82
|
+
|
|
83
|
+
export const getStaticPaths: GetPageStaticPaths = async ({ locales = [] }) => {
|
|
84
|
+
...
|
|
85
|
+
const path = (locale: string) =>
|
|
86
|
+
getProductStaticPaths(
|
|
87
|
+
graphqlSsrClient(locale),
|
|
88
|
+
locale,
|
|
89
|
+
'ConfigurableProduct',
|
|
90
|
+
)
|
|
91
|
+
const paths = (await Promise.all(locales.map(path))).flat(1)
|
|
92
|
+
|
|
93
|
+
return { paths, fallback: 'blocking' }
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
// Example from /node_modules/@graphcommerce/magento-product/components/ProductStaticPaths/ProductStaticPaths.graphql
|
|
99
|
+
|
|
100
|
+
query ProductStaticPaths($currentPage: Int!, $pageSize: Int!) {
|
|
101
|
+
products(filter: {}, pageSize: $pageSize, currentPage: $currentPage) {
|
|
102
|
+
page_info {
|
|
103
|
+
current_page
|
|
104
|
+
total_pages
|
|
105
|
+
}
|
|
106
|
+
total_count
|
|
107
|
+
items {
|
|
108
|
+
...ProductLink
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Build your local environment
|
|
115
|
+
|
|
116
|
+
You can test the static build process by running it locally:
|
|
117
|
+
|
|
118
|
+
- `cd /examples/magento-graphcms/` Navigate to the project directory
|
|
119
|
+
- `yarn build` Start static build process
|
|
120
|
+
|
|
121
|
+
The build proces locally will not pre-render product pages to reduce build time:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
// Example from /pages/product/configurable/[url].tsx
|
|
125
|
+
|
|
126
|
+
export const getStaticPaths: GetPageStaticPaths = async ({ locales = [] }) => {
|
|
127
|
+
|
|
128
|
+
if (process.env.NODE_ENV === 'development') return { paths: [], fallback: 'blocking' }
|
|
129
|
+
...
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
<details open>
|
|
134
|
+
<summary>Disabling Static Generation on production</summary>
|
|
135
|
+
|
|
136
|
+
To disable or limit the amount of pages that are statically pre-redered, slice
|
|
137
|
+
the paths array. This will reduce build-time:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
// Example from /pages/product/configurable/[url].tsx
|
|
141
|
+
|
|
142
|
+
export const getStaticPaths: GetPageStaticPaths = async ({ locales = [] }) => {
|
|
143
|
+
...
|
|
144
|
+
|
|
145
|
+
return { paths: paths.slice(0, 10), fallback: 'blocking' }
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Pages that are not pre-rendered at build-time, will be rendered at run-time
|
|
150
|
+
(on-demand).
|
|
151
|
+
|
|
152
|
+
</details>
|
|
153
|
+
|
|
154
|
+
## Incremental Static Regeneration
|
|
155
|
+
|
|
156
|
+
Most pages have value for `revalidate` in the object that is returned by
|
|
157
|
+
`getStaticProps`:
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
// Example from /pages/product/configurable/[url].tsx
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
props: {
|
|
164
|
+
...(await productPage).data,
|
|
165
|
+
...(await typeProductPage).data,
|
|
166
|
+
apolloState: await conf.then(() => client.cache.extract()),
|
|
167
|
+
up,
|
|
168
|
+
},
|
|
169
|
+
revalidate: 60 * 20,
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
When set, static pages will be regenerated at run-time (on-demand) every 20
|
|
174
|
+
minutes.
|
|
175
|
+
|
|
176
|
+
The initial request to the product page will show the cached page. After 20
|
|
177
|
+
minutes, the regeneration of the page is triggered on the first following
|
|
178
|
+
request. Once the page has been successfully generated, the cache will be
|
|
179
|
+
invalidated and the updated product page is shown.
|
|
180
|
+
|
|
181
|
+
## FAQ
|
|
182
|
+
|
|
183
|
+
<div>
|
|
184
|
+
<details>
|
|
185
|
+
<summary>When is GraphCommerce a suitable Nextjs ecommerce solution?</summary>
|
|
186
|
+
|
|
187
|
+
### When is GraphCommerce a suitable Nextjs ecommerce solution?
|
|
188
|
+
|
|
189
|
+
GraphCommerce is a suitable Nextjs ecommerce solution if your e-commerce store
|
|
190
|
+
is already running on Magento Open Source or Adobe Commerce. A Nextjs Magento
|
|
191
|
+
stack offers interesting features like Static Site Generation (SSG), which will
|
|
192
|
+
improve Magento catalog performance. Nextjs Magento is also a great combination
|
|
193
|
+
if you are looking to migrate to Magento.
|
|
194
|
+
|
|
195
|
+
</details>
|
|
196
|
+
|
|
197
|
+
<details>
|
|
198
|
+
<summary>What are the advantages of a Nextjs React Magento stack?</summary>
|
|
199
|
+
|
|
200
|
+
### What are the advantages of a Nextjs React Magento stack?
|
|
201
|
+
|
|
202
|
+
Nextjs React Magento is considered newer web technology, offering a modern
|
|
203
|
+
approach to e-commerce development. React can be viewed as the industry standard
|
|
204
|
+
for large-scale web apps. Next.js adds the ability for Static Site Generation (a
|
|
205
|
+
form of Server-side Rendering), enabling indexing by search engines.
|
|
206
|
+
GraphCommerce is a framework that combines Nextjs, React and Magento, and
|
|
207
|
+
simplifies building Magento Nextjs PWA's.
|
|
208
|
+
|
|
209
|
+
</details>
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
## Next steps
|
|
213
|
+
|
|
214
|
+
- Learn more about [building pages](../getting-started/pages.md) in
|
|
215
|
+
GraphCommerce
|
|
216
|
+
- Learn more about [Static File Serving](../framework/static-file-serving.md)
|
|
217
|
+
- Learn more about
|
|
218
|
+
[getStaticProps ↗](https://nextjs.org/docs/basic-features/data-fetching/get-static-props)
|
|
219
|
+
or
|
|
220
|
+
[getStaticPaths ↗](https://nextjs.org/docs/basic-features/data-fetching/get-static-paths)
|
|
221
|
+
in the Next.js documentation
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# Theming
|
|
2
|
+
|
|
3
|
+
The GraphCommerce [magento-graphcms](../getting-started/readme.md) example and
|
|
4
|
+
GraphCommerce components are built with [MUI ↗](https://mui.com/). MUI provides
|
|
5
|
+
a robust, customizable, and accessible library of foundational and advanced
|
|
6
|
+
components, enabling you to build your design system and develop React
|
|
7
|
+
applications faster.
|
|
8
|
+
|
|
9
|
+
This guide covers how to customize the global look and feel of your application,
|
|
10
|
+
as well as some common theming needs.
|
|
11
|
+
|
|
12
|
+
## Changing the color palette
|
|
13
|
+
|
|
14
|
+
The global styles or your GraphCommerce app are located in /components/theme.ts.
|
|
15
|
+
To customize the app with your preferred colors, change the primary, secondary
|
|
16
|
+
and text colors. Save the file to see your changes updated in real-time:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
primary: {
|
|
20
|
+
main: '#FF4A55',
|
|
21
|
+
contrastText: '#FFFFFF',
|
|
22
|
+
dark: '#F33642',
|
|
23
|
+
},
|
|
24
|
+
secondary: {
|
|
25
|
+
main: '#006BFF',
|
|
26
|
+
light: '#D1E4FF',
|
|
27
|
+
contrastText: '#ffffff',
|
|
28
|
+
},
|
|
29
|
+
...
|
|
30
|
+
text: {
|
|
31
|
+
primary: '#000000',
|
|
32
|
+
secondary: '#00000050',
|
|
33
|
+
disabled: '#00000030',
|
|
34
|
+
},
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You can search through your codebase to discover which component will be
|
|
38
|
+
affected by your changes. For example, search for occurrences of
|
|
39
|
+
`theme.palette.primary.main`.
|
|
40
|
+
|
|
41
|
+
### Best practices
|
|
42
|
+
|
|
43
|
+
- Limit the number of global style overwrites in /components/theme.ts. to a
|
|
44
|
+
minimum if possible. In most cases, styling within the context of a component
|
|
45
|
+
is the better solution.
|
|
46
|
+
|
|
47
|
+
## Styling component with props
|
|
48
|
+
|
|
49
|
+
Most components have props that define their look and feel. Most common are the
|
|
50
|
+
`color` and `variant` props:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
<Button
|
|
54
|
+
...
|
|
55
|
+
color='primary'
|
|
56
|
+
variant='pill'
|
|
57
|
+
>
|
|
58
|
+
</Button>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Learn about a component's features in the MUI documentation:
|
|
62
|
+
[MUI Button documentation ↗](https://mui.com/components/buttons/)
|
|
63
|
+
- To learn which options are accepted by a prop, refer to the component's API:
|
|
64
|
+
[MUI Button API ↗](https://mui.com/api/button/). You can also use your IDE's
|
|
65
|
+
suggestions functionality. For [VS Code's](../getting-started/vscode.md)
|
|
66
|
+
IntelliSense feature, type Ctrl+Space.
|
|
67
|
+
- It can be helpful to learn how a component is styled, for example, to explore
|
|
68
|
+
how palette variables are used. Refer to the
|
|
69
|
+
[MUI Button source code ↗](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Button/Button.js)
|
|
70
|
+
|
|
71
|
+
## Change a component's styling with the sx prop
|
|
72
|
+
|
|
73
|
+
A simple way to style a component is by using the
|
|
74
|
+
[sx prop ↗](https://mui.com/system/the-sx-prop/). To get started with the sx
|
|
75
|
+
prop in your GraphCommerce storefront, refer to
|
|
76
|
+
[start building a GraphCommerce custom storefront](../getting-started/start-building.md).
|
|
77
|
+
|
|
78
|
+
### Accessing the theme
|
|
79
|
+
|
|
80
|
+
To access the theme object, set an anonymous function as the value of the
|
|
81
|
+
property:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
sx={{
|
|
85
|
+
borderRadius: 2,
|
|
86
|
+
backgroundColor: (theme) => theme.palette.primary.main,
|
|
87
|
+
}}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
To use the theme object for multiple property's:
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
sx={(theme) => ({
|
|
94
|
+
borderRadius: `1px solid ${theme.palette.divider}`,
|
|
95
|
+
backgroundColor: theme.palette.primary.main,
|
|
96
|
+
})}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Creating styled components with the styled() utility
|
|
100
|
+
|
|
101
|
+
A more advanced way is to use the
|
|
102
|
+
[MUI styled() ↗](https://mui.com/system/styled/) utility for creating styled
|
|
103
|
+
components:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { styled } from '@mui/material'
|
|
107
|
+
|
|
108
|
+
const AnimatedButton = styled(Button, { name: 'animatedButton' })(
|
|
109
|
+
({ theme }) => ({
|
|
110
|
+
'@keyframes pulse': {
|
|
111
|
+
'0%': {
|
|
112
|
+
boxShadow: `0 0 0 0 ${theme.palette.primary.main}`,
|
|
113
|
+
},
|
|
114
|
+
'100%': {
|
|
115
|
+
boxShadow: `0 0 0 15px ${theme.palette.background.default}`,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
animation: 'pulse 1.5s infinite',
|
|
119
|
+
}),
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<AnimatedButton color='primary' variant='contained'>
|
|
125
|
+
<Trans>About Us</Trans>
|
|
126
|
+
</AnimatedButton>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
<figure>
|
|
130
|
+
|
|
131
|
+
https://user-images.githubusercontent.com/1251986/155032870-ddecefe0-afb3-418c-af3d-91d8bc435dff.mp4
|
|
132
|
+
|
|
133
|
+
<video width="100%" controls autoPlay loop muted>
|
|
134
|
+
<source src="https://user-images.githubusercontent.com/1251986/155032870-ddecefe0-afb3-418c-af3d-91d8bc435dff.mp4" type="video/mp4"/>
|
|
135
|
+
</video>
|
|
136
|
+
|
|
137
|
+
<figcaption>Example of a styled component</figcaption>
|
|
138
|
+
</figure>
|
|
139
|
+
|
|
140
|
+
## Overriding components state styling
|
|
141
|
+
|
|
142
|
+
To overwrite a component's hover state, add the sx prop:
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
<Button
|
|
146
|
+
color='primary'
|
|
147
|
+
variant='contained'
|
|
148
|
+
sx={{ '&&:hover': { background: 'green' } }}
|
|
149
|
+
>
|
|
150
|
+
<Trans>Contact Us</Trans>
|
|
151
|
+
</Button>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
> Learn more about
|
|
155
|
+
> [overriding styles with class names ↗](https://mui.com/customization/how-to-customize/#overriding-styles-with-class-names)
|
|
156
|
+
> in the MUI documentation
|
|
157
|
+
|
|
158
|
+
## Adding a background image
|
|
159
|
+
|
|
160
|
+
- In /Layout/LayoutFull.tsx, add the sx prop to the `<LayoutDefault>` component:
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
<LayoutDefault sx={{ backgroundImage: `url(/images/stripes.svg)` }} />
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- Place your background image in the /public/images directory
|
|
167
|
+
|
|
168
|
+
## Customizing default border-radius
|
|
169
|
+
|
|
170
|
+
All components that render content with a border-radius, except for pill buttons
|
|
171
|
+
and circular buttons, are dependent on the value of `shape`. A simple way to
|
|
172
|
+
remove this effect is to set its value to 0:
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
shape: { borderRadius: 0 },
|
|
176
|
+
typography: {
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Adding an external CSS style sheet
|
|
180
|
+
|
|
181
|
+
- In /pages/\_document.tsx, add your CSS `<link>` element as a child of the
|
|
182
|
+
`<Head>` component:
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
<Head>
|
|
186
|
+
...
|
|
187
|
+
<link
|
|
188
|
+
rel='stylesheet'
|
|
189
|
+
type='text/css'
|
|
190
|
+
media='all'
|
|
191
|
+
href='https://www.graphcommerce.org/pagebuilder.min.css'
|
|
192
|
+
/>
|
|
193
|
+
</Head>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- The external CSS file will affect the styling of all your app's pages
|
|
197
|
+
|
|
198
|
+
## Styling a component with CSS from external style sheet
|
|
199
|
+
|
|
200
|
+
- Add the fetch query to the `getStaticProps` function of a page
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
const stylesheet = await(
|
|
204
|
+
await fetch('https://www.graphcommerce.org/pagebuilder.min.css'),
|
|
205
|
+
).text()
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
- Pass the data as prop:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
return { props: { ...stylesheet } }
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
- Specify its type:
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
function CategoryPage(props: Props & { stylesheet: string }) {
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
- Add it to the default function's props:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
|
|
225
|
+
const { categories, products, ..., stylesheet } = props
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
- Use the sx prop to apply the styles
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
<CategoryDescription
|
|
233
|
+
description={category.description}
|
|
234
|
+
sx={{ stylesheet, minWidth: '100vw' }}
|
|
235
|
+
/>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Lineair scaling with responsiveVal
|
|
239
|
+
|
|
240
|
+
The helper function `responsiveVal` offers lineair scaling based on the viewport
|
|
241
|
+
width. For example: `responsiveVal(16, 22)` will render 16px at 320px window
|
|
242
|
+
width, 22px at 1280px window width.
|
|
243
|
+
|
|
244
|
+
`responsiveVal` can be used to linear scale almost all CSS properties, including
|
|
245
|
+
width, borderRadius and margin. Performance-wise, font-size and line-height
|
|
246
|
+
should not be scaled with responsiveVal. To learn more, look into
|
|
247
|
+
[responsive font sizes](../framework/typography.md).
|
|
248
|
+
|
|
249
|
+
## Next steps
|
|
250
|
+
|
|
251
|
+
- Learn about [icons](../framework/icons.md) in GraphCommerce
|
|
252
|
+
- Learn more about
|
|
253
|
+
[customizing components ↗](https://mui.com/customization/how-to-customize/#overriding-styles-with-class-names)
|
|
254
|
+
in the MUI documentation
|
|
255
|
+
- Take a look at MUI's
|
|
256
|
+
[Default Theme object ↗](https://mui.com/customization/default-theme/)
|
|
257
|
+
- Learn more about a component's default styles by looking them up in the
|
|
258
|
+
[MUI repository ↗](https://github.com/mui/material-ui/tree/master/packages/mui-material/src)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Translations
|
|
2
|
+
|
|
3
|
+
GraphCommerces uses Linqui for interface translations. This guide provides an
|
|
4
|
+
introduction to how translations work in your graphCommerce app and how to add
|
|
5
|
+
support for a language of your choosing.
|
|
6
|
+
|
|
7
|
+
## How translations work
|
|
8
|
+
|
|
9
|
+
All available interface translations are stored as .po files in the /locales
|
|
10
|
+
directory.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
Example of /locales/es.po
|
|
14
|
+
|
|
15
|
+
...
|
|
16
|
+
|
|
17
|
+
msgid "Your cart is empty"
|
|
18
|
+
msgstr "Su carrito está vacío"
|
|
19
|
+
|
|
20
|
+
msgid "Your session is expired"
|
|
21
|
+
msgstr "Su sesión ha caducado"
|
|
22
|
+
|
|
23
|
+
msgid "canceled"
|
|
24
|
+
msgstr "cancelado"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The msgid is the message being translated. In
|
|
28
|
+
/node_modules/@graphcommerce/magento-cart/components/EmptyCart/EmptyCart.tsx,
|
|
29
|
+
you can see a the first msgid is passed as a propped, wrapped in the `<Trans>`
|
|
30
|
+
component:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
<FullPageMessage
|
|
34
|
+
title={<Trans>Your cart is empty</Trans>}
|
|
35
|
+
...
|
|
36
|
+
>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Customize translations
|
|
40
|
+
|
|
41
|
+
In /locales/en.po, find the msgid `Your cart is empty` and change the msgstr:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
msgid "Your cart is empty"
|
|
45
|
+
msgstr "Empty cart!"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Refresh to see your changes updated
|
|
49
|
+
|
|
50
|
+
<figure>
|
|
51
|
+
<img src="https://cdn-std.droplr.net/files/acc_857465/ipzm99" />
|
|
52
|
+
<figcaption>Make changes to translations. Refresh to see changes updated.</figcaption>
|
|
53
|
+
</figure>
|
|
54
|
+
|
|
55
|
+
## Adding translations to custom component
|
|
56
|
+
|
|
57
|
+
If you're building a component, you can wrap the strings you want to translate
|
|
58
|
+
in the `<Trans>` jsx macro:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
<Typography variant='h3'>
|
|
62
|
+
<Trans>Call us now</Trans>
|
|
63
|
+
</Typography>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Add Linqui to the component's imports:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { t, Trans } from '@lingui/macro'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Add the msgid and translation to the translation files:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
Example of /locales/es.po
|
|
76
|
+
|
|
77
|
+
...
|
|
78
|
+
|
|
79
|
+
msgid "Call us now"
|
|
80
|
+
msgstr "Llámanos ahora"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Passing `{values}` to translations
|
|
84
|
+
|
|
85
|
+
You can pass values in msgid's:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
<PageMeta
|
|
89
|
+
title={t`Cart (${data?.cart?.total_quantity ?? 0})`}
|
|
90
|
+
...
|
|
91
|
+
/>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The syntax in the translation files:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
Example of /locales/en.po
|
|
98
|
+
|
|
99
|
+
...
|
|
100
|
+
|
|
101
|
+
msgid "Cart"
|
|
102
|
+
msgstr "Cart"
|
|
103
|
+
|
|
104
|
+
msgid "Cart ({0})"
|
|
105
|
+
msgstr "Cart ({0})"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Next steps
|
|
109
|
+
|
|
110
|
+
- Learn more about
|
|
111
|
+
[Linqui patterns in react ↗](https://lingui.js.org/tutorials/react-patterns.html)
|
|
112
|
+
in the Linqui docs
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
> **Developer preview**
|
|
2
|
+
> This is a developer preview of GraphCommerce. The documentation will be
|
|
3
|
+
> updated as GraphCommerce introduces
|
|
4
|
+
> [new features and refines existing functionality](https://github.com/ho-nl/m2-pwa/releases).
|
|
5
|
+
|
|
6
|
+
# Troubleshouting
|
|
7
|
+
|
|
8
|
+
## Common build errors
|
|
9
|
+
|
|
10
|
+
If any errors are detected during the build phase, the console and browser will
|
|
11
|
+
display an error message. Common causes for errors are:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
[next] 🕸️ - m2: Failed to generate schema: request to [...] failed, reason: connect ETIMEDOUT
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Missing MAGENTO_ENDPOINT environment variable in your .env file
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
🕸️ - m2: Failed to generate schema: invalid json response body at [...] reason: Unexpected '<'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
MAGENTO_ENDPOINT environment variable is not pointing to a Magento graphql
|
|
24
|
+
endpoint
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
[next] error - Error: Unexpected token < in JSON at position 0
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The Magento version is outdated. Make sure you are running Magento 2.4.3 and up
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
Error: Invalid src prop ([...]) on 'next/image', hostname "[...]" is not configured under images in your 'next.config.js'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Add the image domain to IMAGE_DOMAINS in your .env file
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
File /[...]/node_modules/@graphcommerce/magento-payment-braint
|
|
40
|
+
ree/hooks/UseBraintree.graphql caused error: Unable to find field "createBraintreeClientToken" on type "Mutation"!
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Remove "@graphcommerce/magento-payment-braintree" from your dependencies in
|
|
44
|
+
package.json. Run `yarn` to update dependencies, then run `yarn dev`.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
File /[...]/node_modules/@graphcommerce/mollie-magento-payment
|
|
48
|
+
/components/MolliePlaceOrder/MolliePlaceOrder.graphql caused error: Unable to
|
|
49
|
+
find field "mollie_redirect_url" on type "Order"!
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Remove "@graphcommerce/mollie-magento-payment" from your dependencies in
|
|
53
|
+
package.json. Run `yarn` to update dependencies, then run `yarn dev`.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
node_modules/@graphcommerce/graphql/generated/fragments.json
|
|
57
|
+
Error: Interface field RoutableInterface.type expects type UrlRewriteEntityTypeEnum but BundleProduct.type is type String.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
In the Magento store, a product attribute is configured with attribute_code
|
|
61
|
+
'type'. Migrate the product information to a new attribute and remove the
|
|
62
|
+
product attribute named 'type'.
|
|
63
|
+
|
|
64
|
+
## Next steps
|
|
65
|
+
|
|
66
|
+
- Learn how to [Set up Visual Studio Code](../getting-started/vscode.md) and
|
|
67
|
+
install usefull extensions for an optimal development experience
|