Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(breadcrumb): conditionally renders button when no redirection link given #5077

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 41 additions & 47 deletions src/components/NcBreadcrumb/NcBreadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
### General description

This component is meant to be used inside a Breadcrumbs component.
Renders a button element when given no redirection props, otherwise, renders <a/> or <router-link/> elements

</docs>

Expand All @@ -39,18 +40,22 @@ This component is meant to be used inside a Breadcrumbs component.
@dragover.prevent="() => {}"
@dragenter="dragEnter"
@dragleave="dragLeave">
<component :is="tag"
v-if="(name || icon) && !$slots.default"
<NcButton v-if="(name || icon) && !$slots.default"
:title="title"
:aria-label="icon ? name : undefined"
type="tertiary"
v-bind="linkAttributes"
v-on="$listeners">
<!-- @slot Slot for passing a material design icon. Precedes the icon and name prop. -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be kept for the docs 😉

<slot name="icon">
<span v-if="icon" :class="icon" class="icon" />
<span v-else>{{ name }}</span>
</slot>
</component>
<template v-if="$slots.icon || icon" #icon>
<!-- @slot Slot for passing a material design icon. Precedes the icon and name prop. -->
<slot name="icon">
<span :class="icon" class="icon" />
</slot>
</template>
<template v-else #default>
{{ name }}
</template>
</NcButton>
<NcActions v-if="$slots.default"
ref="actions"
type="tertiary"
Expand All @@ -75,6 +80,7 @@ This component is meant to be used inside a Breadcrumbs component.
<script>
import NcActions from '../NcActions/index.js'
import GenRandomId from '../../utils/GenRandomId.js'
import NcButton from '../NcButton/NcButton.vue'

import ChevronRight from 'vue-material-design-icons/ChevronRight.vue'

Expand All @@ -83,6 +89,7 @@ export default {
components: {
NcActions,
ChevronRight,
NcButton,
},
inheritAttrs: false,
props: {
Expand Down Expand Up @@ -179,21 +186,17 @@ export default {
}
},
computed: {
/**
* Determines which element tag to use
*
* @return {string} the tag
*/
tag() {
return this.to ? 'router-link' : 'a'
},

/**
* The attributes to pass to `router-link` or `a`
*/
linkAttributes() {
// If it's a router-link, we pass `to` and `exact`, otherwise only `href`
return this.to ? { to: this.to, exact: this.exact, ...this.$attrs } : { href: this.href, ...this.$attrs }
// If it's a router-link, we pass `to` and `exact`, if its an <a/> element, we pass `href`, otherwise we have a button
return this.to
? { to: this.to, exact: this.exact, ...this.$attrs }
: (this.href
? { href: this.href, ...this.$attrs }
: this.$attrs
)
},
},
methods: {
Expand Down Expand Up @@ -284,7 +287,6 @@ export default {
padding: 0;

&:last-child {
font-weight: bold;
min-width: 0;

// Don't show breadcrumb separator for last crumb
Expand All @@ -293,44 +295,36 @@ export default {
}
}

// Hover and focus effect for crumbs
& > a:hover,
& > a:focus {
background-color: var(--color-background-dark);
color: var(--color-main-text);
}

// Necessary to hide hidden crumbs
&--hidden {
display: none;
}

&#{&}--hovered > a {
background-color: var(--color-background-dark);
color: var(--color-main-text);
}

&__separator {
padding: 0;
color: var(--color-text-maxcontrast);
}

> a {
overflow: hidden;
// Necessary for indicating hovering for drag and drop
&#{&}--hovered :deep(.button-vue) {
background-color: var(--color-background-dark);
color: var(--color-main-text);
}
// Adjust button style
&:not(:last-child) :deep() .button-vue {
color: var(--color-text-maxcontrast);
padding: 12px;
min-width: $clickable-area;
max-width: 100%;
border-radius: var(--border-radius-pill);
align-items: center;
display: inline-flex;
justify-content: center;

> span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
&:hover,
&:focus {
background-color: var(--color-background-dark);
color: var(--color-main-text);
}

&__text {
font-weight: normal;
}
}
:deep(.button-vue__text) {
margin: 0;
}

// Adjust action item appearance for crumbs with actions
// to match other crumbs
Expand Down