mirror of
https://github.com/yldio/copilot.git
synced 2024-12-01 07:30:07 +02:00
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;
|
||||||
`;
|
|
||||||
|
|
||||||
const BreadcrumbSpan = styled.span`
|
&:visited {
|
||||||
color: ${props => props.theme.text};
|
color: inherit;
|
||||||
`;
|
|
||||||
|
|
||||||
function getBreadcrumbLinks(links) {
|
|
||||||
if (links.length) {
|
|
||||||
return links.reduce((breadcrumb, link, index) => {
|
|
||||||
if (breadcrumb.length) {
|
|
||||||
breadcrumb.push(
|
|
||||||
<BreadcrumbSpan key={breadcrumb.length}> / </BreadcrumbSpan>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
breadcrumb.push(
|
|
||||||
<BreadcrumbLink key={breadcrumb.length} to={link.pathname}>
|
|
||||||
{link.name}
|
|
||||||
</BreadcrumbLink>
|
|
||||||
);
|
|
||||||
return breadcrumb;
|
|
||||||
}, []);
|
|
||||||
}
|
}
|
||||||
return null;
|
`;
|
||||||
}
|
|
||||||
|
|
||||||
const Breadcrumb = ({ links = [] }) =>
|
const BreadcrumbContainer = styled.div`
|
||||||
<Grid>
|
border-bottom: solid ${remcalc(1)} ${props => props.theme.grey};
|
||||||
<Row>
|
`;
|
||||||
<Col xs={12}>
|
|
||||||
<StyledDiv>
|
|
||||||
<StyledH2>
|
|
||||||
{getBreadcrumbLinks(links)}
|
|
||||||
</StyledH2>
|
|
||||||
</StyledDiv>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</Grid>;
|
|
||||||
|
|
||||||
Breadcrumb.propTypes = {
|
const getBreadcrumbItems = (...links) =>
|
||||||
|
forceArray(links).map(({ pathname, name }, i) => {
|
||||||
|
const item = i + 1 >= links.length
|
||||||
|
? name
|
||||||
|
: <BreadcrumbLink to={pathname}>{name}</BreadcrumbLink>;
|
||||||
|
|
||||||
|
return <BreadcrumbItem key={name}>{item}</BreadcrumbItem>;
|
||||||
|
});
|
||||||
|
|
||||||
|
const NavBreadcrumb = ({ links = [] }) =>
|
||||||
|
<BreadcrumbContainer>
|
||||||
|
<Grid>
|
||||||
|
<Breadcrumb>
|
||||||
|
{getBreadcrumbItems(...links)}
|
||||||
|
</Breadcrumb>
|
||||||
|
</Grid>
|
||||||
|
</BreadcrumbContainer>;
|
||||||
|
|
||||||
|
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