diff --git a/src/components/Breadcrumb/Step.js b/src/components/Breadcrumb/Step.js new file mode 100644 index 00000000..ca3aae2a --- /dev/null +++ b/src/components/Breadcrumb/Step.js @@ -0,0 +1,81 @@ +// @flow + +import React, { Fragment } from 'react' +import styled from 'styled-components' + +import Box from 'components/base/Box' + +const Wrapper = styled(Box).attrs({ + align: 'center', + justify: 'center', + color: p => (p.isActive ? 'blue' : 'mouse'), +})` + width: 40px; + flex-shrink: 0; + text-align: center; + font-size: 9px; +` + +const Number = styled(Box).attrs({ + align: 'center', + justify: 'center', + color: p => (p.isActive ? 'white' : 'mouse'), + bg: p => (p.isActive ? 'blue' : 'pearl'), +})` + width: 20px; + height: 20px; + border-radius: 50%; + font-size: 9px; + box-shadow: ${p => `0 0 0 ${p.isActive ? 4 : 0}px ${p.theme.colors.cream}`}; + transition: all ease-in-out 0.1s ${p => (p.isActive ? 0.4 : 0)}s; +` + +const Bar = styled.div` + height: 2px; + background: ${p => p.theme.colors.pearl}; + flex-grow: 1; + position: relative; + + &:after { + background: ${p => p.theme.colors.pearl}; + content: ''; + display: block; + left: 0; + right: 0; + top: 0; + bottom: 0; + position: absolute; + background: ${p => p.theme.colors.blue}; + transition: transform ease-in-out 0.4s; + transform-origin: center left; + transform: scaleX(${p => (p.isActive ? 1 : 0)}); + } +` + +const Label = styled(Box)` + position: absolute; + margin-top: 30px; + transition: color ease-in-out 0.1s ${p => (p.isActive ? 0.4 : 0)}s; +` + +type Props = { + number: number, + isActive: boolean, + isFirst: boolean, + children: any, +} + +function Step(props: Props) { + const { number, isActive, isFirst, children } = props + return ( + + {!isFirst && } + + {number} + + + + ) +} + +export default Step diff --git a/src/components/Breadcrumb/index.js b/src/components/Breadcrumb/index.js index 50c96403..436d05e3 100644 --- a/src/components/Breadcrumb/index.js +++ b/src/components/Breadcrumb/index.js @@ -1,99 +1,36 @@ // @flow -import React, { PureComponent, Fragment } from 'react' +/* eslint-disable react/no-array-index-key */ + +import React, { PureComponent } from 'react' import styled from 'styled-components' import Box from 'components/base/Box' - -const BreadcrumbWrapper = styled(Box).attrs({ - horizontal: true, - alignItems: 'center', - relative: true, -})`` - -const BreadcrumbStep = styled(({ start, active, end, ...props }) => ( - -)).attrs({ - color: p => (p.active ? 'blue' : 'mouse'), - alignItems: 'center', - flow: 5, - relative: true, -})` - transition: color ease-in-out 0.1s ${p => (p.active ? 0.4 : 0)}s; -` - -const BreadcrumbSeparator = styled(Box).attrs({ - grow: true, - relative: true, -})` - &:before, - &:after { - background: ${p => p.theme.colors.pearl}; - content: ' '; - display: block; - height: 2px; - left: -20px; - position: absolute; - right: -20px; - top: -13px; - } - - &:after { - background: ${p => p.theme.colors.blue}; - right: ${p => (p.active ? '-20px' : 'calc(100% + 20px)')}; - transition: right ease-in-out 0.4s; - } -` - -const BreadcrumbNumberWrapper = styled(Box).attrs({ - bg: 'white', - px: 3, - relative: true, -})` - z-index: 1; -` -const BreadcrumbNumber = styled(Box).attrs({ - color: p => (p.active ? 'white' : 'mouse'), - bg: p => (p.active ? 'blue' : 'pearl'), - alignItems: 'center', - justifyContent: 'center', -})` - border-radius: 50%; - box-shadow: ${p => `0 0 0 ${p.active ? 4 : 0}px ${p.theme.colors.cream}`}; - font-size: 9px; - height: 20px; - width: 20px; - transition: all ease-in-out 0.1s ${p => (p.active ? 0.4 : 0)}s; -` +import Step from './Step' type Props = { items: Array, currentStep: number | string, } +const Wrapper = styled(Box).attrs({ + horizontal: true, + align: 'center', +})` + margin-bottom: 25px; +` + class Breadcrumb extends PureComponent { render() { const { items, currentStep } = this.props return ( - - {items.map((item, i) => { - const active = i < parseInt(currentStep, 10) - const start = i === 0 - return ( - - {!start && } - - - {i + 1} - - {item.label} - - - ) - })} - + + {items.map((item, i) => ( + + {item.label} + + ))} + ) } }