Skip to content

Commit a30f51a

Browse files
added block rendering
1 parent 514ddc5 commit a30f51a

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

src/components/style-guide/index.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import { i18n } from 'stackable'
77
* Internal dependencies
88
*/
99
import { toPng } from 'html-to-image'
10+
import { isDarkColor } from '~stackable/util'
1011

1112
/**
1213
* WordPress dependencies
1314
*/
1415
import { sprintf, __ } from '@wordpress/i18n'
15-
import { useRef, useState } from '@wordpress/element'
16+
import {
17+
RawHTML, useRef, useState,
18+
} from '@wordpress/element'
1619
import { Icon, download as downloadIcon } from '@wordpress/icons'
1720
import { Button } from '@wordpress/components'
18-
import { isDarkColor } from '~stackable/util'
21+
import { createBlock, serialize } from '@wordpress/blocks'
1922

2023
export { default as StyleGuidePopover } from './popover'
2124

@@ -75,17 +78,43 @@ const StyleGuide = () => {
7578
<div className="ugb-style-guide__columns">
7679
<div className="ugb-style-guide__column">
7780
<h2 className="ugb-style-guide__section-subheading">{ __( 'Titles & Headings', i18n ) }</h2>
78-
<h1>{ __( 'Heading 1', i18n ) }</h1>
79-
<h2>{ __( 'Heading 2', i18n ) }</h2>
80-
<h3>{ __( 'Heading 3', i18n ) }</h3>
81-
<h4>{ __( 'Heading 4', i18n ) }</h4>
82-
<h5>{ __( 'Heading 5', i18n ) }</h5>
83-
<h6>{ __( 'Heading 6', i18n ) }</h6>
84-
<p>{ __( 'Paragraph', i18n ) }</p>
81+
<RenderBlock blockName="stackable/heading" attributes={ {
82+
uniqueId: '174a096',
83+
textTag: 'h1',
84+
text: __( 'Heading 1', i18n ),
85+
} } />
86+
<RenderBlock blockName="stackable/heading" attributes={ {
87+
uniqueId: '174a092',
88+
textTag: 'h2',
89+
text: __( 'Heading 2', i18n ),
90+
} } />
91+
<RenderBlock blockName="stackable/heading" attributes={ {
92+
uniqueId: '174a093',
93+
textTag: 'h3',
94+
text: __( 'Heading 3', i18n ),
95+
} } />
96+
<RenderBlock blockName="stackable/heading" attributes={ {
97+
uniqueId: '174a094',
98+
textTag: 'h4',
99+
text: __( 'Heading 4', i18n ),
100+
} } />
101+
<RenderBlock blockName="stackable/heading" attributes={ {
102+
uniqueId: '174a095',
103+
textTag: 'h5',
104+
text: __( 'Heading 5', i18n ),
105+
} } />
106+
<RenderBlock blockName="stackable/heading" attributes={ {
107+
uniqueId: '174a096',
108+
textTag: 'h6',
109+
text: __( 'Heading 6', i18n ),
110+
} } />
85111
</div>
86112
<div className="ugb-style-guide__column">
87113
<h2 className="ugb-style-guide__section-subheading">{ __( 'Body Text', i18n ) }</h2>
88-
<p>Morning sunlight filters through city windows as familiar voices fill the room. The table is scattered with mugs and yesterday\’s news, while someone debates the best way to arrange the cushions. Laughter drifts from the kitchen, and plans for the day are made between sips of coffee and playful banter.</p>
114+
<RenderBlock blockName="stackable/text" attributes={ {
115+
uniqueId: '174a097',
116+
text: __( 'Morning sunlight filters through city windows as familiar voices fill the room. The table is scattered with mugs and yesterday\'s news, while someone debates the best way to arrange the cushions. Laughter drifts from the kitchen, and plans for the day are made between sips of coffee and playful banter.', i18n ),
117+
} } />
89118
</div>
90119
</div>
91120
</div>
@@ -129,3 +158,19 @@ const ExportButton = props => {
129158
</Button>
130159
)
131160
}
161+
162+
const RenderBlock = props => {
163+
const {
164+
blockName, attributes, innerBlocks,
165+
} = props
166+
167+
return (
168+
<RawHTML>
169+
{ serialize( createBlock(
170+
blockName,
171+
attributes,
172+
innerBlocks
173+
) ) }
174+
</RawHTML>
175+
)
176+
}

0 commit comments

Comments
 (0)