Skip to content

Commit

Permalink
feat(comp:table): the selectable column supports custom cell (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm authored Sep 22, 2022
1 parent e22dde5 commit 787f3f1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ module.exports = {
},
ignorePatterns: [
'dist',
'packages/site/components.ts',
'packages/site/components.d.ts',
'packages/site/src/router.ts',
'packages/site/src/sideNav.ts',
'packages/site/src/components/global/themeConfig.ts',
Expand Down
2 changes: 2 additions & 0 deletions packages/components/checkbox/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

/* eslint-disable vue/no-ref-as-operand */

import { type ComputedRef, computed, defineComponent, inject, normalizeClass, ref } from 'vue'

import { isNil } from 'lodash-es'
Expand Down
2 changes: 2 additions & 0 deletions packages/components/radio/src/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

/* eslint-disable vue/no-ref-as-operand */

import { type ComputedRef, type Ref, computed, defineComponent, inject, normalizeClass, ref } from 'vue'

import { isNil } from 'lodash-es'
Expand Down
1 change: 1 addition & 0 deletions packages/components/table/docs/Api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export type TableColumn<T = any, V = any> =
| `onSelectInvert` | 点击反选所有时触发 | `(selectedRowKeys: (string \| number)[]) => void` | - | - | 配置 `menus= ['invert']` 时生效 |
| `onSelectNone` | 点击清空所有时触发 | `() => void` | - | - | 配置 `menus= ['none']` 时生效 |
| `onSelectPageInvert` | 点击反选当页所有时触发 | `() => void` | - | - | 配置 `menus= ['pageInvert']` 时生效 |
| `customCell` | 自定义单元格内容 | `string \| ((data: { checked: boolean; disabled: boolean; indeterminate?: boolean, onChange: () => void, onClick: () => void }) => VNodeChild)` | - | - | 类型为 `string` 时,对应插槽名 |
##### TableColumnSortable
Expand Down
10 changes: 6 additions & 4 deletions packages/components/table/src/main/body/BodyCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default defineComponent({
let title: string | undefined

if (type === 'selectable') {
children = renderSelectableChildren(props, selectable, handleClick)
children = renderSelectableChildren(props, slots, selectable, handleClick)
} else {
const { ellipsis = tableProps.ellipsis } = column
const text = dataValue.value
Expand Down Expand Up @@ -205,16 +205,18 @@ function renderExpandableChildren(

function renderSelectableChildren(
props: TableBodyCellProps,
slots: Slots,
selectable: ComputedRef<TableColumnMergedSelectable | undefined>,
onClick: (evt: Event) => void,
) {
const { selected: checked, indeterminate, disabled, handleSelect: onChange } = props
const { multiple } = selectable.value!
const { multiple, customCell } = selectable.value!
const customRender = isString(customCell) ? slots[customCell] : customCell
if (multiple) {
const checkboxProps = { checked, disabled, indeterminate, onChange, onClick }
return <IxCheckbox {...checkboxProps}></IxCheckbox>
return customRender ? customRender(checkboxProps) : <IxCheckbox {...checkboxProps}></IxCheckbox>
} else {
const radioProps = { checked, disabled, onChange, onClick }
return <IxRadio {...radioProps}></IxRadio>
return customRender ? customRender(radioProps) : <IxRadio {...radioProps}></IxRadio>
}
}
10 changes: 10 additions & 0 deletions packages/components/table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ export interface TableColumnSelectable<T = any, K = VKey> extends TableColumnCom
onSelectInvert?: (selectedRowKeys: K[]) => void
onSelectNone?: () => void
onSelectPageInvert?: (selectedRowKeys: K[]) => void

customCell?:
| string
| ((data: {
checked: boolean
disabled: boolean
indeterminate?: boolean
onChange: () => void
onClick: () => void
}) => VNodeChild)
}

export interface TableCustomAdditional<T = any, K = VKey> {
Expand Down
12 changes: 6 additions & 6 deletions packages/components/table/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
}

th {
position: relative;
text-align: start;
overflow-wrap: break-word;
color: @table-head-color;
background-color: @table-head-background-color;
font-weight: @table-head-font-weight;
Expand All @@ -73,9 +70,6 @@
}

td {
position: relative;
text-align: start;
overflow-wrap: break-word;
transition: background @transition-duration-base;

// TODO: Nest Table
Expand All @@ -98,6 +92,12 @@
}
}

&-cell {
position: relative;
text-align: start;
overflow-wrap: break-word;
}

&-cell-align {
&-center {
text-align: center;
Expand Down

0 comments on commit 787f3f1

Please sign in to comment.