Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the global styles preview to the sidebar #34991

Merged
merged 2 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback values for all the properties here are the browser defaults. Note that they can defer for the actual fallback in the theme if it's using CSS to define these.


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