|
| 1 | +import React from 'react'; |
| 2 | +import Tooltip from 'rc-tooltip'; |
| 3 | +import Table from '../src'; |
| 4 | +import '../assets/index.less'; |
| 5 | +import 'rc-tooltip/assets/bootstrap.css'; |
| 6 | + |
| 7 | +const createColumns = (length: number) => { |
| 8 | + return Array.from({ length }, (_, i) => ({ |
| 9 | + title: 'description', |
| 10 | + dataIndex: 'description', |
| 11 | + key: `description ${i + 1}`, |
| 12 | + ellipsis: { |
| 13 | + showTitle: false, |
| 14 | + }, |
| 15 | + ...(i === 0 ? { width: 50 } : null), |
| 16 | + render(description: string) { |
| 17 | + return ( |
| 18 | + <Tooltip placement="topLeft" overlay={description}> |
| 19 | + <span>{description}</span> |
| 20 | + </Tooltip> |
| 21 | + ); |
| 22 | + }, |
| 23 | + })); |
| 24 | +}; |
| 25 | + |
| 26 | +const columns = [ |
| 27 | + { |
| 28 | + title: 'name', |
| 29 | + dataIndex: 'name', |
| 30 | + width: 100, |
| 31 | + ellipsis: { |
| 32 | + showTitle: false, |
| 33 | + }, |
| 34 | + render: (name: string) => ( |
| 35 | + <Tooltip placement="topLeft" overlay={name}> |
| 36 | + <span>{name}</span> |
| 37 | + </Tooltip> |
| 38 | + ), |
| 39 | + }, |
| 40 | + ...createColumns(10), |
| 41 | + { |
| 42 | + title: 'Operations', |
| 43 | + key: 'operations', |
| 44 | + ellipsis: { |
| 45 | + showTitle: false, |
| 46 | + }, |
| 47 | + render() { |
| 48 | + return ( |
| 49 | + <Tooltip placement="topLeft" overlay="Operations"> |
| 50 | + <a href="#">Operations</a> |
| 51 | + </Tooltip> |
| 52 | + ); |
| 53 | + }, |
| 54 | + }, |
| 55 | +]; |
| 56 | + |
| 57 | +const data = [ |
| 58 | + { name: 'jack', description: 'description description', key: '1' }, |
| 59 | + { name: 'jackjackjackjackjackjack', description: 'description description', key: '2' }, |
| 60 | + { name: 'jack ma', description: 'description description', key: '3' }, |
| 61 | + { name: 'jack nickson', description: 'description description', key: '4' }, |
| 62 | +]; |
| 63 | + |
| 64 | +const Demo = () => ( |
| 65 | + <div> |
| 66 | + <h2>Table ellipsis custom tooltip</h2> |
| 67 | + <Table columns={columns} data={data} /> |
| 68 | + </div> |
| 69 | +); |
| 70 | + |
| 71 | +export default Demo; |
0 commit comments