2019-10-20 16:59:02 +02:00
|
|
|
import React, { ReactNode } from "react";
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
import styled from "styled-components";
|
2019-07-09 13:29:25 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string;
|
2019-10-20 16:59:02 +02:00
|
|
|
elements: ReactNode[];
|
2019-07-09 13:29:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
2019-10-19 16:38:07 +02:00
|
|
|
collapsed: boolean;
|
2019-07-09 13:29:25 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-08 16:42:08 +02:00
|
|
|
const Container = styled.div`
|
|
|
|
|
margin-bottom: 1em;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Wrapper = styled.div`
|
|
|
|
|
padding: 0 0.75rem;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export default class CardColumnGroup extends React.Component<Props, State> {
|
2019-07-09 13:29:25 +02:00
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
2019-10-20 16:59:02 +02:00
|
|
|
collapsed: false
|
2019-07-09 13:29:25 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleCollapse = () => {
|
|
|
|
|
this.setState(prevState => ({
|
2019-10-20 16:59:02 +02:00
|
|
|
collapsed: !prevState.collapsed
|
2019-07-09 13:29:25 +02:00
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
isLastEntry = (array: ReactNode[], index: number) => {
|
2019-07-09 13:29:25 +02:00
|
|
|
return index === array.length - 1;
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
isLengthOdd = (array: ReactNode[]) => {
|
2019-07-09 13:29:25 +02:00
|
|
|
return array.length % 2 !== 0;
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
isFullSize = (array: ReactNode[], index: number) => {
|
2019-07-09 13:29:25 +02:00
|
|
|
return this.isLastEntry(array, index) && this.isLengthOdd(array);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-10-08 16:42:08 +02:00
|
|
|
const { name, elements } = this.props;
|
2019-07-09 13:29:25 +02:00
|
|
|
const { collapsed } = this.state;
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
const icon = collapsed ? "fa-angle-right" : "fa-angle-down";
|
2019-07-09 13:29:25 +02:00
|
|
|
let content = null;
|
|
|
|
|
if (!collapsed) {
|
|
|
|
|
content = elements.map((entry, index) => {
|
|
|
|
|
const fullColumnWidth = this.isFullSize(elements, index);
|
2019-10-20 16:59:02 +02:00
|
|
|
const sizeClass = fullColumnWidth ? "is-full" : "is-half";
|
2019-07-09 13:29:25 +02:00
|
|
|
return (
|
2019-10-21 10:57:56 +02:00
|
|
|
<div className={classNames("box", "box-link-shadow", "column", "is-clipped", sizeClass)} key={index}>
|
2019-07-09 13:29:25 +02:00
|
|
|
{entry}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return (
|
2019-10-10 14:31:11 +02:00
|
|
|
<Container>
|
2019-07-09 13:29:25 +02:00
|
|
|
<h2>
|
2019-10-21 10:57:56 +02:00
|
|
|
<span className={classNames("is-size-4", "has-cursor-pointer")} onClick={this.toggleCollapse}>
|
2019-10-20 16:59:02 +02:00
|
|
|
<i className={classNames("fa", icon)} /> {name}
|
2019-07-09 13:29:25 +02:00
|
|
|
</span>
|
|
|
|
|
</h2>
|
|
|
|
|
<hr />
|
2019-10-21 10:57:56 +02:00
|
|
|
<Wrapper className={classNames("columns", "is-multiline")}>{content}</Wrapper>
|
2019-10-10 14:31:11 +02:00
|
|
|
<div className="is-clearfix" />
|
2019-10-08 16:42:08 +02:00
|
|
|
</Container>
|
2019-07-09 13:29:25 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|