Skip to content

Commit

Permalink
Style Book: Add color tab (#65692)
Browse files Browse the repository at this point in the history
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ramonjd <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent b0db4f8 commit 5437114
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function useMultipleOriginColorsAndGradients() {
'Theme',
'Indicates this palette comes from the theme.'
),
slug: 'theme',
colors: themeColors,
} );
}
Expand All @@ -68,15 +69,17 @@ export default function useMultipleOriginColorsAndGradients() {
'Default',
'Indicates this palette comes from WordPress.'
),
slug: 'default',
colors: defaultColors,
} );
}
if ( customColors && customColors.length ) {
result.push( {
name: _x(
'Custom',
'Indicates this palette comes from the theme.'
'Indicates this palette is created by the user.'
),
slug: 'custom',
colors: customColors,
} );
}
Expand All @@ -96,6 +99,7 @@ export default function useMultipleOriginColorsAndGradients() {
'Theme',
'Indicates this palette comes from the theme.'
),
slug: 'theme',
gradients: themeGradients,
} );
}
Expand All @@ -109,6 +113,7 @@ export default function useMultipleOriginColorsAndGradients() {
'Default',
'Indicates this palette comes from WordPress.'
),
slug: 'default',
gradients: defaultGradients,
} );
}
Expand All @@ -118,6 +123,7 @@ export default function useMultipleOriginColorsAndGradients() {
'Custom',
'Indicates this palette is created by the user.'
),
slug: 'custom',
gradients: customGradients,
} );
}
Expand Down
11 changes: 11 additions & 0 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import ScreenCSS from './screen-css';
import ScreenRevisions from './screen-revisions';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import { STYLE_BOOK_COLOR_GROUPS } from '../style-book/constants';

