Skip to content

Commit

Permalink
feat(comp:tabs): customTitle supports overflowed paramater (#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Sep 8, 2023
1 parent fb1adb2 commit 5da8900
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/components/tabs/demo/Scroll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</IxTabs>
<IxTabs v-model:selectedKey="selectedKey" :dataSource="dataSource" type="segment">
<template #content="{ key }"> Content of Tab {{ key }} </template>
<template #title="{ title, overflowed }"> {{ title }}{{ overflowed ? '(overflowed)' : '' }} </template>
</IxTabs>
<IxSpace align="center">
<IxInputNumber v-model:value="selectedKey" :max="98" :min="0"></IxInputNumber>
Expand Down
4 changes: 2 additions & 2 deletions packages/components/tabs/docs/Api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
export interface TabsData<K = VKey> extends TabProps {
key: K
customContent?: string | ((data: { key: VKey; content?: string; selected?: boolean }) => VNodeChild)
customTitle?: string | ((data: { key: VKey; disabled?: boolean; selected?: boolean; title?: string }) => VNodeChild)
customTitle?: string | ((data: { key: VKey; disabled?: boolean; selected?: boolean; title?: string; overflowed: boolean }) => VNodeChild)
[key: string]: any
}
```
Expand All @@ -42,7 +42,7 @@ export interface TabsData<K = VKey> extends TabProps {

| 名称 | 说明 | 参数类型 | 备注 |
| --- | --- | --- | --- |
| `title` | 标题插槽 | `{ key:VKey, disabled:boolean, selected:boolean, title: string }` | - |
| `title` | 标题插槽 | `{ key:VKey, disabled:boolean, selected:boolean, title: string, overflowed: boolean }` | `overflowed`代表tab溢出且展示在更多tab的浮层中 |
| `content` | 内容插槽 | `{key:VKey, content: any, selected: boolean}` | - |
| `addIcon` | 新增图标 | - | 也可以用于自定义其他操作 |

Expand Down
11 changes: 8 additions & 3 deletions packages/components/tabs/src/contents/MoreSelectPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import { defineComponent, inject, shallowRef, watch } from 'vue'

import { isString } from 'lodash-es'

import { VKey, useState } from '@idux/cdk/utils'
import { IxCol, IxRow } from '@idux/components/grid'
import { IxIcon } from '@idux/components/icon'
Expand All @@ -18,7 +20,7 @@ import { moreSelectPaneProps } from '../types'

export default defineComponent({
props: moreSelectPaneProps,
setup(props) {
setup(props, { slots }) {
const { props: tabsProps, mergedPrefixCls, handleTabClose, setSelectedKey } = inject(tabsToken)!

const [searchValue, setSearchValue] = useState('')
Expand All @@ -45,11 +47,14 @@ export default defineComponent({
}

const optionLabelRender = (data: SelectData) => {
const { key, label, disabled } = data
const { key, label, disabled, customTitle } = data
const titleSlot = isString(customTitle) ? slots[customTitle] : customTitle

return (
<IxRow>
<IxCol flex="auto">{label}</IxCol>
<IxCol flex="auto">
{titleSlot?.({ key, disabled, selected: false, title: label, overflowed: true }) ?? label}
</IxCol>
{tabsProps.closable && (
<IxCol flex="none">
<IxIcon
Expand Down
10 changes: 9 additions & 1 deletion packages/components/tabs/src/contents/TabNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ export default defineComponent({
}

return () => {
/* eslint-disable indent */
const titleNode = slots.title
? slots.title({ key, disabled: props.disabled, selected: props.selected, title: props.title })
? slots.title({
key,
disabled: props.disabled,
selected: props.selected,
title: props.title,
overflowed: false,
})
: props.title
/* eslint-enable indent */
return (
<div ref={elementRef} class={classes.value} onClick={handleClick}>
<span class={`${prefixCls.value}-label`}>{titleNode}</span>
Expand Down
9 changes: 8 additions & 1 deletion packages/components/tabs/src/contents/TabNavWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default defineComponent({
key: data.key,
label: data.title,
disabled: data.disabled,
customTitle: data.customTitle ?? 'title',
})
}
return acc
Expand Down Expand Up @@ -173,7 +174,13 @@ export default defineComponent({
class={`${prefixCls}-nav-operations-popover`}
v-slots={{
content: () => {
return <MoreSelectPane visible={moreSelectPaneVisible.value} dataSource={moreNavDataSource.value} />
return (
<MoreSelectPane
visible={moreSelectPaneVisible.value}
dataSource={moreNavDataSource.value}
v-slots={slots}
/>
)
},
}}
>
Expand Down
4 changes: 3 additions & 1 deletion packages/components/tabs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export type TabComponent = FunctionalComponent<Omit<HTMLAttributes, keyof TabPro
export interface TabsData<K = VKey> extends TabProps {
key: K
customContent?: string | ((data: { key: VKey; content?: string; selected?: boolean }) => VNodeChild)
customTitle?: string | ((data: { key: VKey; disabled?: boolean; selected?: boolean; title?: string }) => VNodeChild)
customTitle?:
| string
| ((data: { key: VKey; disabled?: boolean; selected?: boolean; title?: string; overflowed: boolean }) => VNodeChild)
[key: string]: any
}

Expand Down

0 comments on commit 5da8900

Please sign in to comment.