Skip to content

Commit

Permalink
Refactor #4739 - For Breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Nov 8, 2023
1 parent a6e0657 commit ad9b437
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 31 deletions.
4 changes: 0 additions & 4 deletions components/lib/breadcrumb/BaseBreadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export default {
home: {
type: null,
default: null
},
exact: {
type: Boolean,
default: true
}
},
style: BreadcrumbStyle,
Expand Down
1 change: 1 addition & 0 deletions components/lib/breadcrumb/Breadcrumb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export interface BreadcrumbProps {
home?: MenuItem | undefined;
/**
* Whether to apply 'router-link-active-exact' class if route exactly matches the item path.
* @deprecated since v3.40.0.
* @defaultValue true
*/
exact?: boolean | undefined;
Expand Down
9 changes: 2 additions & 7 deletions components/lib/breadcrumb/Breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<nav :class="cx('root')" v-bind="ptm('root')" data-pc-name="breadcrumb">
<ol :class="cx('menu')" v-bind="ptm('menu')">
<BreadcrumbItem v-if="home" :item="home" :class="cx('home')" :templates="$slots" :exact="exact" :pt="pt" :unstyled="unstyled" v-bind="ptm('home')" />
<BreadcrumbItem v-if="home" :item="home" :class="cx('home')" :templates="$slots" :pt="pt" :unstyled="unstyled" v-bind="ptm('home')" />
<template v-for="(item, i) of model" :key="item.label + '_' + i">
<li v-if="home || i !== 0" :class="cx('separator')" v-bind="ptm('separator')">
<slot name="separator">
<ChevronRightIcon aria-hidden="true" v-bind="ptm('separatorIcon')" />
</slot>
</li>
<BreadcrumbItem :item="item" :index="i" :templates="$slots" :exact="exact" :pt="pt" :unstyled="unstyled" />
<BreadcrumbItem :item="item" :index="i" :templates="$slots" :pt="pt" :unstyled="unstyled" />
</template>
</ol>
</nav>
Expand All @@ -22,11 +22,6 @@ import BreadcrumbItem from './BreadcrumbItem.vue';
export default {
name: 'Breadcrumb',
extends: BaseBreadcrumb,
beforeMount() {
if (!this.$slots.item) {
console.warn('In future versions, vue-router support will be removed. Item templating should be used.');
}
},
components: {
BreadcrumbItem: BreadcrumbItem,
ChevronRightIcon: ChevronRightIcon
Expand Down
14 changes: 1 addition & 13 deletions components/lib/breadcrumb/BreadcrumbItem.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<template>
<li v-if="visible()" :class="[cx('menuitem'), item.class]" v-bind="ptm('menuitem', ptmOptions)">
<template v-if="!templates.item">
<router-link v-if="item.to" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
<a :href="href" :class="cx('action', { isActive, isExactActive })" :aria-current="isCurrentUrl()" @click="onClick($event, navigate)" v-bind="ptm('action', ptmOptions)">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="cx('icon')" />
<span v-else-if="item.icon" :class="[cx('icon'), item.icon]" v-bind="ptm('icon', ptmOptions)" />
<span v-if="item.label" :class="cx('label')" v-bind="ptm('label', ptmOptions)">{{ label() }}</span>
</a>
</router-link>
<a v-else :href="item.url || '#'" :class="cx('action')" :target="item.target" :aria-current="isCurrentUrl()" @click="onClick" v-bind="ptm('action', ptmOptions)">
<a :href="item.url || '#'" :class="cx('action')" :target="item.target" :aria-current="isCurrentUrl()" @click="onClick" v-bind="ptm('action', ptmOptions)">
<component v-if="templates && templates.itemicon" :is="templates.itemicon" :item="item" :class="cx('icon', ptmOptions)" />
<span v-else-if="item.icon" :class="[cx('icon'), item.icon]" v-bind="ptm('icon', ptmOptions)" />
<span v-if="item.label" :class="cx('label')" v-bind="ptm('label', ptmOptions)">{{ label() }}</span>
Expand All @@ -29,7 +22,6 @@ export default {
props: {
item: null,
templates: null,
exact: null,
index: null
},
methods: {
Expand All @@ -40,10 +32,6 @@ export default {
item: this.item
});
}
if (this.item.to && navigate) {
navigate(event);
}
},
visible() {
return typeof this.item.visible === 'function' ? this.item.visible() : this.item.visible !== false;
Expand Down
8 changes: 1 addition & 7 deletions components/lib/breadcrumb/style/BreadcrumbStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ const classes = {
home: 'p-breadcrumb-home',
separator: 'p-menuitem-separator',
menuitem: ({ instance }) => ['p-menuitem', { 'p-disabled': instance.disabled() }],
action: ({ props, isActive, isExactActive }) => [
'p-menuitem-link',
{
'router-link-active': isActive,
'router-link-active-exact': props.exact && isExactActive
}
],
action: 'p-menuitem-link',
icon: 'p-menuitem-icon',
label: 'p-menuitem-text'
};
Expand Down

0 comments on commit ad9b437

Please sign in to comment.