Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit d7ab4a1

Browse files
committed
Initial commit
1 parent fa4820b commit d7ab4a1

File tree

10 files changed

+100
-70
lines changed

10 files changed

+100
-70
lines changed

components/blocks/BlockAlgolia/BlockAlgolia.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

components/blocks/BlockAlgolia/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/blocks/BlockParagraph/BlockParagraph.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ export default function BlockParagraph({props}) {
1414
// TODO Add settings for unused props in default WP Paragraph Block
1515
const alignment = !align ? 'left' : align
1616
return (
17-
<p
18-
className={cn(
19-
'container',
20-
'container--sm',
21-
`text-${alignment}`,
22-
className
23-
)}
24-
id={anchor}
25-
tag="p"
26-
>
17+
<p className={cn(`text-${alignment}`, className)} id={anchor !== null}>
2718
{content}
2819
</p>
2920
)

components/blocks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {default as BlockImageGallery} from './BlockImageGallery'
77
export {default as BlockList} from './BlockList'
88
export {default as BlockNetflixCarousel} from './BlockNetflixCarousel'
99
export {default as BlockParagraph} from './BlockParagraph'
10+
export {default as BlockHeadings} from './BlockHeadings'
1011
export {default as BlockSeparator} from './BlockSeparator'
1112
export {default as BlockShortcode} from './BlockShortcode'
1213
export {default as BlockSpacer} from './BlockSpacer'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.alert {
2+
@apply flex items-center px-16 py-8 rounded font-primary text-sm text-white bg-primary;
3+
4+
& .icon {
5+
@apply mr-24;
6+
}
7+
8+
&.success {
9+
@apply bg-success;
10+
}
11+
12+
&.error {
13+
@apply bg-error;
14+
}
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {Canvas, Meta, Story} from '@storybook/addon-docs/blocks'
2+
import Alert from './'
3+
4+
<Meta title="Components/Molecules/Alert" component={Alert} />
5+
6+
# Alert
7+
8+
Use this to alert the user of an event.
9+
10+
<Canvas>
11+
<Story name="Alert">
12+
<Alert body="This is an alert." />
13+
</Story>
14+
</Canvas>
15+
16+
## Types
17+
18+
Use different alert types depending on the context of the alert.
19+
20+
<Canvas>
21+
<Story name="Types">
22+
<Alert className="mb-8" type="default" body="Updates now available!" />
23+
<Alert
24+
className="mb-8"
25+
type="success"
26+
icon="checkmarkCircle"
27+
body="Your changes have been saved."
28+
/>
29+
<Alert
30+
className="mb-8"
31+
type="error"
32+
icon="eyeOff"
33+
body="Oops! Changes were not saved."
34+
/>
35+
</Story>
36+
</Canvas>
37+
38+
## Icon
39+
40+
Pick any icon from the [icon system](?path=/docs/general-icons--page) to use in your alert.
41+
42+
<Canvas>
43+
<Story name="Icon">
44+
<Alert icon="shieldOff" body="You are not protected!" type="error" />
45+
</Story>
46+
</Canvas>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Icon from '@/components/atoms/Icon'
2+
import cn from 'classnames'
3+
import PropTypes from 'prop-types'
4+
import React from 'react'
5+
import displayBlock from '@/functions/displayBlock'
6+
7+
/**
8+
* Render the BlockRender component.
9+
*
10+
* @param {array} blocks An array of blocks.
11+
* @return {Element} The BlockRender component.
12+
*/
13+
export default function BlockRender({blocks}) {
14+
return (
15+
<>
16+
{
17+
// If there are blocks, loop over and display.
18+
!!blocks &&
19+
blocks.length > 0 &&
20+
blocks.map((block, index) => {
21+
return displayBlock(block, index)
22+
})
23+
}
24+
</>
25+
)
26+
}
27+
28+
BlockRender.propTypes = {
29+
blocks: PropTypes.array.isRequired
30+
}
31+
32+
BlockRender.defaultProps = {
33+
blocks: []
34+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './BlockRender'

functions/displayBlock.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,11 @@ import PropTypes from 'prop-types'
1212
*/
1313
export default function displayBlock(block, index, siteSettings) {
1414
const {attributes, name} = block
15-
const {algolia} = siteSettings
1615

1716
// prettier-ignore
1817
switch (name) {
1918
case 'acf/accordions':
2019
return <Blocks.BlockAccordions props={attributes} key={index} />
21-
case 'acf/algolia':
22-
return (
23-
<Blocks.BlockAlgolia
24-
props={attributes}
25-
key={index}
26-
indexName={
27-
algolia?.indexName
28-
? algolia.indexName
29-
: ''
30-
}
31-
/>
32-
)
3320
case 'acf/netflix':
3421
return (
3522
<Blocks.BlockNetflixCarousel props={attributes} key={index} />

pages/blog/[[...slug]].js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Layout from '@/components/common/Layout'
44
import Link from 'next/link'
55
import getArchivePosts from '@/api/frontend/wp/archive/getArchivePosts'
66
import getPagePropTypes from '@/functions/getPagePropTypes'
7+
import BlockRender from '@/components/molecules/BlockRender'
78

89
// Define route post type.
910
const postType = 'post'
@@ -65,11 +66,7 @@ export default function BlogPost({post, archive, posts, pagination}) {
6566
<section>
6667
<article>
6768
<h1 dangerouslySetInnerHTML={{__html: post?.title}} />
68-
<div
69-
dangerouslySetInnerHTML={{
70-
__html: JSON.stringify(post?.blocks ?? [])
71-
}}
72-
/>
69+
<BlockRender blocks={post?.blocks} />
7370
</article>
7471
</section>
7572
</div>

0 commit comments

Comments
 (0)