UNPKG

1.37 kBJavaScriptView Raw
1import React from 'react';
2import OverflowExpander from './OverflowExpander';
3import PropTypes from 'prop-types';
4
5const HORZ_PADDING = 6;
6
7export const TextCell = (props) => {
8 let content;
9
10 if (props.cellData.type === 'TEXT') {
11 if (!props.cellData.main) {
12 content = '';
13 } else {
14 content = props.cellData.main.text;
15 const href = props.disabled ? 'javascript:void(0);' : props.cellData.main.href;
16 if (href) {
17 content = <a href={href} target="_blank">{content}</a>;
18 }
19 }
20 } else {
21 // type === 'AUTO', probably
22 if (props.cellData.text) {
23 content = props.cellData.text;
24 } else if (props.cellData.main) {
25 if (typeof props.cellData.main.text === 'string') {
26 content = props.cellData.main.text;
27 } else {
28 content = props.cellData.main;
29 }
30 } else {
31 content = '';
32 }
33
34 if (!typeof content === 'string') {
35 content = JSON.stringify(content);
36 }
37 }
38
39 return (
40 <div
41 className="text-cell"
42 style={{
43 float: 'left',
44 padding: `0 ${HORZ_PADDING}px`,
45 }}
46 >
47 <OverflowExpander availableWidth={props.width - HORZ_PADDING * 2}>{content}</OverflowExpander>
48 </div>
49 );
50};
51
52TextCell.propTypes = {
53 cellData: PropTypes.object.isRequired,
54 width: PropTypes.number.isRequired,
55 disabled: PropTypes.bool.isRequired,
56};