Skip to content

Commit

Permalink
styles: background color in panels
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Nov 23, 2020
1 parent cb8fdee commit 22995fd
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export AccordionBlockEdit from './manage/Blocks/Accordion/Edit';
export AccordionBlockView from './manage/Blocks/Accordion/View';
export AccordionBlockSchema from './manage/Blocks/Accordion/Schema';
export PanelWidget from './manage/Widgets/PanelWidget';
export ColorPickerWidget from './manage/Widgets/ColorPickerWidget';

export { options } from './manage/Blocks/Accordion/panels';
6 changes: 5 additions & 1 deletion src/components/manage/Blocks/Accordion/AccordionEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Accordion, Input } from 'semantic-ui-react';

import { getStyle } from '@eeacms/volto-accordion-block/components/manage/Styles';
import cx from 'classnames';
import { Icon } from '@plone/volto/components';
import rightSVG from '@plone/volto/icons/right-key.svg';
Expand Down Expand Up @@ -56,7 +57,10 @@ export default ({
</Accordion.Title>
<div>
<Accordion.Content active={activeIndex === 0}>
<div style={{ margin: '1em' }}>
<div
style={{ margin: '1em' }}
{...getStyle(data?.data?.blocks?.settings || {})}
>
<AnimateHeight
animateOpacity
duration={500}
Expand Down
35 changes: 28 additions & 7 deletions src/components/manage/Blocks/Accordion/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import EditBlockWrapper from './EditBlockWrapper';
import Panels from './Panels.jsx';
import { empty, getColumns } from './util';
import { options } from './panels';
import { blocks } from '~/config';
import { makeStyleSchema } from '@eeacms/volto-accordion-block/components/manage/Styles';
import './editor.less';
import upSVG from '@plone/volto/icons/up.svg';
import tuneSVG from '@plone/volto/icons/tune.svg';
Expand All @@ -33,6 +35,25 @@ const Edit = (props) => {
};
};

const onChangeColumnSettings = (id, value) => {
const { data, onChangeBlock, block } = props;
const coldata = data.data;
const formData = {
...data,
data: {
...coldata,
blocks: {
...coldata.blocks,
settings: {
...coldata.blocks?.settings,
[id]: value,
},
},
},
};
onChangeBlock(block, formData);
};

const blockState = {};
const coldata = properties;
const columnList = getColumns(coldata);
Expand All @@ -57,6 +78,8 @@ const Edit = (props) => {
},
});
};
const { available_colors } = blocks.blocksConfig['accordion'];
const AccodionStyleSchema = makeStyleSchema({ available_colors });

