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

Commit 42a21f1

Browse files
committed
Adding Spacer block and component.
1 parent 4441daf commit 42a21f1

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-2
lines changed

components/atoms/Spacer/Spacer.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import PropTypes from 'prop-types'
2+
import React from 'react'
3+
import tailwindConfig from '../../../tailwind.config'
4+
5+
/**
6+
* @param props
7+
*/
8+
export default function Spacer(props) {
9+
const {pxHeight, anchor} = props
10+
11+
const rootEmVal = parseFloat(tailwindConfig.theme.fontSize['root-em'])
12+
13+
return (
14+
<div
15+
id={anchor || null}
16+
style={{
17+
/* stylelint-disable-next-line value-keyword-case */
18+
height: `${pxHeight / rootEmVal}rem`
19+
}}
20+
aria-hidden="true"
21+
/>
22+
)
23+
}
24+
25+
Spacer.propTypes = {
26+
anchor: PropTypes.string,
27+
pxHeight: PropTypes.number.isRequired
28+
}
29+
30+
Spacer.defaultProps = {
31+
pxHeight: 40
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.divider {
2+
@apply w-full py-0 border-blue-500 my-40;
3+
4+
opacity: 0.1;
5+
6+
@media print {
7+
@apply hidden;
8+
}
9+
}
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 Spacer from '.'
4+
5+
<Meta title="Components/Atoms/Spacer" component={Spacer} />
6+
7+
# Spacer
8+
9+
Use this component to display a spacer with a height. Use it anywhere you would need a blank spacing element.
10+
11+
<Canvas>
12+
<Story name="Component">
13+
<Spacer pxHeight={100} />
14+
</Story>
15+
</Canvas>
16+
17+
## Height
18+
19+
Specify the height in pixels as a `number`. The component will convert it to rem based on the tailwind config file's `root-em` value.
20+
21+
<Canvas>
22+
<Story name="Height">
23+
<Spacer pxHeight={400} />
24+
</Story>
25+
</Canvas>
26+
27+
## Controls
28+
29+
Play around with `<Spacer />` props in the [Canvas tab of the Controls story](?path=/story/design-system-atoms-spacer--controls).
30+
31+
export const Template = (args) => <Spacer {...args} />
32+
33+
<Canvas>
34+
<Story
35+
name="Controls"
36+
args={{
37+
pxHeight: 100
38+
}}
39+
>
40+
{Template.bind({})}
41+
</Story>
42+
</Canvas>

components/atoms/Spacer/index.js

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

components/blocks/BlockSpacer/BlockSpacer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Spacer from '@/components/atoms/Spacer'
12
import PropTypes from 'prop-types'
23

34
/**
@@ -6,11 +7,15 @@ import PropTypes from 'prop-types'
67
* The core Spacer block from Gutenberg.
78
*
89
* @author WebDevStudios
9-
* @param {object} props The component attributes as props.
10+
* @param props.props
11+
* @param {object} props The component attributes as props.
12+
* @param {string} props.anchor Optional anchor/id.
13+
* @param {string} props.height The height of the spacer.
14+
* @return {Element} The Spacer component.
1015
*/
1116
export default function BlockSpacer({props}) {
1217
const {anchor, height} = props
13-
return <pre>{JSON.stringify({anchor, height}, null, 2)}</pre>
18+
return <Spacer pxHeight={height} id={anchor} />
1419
}
1520

1621
BlockSpacer.propTypes = {

0 commit comments

Comments
 (0)