Loëck Vézien
7 years ago
committed by
GitHub
12 changed files with 165 additions and 18 deletions
@ -0,0 +1,60 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React, { PureComponent, Fragment } from 'react' |
||||
|
import styled from 'styled-components' |
||||
|
|
||||
|
import Box from 'components/base/Box' |
||||
|
import Text from 'components/base/Text' |
||||
|
import IconChevronRight from 'icons/ChevronRight' |
||||
|
|
||||
|
type Props = { |
||||
|
children: any, |
||||
|
title: string, |
||||
|
} |
||||
|
|
||||
|
type State = { |
||||
|
isOpened: boolean, |
||||
|
} |
||||
|
|
||||
|
const Title = styled(Text).attrs({ |
||||
|
ff: 'Museo Sans|Bold', |
||||
|
fontSize: 2, |
||||
|
color: 'dark', |
||||
|
tabIndex: 0, |
||||
|
})` |
||||
|
text-transform: uppercase; |
||||
|
letter-spacing: 1px; |
||||
|
cursor: pointer; |
||||
|
outline: none; |
||||
|
` |
||||
|
|
||||
|
const IconContainer = styled(Box)` |
||||
|
transform: rotate(${p => (p.isOpened ? '90' : '0')}deg); |
||||
|
transition: 150ms linear transform; |
||||
|
` |
||||
|
|
||||
|
class Spoiler extends PureComponent<Props, State> { |
||||
|
state = { |
||||
|
isOpened: false, |
||||
|
} |
||||
|
|
||||
|
toggle = () => this.setState({ isOpened: !this.state.isOpened }) |
||||
|
|
||||
|
render() { |
||||
|
const { title, children } = this.props |
||||
|
const { isOpened } = this.state |
||||
|
return ( |
||||
|
<Fragment> |
||||
|
<Box horizontal flow={1} color="dark" align="center"> |
||||
|
<IconContainer isOpened={isOpened}> |
||||
|
<IconChevronRight width={12} height={12} /> |
||||
|
</IconContainer> |
||||
|
<Title onClick={this.toggle}>{title}</Title> |
||||
|
</Box> |
||||
|
{isOpened && children} |
||||
|
</Fragment> |
||||
|
) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default Spoiler |
@ -0,0 +1,10 @@ |
|||||
|
import React from 'react' |
||||
|
|
||||
|
export default props => ( |
||||
|
<svg viewBox="0 0 16 16" {...props}> |
||||
|
<path |
||||
|
fill="currentColor" |
||||
|
d="M10.869 8.266L6.28 12.89a.375.375 0 0 1-.531 0l-.619-.62a.375.375 0 0 1 0-.53L8.834 8 5.131 4.26a.375.375 0 0 1 0-.532l.619-.619a.375.375 0 0 1 .531 0l4.588 4.625a.375.375 0 0 1 0 .532z" |
||||
|
/> |
||||
|
</svg> |
||||
|
) |
Loading…
Reference in new issue