Skip to content

Commit

Permalink
feat(Breadcrumb): handle labelClass and merge iconClass
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Dec 12, 2023
1 parent a79f7c0 commit f623ec1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/content/5.navigation/5.breadcrumb.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ description: A list of links that indicate the current page's location within a
Pass an array to the `links` prop of the Breadcrumb component. Each link can have the following properties:

- `label` - The label of the link.
- `labelClass` - The class of the link label. :u-badge{label="New" class="!rounded-full" variant="subtle"}
- `icon` - The icon of the link.
- `iconClass` - The class of the icon link.
- `iconClass` - The class of the link icon.

You can also pass any property from the [NuxtLink](https://nuxt.com/docs/api/components/nuxt-link#props) component such as `to`, `exact`, etc.

Expand Down
11 changes: 7 additions & 4 deletions src/runtime/components/navigation/Breadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
<ULink
as="span"
:class="[ui.base, index === links.length - 1 ? ui.active : !!link.to ? ui.inactive : '']"
v-bind="omit(link, ['label', 'icon', 'iconClass'])"
v-bind="omit(link, ['label', 'labelClass', 'icon', 'iconClass'])"
:aria-current="index === links.length - 1 ? 'page' : undefined"
>
<slot name="icon" :link="link" :index="index" :is-active="index === links.length - 1">
<UIcon
v-if="link.icon"
:name="link.icon"
:class="[ui.icon.base, index === links.length - 1 ? ui.icon.active : !!link.to ? ui.icon.inactive : '', link.iconClass]"
:class="twMerge(twJoin(ui.icon.base, index === links.length - 1 ? ui.icon.active : !!link.to ? ui.icon.inactive : ''), link.iconClass)"
/>
</slot>

<slot :link="link" :index="index" :is-active="index === links.length - 1">
{{ link.label }}
<span v-if="link.label" :class="twMerge(ui.label, link.labelClass)">{{ link.label }}</span>
</slot>
</ULink>

Expand All @@ -35,6 +35,7 @@
<script lang="ts">
import { defineComponent, toRef } from 'vue'
import type { PropType } from 'vue'
import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue'
import ULink from '../elements/Link.vue'
import { useUI } from '../../composables/useUI'
Expand Down Expand Up @@ -77,7 +78,9 @@ export default defineComponent({
// eslint-disable-next-line vue/no-dupe-keys
ui,
attrs,
omit
omit,
twMerge,
twJoin
}
}
})
Expand Down
1 change: 1 addition & 0 deletions src/runtime/types/breadcrumb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Link } from './link'

export interface BreadcrumbLink extends Link {
label: string
labelClass?: string
icon?: string
iconClass?: string
// FIXME: This is a workaround for `link.to` not being resolved although it extends `NuxtLinkProps`
Expand Down
1 change: 1 addition & 0 deletions src/runtime/ui.config/navigation/breadcrumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default {
ol: 'flex items-center gap-x-1.5',
li: 'flex items-center gap-x-1.5 text-gray-500 dark:text-gray-400 text-sm',
base: 'flex items-center gap-x-1.5 group font-semibold',
label: '',
icon: {
base: 'flex-shrink-0 w-4 h-4',
active: '',
Expand Down

1 comment on commit f623ec1

@vercel
Copy link

@vercel vercel bot commented on f623ec1 Dec 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

ui – ./

ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com
ui-nuxt-js.vercel.app

Please sign in to comment.