Refactor #3983 - For TabView

pull/3997/head
Tuğçe Küçükoğlu 2023-05-24 10:07:13 +03:00
parent 0ddf82f471
commit 6e65824aeb
3 changed files with 29 additions and 7 deletions

View File

@ -19,6 +19,7 @@ export declare type TabPanelPassThroughOptionType = TabPanelPassThroughAttribute
export interface TabPanelPassThroughMethodOptions { export interface TabPanelPassThroughMethodOptions {
props: TabPanelProps; props: TabPanelProps;
parent: TabViewPassThroughOptions; parent: TabViewPassThroughOptions;
context: TabPanelContext;
} }
/** /**
@ -102,6 +103,17 @@ export interface TabPanelProps {
*/ */
pt?: TabPanelPassThroughOptions; pt?: TabPanelPassThroughOptions;
} }
/**
* Defines current options in TabPanel component.
*/
export interface TabPanelContext {
/**
* Current index of the tab.
*/
index: number;
}
/** /**
* Defines valid slots in TabPanel slots. * Defines valid slots in TabPanel slots.
*/ */

View File

@ -8,6 +8,7 @@
* *
*/ */
import { ButtonHTMLAttributes, VNode } from 'vue'; import { ButtonHTMLAttributes, VNode } from 'vue';
import { TabPanelPassThroughOptionType } from '../tabpanel';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type TabViewPassThroughOptionType = TabViewPassThroughAttributes | ((options: { props: TabViewProps; state: TabViewState }) => TabViewPassThroughAttributes) | null | undefined; export declare type TabViewPassThroughOptionType = TabViewPassThroughAttributes | ((options: { props: TabViewProps; state: TabViewState }) => TabViewPassThroughAttributes) | null | undefined;
@ -55,6 +56,10 @@ export interface TabViewPassThroughOptions {
* Uses to pass attributes to the list's DOM element. * Uses to pass attributes to the list's DOM element.
*/ */
nav?: TabViewPassThroughOptionType; nav?: TabViewPassThroughOptionType;
/**
* Uses to pass attributes to TabPanel helper components.
*/
tab?: TabPanelPassThroughOptionType;
/** /**
* Uses to pass attributes to the inkbar's DOM element. * Uses to pass attributes to the inkbar's DOM element.
*/ */

View File

@ -29,7 +29,7 @@
:data-p-highlight="d_activeIndex === index" :data-p-highlight="d_activeIndex === index"
:data-p-disabled="getTabProp(tab, 'disabled')" :data-p-disabled="getTabProp(tab, 'disabled')"
data-pc-section="header" data-pc-section="header"
v-bind="{ ...getTabProp(tab, 'headerProps'), ...getTabPT(tab, 'root'), ...getTabPT(tab, 'header') }" v-bind="{ ...getTabProp(tab, 'headerProps'), ...getTabPT(tab, 'root', index), ...getTabPT(tab, 'header', index) }"
> >
<a <a
:id="getTabHeaderActionId(index)" :id="getTabHeaderActionId(index)"
@ -43,9 +43,9 @@
@click="onTabClick($event, tab, index)" @click="onTabClick($event, tab, index)"
@keydown="onTabKeyDown($event, tab, index)" @keydown="onTabKeyDown($event, tab, index)"
data-pc-section="headeraction" data-pc-section="headeraction"
v-bind="{ ...getTabProp(tab, 'headerActionProps'), ...getTabPT(tab, 'headerAction') }" v-bind="{ ...getTabProp(tab, 'headerActionProps'), ...getTabPT(tab, 'headerAction', index) }"
> >
<span v-if="tab.props && tab.props.header" :class="cx('tab.headerTitle')" data-pc-section="headertitle" v-bind="getTabPT(tab, 'headerTitle')">{{ tab.props.header }}</span> <span v-if="tab.props && tab.props.header" :class="cx('tab.headerTitle')" data-pc-section="headertitle" v-bind="getTabPT(tab, 'headerTitle', index)">{{ tab.props.header }}</span>
<component v-if="tab.children && tab.children.header" :is="tab.children.header"></component> <component v-if="tab.children && tab.children.header" :is="tab.children.header"></component>
</a> </a>
</li> </li>
@ -79,7 +79,7 @@
role="tabpanel" role="tabpanel"
:aria-labelledby="getTabHeaderActionId(index)" :aria-labelledby="getTabHeaderActionId(index)"
data-pc-section="content" data-pc-section="content"
v-bind="{ ...getTabProp(tab, 'contentProps'), ...getTabPT(tab, 'root'), ...getTabPT(tab, 'content') }" v-bind="{ ...getTabProp(tab, 'contentProps'), ...getTabPT(tab, 'root', index), ...getTabPT(tab, 'content', index) }"
> >
<component :is="tab"></component> <component :is="tab"></component>
</div> </div>
@ -145,14 +145,19 @@ export default {
getTabContentId(index) { getTabContentId(index) {
return `${this.id}_${index}_content`; return `${this.id}_${index}_content`;
}, },
getTabPT(tab, key) { getTabPT(tab, key, index) {
return this.ptmo(this.getTabProp(tab, 'pt'), key, { const tabMetaData = {
props: tab.props, props: tab.props,
parent: { parent: {
props: this.$props, props: this.$props,
state: this.$data state: this.$data
},
context: {
index
} }
}); };
return { ...this.ptm(`tab.${key}`, { tab: tabMetaData }), ...this.ptmo(this.getTabProp(tab, 'pt'), key, tabMetaData) };
}, },
onScroll(event) { onScroll(event) {
this.scrollable && this.updateButtonState(); this.scrollable && this.updateButtonState();