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

Commit e6ccab2

Browse files
committed
Adding code block and code cleanup of other blocks
1 parent 47d57f7 commit e6ccab2

File tree

13 files changed

+171
-17
lines changed

13 files changed

+171
-17
lines changed

components/atoms/Code/Code.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import PropTypes from 'prop-types'
2+
import React from 'react'
3+
import styles from './Code.module.css'
4+
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
5+
import {tomorrow} from 'react-syntax-highlighter/dist/cjs/styles/prism'
6+
7+
/**
8+
* Render the Code component.
9+
*
10+
* @author WebDevStudios
11+
* @param {object} props The component attributes as props.
12+
* @param {string} props.className Optional classname.
13+
* @param props.id
14+
* @param props.content
15+
* @param {boolean} props.fullWidth Is this a fullwidth block.
16+
* @return {Element} The Code component.
17+
*/
18+
export default function Code({id, className, content}) {
19+
// Use the className to pass the langauge.
20+
const language = className ? className : 'javascript'
21+
22+
// Replace any `<` encoded HTML.
23+
const code = content.replace(/&lt;/g, '<')
24+
25+
return (
26+
<>
27+
{!!content && (
28+
<div id={id ? id : null} className={styles.code}>
29+
<SyntaxHighlighter style={tomorrow} language={language}>
30+
{code}
31+
</SyntaxHighlighter>
32+
</div>
33+
)}
34+
</>
35+
)
36+
}
37+
38+
Code.propTypes = {
39+
id: PropTypes.string,
40+
content: PropTypes.string,
41+
className: PropTypes.string
42+
}

components/atoms/Code/Code.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.code {
2+
@apply mb-40;
3+
4+
& > pre {
5+
@apply rounded-larger;
6+
}
7+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {Meta, Story, Canvas} from '@storybook/addon-docs/blocks'
2+
3+
import Separator from '.'
4+
5+
<Meta title="Components/Atoms/Separator" component={Separator} />
6+
7+
# Separator
8+
9+
Use this component to display a page separator with top and bottom margins. Use it anywhere you would use an `<hr>` element.
10+
11+
<Canvas>
12+
<Story name="Component">
13+
<Separator />
14+
</Story>
15+
</Canvas>
16+
17+
## Full Width
18+
19+
The default separator is equal to the container width. To get a full width separator, set the `fullWidth` prop to true.
20+
21+
<Canvas>
22+
<Story name="Full Width">
23+
<Separator fullWidth />
24+
</Story>
25+
</Canvas>
26+
27+
## Controls
28+
29+
Play around with `<Separator />` props in the [Canvas tab of the Controls story](?path=/story/design-system-atoms-separator--controls).
30+
31+
export const Template = (args) => <Separator {...args} />
32+
33+
<Canvas>
34+
<Story
35+
name="Controls"
36+
args={{
37+
fullWidth: false
38+
}}
39+
>
40+
{Template.bind({})}
41+
</Story>
42+
</Canvas>

components/atoms/Code/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './Code'

components/atoms/Image/Image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Image.propTypes = {
7575
anchor: PropTypes.string,
7676
caption: PropTypes.string,
7777
className: PropTypes.string,
78-
id: PropTypes.number,
78+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
7979
href: PropTypes.string,
8080
linkClass: PropTypes.string,
8181
linkTarget: PropTypes.string,

components/atoms/Separator/Separator.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ import styles from './Separator.module.css'
77
* Render the Separator component.
88
*
99
* @author WebDevStudios
10-
* @param {object} props The component attributes as props.
11-
* @param {string} props.className Optional classname.
12-
* @param {boolean} props.fullWidth Is this a fullwidth block.
13-
* @return {Element} The Separator component.
10+
* @param {string} className Optional classname.
11+
* @param {boolean} fullWidth Is this a fullwidth block.
12+
* @return {Element} The Separator component.
1413
*/
15-
export default function Separator(props) {
16-
const {className, fullWidth} = props
17-
14+
export default function Separator({className, fullWidth}) {
1815
return (
1916
<>
2017
{fullWidth ? (

components/atoms/Spacer/Spacer.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ import tailwindConfig from '../../../tailwind.config'
66
* Render the Spacer component.
77
*
88
* @author WebDevStudios
9-
* @param {object} props The component attributes as props.
10-
* @param {string} props.anchor Optional anchor/id.
11-
* @param {number} props.height The height of the spacer.
12-
* @return {Element} The Spacer component.
9+
* @param {string} anchor Optional anchor/id.
10+
* @param {number} height The height of the spacer.
11+
* @return {Element} The Spacer component.
1312
*/
14-
export default function Spacer(props) {
15-
const {height, anchor} = props
16-
13+
export default function Spacer({height, anchor}) {
1714
const rootEmVal = parseFloat(tailwindConfig.theme.fontSize['root-em'])
1815

1916
return (
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Code from '@/components/atoms/Code'
2+
import PropTypes from 'prop-types'
3+
4+
/**
5+
* Code Block
6+
*
7+
* The core Code block from Gutenberg.
8+
*
9+
* @author WebDevStudios
10+
* @param {string} className Optional classnames.
11+
* @param {string} anchor Optional anchor/id.
12+
* @param {string} content The content of the block.
13+
* @return {Element} The Code component.
14+
*/
15+
export default function BlockCode({anchor, className, content}) {
16+
return <Code className={className} id={anchor} content={content} />
17+
}
18+
19+
BlockCode.propTypes = {
20+
anchor: PropTypes.string,
21+
content: PropTypes.string,
22+
className: PropTypes.string
23+
}

components/blocks/BlockCode/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './BlockCode'

components/blocks/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Create default exports for each Block.
22
export {default as BlockAccordions} from './BlockAccordions'
33
export {default as BlockQuote} from './BlockQuote'
4-
export {default as PullQuote} from './BlockPullQuote'
4+
export {default as BlockPullQuote} from './BlockPullQuote'
55
export {default as BlockImage} from './BlockImage'
66
export {default as BlockImageGallery} from './BlockImageGallery'
77
export {default as BlockList} from './BlockList'
@@ -13,3 +13,4 @@ export {default as BlockShortcode} from './BlockShortcode'
1313
export {default as BlockSpacer} from './BlockSpacer'
1414
export {default as BlockVideoEmbed} from './BlockVideoEmbed'
1515
export {default as BlockTable} from './BlockTable'
16+
export {default as BlockCode} from './BlockCode'

0 commit comments

Comments
 (0)