const SLOT_FILL_NAME = 'GlobalStylesMenu';
const { useGlobalStylesReset } = unlock( blockEditorPrivateApis );
Expand Down Expand Up @@ -191,6 +192,16 @@ function GlobalStylesStyleBook() {
)
}
onSelect={ ( blockName ) => {
if (
STYLE_BOOK_COLOR_GROUPS.find(
( group ) => group.slug === blockName
)
) {
// Go to color palettes Global Styles.
navigator.goTo( '/colors/palette' );
return;
}

// Now go to the selected block.
navigator.goTo( '/blocks/' + encodeURIComponent( blockName ) );
} }
Expand Down
44 changes: 44 additions & 0 deletions packages/edit-site/src/components/style-book/color-examples.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import { __experimentalGrid as Grid } from '@wordpress/components';
import { View } from '@wordpress/primitives';
import {
getColorClassName,
__experimentalGetGradientClass,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import type { Color, Gradient } from './types';

const ColorExamples = ( { colors, type } ): JSX.Element | null => {
if ( ! colors ) {
return null;
}

return (
<Grid columns={ 2 } rowGap={ 8 } columnGap={ 16 }>
{ colors.map( ( color: Color | Gradient ) => {
const className =
type === 'gradients'
? __experimentalGetGradientClass( color.slug )
: getColorClassName( 'background-color', color.slug );
const classes = clsx(
'edit-site-style-book__color-example',
className
);

return <View key={ color.slug } className={ classes } />;
} ) }
</Grid>
);
};

export default ColorExamples;
80 changes: 75 additions & 5 deletions packages/edit-site/src/components/style-book/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,52 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import type { StyleBookCategory } from './types';
import type { StyleBookCategory, StyleBookColorGroup } from './types';

export const STYLE_BOOK_COLOR_GROUPS: StyleBookColorGroup[] = [
{
slug: 'theme-colors',
title: __( 'Theme Colors' ),
origin: 'theme',
type: 'colors',
},
{
slug: 'theme-gradients',
title: __( 'Theme Gradients' ),
origin: 'theme',
type: 'gradients',
},
{
slug: 'custom-colors',
title: __( 'Custom Colors' ),
origin: 'custom',
type: 'colors',
},
{
slug: 'custom-gradients',
title: __( 'Custom Gradients' ),
origin: 'custom', // User.
type: 'gradients',
},
{
slug: 'duotones',
title: __( 'Duotones' ),
origin: 'theme',
type: 'duotones',
},
{
slug: 'default-colors',
title: __( 'Default Colors' ),
origin: 'default',
type: 'colors',
},
{
slug: 'default-gradients',
title: __( 'Default Gradients' ),
origin: 'default',
type: 'gradients',
},
];

export const STYLE_BOOK_THEME_SUBCATEGORIES: Omit<
StyleBookCategory,
Expand Down Expand Up @@ -74,7 +119,7 @@ export const STYLE_BOOK_CATEGORIES: StyleBookCategory[] = [
{
slug: 'colors',
title: __( 'Colors' ),
blocks: [ 'custom/colors' ],
blocks: [],
},
{
slug: 'theme',
Expand Down Expand Up @@ -111,7 +156,7 @@ export const STYLE_BOOK_IFRAME_STYLES = `
.is-root-container {
display: flow-root;
}
body {
position: relative;
padding: 32px !important;
Expand Down Expand Up @@ -141,15 +186,40 @@ export const STYLE_BOOK_IFRAME_STYLES = `
box-shadow: 0 0 0 1px var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
}
.edit-site-style-book__example.is-disabled-example {
pointer-events: none;
}
.edit-site-style-book__example:focus:not(:disabled) {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
outline: 3px solid transparent;
}
.edit-site-style-book__duotone-example > div:first-child {
display: flex;
aspect-ratio: 16 / 9;
grid-row: span 1;
grid-column: span 2;
}
.edit-site-style-book__duotone-example img {
width: 100%;
height: 100%;
object-fit: cover;
}
.edit-site-style-book__duotone-example > div:not(:first-child) {
height: 20px;
border: 1px solid #ddd;
}
.edit-site-style-book__color-example {
height: 52px;
border: 1px solid #ddd;
}
.edit-site-style-book__examples.is-wide .edit-site-style-book__example {
flex-direction: row;
}
.edit-site-style-book__subcategory-title,
.edit-site-style-book__example-title {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
Expand All @@ -160,7 +230,7 @@ export const STYLE_BOOK_IFRAME_STYLES = `
text-align: left;
text-transform: uppercase;
}
.edit-site-style-book__subcategory-title {
font-size: 16px;
margin-bottom: 40px;
Expand Down
53 changes: 53 additions & 0 deletions packages/edit-site/src/components/style-book/duotone-examples.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* WordPress dependencies
*/
import { __experimentalGrid as Grid } from '@wordpress/components';
import { View } from '@wordpress/primitives';

/**
* Internal dependencies
*/
import type { Duotone } from './types';

const DuotoneExamples = ( { duotones } ): JSX.Element | null => {
if ( ! duotones ) {
return null;
}

return (
<Grid columns={ 2 } rowGap={ 16 } columnGap={ 16 }>
{ duotones.map( ( duotone: Duotone ) => {
return (
<Grid
key={ duotone.slug }
className="edit-site-style-book__duotone-example"
columns={ 2 }
rowGap={ 8 }
columnGap={ 8 }
>
<View>
<img
alt={ `Duotone example: ${ duotone.slug }` }
src="https://s.w.org/images/core/5.3/MtBlanc1.jpg"
style={ {
filter: `url(#wp-duotone-${ duotone.slug })`,
} }
/>
</View>
{ duotone.colors.map( ( color ) => {
return (
<View
key={ color }
className="edit-site-style-book__color-example"
style={ { backgroundColor: color } }
/>
);
} ) }
</Grid>
);
} ) }
</Grid>
);
};

export default DuotoneExamples;
63 changes: 0 additions & 63 deletions packages/edit-site/src/components/style-book/examples.ts

This file was deleted.

Loading

0 comments on commit 5437114

Please sign in to comment.