Skip to content

Commit 23066c4

Browse files
committed
display global color palette in the style guide
1 parent a30f51a commit 23066c4

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

src/components/style-guide/editor.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636
font-size: 1em;
3737
font-weight: 500;
3838
line-height: 1;
39+
40+
p:first-child {
41+
margin: 0;
42+
}
43+
44+
p:last-child {
45+
margin-top: 4px;
46+
margin-bottom: 0;
47+
}
3948
}
4049

4150
.ugb-style-guide__colors {

src/components/style-guide/index.js

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import { createBlock, serialize } from '@wordpress/blocks'
2323
export { default as StyleGuidePopover } from './popover'
2424

2525
// TODO: This is not yet finished
26-
const StyleGuide = () => {
26+
const StyleGuide = props => {
27+
const { designSystem } = props
28+
29+
const { colors } = designSystem
30+
2731
const styleGuideRef = useRef( null )
2832

2933
return (
@@ -35,41 +39,14 @@ const StyleGuide = () => {
3539
<h1 className="ugb-style-guide__section-title">{ __( 'Colors', i18n ) }</h1>
3640
<h2 className="ugb-style-guide__section-subheading">{ __( 'Color Palette', i18n ) }</h2>
3741
<div className="ugb-style-guide__columns ugb-style-guide__colors">
38-
<div className="ugb-style-guide__column" style={ { backgroundColor: '#f00069' } }>
39-
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#f00069' ) ? '#fff' : '#000' } }>
40-
#F00069
41-
</div>
42-
</div>
43-
<div className="ugb-style-guide__column" style={ { backgroundColor: '#111' } }>
44-
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#111' ) ? '#fff' : '#000' } }>
45-
#111111
46-
</div>
47-
</div>
48-
<div className="ugb-style-guide__column" style={ { backgroundColor: '#222' } }>
49-
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#222' ) ? '#fff' : '#000' } }>
50-
#222222
51-
</div>
52-
</div>
53-
<div className="ugb-style-guide__column" style={ { backgroundColor: '#333' } }>
54-
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#333' ) ? '#fff' : '#000' } }>
55-
#333333
42+
{ colors.map( ( color, key ) => {
43+
return <div key={ key } className="ugb-style-guide__column" style={ { backgroundColor: color.color } }>
44+
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( color.color ) ? '#fff' : '#000' } }>
45+
<p> { color.name } </p>
46+
<p> { color.color } </p>
47+
</div>
5648
</div>
57-
</div>
58-
<div className="ugb-style-guide__column" style={ { backgroundColor: '#444' } }>
59-
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#444' ) ? '#fff' : '#000' } }>
60-
#444444
61-
</div>
62-
</div>
63-
<div className="ugb-style-guide__column" style={ { backgroundColor: '#555' } }>
64-
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#555' ) ? '#fff' : '#000' } }>
65-
#555555
66-
</div>
67-
</div>
68-
<div className="ugb-style-guide__column" style={ { backgroundColor: '#666' } }>
69-
<div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#666' ) ? '#fff' : '#000' } }>
70-
#666666
71-
</div>
72-
</div>
49+
} ) }
7350
</div>
7451

7552
<h2 className="ugb-style-guide__section-subheading">{ __( 'Color Schemes', i18n ) }</h2>

src/components/style-guide/popover.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { __ } from '@wordpress/i18n'
1515
import { useMemo } from '@wordpress/element'
1616
import { Popover, Button } from '@wordpress/components'
1717
import { Icon, close as closeIcon } from '@wordpress/icons'
18+
import { useDesignSystem } from '~stackable/hooks'
1819

1920
const StyleGuidePopover = props => {
2021
const { onClose } = props
@@ -25,6 +26,8 @@ const StyleGuidePopover = props => {
2526
return [ el, el?.offsetWidth, el?.offsetHeight ]
2627
}, [] )
2728

29+
const designSystem = useDesignSystem()
30+
2831
const style = width && height ? { '--width': `${ width }px`, '--height': `${ height }px` } : {}
2932

3033
return (
@@ -42,7 +45,7 @@ const StyleGuidePopover = props => {
4245
<Icon icon={ closeIcon } />
4346
</Button>
4447
<h1 className="ugb-style-guide-popover__title">{ __( 'Design System Style Guide', i18n ) }</h1>
45-
<StyleGuide { ...props } />
48+
<StyleGuide { ...props } designSystem={ designSystem } />
4649
</Popover>
4750
)
4851
}

src/hooks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ export * from './use-global-block-layout-defaults'
2121
export * from './use-block-color-schemes'
2222
export * from './use-preset-controls'
2323
export * from './use-block-style-context'
24+
export * from './use-design-system'

src/hooks/use-design-system.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useSelect } from '@wordpress/data'
2+
3+
export const useDesignSystem = () => {
4+
const { colors } = useSelect( select => {
5+
const colors = select( 'stackable/global-colors' ).getSettings().stackableColors || []
6+
7+
// TODO: get other settings in the design system
8+
9+
return { colors }
10+
}, [] )
11+
12+
return {
13+
colors,
14+
}
15+
}

0 commit comments

Comments
 (0)