Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add blockExtension and className extension support #2

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support of block and class extensions @ionlizarazu
4 changes: 2 additions & 2 deletions src/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SidebarPortal, BlockDataForm } from '@plone/volto/components';
import { useIntl } from 'react-intl';

import { CountUpBlockSchema } from './schema';
import { BlockViewComponent } from './View';
import CountUpBlockView from './View';

export const CountUpBlockEdit = (props) => {
const { block, data, selected } = props;
Expand All @@ -28,7 +28,7 @@ export const CountUpBlockEdit = (props) => {
onChangeField={handleChange}
/>
</SidebarPortal>
<BlockViewComponent data={data} />
<CountUpBlockView data={data} />
</>
);
};
37 changes: 7 additions & 30 deletions src/View.jsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,23 @@
import React from 'react';
import CountUp from 'react-countup';
import { Segment } from 'semantic-ui-react';
export const BlockViewComponent = ({ data }) => {
// Counter config
const {
start,
end,
duration,
prefix,
suffix,
decimal,
decimals,
separator,
delay = 2,
} = data;
import { withBlockExtensions } from '@plone/volto/helpers';

const CountUpBlockView = ({ data, className }) => {
const { delay = 2 } = data;

// Title config
const { title, titleTag, titlePosition = 'above' } = data;
const TitleTag = titleTag || 'h2';

return (
<Segment>
<Segment className={className}>
{title && titlePosition === 'above' && <TitleTag>{title}</TitleTag>}

<CountUp
delay={delay}
start={start}
end={end}
duration={duration}
prefix={prefix}
suffix={suffix}
decimal={decimal}
decimals={decimals}
separator={separator}
/>
<CountUp {...data} delay={delay} />
{title && titlePosition === 'below' && <TitleTag>{title}</TitleTag>}
</Segment>
);
};

export const CountUpBlockView = (props) => {
const { data } = props;

return <BlockViewComponent data={data} />;
};
export default withBlockExtensions(CountUpBlockView);
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CountUpBlockEdit } from './Edit.jsx';
import { CountUpBlockView } from './View.jsx';
import mapSVG from '@plone/volto/icons/map.svg';
import CountUpBlockView from './View.jsx';
import iconSVG from '@plone/volto/icons/circle-top.svg';

const applyConfig = (config) => {
// Own blocks
config.blocks.blocksConfig['countUpBlock'] = {
id: 'countUpBlock',
title: 'Count Up',
icon: mapSVG,
icon: iconSVG,
edit: CountUpBlockEdit,
view: CountUpBlockView,
restricted: false,
Expand Down
2 changes: 1 addition & 1 deletion src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import messages from './messages.js';

export const CountUpBlockSchema = (intl, data) => {
const decimals =
data.start % 1 !== 0 || data.end % 1 !== 0 ? [('decimal', 'decimals')] : [];
data.start % 1 !== 0 || data.end % 1 !== 0 ? ['decimal', 'decimals'] : [];
const thousands = data.start >= 1000 || data.end >= 1000 ? ['separator'] : [];
const separator =
decimals.length || thousands.length
Expand Down
Loading