Skip to content

Commit

Permalink
feat: support tooltipRender for header cell ellipsis
Browse files Browse the repository at this point in the history
break-change:
1. no need to import `css` anymore
2. package rename to `use-antd-resizable-header`

fix bugs
fix type

1. fix protable `hideInTable` bug
2. fix columns type
  • Loading branch information
hemengke1997 committed Nov 26, 2023
1 parent 35d581c commit 3345589
Show file tree
Hide file tree
Showing 26 changed files with 604 additions and 167 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
strict-peer-dependencies=false
ignore-workspace-root-check=true
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## 安装

```bash
pnpm add @minko-fe/use-antd-resizable-header
pnpm add use-antd-resizable-header
```

## API
Expand Down Expand Up @@ -46,15 +46,13 @@ pnpm add @minko-fe/use-antd-resizable-header
- **至少一列不能拖动(width 不设置即可),[请保持至少一列的自适应](https://ant-design.gitee.io/components/table-cn/#components-table-demo-fixed-columns)**
- **若 column 未传入`dataIndex`,请传入一个唯一的`key`,否则按照将按照 column 的序号 index 计算唯一 key**
- **若 column 有副作用,请把依赖项传入 useMemo deps 中**
- **remember import style**

## Example

```tsx
import ProTable from '@ant-design/pro-table'
import { useAntdResizableHeader } from '@minko-fe/use-antd-resizable-header'
import { Button, Table } from 'antd'
import '@minko-fe/use-antd-resizable-header/index.css'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

function App() {
const columns = []
Expand Down Expand Up @@ -86,10 +84,9 @@ function App() {
```

```tsx
import { useAntdResizableHeader } from '@minko-fe/use-antd-resizable-header'
import { Space, Table, Tag } from 'antd'
import React, { useReducer } from 'react'
import '@minko-fe/use-antd-resizable-header/index.css'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

const data = [
{
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@minko-fe/use-antd-resizable-header",
"name": "use-antd-resizable-header",
"version": "2.8.15",
"description": "antd resizable header column hook",
"type": "module",
Expand Down Expand Up @@ -61,9 +61,11 @@
"dependencies": {
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"react-detectable-overflow": "^0.7.1",
"react-resizable": "^3.0.5"
},
"devDependencies": {
"@ant-design/pro-table": "^3.13.11",
"@minko-fe/eslint-config": "^2.0.5",
"@minko-fe/tsconfig": "^2.0.5",
"@testing-library/dom": "^8.20.0",
Expand Down
5 changes: 3 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
},
"dependencies": {
"@ant-design/pro-table": "^3.4.0",
"@minko-fe/use-antd-resizable-header": "workspace:*",
"ahooks": "^3.7.5",
"antd": "5.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.8.2",
"react-router-dom": "^6.8.2"
"react-router-dom": "^6.8.2",
"umi-request": "^1.4.0",
"use-antd-resizable-header": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.2.28",
Expand Down
3 changes: 1 addition & 2 deletions playground/src/36/TableComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useAntdResizableHeader } from '@minko-fe/use-antd-resizable-header'
import { Table } from 'antd'
import React from 'react'
import '@minko-fe/use-antd-resizable-header/index.css'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

interface IProps {
columns: any[]
Expand Down
3 changes: 1 addition & 2 deletions playground/src/37/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import useARH from '@minko-fe/use-antd-resizable-header'
import { Table } from 'antd'
import React, { useEffect, useMemo, useState } from 'react'
import '@minko-fe/use-antd-resizable-header/index.css'
import useARH from 'use-antd-resizable-header'

const columns = [
{
Expand Down
3 changes: 1 addition & 2 deletions playground/src/42/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ProTable from '@ant-design/pro-table'
import { useAntdResizableHeader } from '@minko-fe/use-antd-resizable-header'
import { Tooltip } from 'antd'
import '@minko-fe/use-antd-resizable-header/index.css'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

const columns: any[] = [
{
Expand Down
13 changes: 6 additions & 7 deletions playground/src/43/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { useAntdResizableHeader } from '@minko-fe/use-antd-resizable-header'
import { Table } from 'antd'
import React, { useMemo } from 'react'
import '@minko-fe/use-antd-resizable-header/index.css'
import { useMemo } from 'react'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

const columns: any[] = [
{
title: <div>title1</div>,
dataIndex: 'putrecNo',
dataIndex: 'name',
width: 150,
key: 'putrecNo',
key: 'name',
ellipsis: true,
search: false,
},
{
title: <div>title2</div>,
dataIndex: 'createTime',
key: 'createTime',
dataIndex: 'street',
key: 'street',
valueType: 'dateRange',
hideInTable: true,
},
Expand Down
5 changes: 2 additions & 3 deletions playground/src/44/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ProTable from '@ant-design/pro-table'
import { useAntdResizableHeader } from '@minko-fe/use-antd-resizable-header'
import React from 'react'
import '@minko-fe/use-antd-resizable-header/dist/style.css'
import { useAntdResizableHeader } from 'use-antd-resizable-header'
import 'use-antd-resizable-header/dist/style.css'

const columns: any[] = [
{
Expand Down
23 changes: 23 additions & 0 deletions playground/src/67/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ProTable, { type ProColumnType, type ProColumns } from '@ant-design/pro-table'
import Table, { type ColumnsType } from 'antd/es/table'
import { useState } from 'react'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

export default function () {
const [proCols, _setProCols] = useState<ProColumns<any>[]>([])
const {} = useAntdResizableHeader<ProColumnType>({
columns: proCols,
})

const [cols, _setCols] = useState<ColumnsType>([{ title: 'Name', dataIndex: 'name' }])
const { resizableColumns } = useAntdResizableHeader<ColumnsType[number]>({
columns: cols,
})

return (
<>
<ProTable columns={proCols}></ProTable>
<Table columns={resizableColumns} />
</>
)
}
59 changes: 59 additions & 0 deletions playground/src/68/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import ProTable, { type ProColumns } from '@ant-design/pro-table'
import { Tooltip } from 'antd'
import { useMemo } from 'react'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

const columns: ProColumns[] = [
{
title: 'title mmmmmmmmmmmmmmmmmm',
dataIndex: 'name',
width: 150,
key: 'name',
ellipsis: {
showTitle: true,
},
search: false,
},
{
title: <div>title2</div>,
dataIndex: 'street',
key: 'street',
valueType: 'dateRange',
},
]

const data: any[] = []
for (let i = 0; i < 100; i++) {
data.push({
key: i,
name: 'John Brown',
age: i + 1,
street: 'Lake Park',
building: 'C',
number: 2035,
remark: 'Lake Street 42',
companyName: 'SoftLake Co',
gender: 'M',
})
}

const ResizableTable = () => {
const { components, resizableColumns, tableWidth } = useAntdResizableHeader({
columns: useMemo(() => columns, []),
columnsState: {
persistenceKey: 'localKey',
persistenceType: 'localStorage',
},
tooltipRender: (props) => <Tooltip {...props} />,
})
return (
<>
<div>
<ProTable columns={resizableColumns} components={components} dataSource={data} scroll={{ x: tableWidth }} />
<Tooltip title={'123'} open={undefined} children='test'></Tooltip>
</div>
</>
)
}

export default ResizableTable
144 changes: 144 additions & 0 deletions playground/src/69/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import ProTable, { type ProColumns } from '@ant-design/pro-table'
import { Space, Tag } from 'antd'
import { useMemo } from 'react'
import request from 'umi-request'
import { useAntdResizableHeader } from 'use-antd-resizable-header'

type GithubIssueItem = {
url: string
id: number
number: number
title: string
labels: {
name: string
color: string
}[]
state: string
comments: number
created_at: string
updated_at: string
closed_at?: string
}

const columns: ProColumns<GithubIssueItem>[] = [
{
dataIndex: 'index',
valueType: 'indexBorder',
width: 48,
},
{
title: '标题',
dataIndex: 'title',
copyable: true,
ellipsis: true,
tip: '标题过长会自动收缩',
width: 200,
},
{
disable: true,
title: '状态',
dataIndex: 'state',
filters: true,
onFilter: true,
ellipsis: true,
width: 100,
valueType: 'select',
valueEnum: {
all: { text: '超长'.repeat(50) },
open: {
text: '未解决',
status: 'Error',
},
closed: {
text: '已解决',
status: 'Success',
disabled: true,
},
processing: {
text: '解决中',
status: 'Processing',
},
},
},
{
disable: true,
title: '标签',
dataIndex: 'labels',
width: 180,
search: false,
renderFormItem: (_, { defaultRender }) => {
return defaultRender(_)
},
render: (_, record) => (
<Space>
{record.labels.map(({ name, color }) => (
<Tag color={color} key={name}>
{name}
</Tag>
))}
</Space>
),
},
{
title: '创建时间',
key: 'aaa',
dataIndex: 'created_at',
valueType: 'dateRange',
width: 200,
hideInTable: true,
search: {
transform: (value) => {
return {
startTime: value[0],
endTime: value[1],
}
},
},
},
{
title: '创建时间',
dataIndex: 'created_at',
valueType: 'date',
width: 200,
sorter: true,
hideInSearch: true,
},

{
title: '操作',
valueType: 'option',
key: 'option',
render: (text, record, _, action) => [
<a href={record.url} target='_blank' rel='noopener noreferrer' key='view'>
查看
</a>,
],
},
]

export default () => {
const { components, resizableColumns, tableWidth } = useAntdResizableHeader({
columns: useMemo(() => columns, []),
columnsState: {
persistenceType: 'localStorage',
persistenceKey: 'aaaaa',
},
})
return (
<ProTable<GithubIssueItem>
columns={resizableColumns}
components={components}
scroll={{ x: tableWidth }}
cardBordered
request={async (params = {}, sort, filter) => {
return request<{
data: GithubIssueItem[]
}>('https://proapi.azurewebsites.net/github/issues', {
params,
})
}}
rowKey='id'
headerTitle='高级表格'
/>
)
}
Loading

0 comments on commit 3345589

Please sign in to comment.