-
Notifications
You must be signed in to change notification settings - Fork 7
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 #23 from eea/develop
Add accordion template for mobile
- Loading branch information
Showing
14 changed files
with
445 additions
and
13 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
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,46 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const projectRootPath = fs.realpathSync('./project'); // __dirname | ||
const packageJson = require(path.join(projectRootPath, 'package.json')); | ||
const jsConfig = require(path.join(projectRootPath, 'jsconfig.json')).compilerOptions; | ||
|
||
const pathsConfig = jsConfig.paths; | ||
|
||
let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); | ||
|
||
Object.keys(pathsConfig).forEach(pkg => { | ||
if (pkg === '@plone/volto') { | ||
voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`; | ||
} | ||
}); | ||
const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); | ||
const reg = new AddonConfigurationRegistry(projectRootPath); | ||
|
||
// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons | ||
const addonAliases = Object.keys(reg.packages).map(o => [ | ||
o, | ||
reg.packages[o].modulePath, | ||
]); | ||
|
||
|
||
module.exports = { | ||
extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`, | ||
settings: { | ||
'import/resolver': { | ||
alias: { | ||
map: [ | ||
['@plone/volto', '@plone/volto/src'], | ||
...addonAliases, | ||
['@package', `${__dirname}/src`], | ||
['~', `${__dirname}/src`], | ||
], | ||
extensions: ['.js', '.jsx', '.json'], | ||
}, | ||
'babel-plugin-root-import': { | ||
rootPathSuffix: 'src', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
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,17 @@ | ||
module.exports = function (api) { | ||
api.cache(true); | ||
const presets = ['razzle/babel']; | ||
const plugins = [ | ||
[ | ||
'react-intl', // React Intl extractor, required for the whole i18n infrastructure to work | ||
{ | ||
messagesDir: './build/messages/', | ||
}, | ||
], | ||
]; | ||
|
||
return { | ||
plugins, | ||
presets, | ||
}; | ||
}; |
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,18 @@ | ||
import { DefaultEdit } from '../default'; | ||
|
||
const Edit = (props) => { | ||
return ( | ||
<DefaultEdit | ||
{...props} | ||
data={{ | ||
...props.data, | ||
menuPointing: true, | ||
menuSecondary: true, | ||
menuFluid: false, | ||
menuText: false, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
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,125 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { compose } from 'redux'; | ||
import { withRouter } from 'react-router'; | ||
import Tabs from 'react-responsive-tabs'; | ||
import AnimateHeight from 'react-animate-height'; | ||
import { Icon } from 'semantic-ui-react'; | ||
import config from '@plone/volto/registry'; | ||
import { Icon as VoltoIcon, RenderBlocks } from '@plone/volto/components'; | ||
import { TABS_BLOCK } from '@eeacms/volto-tabs-block/constants'; | ||
import { withScrollToTarget } from '@eeacms/volto-tabs-block/hocs'; | ||
|
||
import 'react-responsive-tabs/styles.css'; | ||
import '@eeacms/volto-tabs-block/less/menu.less'; | ||
|
||
class Tab extends React.Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
height: 0, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
if (this.state.height === 0) { | ||
requestAnimationFrame(() => { | ||
this.setState({ height: 'auto' }); | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<AnimateHeight animateOpacity duration={500} height={this.state.height}> | ||
<RenderBlocks {...this.props} /> | ||
</AnimateHeight> | ||
); | ||
} | ||
} | ||
|
||
const View = (props) => { | ||
const { | ||
data = {}, | ||
tabsList = [], | ||
tabs = {}, | ||
activeTabIndex = 0, | ||
setActiveTab = () => {}, | ||
} = props; | ||
const accordionConfig = | ||
config.blocks.blocksConfig.tabs_block.templates.accordion; | ||
const { icons, semanticIcon } = accordionConfig; | ||
|
||
const schema = React.useMemo( | ||
() => | ||
config.blocks.blocksConfig[TABS_BLOCK].templates?.['default']?.schema( | ||
config, | ||
props, | ||
) || {}, | ||
[props], | ||
); | ||
|
||
const getDataValue = React.useCallback( | ||
(key) => { | ||
return ( | ||
(schema.properties[key]?.value || data[key]) ?? | ||
schema.properties[key]?.defaultValue | ||
); | ||
}, | ||
[schema, data], | ||
); | ||
|
||
const items = tabsList.map((tab, index) => { | ||
const title = tabs[tab].title; | ||
const defaultTitle = `Tab ${index + 1}`; | ||
const active = activeTabIndex === index; | ||
return { | ||
title: ( | ||
<> | ||
{semanticIcon ? ( | ||
<Icon name={active ? semanticIcon.opened : semanticIcon.closed} /> | ||
) : ( | ||
<VoltoIcon | ||
name={active ? icons.opened : icons.closed} | ||
size={icons.size} | ||
/> | ||
)} | ||
{title || defaultTitle}{' '} | ||
</> | ||
), | ||
getContent: () => <Tab {...props} tab={tab} content={tabs[tab]} />, | ||
key: tab, | ||
tabClassName: cx('ui button item title', { active }), | ||
panelClassName: cx('ui bottom attached segment tab', { | ||
active, | ||
}), | ||
}; | ||
}); | ||
|
||
return ( | ||
<> | ||
<Tabs | ||
className="tabs aa" | ||
selectedTabKey={tabsList[activeTabIndex]} | ||
items={items} | ||
onChange={(tab) => { | ||
if (tab !== tabsList[activeTabIndex]) { | ||
setActiveTab(tab); | ||
} else { | ||
setActiveTab(null); | ||
} | ||
}} | ||
tabsWrapperClass={cx( | ||
'ui pointing secondary menu', | ||
getDataValue('menuColor'), | ||
{ | ||
inverted: getDataValue('menuInverted'), | ||
}, | ||
)} | ||
showMore={false} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default compose(withScrollToTarget, withRouter)(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,5 @@ | ||
import AccordionEdit from './Edit'; | ||
import AccordionView from './View'; | ||
import accordionSchema from './schema'; | ||
|
||
export { AccordionEdit, AccordionView, accordionSchema }; |
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,44 @@ | ||
export default () => ({ | ||
title: 'Accordion tabs block', | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['description'], | ||
}, | ||
{ | ||
id: 'menu', | ||
title: 'Menu', | ||
fields: ['menuColor', 'menuInverted'], | ||
}, | ||
], | ||
properties: { | ||
description: { | ||
title: 'Description', | ||
}, | ||
menuColor: { | ||
title: 'Color', | ||
defaultValue: 'green', | ||
choices: [ | ||
['red', 'Red'], | ||
['orange', 'Orange'], | ||
['yellow', 'Yellow'], | ||
['olive', 'Olive'], | ||
['green', 'Green'], | ||
['teal', 'Teal'], | ||
['blue', 'Blue'], | ||
['violet', 'Violet'], | ||
['purple', 'Purple'], | ||
['pink', 'Pink'], | ||
['brown', 'Brown'], | ||
['grey', 'Grey'], | ||
['black', 'Black'], | ||
], | ||
}, | ||
menuInverted: { | ||
title: 'Inverted', | ||
type: 'boolean', | ||
}, | ||
}, | ||
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
Oops, something went wrong.