@graphcommerce/graphcms-ui 2.103.1
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/CHANGELOG.md +79 -0
- package/RichText/RichTextColumns.tsx +22 -0
- package/RichText/RichTextDoubleSpread.tsx +18 -0
- package/RichText/RichTextHeadingStrongStroked.tsx +24 -0
- package/RichText/RichTextHero.tsx +24 -0
- package/RichText/RichTextParagraphStrongStroked.tsx +23 -0
- package/RichText/RichTextQuote.tsx +19 -0
- package/RichText/RichTextSpread.tsx +14 -0
- package/RichText/getNodeLength.tsx +10 -0
- package/RichText/index.tsx +315 -0
- package/RichText/useRichTextStyles.tsx +112 -0
- package/index.ts +1 -0
- package/next-env.d.ts +4 -0
- package/package.json +34 -0
- package/tsconfig.json +5 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [2.103.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.103.0...@graphcommerce/graphcms-ui@2.103.1) (2021-09-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @graphcommerce/graphcms-ui
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 2.103.0 (2021-09-27)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
|
|
20
|
+
* implement next-ui barrel imports ([75bea70](https://github.com/ho-nl/m2-pwa/commit/75bea703dba898f18a2a1dfa3243ebd0a4e6f0e1))
|
|
21
|
+
* narrow quote on mobile ([e06ccc2](https://github.com/ho-nl/m2-pwa/commit/e06ccc25048124431dcdb786f1719f688a5e429c))
|
|
22
|
+
* remove conflicting files ([0c17ae4](https://github.com/ho-nl/m2-pwa/commit/0c17ae46be62b775ac83b35f11c532ce2d9401a3))
|
|
23
|
+
* since all links are of next/link we need to add passHref for custom components ([16fb931](https://github.com/ho-nl/m2-pwa/commit/16fb93100d367203ea79bb4f93357221253f2ecd))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* created stacked-pages package ([d86008e](https://github.com/ho-nl/m2-pwa/commit/d86008ee659ccb25b194a41d624b394a1ddbd088))
|
|
29
|
+
* **image:** introduced completely rewritten Image component ([e3413b3](https://github.com/ho-nl/m2-pwa/commit/e3413b3a57392d6571ea64cb8d9c8dca05ea31df))
|
|
30
|
+
* implemented the ability to load graphcms content by URL ([99bc970](https://github.com/ho-nl/m2-pwa/commit/99bc970fc46d40b7efa99a71819529aeaa206bb4))
|
|
31
|
+
* introduced graphcms-ui package to quickly build pages ([04d89c3](https://github.com/ho-nl/m2-pwa/commit/04d89c3fecf25f64923caf437eeb4b73f8887102))
|
|
32
|
+
* introduces framer-next-pages and framer-sheet to next-ui and soxbase package ([e04ad8a](https://github.com/ho-nl/m2-pwa/commit/e04ad8a94cd1fd5a7c5575c9db7916b6e8a88f16))
|
|
33
|
+
* next.js 11 ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
|
|
34
|
+
* **playwright:** added new playwright package to enable browser testing ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
|
|
35
|
+
* renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of [@reachdigital](https://github.com/reachdigital) ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
|
|
36
|
+
* upgrade to node 14 ([d079a75](https://github.com/ho-nl/m2-pwa/commit/d079a751e9bfd8dc7f5009d2c9f31c336a0c96ab))
|
|
37
|
+
* upgraded to nextjs 11 ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Reverts
|
|
41
|
+
|
|
42
|
+
* Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Change Log
|
|
49
|
+
|
|
50
|
+
All notable changes to this project will be documented in this file. See
|
|
51
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
52
|
+
|
|
53
|
+
# [2.102.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.101.9...@graphcommerce/graphcms-ui@2.102.0) (2021-08-12)
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
- upgraded to nextjs 11
|
|
58
|
+
([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
|
|
59
|
+
|
|
60
|
+
## [2.101.9](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.101.8...@graphcommerce/graphcms-ui@2.101.9) (2021-08-09)
|
|
61
|
+
|
|
62
|
+
### Reverts
|
|
63
|
+
|
|
64
|
+
- Revert "chore: upgrade @apollo/client"
|
|
65
|
+
([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
|
|
66
|
+
|
|
67
|
+
# [2.101.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.100.18...@graphcommerce/graphcms-ui@2.101.0) (2021-07-26)
|
|
68
|
+
|
|
69
|
+
### Features
|
|
70
|
+
|
|
71
|
+
- **playwright:** added new playwright package to enable browser testing
|
|
72
|
+
([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
|
|
73
|
+
|
|
74
|
+
## [2.100.11](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.100.10...@graphcommerce/graphcms-ui@2.100.11) (2021-07-20)
|
|
75
|
+
|
|
76
|
+
### Bug Fixes
|
|
77
|
+
|
|
78
|
+
- ignore md files from triggering version updates
|
|
79
|
+
([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { makeStyles, Theme } from '@material-ui/core'
|
|
2
|
+
import { UseStyles } from '@graphcommerce/next-ui'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import RichText, { RichTextProps } from '.'
|
|
5
|
+
|
|
6
|
+
type StyleProps = { columnCount: number }
|
|
7
|
+
|
|
8
|
+
const useStyles = makeStyles(({ spacings, breakpoints }: Theme) => ({
|
|
9
|
+
paragraph: {
|
|
10
|
+
[breakpoints.up('md')]: {
|
|
11
|
+
columnCount: ({ columnCount }: StyleProps) => columnCount,
|
|
12
|
+
columnGap: spacings.md,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
}))
|
|
16
|
+
|
|
17
|
+
type RichTextColumnsProps = UseStyles<typeof useStyles> & StyleProps & RichTextProps
|
|
18
|
+
|
|
19
|
+
export default function RichTextColumns(props: RichTextColumnsProps) {
|
|
20
|
+
const classes = useStyles(props)
|
|
21
|
+
return <RichText classes={classes} {...props} />
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { withStyles, Theme } from '@material-ui/core'
|
|
2
|
+
import RichText from '.'
|
|
3
|
+
|
|
4
|
+
const RichTextDoubleSpread = withStyles((theme: Theme) => ({
|
|
5
|
+
h2: theme.typography.h4,
|
|
6
|
+
paragraph: {
|
|
7
|
+
[theme.breakpoints.up('sm')]: {
|
|
8
|
+
columnCount: 2,
|
|
9
|
+
columnGap: theme.spacings.md,
|
|
10
|
+
},
|
|
11
|
+
[theme.breakpoints.up('lg')]: {
|
|
12
|
+
columnCount: 3,
|
|
13
|
+
columnGap: theme.spacings.md,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}))(RichText)
|
|
17
|
+
|
|
18
|
+
export default RichTextDoubleSpread
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Theme, withStyles } from '@material-ui/core'
|
|
2
|
+
import { responsiveVal } from '@graphcommerce/next-ui'
|
|
3
|
+
import RichText from '.'
|
|
4
|
+
|
|
5
|
+
const RichTextHeadingStrongStroked = withStyles((theme: Theme) => ({
|
|
6
|
+
h2: {
|
|
7
|
+
textTransform: 'uppercase',
|
|
8
|
+
color: theme.palette.text.primary,
|
|
9
|
+
WebkitTextStroke: `0.9px ${theme.palette.text.primary}`,
|
|
10
|
+
fontSize: responsiveVal(18, 50),
|
|
11
|
+
marginTop: responsiveVal(8, 20),
|
|
12
|
+
marginBottom: responsiveVal(18, 20),
|
|
13
|
+
'& strong': {
|
|
14
|
+
color: 'transparent',
|
|
15
|
+
WebkitTextStroke: `0.9px ${theme.palette.text.primary}`,
|
|
16
|
+
},
|
|
17
|
+
[theme.breakpoints.up('md')]: {
|
|
18
|
+
fontSize: responsiveVal(18, 60),
|
|
19
|
+
WebkitTextStroke: `1.2x ${theme.palette.text.primary}`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}))(RichText)
|
|
23
|
+
|
|
24
|
+
export default RichTextHeadingStrongStroked
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Theme, withStyles } from '@material-ui/core'
|
|
2
|
+
import { responsiveVal } from '@graphcommerce/next-ui'
|
|
3
|
+
import RichText from '.'
|
|
4
|
+
|
|
5
|
+
const RichTextHero = withStyles((theme: Theme) => ({
|
|
6
|
+
h1: {
|
|
7
|
+
textTransform: 'uppercase',
|
|
8
|
+
maxWidth: '70%',
|
|
9
|
+
textAlign: 'center',
|
|
10
|
+
fontSize: responsiveVal(42, 50),
|
|
11
|
+
marginBottom: responsiveVal(22, 32),
|
|
12
|
+
[theme.breakpoints.up('md')]: {
|
|
13
|
+
textAlign: 'left',
|
|
14
|
+
fontSize: responsiveVal(18, 90),
|
|
15
|
+
maxWidth: '100%',
|
|
16
|
+
},
|
|
17
|
+
'& strong': {
|
|
18
|
+
color: 'transparent',
|
|
19
|
+
WebkitTextStroke: '1.2px #fff',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}))(RichText)
|
|
23
|
+
|
|
24
|
+
export default RichTextHero
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Theme, withStyles } from '@material-ui/core'
|
|
2
|
+
import { responsiveVal } from '@graphcommerce/next-ui'
|
|
3
|
+
import RichText from '.'
|
|
4
|
+
|
|
5
|
+
const RichTextParagraphStrongStroked = withStyles((theme: Theme) => ({
|
|
6
|
+
paragraph: {
|
|
7
|
+
textTransform: 'uppercase',
|
|
8
|
+
maxWidth: '100%',
|
|
9
|
+
fontWeight: 600,
|
|
10
|
+
textAlign: 'left',
|
|
11
|
+
fontSize: responsiveVal(11, 20),
|
|
12
|
+
[theme.breakpoints.up('md')]: {
|
|
13
|
+
maxWidth: '100%',
|
|
14
|
+
fontSize: responsiveVal(16, 34),
|
|
15
|
+
},
|
|
16
|
+
'& strong': {
|
|
17
|
+
color: 'transparent',
|
|
18
|
+
WebkitTextStroke: '1.2px #fff',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}))(RichText)
|
|
22
|
+
|
|
23
|
+
export default RichTextParagraphStrongStroked
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Theme, withStyles } from '@material-ui/core'
|
|
2
|
+
import { responsiveVal } from '@graphcommerce/next-ui'
|
|
3
|
+
import RichText from '.'
|
|
4
|
+
|
|
5
|
+
const RichTextQuote = withStyles((theme: Theme) => ({
|
|
6
|
+
paragraph: {
|
|
7
|
+
fontWeight: 600,
|
|
8
|
+
textTransform: 'uppercase',
|
|
9
|
+
maxWidth: '60%',
|
|
10
|
+
textAlign: 'center',
|
|
11
|
+
margin: '0 auto',
|
|
12
|
+
fontSize: responsiveVal(14, 26),
|
|
13
|
+
[theme.breakpoints.up('lg')]: {
|
|
14
|
+
maxWidth: '80%',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}))(RichText)
|
|
18
|
+
|
|
19
|
+
export default RichTextQuote
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { withStyles, Theme } from '@material-ui/core'
|
|
2
|
+
import RichText from '.'
|
|
3
|
+
|
|
4
|
+
const RichTextSpread = withStyles((theme: Theme) => ({
|
|
5
|
+
h2: theme.typography.h4,
|
|
6
|
+
paragraph: {
|
|
7
|
+
[theme.breakpoints.up('md')]: {
|
|
8
|
+
columnCount: 2,
|
|
9
|
+
columnGap: theme.spacings.md,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
}))(RichText)
|
|
13
|
+
|
|
14
|
+
export default RichTextSpread
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isElementNode, isTextNode, Node } from '.'
|
|
2
|
+
|
|
3
|
+
export default function getNodeLength(node: Node): number {
|
|
4
|
+
if (isElementNode(node))
|
|
5
|
+
return node.children.map(getNodeLength).reduce<number>((prev, curr) => prev + curr, 0)
|
|
6
|
+
|
|
7
|
+
if (isTextNode(node)) return node.text.length
|
|
8
|
+
|
|
9
|
+
return 0
|
|
10
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { Link, Typography } from '@material-ui/core'
|
|
2
|
+
import { Image } from '@graphcommerce/image'
|
|
3
|
+
import PageLink from 'next/link'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import useRichTextStyles, { UseRichTextStyles } from './useRichTextStyles'
|
|
6
|
+
|
|
7
|
+
export interface Element {
|
|
8
|
+
children: Node[]
|
|
9
|
+
type:
|
|
10
|
+
| 'heading-one'
|
|
11
|
+
| 'heading-two'
|
|
12
|
+
| 'heading-three'
|
|
13
|
+
| 'heading-four'
|
|
14
|
+
| 'heading-five'
|
|
15
|
+
| 'heading-six'
|
|
16
|
+
| 'paragraph'
|
|
17
|
+
| 'numbered-list'
|
|
18
|
+
| 'bulleted-list'
|
|
19
|
+
| 'block-quote'
|
|
20
|
+
| 'paragraph'
|
|
21
|
+
| 'list-item'
|
|
22
|
+
| 'list-item-child'
|
|
23
|
+
| 'table'
|
|
24
|
+
| 'table_head'
|
|
25
|
+
| 'table_body'
|
|
26
|
+
| 'table_row'
|
|
27
|
+
| 'table_cell'
|
|
28
|
+
| string
|
|
29
|
+
[key: string]: unknown
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface Text {
|
|
33
|
+
text: string
|
|
34
|
+
bold?: true
|
|
35
|
+
italic?: true
|
|
36
|
+
underlined?: true
|
|
37
|
+
[key: string]: unknown
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface LinkElement extends Element {
|
|
41
|
+
type: 'link'
|
|
42
|
+
href: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface ImageElement extends Element {
|
|
46
|
+
type: 'image'
|
|
47
|
+
src: string
|
|
48
|
+
title: string
|
|
49
|
+
width: number
|
|
50
|
+
height: number
|
|
51
|
+
mimeType: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface VideoElement extends Element {
|
|
55
|
+
type: 'image'
|
|
56
|
+
src: string
|
|
57
|
+
title: string
|
|
58
|
+
width: number
|
|
59
|
+
height: number
|
|
60
|
+
mimeType: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface LinkElement extends Element {
|
|
64
|
+
type: 'link'
|
|
65
|
+
href: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface IframeElement extends Element {
|
|
69
|
+
type: 'iframe'
|
|
70
|
+
src: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type ElementNode =
|
|
74
|
+
| Element
|
|
75
|
+
| LinkElement
|
|
76
|
+
| ImageElement
|
|
77
|
+
| VideoElement
|
|
78
|
+
| IframeElement
|
|
79
|
+
| LinkElement
|
|
80
|
+
|
|
81
|
+
export type Node = ElementNode | Text
|
|
82
|
+
|
|
83
|
+
const RenderText = ({ classes, text, ...textProps }: Text & Required<UseRichTextStyles>) => {
|
|
84
|
+
let result = <>{text}</>
|
|
85
|
+
if (textProps.bold) result = <strong>{result}</strong>
|
|
86
|
+
if (textProps.italic) result = <em>{result}</em>
|
|
87
|
+
if (textProps.underlined) result = <em>{result}</em>
|
|
88
|
+
|
|
89
|
+
return result
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function isTextNode(node: Node): node is Text {
|
|
93
|
+
return (node as Text).text !== undefined
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function isElementNode(node: Node): node is ElementNode {
|
|
97
|
+
return (node as ElementNode).children !== undefined
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function RenderNode({ classes, ...node }: Node & Required<UseRichTextStyles>) {
|
|
101
|
+
if (isTextNode(node)) {
|
|
102
|
+
return <RenderText {...node} classes={classes} />
|
|
103
|
+
}
|
|
104
|
+
if (isElementNode(node)) {
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
106
|
+
return <RenderElement {...node} classes={classes} />
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.error(node)
|
|
110
|
+
throw Error(`RichText: Node not recognized`)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function RenderChildren({ children, classes }: { children: Node[] } & Required<UseRichTextStyles>) {
|
|
114
|
+
return (
|
|
115
|
+
<>
|
|
116
|
+
{children.map((node, key) => (
|
|
117
|
+
// Since we don't know any unique identifiers of the element and since this doesn't rerender often this is fine.
|
|
118
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
119
|
+
<RenderNode {...node} key={key} classes={classes} />
|
|
120
|
+
))}
|
|
121
|
+
</>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function RenderElement({ classes, ...element }: ElementNode & Required<UseRichTextStyles>) {
|
|
126
|
+
const {
|
|
127
|
+
root,
|
|
128
|
+
asset,
|
|
129
|
+
h1,
|
|
130
|
+
h2,
|
|
131
|
+
h3,
|
|
132
|
+
h4,
|
|
133
|
+
h5,
|
|
134
|
+
h6,
|
|
135
|
+
paragraph,
|
|
136
|
+
ul,
|
|
137
|
+
ol,
|
|
138
|
+
blockQuote,
|
|
139
|
+
code,
|
|
140
|
+
iframe,
|
|
141
|
+
aspectContainer,
|
|
142
|
+
table,
|
|
143
|
+
link,
|
|
144
|
+
} = classes
|
|
145
|
+
|
|
146
|
+
switch (element.type) {
|
|
147
|
+
case 'heading-one':
|
|
148
|
+
return (
|
|
149
|
+
<Typography variant='h1' classes={{ root, h1 }}>
|
|
150
|
+
<RenderChildren {...element} classes={classes} />
|
|
151
|
+
</Typography>
|
|
152
|
+
)
|
|
153
|
+
case 'heading-two':
|
|
154
|
+
return (
|
|
155
|
+
<Typography variant='h2' classes={{ root, h2 }}>
|
|
156
|
+
<RenderChildren {...element} classes={classes} />
|
|
157
|
+
</Typography>
|
|
158
|
+
)
|
|
159
|
+
case 'heading-three':
|
|
160
|
+
return (
|
|
161
|
+
<Typography variant='h3' classes={{ root, h3 }}>
|
|
162
|
+
<RenderChildren {...element} classes={classes} />
|
|
163
|
+
</Typography>
|
|
164
|
+
)
|
|
165
|
+
case 'heading-four':
|
|
166
|
+
return (
|
|
167
|
+
<Typography variant='h4' classes={{ root, h4 }}>
|
|
168
|
+
<RenderChildren {...element} classes={classes} />
|
|
169
|
+
</Typography>
|
|
170
|
+
)
|
|
171
|
+
case 'heading-five':
|
|
172
|
+
return (
|
|
173
|
+
<Typography variant='h5' classes={{ root, h5 }}>
|
|
174
|
+
<RenderChildren {...element} classes={classes} />
|
|
175
|
+
</Typography>
|
|
176
|
+
)
|
|
177
|
+
case 'heading-six':
|
|
178
|
+
return (
|
|
179
|
+
<Typography variant='h6' classes={{ root, h6 }}>
|
|
180
|
+
<RenderChildren {...element} classes={classes} />
|
|
181
|
+
</Typography>
|
|
182
|
+
)
|
|
183
|
+
case 'paragraph':
|
|
184
|
+
return element.children[0].code ? (
|
|
185
|
+
<pre className={classes.code}>
|
|
186
|
+
<code>
|
|
187
|
+
<RenderChildren {...element} classes={classes} />
|
|
188
|
+
</code>
|
|
189
|
+
</pre>
|
|
190
|
+
) : (
|
|
191
|
+
<Typography variant='body1' paragraph classes={{ root, paragraph }}>
|
|
192
|
+
<RenderChildren {...element} classes={classes} />
|
|
193
|
+
</Typography>
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
case 'bulleted-list':
|
|
197
|
+
return (
|
|
198
|
+
<Typography component='ul' classes={{ root: ul }}>
|
|
199
|
+
<RenderChildren {...element} classes={classes} />
|
|
200
|
+
</Typography>
|
|
201
|
+
)
|
|
202
|
+
case 'numbered-list':
|
|
203
|
+
return (
|
|
204
|
+
<Typography component='ol' classes={{ root: ol }}>
|
|
205
|
+
<RenderChildren {...element} classes={classes} />
|
|
206
|
+
</Typography>
|
|
207
|
+
)
|
|
208
|
+
case 'list-item':
|
|
209
|
+
return (
|
|
210
|
+
<li>
|
|
211
|
+
<RenderChildren {...element} classes={classes} />
|
|
212
|
+
</li>
|
|
213
|
+
)
|
|
214
|
+
case 'list-item-child':
|
|
215
|
+
return <RenderChildren {...element} classes={classes} />
|
|
216
|
+
case 'block-quote':
|
|
217
|
+
return (
|
|
218
|
+
<Typography component='blockquote' classes={{ root: blockQuote }}>
|
|
219
|
+
<RenderChildren {...element} classes={classes} />
|
|
220
|
+
</Typography>
|
|
221
|
+
)
|
|
222
|
+
case 'iframe':
|
|
223
|
+
// eslint-disable-next-line no-case-declarations
|
|
224
|
+
const iframeElement = element as IframeElement
|
|
225
|
+
// todo(paales) add security attributes to iframe
|
|
226
|
+
// todo(paales) make iframe responsive
|
|
227
|
+
return (
|
|
228
|
+
<div className={aspectContainer}>
|
|
229
|
+
<iframe
|
|
230
|
+
src={iframeElement.src}
|
|
231
|
+
title='embedded content'
|
|
232
|
+
className={iframe}
|
|
233
|
+
loading='lazy'
|
|
234
|
+
/>
|
|
235
|
+
</div>
|
|
236
|
+
)
|
|
237
|
+
case 'image':
|
|
238
|
+
// eslint-disable-next-line no-case-declarations
|
|
239
|
+
const imageElement = element as ImageElement
|
|
240
|
+
return (
|
|
241
|
+
<Image
|
|
242
|
+
src={imageElement.src}
|
|
243
|
+
width={imageElement.width}
|
|
244
|
+
height={imageElement.height}
|
|
245
|
+
alt={imageElement.title}
|
|
246
|
+
className={asset}
|
|
247
|
+
/>
|
|
248
|
+
)
|
|
249
|
+
case 'video':
|
|
250
|
+
// eslint-disable-next-line no-case-declarations
|
|
251
|
+
const videoElement = element as VideoElement
|
|
252
|
+
return (
|
|
253
|
+
<div>IMPLEMENT VIDEO</div>
|
|
254
|
+
// <Asset
|
|
255
|
+
// asset={{ url: videoElement.src, mimeType: videoElement.mimeType }}
|
|
256
|
+
// autoPlay
|
|
257
|
+
// loop
|
|
258
|
+
// muted
|
|
259
|
+
// playsInline
|
|
260
|
+
// width={380}
|
|
261
|
+
// className={asset}
|
|
262
|
+
// />
|
|
263
|
+
)
|
|
264
|
+
case 'link':
|
|
265
|
+
// eslint-disable-next-line no-case-declarations
|
|
266
|
+
const linkElement = element as LinkElement
|
|
267
|
+
return (
|
|
268
|
+
<PageLink href={linkElement.href} passHref>
|
|
269
|
+
<Link classes={{ root: link }}>
|
|
270
|
+
<RenderChildren {...element} classes={classes} />
|
|
271
|
+
</Link>
|
|
272
|
+
</PageLink>
|
|
273
|
+
)
|
|
274
|
+
case 'table':
|
|
275
|
+
return (
|
|
276
|
+
<table className={table}>
|
|
277
|
+
<RenderChildren {...element} classes={classes} />
|
|
278
|
+
</table>
|
|
279
|
+
)
|
|
280
|
+
case 'table_head':
|
|
281
|
+
return (
|
|
282
|
+
<thead>
|
|
283
|
+
<RenderChildren {...element} classes={classes} />
|
|
284
|
+
</thead>
|
|
285
|
+
)
|
|
286
|
+
case 'table_body':
|
|
287
|
+
return (
|
|
288
|
+
<tbody>
|
|
289
|
+
<RenderChildren {...element} classes={classes} />
|
|
290
|
+
</tbody>
|
|
291
|
+
)
|
|
292
|
+
case 'table_row':
|
|
293
|
+
return (
|
|
294
|
+
<tr>
|
|
295
|
+
<RenderChildren {...element} classes={classes} />
|
|
296
|
+
</tr>
|
|
297
|
+
)
|
|
298
|
+
case 'table_cell':
|
|
299
|
+
return (
|
|
300
|
+
<td>
|
|
301
|
+
<RenderChildren {...element} classes={classes} />
|
|
302
|
+
</td>
|
|
303
|
+
)
|
|
304
|
+
default:
|
|
305
|
+
console.error(element)
|
|
306
|
+
throw Error(`RichText: Unknown Element: ${element.type}`)
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export type RichTextProps = { raw: ElementNode } & UseRichTextStyles
|
|
311
|
+
|
|
312
|
+
export default function RichText({ raw, ...props }: RichTextProps) {
|
|
313
|
+
const classes = useRichTextStyles(props)
|
|
314
|
+
return <RenderChildren classes={classes} {...raw} />
|
|
315
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { makeStyles, Theme } from '@material-ui/core'
|
|
2
|
+
import { UseStyles, responsiveVal } from '@graphcommerce/next-ui'
|
|
3
|
+
|
|
4
|
+
const useRichTextStyles = makeStyles(
|
|
5
|
+
({ spacings, breakpoints, palette, typography }: Theme) => ({
|
|
6
|
+
root: { '&:empty': { display: 'none' }, '&:last-child': { marginBottom: 0 } },
|
|
7
|
+
paragraph: { marginBottom: '1em', wordBreak: 'break-word' },
|
|
8
|
+
h1: { marginTop: responsiveVal(9, 0), marginBottom: responsiveVal(21, 50) },
|
|
9
|
+
h2: {
|
|
10
|
+
marginTop: responsiveVal(22, 40),
|
|
11
|
+
marginBottom: responsiveVal(20, 40),
|
|
12
|
+
'&:first-child': { marginTop: 0 },
|
|
13
|
+
},
|
|
14
|
+
h3: {
|
|
15
|
+
marginTop: responsiveVal(22, 30),
|
|
16
|
+
marginBottom: responsiveVal(22, 30),
|
|
17
|
+
'&:first-child': { marginTop: 0 },
|
|
18
|
+
},
|
|
19
|
+
h4: {
|
|
20
|
+
marginTop: responsiveVal(11, 30),
|
|
21
|
+
marginBottom: responsiveVal(11, 30),
|
|
22
|
+
'&:first-child': { marginTop: 0 },
|
|
23
|
+
},
|
|
24
|
+
h5: {
|
|
25
|
+
marginTop: responsiveVal(7, 20),
|
|
26
|
+
marginBottom: responsiveVal(7, 20),
|
|
27
|
+
'&:first-child': { marginTop: 0 },
|
|
28
|
+
},
|
|
29
|
+
h6: { '&:first-of-type': { marginTop: 0 } },
|
|
30
|
+
asset: { width: '100%', height: 'auto' },
|
|
31
|
+
blockQuote: {
|
|
32
|
+
color: '#777',
|
|
33
|
+
borderLeft: '4px solid #999',
|
|
34
|
+
paddingLeft: spacings.sm,
|
|
35
|
+
margin: `${spacings.md} 0`,
|
|
36
|
+
},
|
|
37
|
+
ol: { marginBottom: '1em' },
|
|
38
|
+
ul: { marginBottom: '1em' },
|
|
39
|
+
strong: {},
|
|
40
|
+
italic: {},
|
|
41
|
+
underlined: {},
|
|
42
|
+
code: {
|
|
43
|
+
width: 'fit-content',
|
|
44
|
+
maxWidth: '100%',
|
|
45
|
+
background: '#d8d8d8',
|
|
46
|
+
padding: 5,
|
|
47
|
+
fontSize: 17,
|
|
48
|
+
overflow: 'scroll',
|
|
49
|
+
},
|
|
50
|
+
aspectContainer: {
|
|
51
|
+
position: 'relative',
|
|
52
|
+
paddingTop: 'calc(100% / 16 * 9)',
|
|
53
|
+
marginBottom: spacings.md,
|
|
54
|
+
'& > *': {
|
|
55
|
+
width: '100%',
|
|
56
|
+
height: '100%',
|
|
57
|
+
position: 'absolute',
|
|
58
|
+
top: 0,
|
|
59
|
+
left: 0,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
iframe: {},
|
|
63
|
+
table: {
|
|
64
|
+
display: 'table',
|
|
65
|
+
width: '100%',
|
|
66
|
+
borderSpacing: '2px',
|
|
67
|
+
borderCollapse: 'collapse',
|
|
68
|
+
marginTop: spacings.md,
|
|
69
|
+
marginBottom: spacings.sm,
|
|
70
|
+
|
|
71
|
+
'& thead, tbody': {
|
|
72
|
+
'& td': {
|
|
73
|
+
padding: '10px 20px',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
'& thead': {
|
|
78
|
+
'& tr': {
|
|
79
|
+
'& td': {
|
|
80
|
+
'& p': {
|
|
81
|
+
fontWeight: typography.fontWeightBold,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
'& tbody': {
|
|
87
|
+
display: 'table-row-group',
|
|
88
|
+
verticalAlign: 'center',
|
|
89
|
+
borderColor: 'inherit',
|
|
90
|
+
|
|
91
|
+
'& tr': {
|
|
92
|
+
'&:nth-child(odd)': {
|
|
93
|
+
background: palette.background.highlight,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
'& td': {
|
|
98
|
+
[breakpoints.up('sm')]: {
|
|
99
|
+
minWidth: '150px',
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
'& p': { fontSize: responsiveVal(12, 15) },
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
link: { wordBreak: 'break-word' },
|
|
107
|
+
}),
|
|
108
|
+
{ name: 'RichText' },
|
|
109
|
+
)
|
|
110
|
+
export type UseRichTextStyles = UseStyles<typeof useRichTextStyles>
|
|
111
|
+
|
|
112
|
+
export default useRichTextStyles
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/next-env.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphcommerce/graphcms-ui",
|
|
3
|
+
"version": "2.103.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
6
|
+
"browserslist": [
|
|
7
|
+
"extends @graphcommerce/browserslist-config-pwa"
|
|
8
|
+
],
|
|
9
|
+
"eslintConfig": {
|
|
10
|
+
"extends": "@graphcommerce/eslint-config-pwa",
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": "./tsconfig.json"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@graphcommerce/browserslist-config-pwa": "^3.0.1",
|
|
17
|
+
"@graphcommerce/eslint-config-pwa": "^3.0.1",
|
|
18
|
+
"@graphcommerce/prettier-config-pwa": "^3.0.1",
|
|
19
|
+
"@graphcommerce/typescript-config-pwa": "^3.0.1",
|
|
20
|
+
"@playwright/test": "^1.14.1"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@apollo/client": "^3.3.21",
|
|
24
|
+
"@graphcommerce/image": "^2.104.1",
|
|
25
|
+
"@graphcommerce/next-ui": "^3.0.1",
|
|
26
|
+
"@graphql-typed-document-node/core": "^3.1.0",
|
|
27
|
+
"@material-ui/core": "^4.12.3",
|
|
28
|
+
"@material-ui/lab": "^4.0.0-alpha.60",
|
|
29
|
+
"next": "^11.1.2",
|
|
30
|
+
"react": "^17.0.2",
|
|
31
|
+
"react-dom": "^17.0.2",
|
|
32
|
+
"type-fest": "^2.1.0"
|
|
33
|
+
}
|
|
34
|
+
}
|