Skip to content

Commit

Permalink
feat: allow extra info in statistics block
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Aug 23, 2022
1 parent 90fea80 commit 3e61e34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/StatisticBlock/View.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Statistic } from 'semantic-ui-react';
import { serializeText } from '@eeacms/volto-statistic-block/helpers';

const View = ({ data, mode }) => {
const {
Expand Down Expand Up @@ -27,6 +28,7 @@ const View = ({ data, mode }) => {
>
<Statistic.Value>{item.value}</Statistic.Value>
<Statistic.Label>{item.label}</Statistic.Label>
<Statistic.Label>{serializeText(item.info)}</Statistic.Label>
</Statistic>
);
})}
Expand Down
8 changes: 7 additions & 1 deletion src/StatisticBlock/schema.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const statisticSchema = {
title: 'Statistic item',
fieldsets: [{ id: 'default', title: 'Default', fields: ['value', 'label'] }],
fieldsets: [
{ id: 'default', title: 'Default', fields: ['value', 'label', 'info'] },
],
properties: {
value: {
title: 'Value',
},
label: {
title: 'Label',
},
info: {
title: 'Extra info',
widget: 'slate_richtext',
},
},
required: [],
};
Expand Down
6 changes: 6 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { isArray } from 'lodash';
import { serializeNodes } from 'volto-slate/editor/render';

export const serializeText = (text) => {
return isArray(text) ? serializeNodes(text) : text;
};

0 comments on commit 3e61e34

Please sign in to comment.