react-toolbox/components/navigation/Navigation.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-05-29 22:56:10 +03:00
import React, { PropTypes } from 'react';
2016-05-22 22:39:40 +03:00
import classnames from 'classnames';
import { themr } from 'react-css-themr';
2017-01-26 20:05:32 +03:00
import { NAVIGATION } from '../identifiers';
import InjectButton from '../button/Button';
import InjectLink from '../link/Link';
2016-05-29 22:56:10 +03:00
const factory = (Button, Link) => {
const Navigation = ({ actions, children, className, routes, theme, type }) => {
const _className = classnames(theme[type], className);
2017-01-26 20:05:32 +03:00
const buttons = actions.map((action, index) => (
<Button className={theme.button} key={index} {...action} /> // eslint-disable-line
));
2017-01-26 20:05:32 +03:00
const links = routes.map((route, index) => (
<Link className={theme.link} key={index} {...route} /> // eslint-disable-line
));
2016-05-29 22:56:10 +03:00
return (
2017-01-26 20:05:32 +03:00
<nav data-react-toolbox="navigation" className={_className}>
2016-05-29 22:56:10 +03:00
{links}
{buttons}
{children}
</nav>
);
};
2016-05-29 22:56:10 +03:00
Navigation.propTypes = {
2017-01-26 20:05:32 +03:00
actions: PropTypes.array, // eslint-disable-line
2016-05-29 22:56:10 +03:00
children: PropTypes.node,
className: PropTypes.string,
2017-01-26 20:05:32 +03:00
routes: PropTypes.array, // eslint-disable-line
2016-05-29 22:56:10 +03:00
theme: PropTypes.shape({
button: PropTypes.string,
horizontal: PropTypes.string,
link: PropTypes.string,
2017-01-26 20:05:32 +03:00
vertical: PropTypes.string,
2016-05-29 22:56:10 +03:00
}),
2017-01-26 20:05:32 +03:00
type: PropTypes.oneOf(['vertical', 'horizontal']),
2016-05-29 22:56:10 +03:00
};
Navigation.defaultProps = {
actions: [],
className: '',
type: 'horizontal',
2017-01-26 20:05:32 +03:00
routes: [],
2016-05-29 22:56:10 +03:00
};
2016-05-29 22:56:10 +03:00
return Navigation;
};
2016-05-29 22:56:10 +03:00
const Navigation = factory(InjectButton, InjectLink);
export default themr(NAVIGATION)(Navigation);
export { factory as navigationFactory };
export { Navigation };