forked from jbetancur/react-data-table-component
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomCell.stories.js
More file actions
78 lines (73 loc) · 1.75 KB
/
Copy pathCustomCell.stories.js
File metadata and controls
78 lines (73 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import data from '../constants/sampleMovieData';
import DataTable from '../../src/index';
const Button = () => <button type="button">Download</button>;
// eslint-disable-next-line react/prop-types
const CustomTitle = ({ row }) => (
<div>
{/* eslint-disable-next-line react/prop-types */}
<div>{row.title}</div>
<div>
<div
data-tag="allowRowEvents"
style={{ color: 'grey', overflow: 'hidden', whiteSpace: 'wrap', textOverflow: 'ellipses' }}
>
{/* eslint-disable-next-line react/prop-types */}
{row.plot}
</div>
</div>
</div>
);
const columns = [
{
name: 'Custom Title',
selector: row => row.title,
sortable: true,
maxWidth: '600px', // when using custom you should use width or maxWidth, otherwise, the table will default to flex grow behavior
cell: row => <CustomTitle row={row} />,
},
{
name: 'Plot Format',
selector: row => row.plot,
wrap: true,
sortable: true,
format: row => `${row.plot.slice(0, 200)}...`,
},
{
name: 'Genres',
// eslint-disable-next-line react/no-array-index-key
cell: row => (
<div>
{row.genres.map((genre, i) => (
<div key={i}>{genre}</div>
))}
</div>
),
},
{
name: 'Thumbnail',
grow: 0,
cell: row => <img height="84px" width="56px" alt={row.name} src={row.posterUrl} />,
},
{
name: 'Poster Link',
button: true,
cell: row => (
<a href={row.posterUrl} target="_blank" rel="noopener noreferrer">
Download
</a>
),
},
{
name: 'Poster Button',
button: true,
cell: () => <Button>Download Poster</Button>,
},
];
export const CustomCells = () => (
<DataTable title="Movie List - Custom Cells" columns={columns} data={data} pagination />
);
export default {
title: 'Columns/Cells/Custom Cells',
component: CustomCells,
};