Refactor #3907 - For Steps

pull/3913/head
Tuğçe Küçükoğlu 2023-04-26 12:58:46 +03:00
parent bc70f24f15
commit 5d40f1c45d
3 changed files with 69 additions and 8 deletions

View File

@ -22,6 +22,12 @@ const StepsProps = [
type: 'boolean', type: 'boolean',
default: 'true', default: 'true',
description: "Whether to apply 'router-link-active-exact' class if route exactly matches the item path." description: "Whether to apply 'router-link-active-exact' class if route exactly matches the item path."
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
} }
]; ];

View File

@ -11,6 +11,53 @@ import { VNode } from 'vue';
import { MenuItem } from '../menuitem'; import { MenuItem } from '../menuitem';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type StepsPassThroughOptionType = StepsPassThroughAttributes | ((options: StepsPassThroughMethodOptions) => StepsPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface StepsPassThroughMethodOptions {
props: StepsProps;
}
/**
* Custom passthrough(pt) options.
* @see {@link StepsProps.pt}
*/
export interface StepsPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: StepsPassThroughOptionType;
/**
* Uses to pass attributes to the list's DOM element.
*/
menu?: StepsPassThroughOptionType;
/**
* Uses to pass attributes to the list item's DOM element.
*/
menuitem?: StepsPassThroughOptionType;
/**
* Uses to pass attributes to the action's DOM element.
*/
action?: StepsPassThroughOptionType;
/**
* Uses to pass attributes to the step's DOM element.
*/
step?: StepsPassThroughOptionType;
/**
* Uses to pass attributes to the label's DOM element.
*/
label?: StepsPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface StepsPassThroughAttributes {
[key: string]: any;
}
/** /**
* Defines valid properties in Steps component. * Defines valid properties in Steps component.
*/ */
@ -33,6 +80,11 @@ export interface StepsProps {
* @defaultValue true * @defaultValue true
*/ */
exact?: boolean | undefined; exact?: boolean | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {StepsPassThroughOptions}
*/
pt?: StepsPassThroughOptions;
} }
/** /**

View File

@ -1,8 +1,8 @@
<template> <template>
<nav :id="id" :class="containerClass"> <nav :id="id" :class="containerClass" v-bind="ptm('root')">
<ol ref="list" class="p-steps-list"> <ol ref="list" class="p-steps-list" v-bind="ptm('menu')">
<template v-for="(item, index) of model" :key="item.to"> <template v-for="(item, index) of model" :key="item.to">
<li v-if="visible(item)" :class="getItemClass(item)" :style="item.style"> <li v-if="visible(item)" :class="getItemClass(item)" :style="item.style" v-bind="ptm('menuitem')">
<template v-if="!$slots.item"> <template v-if="!$slots.item">
<router-link v-if="!isItemDisabled(item)" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom> <router-link v-if="!isItemDisabled(item)" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
<a <a
@ -12,14 +12,15 @@
:aria-current="isExactActive ? 'step' : undefined" :aria-current="isExactActive ? 'step' : undefined"
@click="onItemClick($event, item, navigate)" @click="onItemClick($event, item, navigate)"
@keydown="onItemKeydown($event, item, navigate)" @keydown="onItemKeydown($event, item, navigate)"
v-bind="ptm('action')"
> >
<span class="p-steps-number">{{ index + 1 }}</span> <span class="p-steps-number" v-bind="ptm('step')">{{ index + 1 }}</span>
<span class="p-steps-title">{{ label(item) }}</span> <span class="p-steps-title" v-bind="ptm('label')">{{ label(item) }}</span>
</a> </a>
</router-link> </router-link>
<span v-else :class="linkClass()" @keydown="onItemKeydown($event, item)"> <span v-else :class="linkClass()" @keydown="onItemKeydown($event, item)" v-bind="ptm('action')">
<span class="p-steps-number">{{ index + 1 }}</span> <span class="p-steps-number" v-bind="ptm('step')">{{ index + 1 }}</span>
<span class="p-steps-title">{{ label(item) }}</span> <span class="p-steps-title" v-bind="ptm('label')">{{ label(item) }}</span>
</span> </span>
</template> </template>
<component v-else :is="$slots.item" :item="item"></component> <component v-else :is="$slots.item" :item="item"></component>
@ -30,10 +31,12 @@
</template> </template>
<script> <script>
import BaseComponent from 'primevue/basecomponent';
import { DomHandler, UniqueComponentId } from 'primevue/utils'; import { DomHandler, UniqueComponentId } from 'primevue/utils';
export default { export default {
name: 'Steps', name: 'Steps',
extends: BaseComponent,
props: { props: {
id: { id: {
type: String, type: String,