-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from vuelessjs/VL-29_UBreadcrumbs-new-compone…
…nt_Vitalii-Dudnik VL-29_UBreadcrumbs-new-component_Vitalii-Dudnik
- Loading branch information
Showing
12 changed files
with
453 additions
and
3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<script setup lang="ts"> | ||
import { computed } from "vue"; | ||
import useUI from "../composables/useUI.ts"; | ||
import { getDefaults } from "../utils/ui.ts"; | ||
import defaultConfig from "./config.ts"; | ||
import { COMPONENT_NAME } from "./constants.ts"; | ||
import ULink from "../ui.button-link/ULink.vue"; | ||
import UIcon from "../ui.image-icon/UIcon.vue"; | ||
import type { Props, Config, UBreadcrumb } from "./types.ts"; | ||
import type { ULinkSlotProps } from "../ui.button-link/types.ts"; | ||
defineOptions({ inheritAttrs: false }); | ||
const props = withDefaults(defineProps<Props>(), { | ||
...getDefaults<Props, Config>(defaultConfig, COMPONENT_NAME), | ||
links: () => [], | ||
}); | ||
const emit = defineEmits([ | ||
/** | ||
* Triggers on a link click. | ||
* @property {object} link | ||
*/ | ||
"clickLink", | ||
]); | ||
const getIconColor = computed(() => { | ||
return (link: UBreadcrumb) => (link.disabled || (!link.to && !link.href) ? "gray" : props.color); | ||
}); | ||
function onClickLink(link: UBreadcrumb) { | ||
emit("clickLink", link); | ||
} | ||
/** | ||
* Get element / nested component attributes for each config token ✨ | ||
* Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes. | ||
*/ | ||
const { config, breadcrumbsAttrs, breadcrumbLinkAttrs, breadcrumbIconAttrs, dividerIconAttrs } = | ||
useUI<Config>(defaultConfig); | ||
</script> | ||
|
||
<template> | ||
<div v-bind="breadcrumbsAttrs"> | ||
<template v-for="(link, index) in links" :key="index"> | ||
<!-- | ||
@slot Use it to add something instead of a link icon. | ||
@binding {string} icon-name | ||
@binding {number} index | ||
--> | ||
<slot name="icon" :icon-name="link.icon" :index="index"> | ||
<UIcon | ||
v-if="link.icon" | ||
:name="link.icon" | ||
:color="getIconColor(link)" | ||
v-bind="breadcrumbIconAttrs" | ||
/> | ||
</slot> | ||
|
||
<ULink | ||
:label="link.label" | ||
:href="link.href" | ||
:to="link.to" | ||
:size="size" | ||
:color="color" | ||
:target="link.target || target" | ||
:custom="link.custom" | ||
:replace="link.replace" | ||
:active-class="link.activeClass" | ||
:exact-active-class="link.exactActiveClass" | ||
:aria-current-value="link.ariaCurrentValue" | ||
:underlined="underlined" | ||
:dashed="dashed" | ||
:disabled="link.disabled || (!link.to && !link.href)" | ||
:ring="false" | ||
v-bind="breadcrumbLinkAttrs" | ||
:data-test="dataTest" | ||
@click="onClickLink(link)" | ||
> | ||
<template #default="slotProps"> | ||
<!-- | ||
@slot Use it to add something instead of a link label. | ||
@binding {string} label | ||
@binding {number} index | ||
@binding {boolean} active | ||
@binding {boolean} exact-active | ||
--> | ||
<slot | ||
name="label" | ||
:label="link.label" | ||
:index="index" | ||
:active="(slotProps as ULinkSlotProps).isActive" | ||
:exact-active="(slotProps as ULinkSlotProps).isExactActive" | ||
/> | ||
</template> | ||
</ULink> | ||
|
||
<!-- | ||
@slot Use it to add something instead of the divider. | ||
@binding {string} icon-name | ||
@binding {number} index | ||
--> | ||
<slot | ||
v-if="links.length !== index + 1" | ||
name="divider" | ||
:icon-name="config.defaults.dividerIcon" | ||
:index="index" | ||
> | ||
<UIcon | ||
v-if="links.length !== index + 1" | ||
:name="config.defaults.dividerIcon" | ||
:color="getIconColor(link)" | ||
v-bind="dividerIconAttrs" | ||
/> | ||
</slot> | ||
</template> | ||
</div> | ||
</template> |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export default /*tw*/ { | ||
breadcrumbs: "flex items-center gap-1 py-2", | ||
breadcrumbLink: "{ULink}", | ||
breadcrumbIcon: { | ||
base: "{UIcon}", | ||
defaults: { | ||
size: { | ||
sm: "2xs", | ||
md: "xs", | ||
lg: "sm", | ||
}, | ||
}, | ||
}, | ||
dividerIcon: { | ||
base: "{UIcon}", | ||
defaults: { | ||
size: { | ||
sm: "xs", | ||
md: "sm", | ||
lg: "md", | ||
}, | ||
}, | ||
}, | ||
defaults: { | ||
color: "grayscale", | ||
size: "md", | ||
underlined: undefined, | ||
dashed: false, | ||
target: "_self", | ||
dividerIcon: "arrow_right", | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* | ||
This const is needed to prevent the issue in script setup: | ||
`defineProps` is referencing locally declared variables. (vue/valid-define-props) | ||
*/ | ||
export const COMPONENT_NAME = "UBreadcrumbs"; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Markdown, Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks"; | ||
import { getSource } from "../../utils/storybook.ts"; | ||
|
||
import * as stories from "./stories.ts"; | ||
import defaultConfig from "../config.ts?raw" | ||
|
||
<Meta of={stories} /> | ||
<Title of={stories} /> | ||
<Subtitle of={stories} /> | ||
<Description of={stories} /> | ||
<Primary of={stories} /> | ||
<Controls of={stories.Default} /> | ||
<Stories of={stories} /> | ||
|
||
## Breadcrumb Link Object Properties | ||
Keys you may/have to provide to the component in a `link` object. | ||
|
||
<Markdown> | ||
{` | ||
| Key name | Description | Type | | ||
| ---------------------- | ----------------------------------------------------- | ----------------------- | | ||
| label | Link label | String | | ||
| route | Route object | Object | | ||
| href | Link URL | String | | ||
| disabled | Used to disable link | Boolean | | ||
| icon | Icon name | String | | ||
| target | Specifies where to open the linked page. | String | | ||
| custom | Whether RouterLink should not wrap content in a tag | Boolean | | ||
| replace | Whether to replace current history entry | Boolean | | ||
| activeClass | Classes to apply when route is active | String | | ||
| exactActiveClass | Classes to apply when route is exactly active | String | | ||
| ariaCurrentValue | Value for aria-current when link is exact active | String | | ||
`} | ||
</Markdown> | ||
|
||
## Default config | ||
<Source code={getSource(defaultConfig)} language="jsx" dark /> |
Oops, something went wrong.