generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from eea/develop
add statistic block
- Loading branch information
Showing
8 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
# Changelog | ||
### Changelog | ||
|
||
## 0.1.0 | ||
All notable changes to this project will be documented in this file. Dates are displayed in UTC. | ||
|
||
- Initial release | ||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). | ||
|
||
#### [0.1.1](https://github.com/eea/volto-statistic-block/compare/0.1.0...0.1.1) | ||
|
||
- add statistic block [`df367cb`](https://github.com/eea/volto-statistic-block/commit/df367cbf7912d99ae7fbd0c5f20f1c9f590d1512) | ||
- Update README.md [`2ecde42`](https://github.com/eea/volto-statistic-block/commit/2ecde424229d79e12d2c91223d56117255f33cfc) | ||
- Fix package.json [`91bb2e8`](https://github.com/eea/volto-statistic-block/commit/91bb2e8a0ad0d3bd99165751f319bceb99e181e0) | ||
|
||
#### 0.1.0 | ||
|
||
> 9 March 2022 | ||
- Initial commit [`2e19fe2`](https://github.com/eea/volto-statistic-block/commit/2e19fe2708f89887d2d79f88696e197643ea10f4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import { SidebarPortal } from '@plone/volto/components'; | ||
import InlineForm from '@plone/volto/components/manage/Form/InlineForm'; | ||
import View from './View'; | ||
import schema from './schema'; | ||
|
||
const Edit = (props) => { | ||
const { data = {}, block = null, selected = false, onChangeBlock } = props; | ||
|
||
return ( | ||
<> | ||
<View {...props} mode="edit" /> | ||
|
||
<SidebarPortal selected={selected}> | ||
<InlineForm | ||
schema={schema} | ||
title={schema.title} | ||
onChangeField={(id, value) => { | ||
onChangeBlock(block, { | ||
...data, | ||
[id]: value, | ||
}); | ||
}} | ||
formData={data} | ||
/> | ||
</SidebarPortal> | ||
</> | ||
); | ||
}; | ||
|
||
export default Edit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { Statistic } from 'semantic-ui-react'; | ||
|
||
const View = ({ data, mode }) => { | ||
const { | ||
horizontal = false, | ||
inverted = false, | ||
size = 'small', | ||
widths = 'one', | ||
items = [], | ||
} = data; | ||
|
||
if (!items.length && mode === 'edit') return <p>Add statistic items</p>; | ||
return ( | ||
<div> | ||
<Statistic.Group | ||
horizontal={horizontal} | ||
inverted={inverted} | ||
size={size} | ||
widths={widths} | ||
> | ||
{items.map((item, index) => { | ||
return ( | ||
<Statistic | ||
key={`${index}-${item.label}`} | ||
className="eea-statistics" | ||
> | ||
<Statistic.Value>{item.value}</Statistic.Value> | ||
<Statistic.Label>{item.label}</Statistic.Label> | ||
</Statistic> | ||
); | ||
})} | ||
</Statistic.Group> | ||
</div> | ||
); | ||
}; | ||
|
||
export default View; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import worldSVG from '@plone/volto/icons/world.svg'; | ||
import StatisticBlockEdit from './Edit'; | ||
import StatisticBlockView from './View'; | ||
|
||
export default (config) => { | ||
config.blocks.blocksConfig.statistic_block = { | ||
id: 'statistic_block', | ||
title: 'Statistic block', | ||
icon: worldSVG, | ||
group: 'text', | ||
view: StatisticBlockView, | ||
edit: StatisticBlockEdit, | ||
restricted: false, | ||
mostUsed: false, | ||
sidebarTab: 1, | ||
security: { | ||
addPermission: [], | ||
view: [], | ||
}, | ||
}; | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const statisticSchema = { | ||
title: 'Statistic item', | ||
fieldsets: [{ id: 'default', title: 'Default', fields: ['value', 'label'] }], | ||
properties: { | ||
value: { | ||
title: 'Value', | ||
}, | ||
label: { | ||
title: 'Label', | ||
}, | ||
}, | ||
required: [], | ||
}; | ||
|
||
export default { | ||
title: 'Statistic block', | ||
|
||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['horizontal', 'inverted', 'size', 'widths', 'items'], | ||
}, | ||
], | ||
|
||
properties: { | ||
horizontal: { | ||
title: 'Horizontal', | ||
description: 'Can present its measurement horizontally', | ||
type: 'boolean', | ||
}, | ||
inverted: { | ||
title: 'Inverted', | ||
description: 'Can be formatted to fit on a dark background.', | ||
type: 'boolean', | ||
}, | ||
size: { | ||
title: 'Size', | ||
choices: [ | ||
['mini', 'Mini'], | ||
['tiny', 'Tiny'], | ||
['small', 'Small'], | ||
['large', 'Large'], | ||
['huge', 'Huge'], | ||
], | ||
}, | ||
widths: { | ||
title: 'Columns', | ||
choices: [ | ||
['one', 'One'], | ||
['two', 'Two'], | ||
['three', 'Three'], | ||
['four', 'Four'], | ||
], | ||
}, | ||
items: { | ||
title: 'Statistic items', | ||
widget: 'object_list', | ||
schema: statisticSchema, | ||
}, | ||
}, | ||
|
||
required: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import installStatisticBlock from './StatisticBlock'; | ||
|
||
const applyConfig = (config) => { | ||
return config; | ||
return [installStatisticBlock].reduce((acc, apply) => apply(acc), config); | ||
}; | ||
|
||
export default applyConfig; |