| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import React, { useMemo, useState } from 'react';
- import { Table, Avatar } from '@douyinfe/semi-ui';
- import { IconMore } from '@douyinfe/semi-icons';
- import { RowSelection } from '../../../interface';
- /**
- * test with cypress
- */
- export default function App() {
- const columns = useMemo(() => [
- {
- title: '标题',
- dataIndex: 'name',
- width: 400,
- render: (text, record, index) => {
- return (
- <div>
- <Avatar
- size="small"
- shape="square"
- src={record.nameIconSrc}
- style={{ marginRight: 12 }}
- ></Avatar>
- {text}
- </div>
- );
- },
- },
- {
- title: '大小',
- dataIndex: 'size',
- },
- {
- title: '所有者',
- dataIndex: 'owner',
- render: (text, record, index) => {
- return (
- <div>
- <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>
- {typeof text === 'string' && text.slice(0, 1)}
- </Avatar>
- {text}
- </div>
- );
- },
- },
- {
- title: '更新日期',
- dataIndex: 'updateTime',
- },
- {
- title: '',
- dataIndex: 'operate',
- render: () => {
- return <IconMore />;
- },
- },
- ], []);
- const data = useMemo(() => [
- {
- key: '1',
- name: 'Semi Design 设计稿.fig',
- nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
- size: '2M',
- owner: '姜鹏志',
- updateTime: '2020-02-02 05:13',
- avatarBg: 'grey',
- },
- {
- key: '2',
- name: 'Semi Design 分享演示文稿',
- nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
- size: '2M',
- owner: '郝宣',
- updateTime: '2020-01-17 05:31',
- avatarBg: 'red',
- },
- {
- key: '3',
- name: '设计文档',
- nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
- size: '34KB',
- owner: 'Zoey Edwards',
- updateTime: '2020-01-26 11:01',
- avatarBg: 'light-blue',
- },
- {
- key: '4',
- name: 'Semi D2C 设计稿.fig',
- nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
- size: '2M',
- owner: '姜鹏志',
- updateTime: '2020-02-02 05:13',
- avatarBg: 'grey',
- },
- {
- key: '5',
- name: 'Semi D2C 分享演示文稿',
- nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
- size: '2M',
- owner: '郝宣',
- updateTime: '2020-01-17 05:31',
- avatarBg: 'red',
- },
- {
- key: '6',
- name: 'Semi D2C 设计文档',
- nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
- size: '34KB',
- owner: 'Zoey Edwards',
- updateTime: '2020-01-26 11:01',
- avatarBg: 'light-blue',
- },
- ], []);
- const rowSelection: RowSelection<typeof data[number]> = {
- getCheckboxProps: record => ({
- disabled: record.name === '设计文档', // Column configuration not to be checked
- name: record.name,
- }),
- onCell: () => ({
- style: {
- background: 'red',
- },
- className: 'test-td'
- }),
- onHeaderCell: () => ({
- style: {
- background: 'blue',
- },
- className: 'test-th'
- }),
- };
- return <Table columns={columns} dataSource={data} rowSelection={rowSelection} />;
- }
|