mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 17:02:38 +00:00
Refactor #4196 - For Steps
This commit is contained in:
parent
e01a3f1f36
commit
974a963218
3 changed files with 38 additions and 8 deletions
|
@ -57,7 +57,7 @@ const styles = `
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const classes = {
|
const classes = {
|
||||||
root: ({ instance }) => ['p-steps p-component', { 'p-readonly': instance.readonly }],
|
root: ({ props }) => ['p-steps p-component', { 'p-readonly': props.readonly }],
|
||||||
menu: 'p-steps-list',
|
menu: 'p-steps-list',
|
||||||
menuitem: ({ instance, item }) => [
|
menuitem: ({ instance, item }) => [
|
||||||
'p-steps-item',
|
'p-steps-item',
|
||||||
|
|
21
components/lib/steps/Steps.d.ts
vendored
21
components/lib/steps/Steps.d.ts
vendored
|
@ -20,6 +20,7 @@ export declare type StepsPassThroughOptionType = StepsPassThroughAttributes | ((
|
||||||
export interface StepsPassThroughMethodOptions {
|
export interface StepsPassThroughMethodOptions {
|
||||||
instance: any;
|
instance: any;
|
||||||
props: StepsProps;
|
props: StepsProps;
|
||||||
|
context: StepsContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,6 +66,26 @@ export interface StepsPassThroughAttributes {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines current options in Steps component.
|
||||||
|
*/
|
||||||
|
export interface StepsContext {
|
||||||
|
/**
|
||||||
|
* Index of the menuitem.
|
||||||
|
*/
|
||||||
|
index: number;
|
||||||
|
/**
|
||||||
|
* Current active state of menuitem as a boolean.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
active: boolean;
|
||||||
|
/**
|
||||||
|
* Current disabled state of menuitem as a boolean.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
disabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines valid properties in Steps component.
|
* Defines valid properties in Steps component.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<nav :id="id" :class="cx('root')" v-bind="ptm('root')" data-pc-name="steps">
|
<nav :id="id" :class="cx('root')" v-bind="ptm('root')" data-pc-name="steps">
|
||||||
<ol ref="list" :class="cx('menu')" v-bind="ptm('menu')">
|
<ol ref="list" :class="cx('menu')" 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="[cx('menuitem', { item }), item.class]" :style="item.style" v-bind="ptm('menuitem')" :data-p-highlight="isActive(item)" :data-p-disabled="isItemDisabled(item)">
|
<li v-if="visible(item)" :class="[cx('menuitem', { item }), item.class]" :style="item.style" v-bind="getPTOptions('menuitem', item, index)" :data-p-highlight="isActive(item)" :data-p-disabled="isItemDisabled(item)">
|
||||||
<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,15 +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')"
|
v-bind="getPTOptions('action', item, index)"
|
||||||
>
|
>
|
||||||
<span :class="cx('step')" v-bind="ptm('step')">{{ index + 1 }}</span>
|
<span :class="cx('step')" v-bind="getPTOptions('step', item, index)">{{ index + 1 }}</span>
|
||||||
<span :class="cx('label')" v-bind="ptm('label')">{{ label(item) }}</span>
|
<span :class="cx('label')" v-bind="getPTOptions('label', item, index)">{{ label(item) }}</span>
|
||||||
</a>
|
</a>
|
||||||
</router-link>
|
</router-link>
|
||||||
<span v-else :class="cx('action')" @keydown="onItemKeydown($event, item)" v-bind="ptm('action')">
|
<span v-else :class="cx('action')" @keydown="onItemKeydown($event, item)" v-bind="getPTOptions('action', item, index)">
|
||||||
<span :class="cx('step')" v-bind="ptm('step')">{{ index + 1 }}</span>
|
<span :class="cx('step')" v-bind="getPTOptions('step', item, index)">{{ index + 1 }}</span>
|
||||||
<span :class="cx('label')" v-bind="ptm('label')">{{ label(item) }}</span>
|
<span :class="cx('label')" v-bind="getPTOptions('label', item, index)">{{ 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>
|
||||||
|
@ -43,6 +43,15 @@ export default {
|
||||||
firstItem.tabIndex = '0';
|
firstItem.tabIndex = '0';
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getPTOptions(key, item, index) {
|
||||||
|
return this.ptm(key, {
|
||||||
|
context: {
|
||||||
|
index,
|
||||||
|
active: this.isActive(item),
|
||||||
|
disabled: this.isItemDisabled(item)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
onItemClick(event, item, navigate) {
|
onItemClick(event, item, navigate) {
|
||||||
if (this.disabled(item) || this.readonly) {
|
if (this.disabled(item) || this.readonly) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue