Browse Source

Improved Breadcrumb component

master
Loëck Vézien 7 years ago
parent
commit
5dffc1fded
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 58
      src/components/Breadcrumb/index.js

58
src/components/Breadcrumb/index.js

@ -1,6 +1,6 @@
// @flow // @flow
import React from 'react' import React, { Fragment } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import Box from 'components/base/Box' import Box from 'components/base/Box'
@ -8,7 +8,6 @@ import Box from 'components/base/Box'
const BreadcrumbWrapper = styled(Box).attrs({ const BreadcrumbWrapper = styled(Box).attrs({
horizontal: true, horizontal: true,
align: 'center', align: 'center',
flow: 20,
relative: true, relative: true,
})`` })``
const BreadcrumbStep = styled(({ start, active, end, ...props }) => ( const BreadcrumbStep = styled(({ start, active, end, ...props }) => (
@ -17,29 +16,34 @@ const BreadcrumbStep = styled(({ start, active, end, ...props }) => (
color: p => (p.active ? 'blue' : 'mouse'), color: p => (p.active ? 'blue' : 'mouse'),
align: 'center', align: 'center',
flow: 5, flow: 5,
grow: p => !p.start && !p.end, relative: true,
ml: p => p.end && 20, })`
mr: p => p.start && 20, transition: color ease-in-out 0.1s ${p => (p.active ? 0.4 : 0)}s;
`
const BreadcrumbSeparator = styled(Box).attrs({
grow: true,
relative: true, relative: true,
})` })`
&:before, &:before,
&:after { &:after {
background: ${p => p.theme.colors.pearl};
content: ' '; content: ' ';
display: ${p => (p.start ? 'none' : 'block')}; display: block;
height: 2px; height: 2px;
left: -20px;
position: absolute; position: absolute;
left: -120px; right: -20px;
background: ${p => p.theme.colors.pearl}; top: -13px;
margin-top: 8px;
width: 200px;
} }
&:after { &:after {
background: ${p => p.theme.colors.blue}; background: ${p => p.theme.colors.blue};
width: ${p => (p.active ? 200 : 0)}px; right: ${p => (p.active ? '-20px' : 'calc(100% + 20px)')};
transition: width ease-in-out 0.4s; transition: right ease-in-out 0.4s;
} }
` `
const BreadcrumbNumberWrapper = styled(Box).attrs({ const BreadcrumbNumberWrapper = styled(Box).attrs({
bg: 'white', bg: 'white',
px: 3, px: 3,
@ -58,27 +62,31 @@ const BreadcrumbNumber = styled(Box).attrs({
font-size: 9px; font-size: 9px;
height: 20px; height: 20px;
width: 20px; width: 20px;
transition: all ease-in-out 0.1s; transition: all ease-in-out 0.1s ${p => (p.active ? 0.4 : 0)}s;
` `
const Breadcrumb = ({ items, currentStep }: Object) => ( type Props = {
items: Array<Object>,
currentStep: number | string,
}
const Breadcrumb = ({ items, currentStep }: Props) => (
<BreadcrumbWrapper> <BreadcrumbWrapper>
{items.map((item, i) => { {items.map((item, i) => {
const active = i < currentStep const active = i < parseInt(currentStep, 10)
const start = i === 0 const start = i === 0
const end = i + 1 === items.length
return ( return (
<BreadcrumbStep <Fragment
key={i} // eslint-disable-line react/no-array-index-key key={i} // eslint-disable-line react/no-array-index-key
start={start}
end={end}
active={active}
> >
<BreadcrumbNumberWrapper> {!start && <BreadcrumbSeparator active={active} />}
<BreadcrumbNumber active={active}>{i + 1}</BreadcrumbNumber> <BreadcrumbStep active={active}>
</BreadcrumbNumberWrapper> <BreadcrumbNumberWrapper>
<Box fontSize={0}>{item.label}</Box> <BreadcrumbNumber active={active}>{i + 1}</BreadcrumbNumber>
</BreadcrumbStep> </BreadcrumbNumberWrapper>
<Box fontSize={0}>{item.label}</Box>
</BreadcrumbStep>
</Fragment>
) )
})} })}
</BreadcrumbWrapper> </BreadcrumbWrapper>

Loading…
Cancel
Save