-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add component classes to breadcrumbs (#19)
- Loading branch information
Showing
5 changed files
with
938 additions
and
931 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,40 @@ | ||
<template> | ||
<nav :aria-label="ariaLabel"> | ||
<h2 class="sr-only">{{ ariaLabel }} </h2> | ||
<div class="flex space-x-8"> | ||
<div :class="ccBreadcrumbs.wrapper"> | ||
<breadcrumbify> | ||
<slot /> | ||
</breadcrumbify> | ||
</div> | ||
</nav> | ||
</template> | ||
|
||
<script> | ||
<script setup> | ||
import { h, Fragment } from 'vue' | ||
import { interleave } from '@fabric-ds/core/breadcrumbs' | ||
import { interleave } from '@warp-ds/core/breadcrumbs' | ||
import { breadcrumbs as ccBreadcrumbs } from "@warp-ds/component-classes" | ||
const props = defineProps({ | ||
ariaLabel: { type: String, default: 'Her er du' } | ||
}); | ||
export const wBreadcrumbSeparator = h('span', { ariaHidden: true, class: 'select-none' }, '/') | ||
const isFragment = vnode => vnode.type === Fragment | ||
const collectElements = (vnodes = []) => vnodes?.map(vnode => isFragment(vnode) ? collectElements(vnode.children) : vnode) | ||
const Breadcrumbify = (_, context) => { | ||
const slot = context.slots.default() | ||
const vnodes = slot[0].children | ||
const elements = collectElements(vnodes).flat(Infinity) | ||
return interleave(elements, wBreadcrumbSeparator) | ||
} | ||
const styledElements = elements.map(el => { | ||
const ccClasses = el.type === "a" ? ccBreadcrumbs.link : ccBreadcrumbs.text | ||
el.props.class = el.props.class ? `${el.props.class} ${ccClasses}` : ccClasses | ||
// because most of the logic is in Breadcrumbify | ||
// there's no reason to script-setup this component | ||
export default { | ||
name: 'wBreadcrumbs', | ||
components: { Breadcrumbify }, | ||
props: { | ||
ariaLabel: { type: String, default: 'Her er du' } | ||
} | ||
return el | ||
}) | ||
return interleave(styledElements, wBreadcrumbSeparator) | ||
} | ||
</script> | ||
<script> | ||
export const wBreadcrumbSeparator = h('span', { ariaHidden: true, class: ccBreadcrumbs.separator }, '/') | ||
export default { name: 'wBreadcrumbs' } | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.