joyent-portal/frontend/src/components/section/index.js

73 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-01-03 01:17:12 +02:00
const flatten = require('lodash.flatten');
2016-12-20 21:06:02 +02:00
const React = require('react');
const ReactIntl = require('react-intl');
const ReactRouter = require('react-router');
const H1 = require('@ui/components/h1');
const Li = require('@ui/components/horizontal-list/li');
2017-01-03 01:17:12 +02:00
const PropTypes = require('@root/prop-types');
2016-12-20 21:06:02 +02:00
const Ul = require('@ui/components/horizontal-list/ul');
const {
FormattedMessage
} = ReactIntl;
const {
Link
} = ReactRouter;
const Section = ({
children,
links = [],
2017-01-03 01:17:12 +02:00
name = []
2016-12-20 21:06:02 +02:00
}) => {
const navLinks = links.map((link) => (
<Li key={link.name}>
<Link activeClassName='active' to={link.pathname}>
<FormattedMessage id={link.name} />
</Link>
</Li>
));
2017-01-03 01:17:12 +02:00
const nameLinks = flatten(name.map((part, i) => {
2017-01-03 01:32:15 +02:00
if (!part.name) {
return null;
}
2017-01-03 01:17:12 +02:00
const link = (
<Link key={part.pathname} to={part.pathname}>
{part.name}
</Link>
);
const slash = (
<span key={`${part.pathname}${i}`}> / </span>
);
return (i === 0) ? link : [
slash,
link
];
}));
2016-12-20 21:06:02 +02:00
return (
<div>
2017-01-03 01:17:12 +02:00
<H1>
{nameLinks}
</H1>
2016-12-20 21:06:02 +02:00
<Ul>
{navLinks}
</Ul>
{children}
</div>
);
};
Section.propTypes = {
children: React.PropTypes.node,
2017-01-03 01:17:12 +02:00
links: React.PropTypes.arrayOf(PropTypes.link),
name: React.PropTypes.arrayOf(PropTypes.link)
2016-12-20 21:06:02 +02:00
};
module.exports = Section;