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

VL-29_UBreadcrumbs-new-component_Vitalii-Dudnik #342

Merged
merged 28 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
78c2438
Add new "UBreadcrumbs" component
KinduD21 Jan 16, 2025
d76d517
Remove comment
KinduD21 Jan 16, 2025
bf08e23
Adjust URL markdown
KinduD21 Jan 16, 2025
19313c8
Adjust story description
KinduD21 Jan 16, 2025
1e3f34d
Merge branch 'main' into VL-29_UBreadcrumbs-new-component_Vitalii-Dudnik
KinduD21 Jan 16, 2025
da315fc
Adjust story text
KinduD21 Jan 16, 2025
0296535
Remove comment from the component
KinduD21 Jan 17, 2025
8ca1205
Add markdown table with link object properties for UBreadcrumbs, upda…
KinduD21 Jan 17, 2025
0e23693
Update slots story
KinduD21 Jan 17, 2025
fc5f6ca
Update styles story description
KinduD21 Jan 17, 2025
1154a4f
Pass icon name to divider slot
KinduD21 Jan 17, 2025
c8a72d2
Add separate slots for UBreadcrumbs component (as left and right slot…
KinduD21 Jan 17, 2025
c7a8704
Add last item in array check for divider slot
KinduD21 Jan 17, 2025
f3f7eaa
Add label slot
KinduD21 Jan 17, 2025
eaad2bf
Merge branch 'main' into VL-29_UBreadcrumbs-new-component_Vitalii-Dudnik
KinduD21 Jan 17, 2025
aa230e3
Remove redundant ULink props from UBreadcrumbs
KinduD21 Jan 17, 2025
63b48a6
Rename config keys, remove slots' wrappers
KinduD21 Jan 18, 2025
bd6be7f
Merge branch 'main' into VL-29_UBreadcrumbs-new-component_Vitalii-Dudnik
KinduD21 Jan 20, 2025
5b36852
Change left slot name, update config defaults & stories
KinduD21 Jan 20, 2025
592de11
Update slotProps for ULink, add ULinkSlotProps type
KinduD21 Jan 21, 2025
3318a5a
Adjust slots' docs
KinduD21 Jan 21, 2025
d581f28
Update MD docs
KinduD21 Jan 21, 2025
ea59a66
Small adjustments for slot's props
KinduD21 Jan 21, 2025
2514d91
Merge branch 'main' into VL-29_UBreadcrumbs-new-component_Vitalii-Dudnik
KinduD21 Jan 21, 2025
79b66c1
Update slot's docs
KinduD21 Jan 21, 2025
c780018
Add margin-right for each breadcrumb (to add more space after arrow i…
KinduD21 Jan 21, 2025
addaa2b
Update keys in config
KinduD21 Jan 21, 2025
ca439c6
Merge branch 'main' into VL-29_UBreadcrumbs-new-component_Vitalii-Dudnik
KinduD21 Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/ui.button-link/ULink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getDefaults } from "../utils/ui.ts";
import defaultConfig from "./config.ts";
import { COMPONENT_NAME } from "./constants.ts";

import type { Props, Config } from "./types.ts";
import type { Props, Config, ULinkSlotProps } from "./types.ts";

defineOptions({ inheritAttrs: false });

Expand Down Expand Up @@ -101,6 +101,7 @@ const { getDataTest, linkAttrs } = useUI<Config>(defaultConfig, mutatedProps);
<template>
<router-link
v-if="isPresentRoute"
v-slot="slotProps: ULinkSlotProps"
:to="safeTo"
:custom="custom"
:replace="replace"
Expand All @@ -118,8 +119,14 @@ const { getDataTest, linkAttrs } = useUI<Config>(defaultConfig, mutatedProps);
@keydown="onKeydown"
@mouseover="onMouseover"
>
<!-- @slot Use it replace the label. -->
<slot>{{ label }}</slot>
<!--
@slot Use it replace the label.
@binding {boolean} is-active
@binding {boolean} is-exact-active
-->
<slot :is-active="slotProps.isActive" :is-exact-active="slotProps.isExactActive">{{
label
}}</slot>
Copy link
Contributor

@itsJohnnyGrid itsJohnnyGrid Jan 21, 2025

Choose a reason for hiding this comment

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

<slot :is-active="slotProps.isActive" :is-exact-active="slotProps.isExactActive">
  {{ label }}
</slot>

</router-link>

<a
Expand Down
8 changes: 5 additions & 3 deletions src/ui.button-link/storybook/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ const DefaultTemplate: StoryFn<ULinkArgs> = (args: ULinkArgs) => ({
return { args, slots };
},
template: `
<ULink v-if="args.block" v-bind="args" :config="{ wrapper: 'border-2 border-dashed border-green-500 p-2' }">
${args.slotTemplate || getSlotsFragment("")}
</ULink>
<div v-if="args.block" class="border-2 border-dashed border-green-500 p-2">
<ULink v-bind="args">
${args.slotTemplate || getSlotsFragment("")}
</ULink>
</div>
<ULink v-else v-bind="args">
${args.slotTemplate || getSlotsFragment("")}
</ULink>
Expand Down
5 changes: 5 additions & 0 deletions src/ui.button-link/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type { RouteLocationRaw } from "vue-router";

export type Config = typeof defaultConfig;

export interface ULinkSlotProps {
isActive: boolean;
isExactActive: boolean;
}

export interface Props {
/**
* Button label.
Expand Down
58 changes: 27 additions & 31 deletions src/ui.navigation-breadcrumbs/UBreadcrumbs.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { computed } from "vue";
import { useRoute } from "vue-router";

import useUI from "../composables/useUI.ts";
import { getDefaults } from "../utils/ui.ts";
Expand All @@ -12,6 +11,7 @@ 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 });

Expand All @@ -28,20 +28,10 @@ const emit = defineEmits([
"clickLink",
]);

const route = useRoute();

const getIconColor = computed(() => {
return (link: UBreadcrumb) => (link.disabled || (!link.to && !link.href) ? "gray" : props.color);
});

const isLinkActive = computed(() => {
return (index: number) => {
const link = props.links[index];

return route.path === link.to;
};
});

function onClickLink(link: UBreadcrumb) {
emit("clickLink", link);
}
Expand All @@ -64,12 +54,11 @@ const {
<div v-bind="breadcrumbsAttrs">
<div v-for="(link, index) in links" :key="index" v-bind="breadcrumbAttrs">
<!--
@slot Use it to add something instead of a link icon.
@binding {string} icon-name
@binding {number} index
@binding {boolean} active
-->
<slot name="left" :icon-name="link.icon" :index="index" :active="isLinkActive(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"
Expand All @@ -84,7 +73,7 @@ const {
:to="link.to"
:size="size"
:color="color"
:target-blank="targetBlank"
:target="link.target || target"
:custom="link.custom"
:replace="link.replace"
:active-class="link.activeClass"
Expand All @@ -98,27 +87,34 @@ const {
:data-test="dataTest"
@click="onClickLink(link)"
>
<!--
@slot Use it to add something instead of a link label.
@binding {string} label
@binding {number} index
@binding {boolean} active
-->
<slot name="label" :label="link.label" :index="index" :active="isLinkActive(index)" />
<template #default="slotProps">
Copy link
Contributor

Choose a reason for hiding this comment

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

v-slot="slotProps: ULinkSlotProps"

<!--
@slot Use it to add something instead of a link label.
@binding {string} label
@binding {number} index
@binding {boolean} active
-->
<slot
name="label"
:label="link.label"
:index="index"
:active="
(slotProps as ULinkSlotProps).isActive || (slotProps as ULinkSlotProps).isExactActive
Copy link
Contributor

Choose a reason for hiding this comment

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

I this pass values in different props will be better.

:active="slotProps.isActive"
:exact-active="slotProps.isExactActive"

"
/>
</template>
</ULink>

<!--
@slot Use it to add something instead of the divider.
@binding {string} icon-name
@binding {number} index
@binding {boolean} active
-->
@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"
:active="isLinkActive(index)"
>
<UIcon
v-if="links.length !== index + 1"
Expand Down
2 changes: 1 addition & 1 deletion src/ui.navigation-breadcrumbs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default /*tw*/ {
size: "md",
underlined: undefined,
dashed: false,
targetBlank: false,
target: "_self",
dividerIcon: "arrow_right",
},
};
1 change: 1 addition & 0 deletions src/ui.navigation-breadcrumbs/storybook/docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Keys you may/have to provide to the component in a `link` 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 |
Expand Down
10 changes: 5 additions & 5 deletions src/ui.navigation-breadcrumbs/storybook/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export default {
component: UBreadcrumbs,
args: {
links: [
{ label: "Main", href: "https://vueless.com/" },
{ label: "Category", href: "https://docs.vueless.com/" },
{ label: "Product", href: "https://ui.vueless.com/" },
{ label: "Vueless Docs", href: "https://docs.vueless.com/" },
{ label: "Global Customization", href: "https://docs.vueless.com/global-customization/" },
{ label: "Rounding", href: "https://docs.vueless.com/global-customization/rounding" },
],
targetBlank: true,
target: "_blank",
},
argTypes: {
...getArgTypes(UBreadcrumbs.__name),
Expand Down Expand Up @@ -131,7 +131,7 @@ export const Slots: StoryFn<UBreadcrumbsArgs> = (args) => ({
},
template: `
<UBreadcrumbs v-bind="args">
<template #left="{ index }">
<template #icon="{ index }">
<UBadge
v-if="index === 1"
label="Info"
Expand Down
4 changes: 2 additions & 2 deletions src/ui.navigation-breadcrumbs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export interface Props {
| "brand";

/**
* Open link in the new tab.
* Specifies where to open the linked page.
*/
targetBlank?: boolean;
target?: "_blank" | "_self" | "_parent" | "_top" | string;

/**
* Show underline.
Expand Down