1 | import * as React from 'react';
|
2 | import styled from 'styled-components';
|
3 |
|
4 | import { Sizes, Colors } from '../index';
|
5 | import { getChildrenOfClass } from '../utils/elementsHelper';
|
6 | import { styledByMediaQuery } from '../utils/styles';
|
7 |
|
8 | interface IProps {
|
9 | data?: Object[];
|
10 | defaultHeader?: boolean;
|
11 | header?: Object;
|
12 | children: any;
|
13 | isActive?: boolean;
|
14 | }
|
15 |
|
16 | const DataTableWrapper = styled.div`
|
17 | max-height: 367px;
|
18 | overflow-y: scroll;
|
19 | margin-bottom: 25px;
|
20 | `;
|
21 |
|
22 | const DataHeader = styled.div`
|
23 | font-size: ${Sizes.s2}px;
|
24 | padding-bottom: ${Sizes.s1}px;
|
25 | padding-left: ${Sizes.s1}px;
|
26 | border-bottom: 1px solid ${Colors.line};
|
27 | min-width: 25%;
|
28 | display: flex;
|
29 | ${styledByMediaQuery(`padding-left: ${Sizes.s4}px;`)}
|
30 | `;
|
31 |
|
32 | const TableLine = styled.div<{isActive?: boolean; onClick?: any}>`
|
33 | padding: ${Sizes.s3 + 1}px ${Sizes.s1}px;
|
34 |
|
35 | border-bottom: 1px solid ${Colors.line};
|
36 | display: flex;
|
37 | align-items: center;
|
38 | justify-content: flex-start;
|
39 | transition: all 0.3s;
|
40 | position: relative;
|
41 |
|
42 | ${styledByMediaQuery(`padding: ${Sizes.s3 + 1}px ${Sizes.s4}px;`)}
|
43 |
|
44 | &:hover {
|
45 | background-color: ${Colors.heaven};
|
46 | }
|
47 | `;
|
48 |
|
49 | export default class DataTable extends React.PureComponent<IProps> {
|
50 | static Header = DataHeader;
|
51 | static Line = TableLine;
|
52 |
|
53 | render () {
|
54 | const { children } = this.props;
|
55 |
|
56 | const isHeader = getChildrenOfClass(DataHeader, children);
|
57 | const isContent = getChildrenOfClass(TableLine, children);
|
58 |
|
59 | return (
|
60 | <React.Fragment>
|
61 | {isHeader}
|
62 | <DataTableWrapper>
|
63 | {isContent}
|
64 | </DataTableWrapper>
|
65 | </React.Fragment>
|
66 | );
|
67 | }
|
68 | }
|
69 |
|
\ | No newline at end of file |