Skip to content

Commit

Permalink
Show only common variants in ColumnVariants
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Mar 24, 2021
1 parent 075eebc commit 282b8b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/ColumnsBlock/ColumnsBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import ColumnVariations from './ColumnVariations';
import EditBlockWrapper from './EditBlockWrapper';

import { COLUMNSBLOCK } from '@eeacms/volto-columns-block/constants';
import { variants as defaultVariants } from '@eeacms/volto-columns-block/grid';
import { makeStyleSchema, getStyle } from '@eeacms/volto-columns-block/Styles';

import tuneSVG from '@plone/volto/icons/column.svg';
Expand Down Expand Up @@ -211,8 +210,7 @@ class ColumnsBlockEdit extends React.Component {
};

getColumnsBlockSchema = () => {
const variants =
config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || defaultVariants;
const variants = config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || [];
const schema = ColumnsBlockSchema();
const { data } = this.props;
const { blocks_layout = {} } = data.data || {};
Expand All @@ -228,8 +226,7 @@ class ColumnsBlockEdit extends React.Component {
};

componentDidUpdate(prevProps) {
const variants =
config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || defaultVariants;
const variants = config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || [];
const cols = this.props.data.data?.blocks_layout?.items || [];
const prevCols = prevProps.data.data?.blocks_layout?.items || [];

Expand Down Expand Up @@ -321,7 +318,7 @@ class ColumnsBlockEdit extends React.Component {
{data.coldata ? 'old style columns block, safe to remove it' : ''}
{!data?.data ? (
<ColumnVariations
variants={variants}
variants={variants.filter((variant) => variant.common)}
data={data}
onChange={(initialData) => {
onChangeBlock(block, {
Expand Down
7 changes: 2 additions & 5 deletions src/Widgets/LayoutSelectWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '@plone/volto/components/manage/Widgets/SelectStyling';
import config from '@plone/volto/registry';

import { variants as defaultVariants } from '../grid';
import { COLUMNSBLOCK } from '@eeacms/volto-columns-block/constants';

import checkSVG from '@plone/volto/icons/check.svg';
Expand All @@ -33,8 +32,7 @@ const variantToGridCols = (v) => {
};

export const Option = (props) => {
const variants =
config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || defaultVariants;
const variants = config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || [];
return (
<ReactSelectLib>
{({ components }) => {
Expand Down Expand Up @@ -64,8 +62,7 @@ export const Option = (props) => {

const SingleValue = (props) => {
const { children, className, cx, getStyles, isDisabled, innerProps } = props;
const variants =
config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || defaultVariants;
const variants = config.blocks.blocksConfig?.[COLUMNSBLOCK]?.variants || [];

const variant = variants.find((v) =>
gridColsAreEqual(variantToGridCols(v), props.data.value),
Expand Down
10 changes: 10 additions & 0 deletions src/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const variants = [
gridSize: 12,
gridCols: ['halfWidth', 'halfWidth'],
},
common: true,
title: '50 / 50',
},
{
Expand All @@ -79,6 +80,7 @@ export const variants = [
gridSize: 12,
gridCols: ['oneFifth', 'fourFifths'],
},
common: true,
title: '20 / 80',
},
{
Expand All @@ -87,6 +89,7 @@ export const variants = [
gridSize: 12,
gridCols: ['oneThird', 'twoThirds'],
},
common: true,
title: '30 / 70',
},
{
Expand All @@ -95,6 +98,7 @@ export const variants = [
gridSize: 12,
gridCols: ['twoThirds', 'oneThird'],
},
common: true,
title: '70 / 30',
},
{
Expand All @@ -103,6 +107,7 @@ export const variants = [
gridSize: 12,
gridCols: ['fourFifths', 'oneFifth'],
},
common: true,
title: '80 / 20',
},
{
Expand All @@ -111,6 +116,7 @@ export const variants = [
gridSize: 12,
gridCols: ['oneThird', 'oneThird', 'oneThird'],
},
common: true,
title: '33 / 33 / 33',
},
{
Expand All @@ -119,6 +125,7 @@ export const variants = [
gridSize: 12,
gridCols: ['oneThirdSmall', 'halfWidthBig', 'oneThirdSmall'],
},
common: true,
title: '25 / 50 / 25',
},
{
Expand All @@ -127,6 +134,7 @@ export const variants = [
gridSize: 12,
gridCols: ['oneQuarter', 'oneQuarter', 'oneQuarter', 'oneQuarter'],
},
common: true,
title: '25 / 25 / 25 / 25',
},
{
Expand All @@ -135,6 +143,7 @@ export const variants = [
gridSize: 12,
gridCols: ['full'],
},
common: true,
title: '100',
},
{
Expand All @@ -143,6 +152,7 @@ export const variants = [
gridSize: 12,
gridCols: ['threeFifths', 'twoFifths'],
},
common: true,
title: '60 / 40',
},
];

0 comments on commit 282b8b1

Please sign in to comment.