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

Commit df5fc02

Browse files
committed
Adding Button blocks
1 parent 1b979f3 commit df5fc02

File tree

10 files changed

+202
-4
lines changed

10 files changed

+202
-4
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Button from '@/components/atoms/Button'
2+
import PropTypes from 'prop-types'
3+
4+
/**
5+
* Button Block
6+
*
7+
* The core Button block from Gutenberg.
8+
*
9+
* @author WebDevStudios
10+
* @param {string} anchor Optional anchor/id.
11+
* @param {string} className Optional classnames.
12+
* @param {string} linkTarget The target for the link.
13+
* @param {string} rel The rel attribute for the link.
14+
* @param {string} text The link label.
15+
* @param {string} title The target for the link.
16+
* @param {string} url The link for the button.
17+
* @return {Element} The Button component.
18+
*/
19+
export default function BlockButton({
20+
anchor,
21+
className,
22+
linkTarget,
23+
rel,
24+
text,
25+
url
26+
}) {
27+
return (
28+
<Button
29+
className={className}
30+
text={text}
31+
url={url}
32+
urlExternal={true}
33+
attributes={{
34+
id: anchor || null,
35+
target: linkTarget || null,
36+
rel: rel || null
37+
}}
38+
/>
39+
)
40+
}
41+
42+
BlockButton.propTypes = {
43+
anchor: PropTypes.string,
44+
className: PropTypes.string,
45+
linkTarget: PropTypes.string,
46+
rel: PropTypes.string,
47+
text: PropTypes.string,
48+
title: PropTypes.string,
49+
url: PropTypes.string
50+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './BlockButton'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Blocks from '@/components/molecules/Blocks'
2+
import ButtonGroup from '@/components/molecules/ButtonGroup'
3+
import PropTypes from 'prop-types'
4+
5+
/**
6+
* Buttons Block
7+
*
8+
* The core Buttons block from Gutenberg.
9+
*
10+
* @author WebDevStudios
11+
* @param options.options
12+
* @param {object} options Option props.
13+
* @param {string} options.anchor The anchor/id of the block.
14+
* @param {string} options.orientation The orientation of buttons.
15+
* @param {string} options.contentJustification The justification of the buttons.
16+
* @param options.innerBlocks
17+
* @param {Array} innerBlocks The array of inner blocks to display.
18+
* @return {Element} The Buttons component.
19+
*/
20+
export default function BlockButtons({options, innerBlocks}) {
21+
return (
22+
<ButtonGroup
23+
id={options?.anchor}
24+
orientation={options?.orientation}
25+
contentJustification={options?.contentJustification}
26+
>
27+
{!!innerBlocks?.length && <Blocks blocks={innerBlocks} />}
28+
</ButtonGroup>
29+
)
30+
}
31+
32+
BlockButtons.propTypes = {
33+
options: PropTypes.shape({
34+
anchor: PropTypes.string,
35+
contentJustification: PropTypes.string,
36+
orientation: PropTypes.string
37+
}),
38+
innerBlocks: PropTypes.arrayOf(
39+
PropTypes.shape({
40+
name: PropTypes.string,
41+
attributes: PropTypes.object
42+
})
43+
)
44+
}
45+
46+
BlockButtons.defaultProps = {
47+
options: PropTypes.shape({
48+
orientation: 'horizontal',
49+
contentJustification: 'left'
50+
})
51+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './BlockButtons'

components/blocks/BlockMediaText/BlockMediaText.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@ import PropTypes from 'prop-types'
88
* The core Code block from Gutenberg.
99
*
1010
* @author WebDevStudios
11-
* @param {string} className Optional classnames.
12-
* @param {string} anchor Optional anchor/id.
13-
* @param {string} content The content of the block.
11+
* @param media.media
12+
* @param {object} media media props.
13+
* @param {string} media.anchor The anchor/id of the block.
14+
* @param {string} media.mediaAlt The image alt text.
15+
* @param {string} media.caption The image caption.
16+
* @param {string} media.className The image class.
17+
* @param {string} media.mediaId The image ID.
18+
* @param {string} media.href The URL of the link.
19+
* @param {string} media.linkTarget Target for the link.
20+
* @param {string} media.linkClass Class for the link.
21+
* @param {string} media.rel The rel attribute for the link.
22+
* @param {string} media.sizeSlug The WP image size.
23+
* @param {string} media.mediaUrl The full URL path of the image.
24+
* @param {string} media.mediaPosition The position of the image, left or right.
25+
* @param media.innerBlocks
26+
* @param {Array} innerBlocks The array of inner blocks to display.
1427
* @return {Element} The Code component.
1528
*/
1629
export default function BlockMediaText({media, innerBlocks}) {
17-
//const position = media?.mediaPosition === 'right' ? 'right' : 'left';
1830
return (
1931
<div>
2032
{!!media && (
@@ -60,3 +72,8 @@ BlockMediaText.propTypes = {
6072
})
6173
)
6274
}
75+
BlockMediaText.defaultProps = {
76+
media: PropTypes.shape({
77+
mediaPosition: 'left'
78+
})
79+
}

components/blocks/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ export {default as BlockVideoEmbed} from './BlockVideoEmbed'
1515
export {default as BlockTable} from './BlockTable'
1616
export {default as BlockCode} from './BlockCode'
1717
export {default as BlockMediaText} from './BlockMediaText'
18+
export {default as BlockButton} from './BlockButton'
19+
export {default as BlockButtons} from './BlockButtons'
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import cn from 'classnames'
2+
import PropTypes from 'prop-types'
3+
import React from 'react'
4+
import styles from './ButtonGroup.module.css'
5+
6+
// TODO: Create storybook for ButtonGroup component.
7+
8+
/**
9+
* Render the ButtonGroup component.
10+
*
11+
* @author WebDevStudios
12+
* @param {string} id The id of the block.
13+
* @param {string} orientation The orientation of buttons.
14+
* @param {string} contentJustification The justification of the buttons.
15+
* @param {children} children The children props to render.
16+
* @return {Element} The ButtonGroup component.
17+
*/
18+
export default function ButtonGroup({
19+
id,
20+
orientation,
21+
contentJustification,
22+
children
23+
}) {
24+
return (
25+
<>
26+
<div
27+
id={id || null}
28+
className={cn(
29+
styles.buttonGroup,
30+
styles[orientation],
31+
styles[contentJustification]
32+
)}
33+
>
34+
{children}
35+
</div>
36+
</>
37+
)
38+
}
39+
40+
ButtonGroup.propTypes = {
41+
id: PropTypes.string,
42+
orientation: PropTypes.string,
43+
contentJustification: PropTypes.string,
44+
children: PropTypes.children
45+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.buttonGroup {
2+
@apply mb-40;
3+
4+
&.horizontal {
5+
@apply flex;
6+
}
7+
8+
&.center {
9+
@apply justify-center;
10+
}
11+
12+
&.right {
13+
@apply justify-end;
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './ButtonGroup'

functions/displayBlock.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ export default function displayBlock(block, index) {
3535
key={index}
3636
/>
3737
)
38+
case 'core/button':
39+
return (
40+
<Blocks.BlockButton
41+
{...attributes}
42+
key={index}
43+
/>
44+
)
45+
case 'core/buttons':
46+
return (
47+
<Blocks.BlockButtons
48+
options={attributes}
49+
innerBlocks={innerBlocks}
50+
key={index}
51+
/>
52+
)
3853
case 'core/heading':
3954
return <Blocks.BlockHeadings {...attributes} key={index} />
4055
case 'core/image':

0 commit comments

Comments
 (0)