return (
<section className="section-block">
Expand Down Expand Up @@ -177,14 +200,12 @@ const Edit = (props) => {
Edit parent Accordion block
</Button>
</Segment>
{/* <InlineForm
schema={''}
title={`Panel ${
columnList.map(([colId]) => colId).indexOf(activePanel) + 1
}`}
<InlineForm
schema={AccodionStyleSchema}
title="Panels"
onChangeField={onChangeColumnSettings}
formData={data?.data?.blocks?.[activePanel]?.settings || {}}
/> */}
formData={data?.data?.blocks?.settings || {}}
/>
</>
) : (
<InlineForm
Expand Down
3 changes: 2 additions & 1 deletion src/components/manage/Blocks/Accordion/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { RenderBlocks } from '@eeacms/volto-blocks-form/components';
import { getColumns, GroupblockHasValue } from './util';
import { Accordion } from 'semantic-ui-react';
import { getStyle } from '@eeacms/volto-accordion-block/components/manage/Styles';

import cx from 'classnames';
import { Icon } from '@plone/volto/components';
Expand Down Expand Up @@ -51,7 +52,7 @@ const View = (props) => {
</Accordion.Title>
<div>
<Accordion.Content active={activeIndex === index}>
<div>
<div {...getStyle(data?.blocks?.settings || {})}>
<AnimateHeight
animateOpacity
duration={500}
Expand Down
15 changes: 15 additions & 0 deletions src/components/manage/Styles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { StyleSchema } from './schema';

export function makeStyleSchema({ available_colors }) {
const schema = StyleSchema();
schema.properties.backgroundColor.available_colors = available_colors;
return schema;
}

export function getStyle(props) {
return {
style: {
backgroundColor: props.backgroundColor,
},
};
}
48 changes: 48 additions & 0 deletions src/components/manage/Styles/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export const StyleSchema = () => ({
title: 'Styling',
fieldsets: [
{
id: 'default',
title: 'Style',
fields: ['backgroundColor'],
},
],
properties: {
backgroundColor: {
title: 'Background color',
type: 'color',
widget: 'color_picker',
},
// grid_vertical_align: {
// title: 'Vertical align',
// choices: [
// ['bottom', 'Bottom'],
// ['middle', 'Middle'],
// ['top', 'Top'],
// ],
// },
},
required: [],
});

export const TextSettingsSchema = {
title: 'Text settings',
fieldsets: [
{
id: 'text_settings',
title: 'Text settings',
fields: ['grid_column_align_text', 'grid_column_text_color'],
},
],
properties: {
grid_column_align_text: {
title: 'Text align',
widget: 'align',
},
grid_column_text_color: {
title: 'Text color',
widget: 'color_picker',
},
},
required: [],
};
63 changes: 63 additions & 0 deletions src/components/manage/Widgets/ColorPickerWidget.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import { FormFieldWrapper, Icon } from '@plone/volto/components';
import { Button } from 'semantic-ui-react';
import loadable from '@loadable/component';
import clearSVG from '@plone/volto/icons/clear.svg';

const ReactColor = loadable.lib(() => import('react-color'));

export default (props) => {
const { id, value, onChange, available_colors } = props;
const [showPicker, setShowPicker] = React.useState(false);

return (
<FormFieldWrapper
{...props}
draggable={false}
className="simple-color-picker-widget"
>
<div>
<Button.Group>
<Button
color={value}
style={{ backgroundColor: value }}
onClick={() => setShowPicker(true)}
size="huge"
title="Pick color"
>
{''}
</Button>
<Button
compact
style={{ paddingLeft: '8px', paddingRight: '0px' }}
onClick={() => onChange(id, null)}
>
<Icon name={clearSVG} size="18px" color="red" />
</Button>
</Button.Group>

{showPicker ? (
<ReactColor>
{({ GithubPicker }) => {
return (
<GithubPicker
width="220px"
triangle="top"
className="color-picker"
colors={available_colors}
color={value || '#000'}
onChangeComplete={(value) => {
setShowPicker(false);
onChange(id, value.hex);
}}
></GithubPicker>
);
}}
</ReactColor>
) : (
''
)}
</div>
</FormFieldWrapper>
);
};
25 changes: 24 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
AccordionBlockView,
AccordionBlockSchema,
} from './components';
import { PanelWidget } from '@eeacms/volto-accordion-block/components';
import {
PanelWidget,
ColorPickerWidget,
} from '@eeacms/volto-accordion-block/components';
import { options } from '@eeacms/volto-accordion-block/components';

const applyConfig = (config) => {
Expand Down Expand Up @@ -50,8 +53,28 @@ const applyConfig = (config) => {
addPermission: [],
view: [],
},
available_colors: [
// '#B80000',
// '#DB3E00',
// '#FCCB00',
// '#008B02',
// '#006B76',
// '#1273DE',
// '#004DCF',
// '#5300EB',
'#EFEFEF',
'#EB9694',
'#FAD0C3',
'#FEF3BD',
'#C1E1C5',
'#BEDADC',
'#C4DEF6',
'#BED3F3',
'#D4C4FB',
],
};
config.widgets.type.panels = PanelWidget;
config.widgets.widget.color_picker = ColorPickerWidget;
return config;
};

Expand Down

0 comments on commit 22995fd

Please sign in to comment.