Skip to content

Commit

Permalink
Stylebook: render overview colors in 4 columns (WordPress#67597)
Browse files Browse the repository at this point in the history
* render overview colors in 4 columns

* use templateColums instead of colums to enable responsive columns

* use templateColumns instead of columns

* tweak CSS

Co-authored-by: matiasbenedetto <[email protected]>
Co-authored-by: tellthemachines <[email protected]>
Co-authored-by: jasmussen <[email protected]>
  • Loading branch information
4 people authored Dec 9, 2024
1 parent 91b130b commit 0154339
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
24 changes: 21 additions & 3 deletions packages/edit-site/src/components/style-book/color-examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@ import {
*/
import type { Color, Gradient } from './types';

const ColorExamples = ( { colors, type } ): JSX.Element | null => {
type Props = {
colors: Color[] | Gradient[];
type: 'colors' | 'gradients';
templateColumns?: string | number;
itemHeight?: string;
};

const ColorExamples = ( {
colors,
type,
templateColumns = '1fr 1fr',
itemHeight = '52px',
}: Props ): JSX.Element | null => {
if ( ! colors ) {
return null;
}

return (
<Grid columns={ 2 } rowGap={ 8 } columnGap={ 16 }>
<Grid templateColumns={ templateColumns } rowGap={ 8 } columnGap={ 16 }>
{ colors.map( ( color: Color | Gradient ) => {
const className =
type === 'gradients'
Expand All @@ -35,7 +47,13 @@ const ColorExamples = ( { colors, type } ): JSX.Element | null => {
className
);

return <View key={ color.slug } className={ classes } />;
return (
<View
key={ color.slug }
className={ classes }
style={ { height: itemHeight } }
/>
);
} ) }
</Grid>
);
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/components/style-book/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export const STYLE_BOOK_IFRAME_STYLES = `
}
.edit-site-style-book__color-example {
height: 32px;
border: 1px solid color-mix( in srgb, currentColor 10%, transparent );
}
Expand Down
7 changes: 6 additions & 1 deletion packages/edit-site/src/components/style-book/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ function getOverviewBlockExamples(
title: __( 'Colors' ),
category: 'overview',
content: (
<ColorExamples colors={ themePalette.colors } type={ colors } />
<ColorExamples
colors={ themePalette.colors }
type={ colors }
templateColumns="repeat(auto-fill, minmax( 200px, 1fr ))"
itemHeight="32px"
/>
),
};

Expand Down

0 comments on commit 0154339

Please sign in to comment.