feat(joyent-cp-frontend): integrate toolkit's Breadcrumb
This commit is contained in:
parent
e6b6f6a761
commit
eb37c7de49
@ -1,66 +1,45 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import { Grid } from 'react-styled-flexboxgrid';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Grid, Col, Row } from 'react-styled-flexboxgrid';
|
import forceArray from 'force-array';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import remcalc from 'remcalc';
|
import remcalc from 'remcalc';
|
||||||
import unitcalc from 'unitcalc';
|
|
||||||
|
|
||||||
import { H2 } from 'joyent-ui-toolkit';
|
import { Breadcrumb, BreadcrumbItem } from 'joyent-ui-toolkit';
|
||||||
|
|
||||||
const StyledDiv = styled.div`
|
|
||||||
border-bottom: solid ${remcalc(1)} ${props => props.theme.grey};
|
|
||||||
padding: ${unitcalc(4.5)} 0 ${unitcalc(4.5)} 0;
|
|
||||||
margin-bottom: ${remcalc(18)};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledH2 = H2.extend`
|
|
||||||
color: ${props => props.theme.primary};
|
|
||||||
margin: 0;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const BreadcrumbLink = styled(Link)`
|
const BreadcrumbLink = styled(Link)`
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: ${props => props.theme.primary};
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:visited {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const BreadcrumbSpan = styled.span`
|
const BreadcrumbContainer = styled.div`
|
||||||
color: ${props => props.theme.text};
|
border-bottom: solid ${remcalc(1)} ${props => props.theme.grey};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function getBreadcrumbLinks(links) {
|
const getBreadcrumbItems = (...links) =>
|
||||||
if (links.length) {
|
forceArray(links).map(({ pathname, name }, i) => {
|
||||||
return links.reduce((breadcrumb, link, index) => {
|
const item = i + 1 >= links.length
|
||||||
if (breadcrumb.length) {
|
? name
|
||||||
breadcrumb.push(
|
: <BreadcrumbLink to={pathname}>{name}</BreadcrumbLink>;
|
||||||
<BreadcrumbSpan key={breadcrumb.length}> / </BreadcrumbSpan>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
breadcrumb.push(
|
|
||||||
<BreadcrumbLink key={breadcrumb.length} to={link.pathname}>
|
|
||||||
{link.name}
|
|
||||||
</BreadcrumbLink>
|
|
||||||
);
|
|
||||||
return breadcrumb;
|
|
||||||
}, []);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Breadcrumb = ({ links = [] }) =>
|
return <BreadcrumbItem key={name}>{item}</BreadcrumbItem>;
|
||||||
|
});
|
||||||
|
|
||||||
|
const NavBreadcrumb = ({ links = [] }) =>
|
||||||
|
<BreadcrumbContainer>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Row>
|
<Breadcrumb>
|
||||||
<Col xs={12}>
|
{getBreadcrumbItems(...links)}
|
||||||
<StyledDiv>
|
</Breadcrumb>
|
||||||
<StyledH2>
|
</Grid>
|
||||||
{getBreadcrumbLinks(links)}
|
</BreadcrumbContainer>;
|
||||||
</StyledH2>
|
|
||||||
</StyledDiv>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</Grid>;
|
|
||||||
|
|
||||||
Breadcrumb.propTypes = {
|
NavBreadcrumb.propTypes = {
|
||||||
links: PropTypes.arrayOf(
|
links: PropTypes.arrayOf(
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
@ -69,4 +48,4 @@ Breadcrumb.propTypes = {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Breadcrumb;
|
export default NavBreadcrumb;
|
||||||
|
@ -14,10 +14,6 @@ import { LayoutContainer } from '@components/layout';
|
|||||||
import { Name, Manifest, Review } from '@components/deployment-groups/create';
|
import { Name, Manifest, Review } from '@components/deployment-groups/create';
|
||||||
import { H2 } from 'joyent-ui-toolkit';
|
import { H2 } from 'joyent-ui-toolkit';
|
||||||
|
|
||||||
const Title = H2.extend`
|
|
||||||
margin-top: 0;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const validateName = async ({ name = '' }) => {
|
const validateName = async ({ name = '' }) => {
|
||||||
const { data } = await client.query({
|
const { data } = await client.query({
|
||||||
fetchPolicy: 'network-only',
|
fetchPolicy: 'network-only',
|
||||||
@ -210,7 +206,7 @@ class DeploymentGroupCreate extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<LayoutContainer>
|
<LayoutContainer>
|
||||||
<Title>Creating deployment group</Title>
|
<H2>Creating deployment group</H2>
|
||||||
{view}
|
{view}
|
||||||
</LayoutContainer>
|
</LayoutContainer>
|
||||||
);
|
);
|
||||||
|
@ -4,10 +4,9 @@ import { Row } from 'react-styled-flexboxgrid';
|
|||||||
/**
|
/**
|
||||||
* @example ./usage.md
|
* @example ./usage.md
|
||||||
*/
|
*/
|
||||||
export default ({ children, ...rest }) => (
|
export default ({ children, ...rest }) =>
|
||||||
<Row name="breadcrum" {...rest}>
|
<Row name="breadcrum" {...rest}>
|
||||||
{children}
|
{children}
|
||||||
</Row>
|
</Row>;
|
||||||
);
|
|
||||||
|
|
||||||
export { default as Item } from './item';
|
export { default as Item } from './item';
|
||||||
|
@ -21,11 +21,10 @@ const Arrow = styled.div`
|
|||||||
margin: ${remcalc(3)} ${remcalc(10)} ${remcalc(3)} ${remcalc(10)};
|
margin: ${remcalc(3)} ${remcalc(10)} ${remcalc(3)} ${remcalc(10)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default ({ children, ...rest }) => (
|
export default ({ children, ...rest }) =>
|
||||||
<div>
|
<div>
|
||||||
<Name name="breadcrum-item" {...rest}>
|
<Name name="breadcrum-item" {...rest}>
|
||||||
{children}
|
{children}
|
||||||
</Name>
|
</Name>
|
||||||
<Arrow />
|
<Arrow />
|
||||||
</div>
|
</div>;
|
||||||
);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user