Skip to content

Commit

Permalink
Prepare for Block Model v3, backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Mar 13, 2024
1 parent e0f68d9 commit a059998
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/components/Data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const messages = defineMessages({
});

const ButtonData = (props) => {
const { data, block, onChangeBlock, schemaEnhancer } = props;
const { data, block, onChangeBlock, schemaEnhancer, navRoot, contentType } =
props;
const intl = useIntl();
const schema = schemaEnhancer
? schemaEnhancer(ButtonSchema({ ...props, intl }), props)
Expand All @@ -27,9 +28,11 @@ const ButtonData = (props) => {
[id]: value,
});
}}
onChangeBlock={onChangeBlock}
formData={data}
fieldIndex={data.index}
block={block}
navRoot={navRoot}
contentType={contentType}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/components/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import View from './View';

const Edit = (props) => {
const { data, block, onChangeBlock, selected } = props;

return (
<>
<View {...props} isEditMode />
Expand Down
20 changes: 13 additions & 7 deletions src/components/View.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { Button } from 'semantic-ui-react';
import cx from 'classnames';
import { ConditionalLink } from '@plone/volto/components';
import { ConditionalLink, MaybeWrap } from '@plone/volto/components';
import { defineMessages, useIntl } from 'react-intl';
import config from '@plone/volto/registry';

const messages = defineMessages({
ButtonText: {
Expand All @@ -11,9 +12,16 @@ const messages = defineMessages({
},
});

const View = ({ data, isEditMode, className }) => {
const LegacyWrapper = (props) => (
<div className={cx('block __button', props.className)}>
<div className="button container">{props.children}</div>
</div>
);

const View = ({ data, isEditMode, className, blocksConfig }) => {
const [hasLink, setHasLink] = React.useState(false);
const intl = useIntl();
const isBlockModelv3 = blocksConfig?.__button?.v3;

React.useEffect(() => {
if (data.href) {
Expand Down Expand Up @@ -47,11 +55,9 @@ const View = ({ data, isEditMode, className }) => {
);

return (
<div className={cx('block __button', className)}>
<div className="button container">
<div className={cx(`align ${data?.inneralign}`)}>{link}</div>
</div>
</div>
<MaybeWrap condition={!isBlockModelv3} as={LegacyWrapper}>
<div className={cx(`align ${data?.inneralign}`)}>{link}</div>
</MaybeWrap>
);
};

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const applyConfig = (config) => {
restricted: false,
mostUsed: true,
sidebarTab: 1,
category: 'action',
};
return config;
};
Expand Down

0 comments on commit a059998

Please sign in to comment.