Skip to content
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
9 changes: 4 additions & 5 deletions packages/edit-site/src/components/global-styles/screen-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const { useGlobalStyle, AdvancedPanel: StylesAdvancedPanel } = unlock(
);

function ScreenCSS() {
const description = __(
'Add your own CSS to customize the appearance and layout of your site.'
);
const [ style ] = useGlobalStyle( '', undefined, 'user', {
shouldDecodeEncode: false,
} );
Expand All @@ -35,10 +32,12 @@ function ScreenCSS() {
return (
<>
<ScreenHeader
title={ __( 'CSS' ) }
title={ __( 'Additional CSS' ) }
description={
<>
{ description }
{ __(
'You can add custom CSS to further customize the appearance and layout of your site.'
) }
<br />
<ExternalLink
href={ __(
Expand Down
56 changes: 5 additions & 51 deletions packages/edit-site/src/components/global-styles/screen-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,10 @@ import RootMenu from './root-menu';
import PreviewStyles from './preview-styles';

function ScreenRoot() {
const { hasVariations, canEditCSS } = useSelect( ( select ) => {
const {
getEntityRecord,
__experimentalGetCurrentGlobalStylesId,
__experimentalGetCurrentThemeGlobalStylesVariations,
} = select( coreStore );

const globalStylesId = __experimentalGetCurrentGlobalStylesId();
const globalStyles = globalStylesId
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
: undefined;

return {
hasVariations:
!! __experimentalGetCurrentThemeGlobalStylesVariations()
?.length,
canEditCSS: !! globalStyles?._links?.[ 'wp:action-edit-css' ],
};
const hasVariations = useSelect( ( select ) => {
const { __experimentalGetCurrentThemeGlobalStylesVariations } =
select( coreStore );
return !! __experimentalGetCurrentThemeGlobalStylesVariations()?.length;
}, [] );

return (
Expand Down Expand Up @@ -92,7 +78,7 @@ function ScreenRoot() {
* the nav button inset should be looked at before reusing further.
*/
paddingX="13px"
marginBottom={ 4 }
marginBottom={ 2 }
>
{ __(
'Customize the appearance of specific blocks for the whole site.'
Expand All @@ -109,38 +95,6 @@ function ScreenRoot() {
</NavigationButtonAsItem>
</ItemGroup>
</CardBody>

{ canEditCSS && (
<>
<CardDivider />
<CardBody>
<Spacer
as="p"
paddingTop={ 2 }
paddingX="13px"
marginBottom={ 4 }
>
{ __(
'Add your own CSS to customize the appearance and layout of your site.'
) }
</Spacer>
<ItemGroup>
<NavigationButtonAsItem path="/css">
<HStack justify="space-between">
<FlexItem>
{ __( 'Additional CSS' ) }
</FlexItem>
<IconWithCurrentColor
icon={
isRTL() ? chevronLeft : chevronRight
}
/>
</HStack>
</NavigationButtonAsItem>
</ItemGroup>
</CardBody>
</>
) }
</Card>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useMemo, useState } from '@wordpress/element';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useViewportMatch } from '@wordpress/compose';
import { Button } from '@wordpress/components';
import {
Button,
__experimentalHStack as HStack,
DropdownMenu,
MenuGroup,
MenuItem,
} from '@wordpress/components';
import { addQueryArgs, removeQueryArgs } from '@wordpress/url';
import { seen } from '@wordpress/icons';
import { seen, moreVertical } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -24,21 +32,59 @@ const GlobalStylesPageActions = ( {
path,
} ) => {
const history = useHistory();
const canEditCSS = useSelect( ( select ) => {
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
select( coreStore );
const globalStylesId = __experimentalGetCurrentGlobalStylesId();
const globalStyles = globalStylesId
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
: undefined;
return !! globalStyles?._links?.[ 'wp:action-edit-css' ];
}, [] );

return (
<Button
isPressed={ isStyleBookOpened }
icon={ seen }
label={ __( 'Style Book' ) }
onClick={ () => {
setIsStyleBookOpened( ! isStyleBookOpened );
const updatedPath = ! isStyleBookOpened
? addQueryArgs( path, { preview: 'stylebook' } )
: removeQueryArgs( path, 'preview' );
// Navigate to the updated path.
history.navigate( updatedPath );
} }
size="compact"
/>
<HStack>
<Button
isPressed={ isStyleBookOpened }
icon={ seen }
label={ __( 'Style Book' ) }
onClick={ () => {
setIsStyleBookOpened( ! isStyleBookOpened );
const updatedPath = ! isStyleBookOpened
? addQueryArgs( path, { preview: 'stylebook' } )
: removeQueryArgs( path, 'preview' );
// Navigate to the updated path.
history.navigate( updatedPath );
} }
size="compact"
/>
{ canEditCSS && (
<DropdownMenu
icon={ moreVertical }
label={ __( 'More' ) }
toggleProps={ { size: 'compact' } }
>
{ ( { onClose } ) => (
<MenuGroup>
{ canEditCSS && (
<MenuItem
onClick={ () => {
onClose();
history.navigate(
addQueryArgs( path, {
section: '/css',
} )
);
} }
>
{ __( 'Additional CSS' ) }
</MenuItem>
) }
</MenuGroup>
) }
</DropdownMenu>
) }
</HStack>
);
};

Expand Down
Loading