Skip to content

Commit

Permalink
Add the global styles preview to the sidebar (#34991)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Sep 21, 2021
1 parent 0c05cfe commit 1b0a380
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
default as DimensionsPanel,
useHasDimensionsPanel,
} from './dimensions-panel';
import { StylePreview } from './global-styles/preview';

function getPanelTitle( blockName ) {
const blockType = getBlockType( blockName );
Expand Down Expand Up @@ -188,6 +189,11 @@ export default function GlobalStylesSidebar() {
>
<Navigation>
<NavigationMenu>
<NavigationGroup>
<NavigationItem>
<StylePreview />
</NavigationItem>
</NavigationGroup>
<GlobalStylesLevel
context={ root }
getStyle={ getStyle }
Expand Down
39 changes: 39 additions & 0 deletions packages/edit-site/src/components/sidebar/global-styles/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
Card,
ColorIndicator,
} from '@wordpress/components';

/**
* Internal dependencies
*/ import { useGlobalStylesContext } from '../../editor/global-styles-provider';

export const StylePreview = () => {
const { getStyle } = useGlobalStylesContext();
const fontFamily = getStyle( 'root', 'fontFamily' ) ?? 'serif';
const textColor = getStyle( 'root', 'color' ) ?? 'black';
const linkColor = getStyle( 'root', 'linkColor' ) ?? 'blue';
const backgroundColor = getStyle( 'root', 'backgroundColor' ) ?? 'white';

return (
<Card
className="edit-site-global-styles-preview"
style={ { background: backgroundColor } }
>
<HStack spacing={ 5 }>
<div>
<span style={ { fontFamily, fontSize: '80px' } }>A</span>
<span style={ { fontFamily, fontSize: '80px' } }>a</span>
</div>
<VStack spacing={ 2 }>
<ColorIndicator colorValue={ textColor } />
<ColorIndicator colorValue={ linkColor } />
</VStack>
</HStack>
</Card>
);
};
16 changes: 16 additions & 0 deletions packages/edit-site/src/components/sidebar/global-styles/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.edit-site-global-styles-preview {
display: flex;
align-items: center;
justify-content: center;
min-height: 152px;

.component-color-indicator {
border-radius: 50%;
border: 0;
height: 36px;
width: 36px;
margin-left: 0;
padding: 0;
}
}

1 change: 1 addition & 0 deletions packages/edit-site/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "./components/navigation-sidebar/navigation-toggle/style.scss";
@import "./components/navigation-sidebar/navigation-panel/style.scss";
@import "./components/sidebar/style.scss";
@import "./components/sidebar/global-styles/style.scss";
@import "./components/sidebar/settings-header/style.scss";
@import "./components/sidebar/template-card/style.scss";
@import "./components/editor/style.scss";
Expand Down

0 comments on commit 1b0a380

Please sign in to comment.