Skip to content

Commit

Permalink
Refactor #4351 - For Steps
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Aug 30, 2023
1 parent 1359cd0 commit 637b3b3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
12 changes: 12 additions & 0 deletions components/lib/steps/Steps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ export interface StepsSlots {
* Menuitem instance
*/
item: MenuItem;
/**
* Label property of the menuitem
*/
label: string | ((...args: any) => string) | undefined;
/**
* Order of the menuitem
*/
index: number;
/**
* Binding properties of the menuitem
*/
props: (...args: any) => string;
}): VNode[];
}

Expand Down
34 changes: 32 additions & 2 deletions components/lib/steps/Steps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<span :class="cx('label')" v-bind="getPTOptions('label', item, index)">{{ label(item) }}</span>
</span>
</template>
<component v-else :is="$slots.item" :item="item"></component>
<component v-else :is="$slots.item" :item="item" :index="index" :label="label(item)" :props="getMenuItemProps(item, index)"></component>
</li>
</template>
</ol>
Expand All @@ -32,11 +32,17 @@

<script>
import { DomHandler } from 'primevue/utils';
import { mergeProps } from 'vue';
import BaseSteps from './BaseSteps.vue';
export default {
name: 'Steps',
extends: BaseSteps,
beforeMount() {
if (!this.$slots.item) {
console.warn('In future versions, vue-router support will be removed. Item templating should be used.');
}
},
mounted() {
const firstItem = this.findFirstItem();
Expand Down Expand Up @@ -159,7 +165,7 @@ export default {
focusableItem.focus();
},
isActive(item) {
return item.to ? this.$router.resolve(item.to).path === this.$route.path : false;
return item.to || item.route ? this.$router.resolve(item.to || item.route).path === this.$route.path : false;
},
isItemDisabled(item) {
return this.disabled(item) || (this.readonly && !this.isActive(item));
Expand All @@ -172,6 +178,30 @@ export default {
},
label(item) {
return typeof item.label === 'function' ? item.label() : item.label;
},
getMenuItemProps(item, index) {
return {
action: mergeProps(
{
class: this.cx('action'),
onClick: ($event) => this.onItemClick($event, item),
onKeyDown: ($event) => this.onItemKeydown($event, item)
},
this.getPTOptions('action', item, index)
),
step: mergeProps(
{
class: this.cx('step')
},
this.getPTOptions('step', item, index)
),
label: mergeProps(
{
class: this.cx('label')
},
this.getPTOptions('label', item, index)
)
};
}
}
};
Expand Down

0 comments on commit 637b3b3

Please sign in to comment.