Skip to content

Commit

Permalink
remove schemaEnhancer
Browse files Browse the repository at this point in the history
  • Loading branch information
danalvrz committed Oct 24, 2024
1 parent 7eafeee commit caec1ad
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 64 deletions.
26 changes: 4 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,19 @@ The Volto Separator Block allows editors to add a visual separator between block

![Separator-Block](https://github.com/kitconcept/volto-separator-block/raw/master/screencast.gif)

## Block Alignment Enhancer
## Block Schema

This block features by default a block `schemaEnhancer` that provides an alignment option for the separator. This can be disabled by overwriting with your own `schemaEnhancer`
This block features an option to make the line short, for visual variety purpuses. If that is the case, the line's `width` points to the custom property `--short-line-width`, which can be set if desired.

```js
config.blocks.blocksConfig.separator = {
...config.blocks.blocksConfig.separator,
schemaEnhancer: mySeparatorSchemaEnhancer,
}
```
or setting it to `null` or `undefined`:
The `schema` can be extended by using with your own `schemaEnhancer`:

```js
config.blocks.blocksConfig.separator = {
...config.blocks.blocksConfig.separator,
schemaEnhancer: null,
schemaEnhancer: mySeparatorSchemaEnhancer,
}
```

Also, if you want to keep the default alignment but still add your own `schemaEnhancer` you can compose it along with your own:

```js
import { composeSchema } from '@plone/volto/helpers';
import { SeparatorStyleEnhancer } from '@kitconcept/volto-separator-block';

config.blocks.blocksConfig.separator = {
...config.blocks.blocksConfig.separator,
schemaEnhancer: composeSchema(mySeparatorSchemaEnhancer, defaultSeparatorEnhancer),
}
```

## Installation

To install your project, you must choose the method appropriate to your version of Volto.
Expand Down
4 changes: 2 additions & 2 deletions packages/volto-separator-block/src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const LegacyWrapper = (props) => (
);

const SeparatorView = (props) => {
const { blocksConfig } = props;
const { blocksConfig, data } = props;
const isBlockModelv3 = blocksConfig?.separator?.blockModel === 3;

return (
<MaybeWrap condition={!isBlockModelv3} as={LegacyWrapper} {...props}>
<div className="line" />
<div className={cx('line', { short: data.shortLine })} />
</MaybeWrap>
);
};
Expand Down
36 changes: 9 additions & 27 deletions packages/volto-separator-block/src/components/schema.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { addStyling } from '@plone/volto/helpers/Extensions/withBlockSchemaEnhancer';
import { defineMessages } from 'react-intl';

const messages = defineMessages({
title: {
id: 'Title',
defaultMessage: 'Title',
},
separatorBlock: {
id: 'Separator Block',
defaultMessage: 'Separator',
Expand All @@ -17,31 +12,18 @@ const messages = defineMessages({
});

export const SeparatorSchema = (props) => {
const { intl } = props;

return {
title: props.intl.formatMessage(messages.separatorBlock),
title: intl.formatMessage(messages.separatorBlock),
block: 'separator',
fieldsets: [
{
id: 'default',
title: 'Default',
fieldsets: [{ id: 'default', title: 'Default', fields: ['shortLine'] }],
properties: {
shortLine: {
title: intl.formatMessage(messages.shortline),
type: 'boolean',
},
],
properties: {},
},
required: [],
};
};

export const SeparatorStyleEnhancer = ({ schema, intl }) => {
addStyling({ schema, intl });

schema.properties.styles.schema.fieldsets[0].fields = [
'shortLine',
...schema.properties.styles.schema.fieldsets[0].fields,
];
schema.properties.styles.schema.properties.shortLine = {
title: intl.formatMessage(messages.shortline),
type: 'boolean',
};

return schema;
};
2 changes: 0 additions & 2 deletions packages/volto-separator-block/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineMessages } from 'react-intl';
import { SeparatorStyleEnhancer } from './components/schema';
import divideHorizontalSVG from '@plone/volto/icons/divide-horizontal.svg';
import SeparatorView from './components/View';
import SeparatorEdit from './components/Edit';
Expand All @@ -20,7 +19,6 @@ const applyConfig = (config) => {
group: 'teasers',
view: SeparatorView,
edit: SeparatorEdit,
schemaEnhancer: SeparatorStyleEnhancer,
restricted: false,
mostUsed: true,
sidebarTab: 1,
Expand Down
6 changes: 3 additions & 3 deletions packages/volto-separator-block/src/theme/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
margin-top: -1px;
content: '';
}
}

&.has--shortLine--true {
width: var(--short-line-width, 25%);
&.short {
width: var(--short-line-width, 25%);
}
}

&.has--align--left {
Expand Down
20 changes: 12 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit caec1ad

Please sign in to comment.