2019-07-22 14:48:06 +00:00
|
|
|
import React from 'react'
|
|
|
|
import styled from 'styled-components'
|
|
|
|
import { Icons } from '../icons'
|
2019-12-04 09:36:13 +00:00
|
|
|
import Heading from '../heading'
|
2019-07-22 15:39:53 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2019-07-22 14:48:06 +00:00
|
|
|
|
2020-01-13 16:01:09 +00:00
|
|
|
const StyledContainer = styled.div`
|
|
|
|
|
2020-02-03 13:08:18 +00:00
|
|
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
|
|
|
2020-01-13 16:01:09 +00:00
|
|
|
.span-toggle-content {
|
|
|
|
cursor: pointer;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.heading-toggle-content {
|
|
|
|
height: 24px;
|
|
|
|
line-height: 26px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
font-style: normal;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
border-bottom: 1px dashed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2019-07-22 14:48:06 +00:00
|
|
|
|
2019-07-23 07:58:49 +00:00
|
|
|
const StyledContent = styled.div`
|
2019-07-22 14:48:06 +00:00
|
|
|
color: #333;
|
|
|
|
display: ${props => props.isOpen ? 'block' : 'none'};
|
2020-01-13 16:01:09 +00:00
|
|
|
padding-top: 6px;
|
2019-07-22 14:48:06 +00:00
|
|
|
`;
|
|
|
|
|
2019-12-03 13:50:14 +00:00
|
|
|
// eslint-disable-next-line react/prop-types, no-unused-vars
|
|
|
|
const IconArrow = ({ isOpen, ...props }) => <Icons.ArrowContentIcon {...props} />;
|
2019-07-25 07:18:03 +00:00
|
|
|
|
|
|
|
const Arrow = styled(IconArrow)`
|
2019-07-22 14:48:06 +00:00
|
|
|
|
|
|
|
margin-right: 9px;
|
|
|
|
margin-bottom: 5px;
|
|
|
|
transform: ${props => props.isOpen && 'rotate(180deg)'};
|
|
|
|
`;
|
|
|
|
|
|
|
|
class ToggleContent extends React.Component {
|
|
|
|
|
2019-07-22 15:39:53 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-07-22 14:48:06 +00:00
|
|
|
|
2020-01-13 16:01:09 +00:00
|
|
|
const { isOpen } = props;
|
|
|
|
|
2019-07-22 14:48:06 +00:00
|
|
|
this.state = {
|
2020-01-13 16:01:09 +00:00
|
|
|
isOpen
|
2019-07-22 14:48:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-01-13 16:01:09 +00:00
|
|
|
toggleContent = () => this.setState({ isOpen: !this.state.isOpen });
|
2019-07-22 14:48:06 +00:00
|
|
|
|
2019-07-22 15:39:53 +00:00
|
|
|
componentDidUpdate(prevProps) {
|
2020-01-13 16:01:09 +00:00
|
|
|
const { isOpen } = this.props;
|
|
|
|
if (isOpen !== prevProps.isOpen) {
|
|
|
|
this.setState({ isOpen });
|
2019-07-22 15:39:53 +00:00
|
|
|
}
|
2019-09-10 07:03:36 +00:00
|
|
|
}
|
2019-07-22 15:39:53 +00:00
|
|
|
|
2019-07-22 14:48:06 +00:00
|
|
|
render() {
|
2020-01-13 16:01:09 +00:00
|
|
|
// console.log("ToggleContent render");
|
|
|
|
|
|
|
|
const {
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
id,
|
|
|
|
label,
|
|
|
|
style
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const { isOpen } = this.state;
|
|
|
|
|
2019-07-22 14:48:06 +00:00
|
|
|
return (
|
2020-01-13 16:01:09 +00:00
|
|
|
<StyledContainer
|
|
|
|
className={className}
|
|
|
|
id={id}
|
|
|
|
style={style}
|
2019-12-03 13:50:14 +00:00
|
|
|
>
|
2020-01-13 16:01:09 +00:00
|
|
|
<span className='span-toggle-content' onClick={this.toggleContent}>
|
|
|
|
<Arrow color="#333" isfill={true} size='medium' isOpen={isOpen} />
|
|
|
|
<Heading className='heading-toggle-content' level={2} size='small' isInline={true}>{label}</Heading>
|
|
|
|
</span>
|
|
|
|
<StyledContent isOpen={isOpen}>{children}</StyledContent>
|
|
|
|
</StyledContainer>
|
2019-07-22 14:48:06 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-22 15:39:53 +00:00
|
|
|
ToggleContent.propTypes = {
|
2019-12-03 13:50:14 +00:00
|
|
|
children: PropTypes.any,
|
2020-01-13 16:01:09 +00:00
|
|
|
className: PropTypes.string,
|
2019-12-03 13:50:14 +00:00
|
|
|
id: PropTypes.string,
|
2020-01-13 16:01:09 +00:00
|
|
|
isOpen: PropTypes.bool,
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
onChange: PropTypes.func,
|
2019-12-03 13:50:14 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
|
2019-07-22 15:39:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 14:48:06 +00:00
|
|
|
ToggleContent.defaultProps = {
|
2019-07-22 15:39:53 +00:00
|
|
|
isOpen: false,
|
2020-01-13 16:01:09 +00:00
|
|
|
label: ""
|
2019-07-22 14:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ToggleContent;
|