@aleph-alpha/ui-library 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/system/index.d.ts +545 -329
- package/dist/system/lib.js +18800 -18015
- package/package.json +1 -1
- package/src/components/UiIconButton/UiIconButton.vue +5 -1
- package/src/components/UiIconButton/types.ts +1 -1
- package/src/components/core/button/index.ts +6 -4
- package/src/components/core/sidebar/SidebarContent.vue +11 -3
- package/src/components/core/sidebar/SidebarFooter.vue +10 -2
- package/src/components/core/sidebar/SidebarGroup.vue +10 -2
- package/src/components/core/sidebar/SidebarGroupLabel.vue +1 -1
- package/src/components/core/sidebar/SidebarHeader.vue +10 -2
- package/src/components/core/sidebar/SidebarMenu.vue +12 -2
- package/src/components/core/sidebar/SidebarMenuButton.vue +2 -2
- package/src/components/core/sidebar/SidebarSeparator.vue +10 -2
- package/src/components/core/sidebar/SidebarTrigger.vue +2 -2
- package/src/components/core/sidebar/index.ts +1 -1
- package/src/components/core/sidebar/utils.ts +11 -2
- package/src/components/index.ts +0 -1
- package/src/directives/index.ts +1 -0
- package/src/directives/vOverlay.ts +94 -0
- package/src/patterns/UiSidebar/UiSidebar.stories.ts +346 -0
- package/src/{components → patterns}/UiSidebar/UiSidebar.vue +9 -3
- package/src/patterns/UiSidebar/UiSidebarChatHistory.stories.ts +77 -0
- package/src/patterns/UiSidebar/UiSidebarChatHistory.vue +35 -0
- package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.stories.ts +85 -0
- package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.vue +139 -0
- package/src/patterns/UiSidebar/UiSidebarContent.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarFooter.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarGroup.stories.ts +91 -0
- package/src/patterns/UiSidebar/UiSidebarGroup.vue +42 -0
- package/src/patterns/UiSidebar/UiSidebarGroupContent.vue +15 -0
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +163 -0
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.vue +131 -0
- package/src/patterns/UiSidebar/UiSidebarHeader.vue +48 -0
- package/src/patterns/UiSidebar/UiSidebarInset.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarMenu.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +205 -0
- package/src/patterns/UiSidebar/UiSidebarMenuButton.vue +121 -0
- package/src/patterns/UiSidebar/UiSidebarMenuItem.stories.ts +67 -0
- package/src/patterns/UiSidebar/UiSidebarMenuItem.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarMenuSub.vue +38 -0
- package/src/patterns/UiSidebar/UiSidebarMenuSubItem.stories.ts +66 -0
- package/src/patterns/UiSidebar/UiSidebarMenuSubItem.vue +67 -0
- package/src/patterns/UiSidebar/UiSidebarPopover.vue +43 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenu.stories.ts +56 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenu.vue +56 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.stories.ts +42 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.vue +79 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.stories.ts +61 -0
- package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.vue +81 -0
- package/src/patterns/UiSidebar/UiSidebarProvider.vue +11 -0
- package/src/patterns/UiSidebar/UiSidebarRail.vue +9 -0
- package/src/patterns/UiSidebar/UiSidebarTrigger.vue +35 -0
- package/src/patterns/UiSidebar/groupContext.ts +9 -0
- package/src/patterns/UiSidebar/index.ts +42 -0
- package/src/patterns/UiSidebar/types.ts +375 -0
- package/src/patterns/index.ts +1 -0
- package/src/components/UiSidebar/UiSidebar.stories.ts +0 -1188
- package/src/components/UiSidebar/UiSidebarGroupAction.vue +0 -18
- package/src/components/UiSidebar/UiSidebarGroupLabel.vue +0 -18
- package/src/components/UiSidebar/UiSidebarHeaderTrigger.vue +0 -53
- package/src/components/UiSidebar/UiSidebarInput.vue +0 -14
- package/src/components/UiSidebar/UiSidebarMenuAction.vue +0 -19
- package/src/components/UiSidebar/UiSidebarMenuButton.vue +0 -27
- package/src/components/UiSidebar/UiSidebarMenuSkeleton.vue +0 -16
- package/src/components/UiSidebar/UiSidebarMenuSubButton.vue +0 -24
- package/src/components/UiSidebar/UiSidebarProvider.vue +0 -16
- package/src/components/UiSidebar/UiSidebarSeparator.vue +0 -13
- package/src/components/UiSidebar/__tests__/UiSidebar.test.ts +0 -221
- package/src/components/UiSidebar/index.ts +0 -34
- package/src/components/UiSidebar/types.ts +0 -165
package/package.json
CHANGED
|
@@ -29,9 +29,13 @@
|
|
|
29
29
|
link: 'link',
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
const sizeMap: Record<
|
|
32
|
+
const sizeMap: Record<
|
|
33
|
+
'icon' | 'icon-sm' | 'icon-sm-no-padding' | 'icon-lg',
|
|
34
|
+
'icon' | 'icon-sm' | 'icon-sm-no-padding' | 'icon-lg'
|
|
35
|
+
> = {
|
|
33
36
|
icon: 'icon',
|
|
34
37
|
'icon-sm': 'icon-sm',
|
|
38
|
+
'icon-sm-no-padding': 'icon-sm-no-padding',
|
|
35
39
|
'icon-lg': 'icon-lg',
|
|
36
40
|
};
|
|
37
41
|
|
|
@@ -12,7 +12,7 @@ export type UiIconButtonVariant =
|
|
|
12
12
|
/**
|
|
13
13
|
* Size variants for UiIconButton.
|
|
14
14
|
*/
|
|
15
|
-
export type UiIconButtonSize = 'icon' | 'icon-sm' | 'icon-lg';
|
|
15
|
+
export type UiIconButtonSize = 'icon' | 'icon-sm' | 'icon-sm-no-padding' | 'icon-lg';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* A button that displays only an icon without text. Use for compact
|
|
@@ -14,7 +14,7 @@ export const buttonVariants = cva(
|
|
|
14
14
|
outline: 'border border-input bg-transparent text-foreground shadow-xs',
|
|
15
15
|
secondary: 'bg-secondary text-secondary-foreground',
|
|
16
16
|
ghost:
|
|
17
|
-
'text-foreground hover:border-border-button-outlined focus-visible:border-border-button-outlined',
|
|
17
|
+
'rounded-sm text-foreground hover:border-border-button-outlined focus-visible:border-border-button-outlined',
|
|
18
18
|
link: 'text-link overlay-link-hover-subtle',
|
|
19
19
|
},
|
|
20
20
|
size: {
|
|
@@ -24,13 +24,15 @@ export const buttonVariants = cva(
|
|
|
24
24
|
lg: 'h-10 rounded-md px-6 has-[>svg]:px-4',
|
|
25
25
|
icon: 'size-9',
|
|
26
26
|
'icon-sm': 'size-8',
|
|
27
|
+
'icon-sm-no-padding': 'size-4',
|
|
27
28
|
'icon-lg': 'size-10',
|
|
28
29
|
},
|
|
29
30
|
},
|
|
30
31
|
compoundVariants: [
|
|
31
|
-
{ variant: 'ghost', size: 'icon', class: 'size-auto' },
|
|
32
|
-
{ variant: 'ghost', size: 'icon-sm', class: 'size-
|
|
33
|
-
{ variant: 'ghost', size: 'icon-
|
|
32
|
+
{ variant: 'ghost', size: 'icon', class: 'size-auto p-2' },
|
|
33
|
+
{ variant: 'ghost', size: 'icon-sm', class: 'size-6 p-1' },
|
|
34
|
+
{ variant: 'ghost', size: 'icon-sm-no-padding', class: 'size-4 p-0' },
|
|
35
|
+
{ variant: 'ghost', size: 'icon-lg', class: 'size-auto p-3' },
|
|
34
36
|
],
|
|
35
37
|
defaultVariants: {
|
|
36
38
|
variant: 'default',
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, useAttrs } from 'vue';
|
|
2
3
|
import { cn } from '@/lib/utils';
|
|
3
4
|
|
|
4
5
|
defineOptions({ inheritAttrs: false });
|
|
6
|
+
|
|
7
|
+
const attrs = useAttrs();
|
|
8
|
+
const passthroughAttrs = computed(() => {
|
|
9
|
+
const { class: _c, ...rest } = attrs as Record<string, unknown>;
|
|
10
|
+
return rest;
|
|
11
|
+
});
|
|
12
|
+
const attrClass = computed(() => (attrs.class as string | undefined) ?? '');
|
|
5
13
|
</script>
|
|
6
14
|
|
|
7
15
|
<template>
|
|
8
16
|
<div
|
|
9
|
-
v-bind="
|
|
17
|
+
v-bind="passthroughAttrs"
|
|
10
18
|
data-slot="sidebar-content"
|
|
11
19
|
data-sidebar="content"
|
|
12
20
|
:class="
|
|
13
21
|
cn(
|
|
14
|
-
'flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden',
|
|
15
|
-
|
|
22
|
+
'flex min-h-0 flex-1 flex-col gap-2 overflow-auto p-2 group-data-[collapsible=icon]:overflow-hidden',
|
|
23
|
+
attrClass,
|
|
16
24
|
)
|
|
17
25
|
"
|
|
18
26
|
>
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, useAttrs } from 'vue';
|
|
2
3
|
import { cn } from '@/lib/utils';
|
|
3
4
|
|
|
4
5
|
defineOptions({ inheritAttrs: false });
|
|
6
|
+
|
|
7
|
+
const attrs = useAttrs();
|
|
8
|
+
const passthroughAttrs = computed(() => {
|
|
9
|
+
const { class: _c, ...rest } = attrs as Record<string, unknown>;
|
|
10
|
+
return rest;
|
|
11
|
+
});
|
|
12
|
+
const attrClass = computed(() => (attrs.class as string | undefined) ?? '');
|
|
5
13
|
</script>
|
|
6
14
|
|
|
7
15
|
<template>
|
|
8
16
|
<div
|
|
9
|
-
v-bind="
|
|
17
|
+
v-bind="passthroughAttrs"
|
|
10
18
|
data-slot="sidebar-footer"
|
|
11
19
|
data-sidebar="footer"
|
|
12
|
-
:class="cn('flex flex-col gap-2 p-2',
|
|
20
|
+
:class="cn('flex flex-col gap-2 p-2', attrClass)"
|
|
13
21
|
>
|
|
14
22
|
<slot />
|
|
15
23
|
</div>
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, useAttrs } from 'vue';
|
|
2
3
|
import { cn } from '@/lib/utils';
|
|
3
4
|
|
|
4
5
|
defineOptions({ inheritAttrs: false });
|
|
6
|
+
|
|
7
|
+
const attrs = useAttrs();
|
|
8
|
+
const passthroughAttrs = computed(() => {
|
|
9
|
+
const { class: _c, ...rest } = attrs as Record<string, unknown>;
|
|
10
|
+
return rest;
|
|
11
|
+
});
|
|
12
|
+
const attrClass = computed(() => (attrs.class as string | undefined) ?? '');
|
|
5
13
|
</script>
|
|
6
14
|
|
|
7
15
|
<template>
|
|
8
16
|
<div
|
|
9
|
-
v-bind="
|
|
17
|
+
v-bind="passthroughAttrs"
|
|
10
18
|
data-slot="sidebar-group"
|
|
11
19
|
data-sidebar="group"
|
|
12
|
-
:class="cn('relative flex w-full min-w-0 flex-col p-
|
|
20
|
+
:class="cn('relative flex w-full min-w-0 flex-col gap-2 p-0', attrClass)"
|
|
13
21
|
>
|
|
14
22
|
<slot />
|
|
15
23
|
</div>
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
:class="
|
|
14
14
|
cn(
|
|
15
15
|
'text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
16
|
-
'group-data-[collapsible=icon]
|
|
16
|
+
'group-data-[collapsible=icon]:hidden',
|
|
17
17
|
$attrs.class ?? '',
|
|
18
18
|
)
|
|
19
19
|
"
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, useAttrs } from 'vue';
|
|
2
3
|
import { cn } from '@/lib/utils';
|
|
3
4
|
|
|
4
5
|
defineOptions({ inheritAttrs: false });
|
|
6
|
+
|
|
7
|
+
const attrs = useAttrs();
|
|
8
|
+
const passthroughAttrs = computed(() => {
|
|
9
|
+
const { class: _c, ...rest } = attrs as Record<string, unknown>;
|
|
10
|
+
return rest;
|
|
11
|
+
});
|
|
12
|
+
const attrClass = computed(() => (attrs.class as string | undefined) ?? '');
|
|
5
13
|
</script>
|
|
6
14
|
|
|
7
15
|
<template>
|
|
8
16
|
<div
|
|
9
|
-
v-bind="
|
|
17
|
+
v-bind="passthroughAttrs"
|
|
10
18
|
data-slot="sidebar-header"
|
|
11
19
|
data-sidebar="header"
|
|
12
|
-
:class="cn('flex flex-col gap-2 p-2',
|
|
20
|
+
:class="cn('flex flex-col gap-2 p-2', attrClass)"
|
|
13
21
|
>
|
|
14
22
|
<slot />
|
|
15
23
|
</div>
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, useAttrs } from 'vue';
|
|
2
3
|
import { cn } from '@/lib/utils';
|
|
3
4
|
|
|
4
5
|
defineOptions({ inheritAttrs: false });
|
|
6
|
+
|
|
7
|
+
const attrs = useAttrs();
|
|
8
|
+
const passthroughAttrs = computed(() => {
|
|
9
|
+
const { class: _c, ...rest } = attrs as Record<string, unknown>;
|
|
10
|
+
return rest;
|
|
11
|
+
});
|
|
12
|
+
const attrClass = computed(() => (attrs.class as string | undefined) ?? '');
|
|
5
13
|
</script>
|
|
6
14
|
|
|
7
15
|
<template>
|
|
8
16
|
<ul
|
|
9
|
-
v-bind="
|
|
17
|
+
v-bind="passthroughAttrs"
|
|
10
18
|
data-slot="sidebar-menu"
|
|
11
19
|
data-sidebar="menu"
|
|
12
|
-
:class="
|
|
20
|
+
:class="
|
|
21
|
+
cn('flex w-full min-w-0 flex-col gap-1 group-data-[collapsible=icon]:items-center', attrClass)
|
|
22
|
+
"
|
|
13
23
|
>
|
|
14
24
|
<slot />
|
|
15
25
|
</ul>
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
<slot />
|
|
34
34
|
</SidebarMenuButtonChild>
|
|
35
35
|
|
|
36
|
-
<Tooltip
|
|
36
|
+
<Tooltip :disabled="state !== 'collapsed' || isMobile" :delay-duration="0">
|
|
37
37
|
<TooltipTrigger as-child>
|
|
38
38
|
<SidebarMenuButtonChild v-bind="{ ...delegatedProps, ...$attrs }">
|
|
39
39
|
<slot />
|
|
40
40
|
</SidebarMenuButtonChild>
|
|
41
41
|
</TooltipTrigger>
|
|
42
|
-
<TooltipContent side="right" align="center"
|
|
42
|
+
<TooltipContent side="right" align="center">
|
|
43
43
|
<template v-if="typeof tooltip === 'string'">
|
|
44
44
|
{{ tooltip }}
|
|
45
45
|
</template>
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, useAttrs } from 'vue';
|
|
2
3
|
import { cn } from '@/lib/utils';
|
|
3
4
|
import { Separator } from '@/components/core/separator';
|
|
4
5
|
|
|
5
6
|
defineOptions({ inheritAttrs: false });
|
|
7
|
+
|
|
8
|
+
const attrs = useAttrs();
|
|
9
|
+
const passthroughAttrs = computed(() => {
|
|
10
|
+
const { class: _c, ...rest } = attrs as Record<string, unknown>;
|
|
11
|
+
return rest;
|
|
12
|
+
});
|
|
13
|
+
const attrClass = computed(() => (attrs.class as string | undefined) ?? '');
|
|
6
14
|
</script>
|
|
7
15
|
|
|
8
16
|
<template>
|
|
9
17
|
<Separator
|
|
10
|
-
v-bind="
|
|
18
|
+
v-bind="passthroughAttrs"
|
|
11
19
|
data-slot="sidebar-separator"
|
|
12
20
|
data-sidebar="separator"
|
|
13
|
-
:class="cn('bg-sidebar-border mx-2 w-auto',
|
|
21
|
+
:class="cn('bg-sidebar-border mx-2 w-auto group-data-[collapsible=icon]:hidden', attrClass)"
|
|
14
22
|
>
|
|
15
23
|
<slot />
|
|
16
24
|
</Separator>
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
data-slot="sidebar-trigger"
|
|
17
17
|
variant="ghost"
|
|
18
18
|
size="icon"
|
|
19
|
+
aria-label="Toggle Sidebar"
|
|
19
20
|
:class="cn('h-7 w-7', $attrs.class ?? '')"
|
|
20
21
|
@click="toggleSidebar"
|
|
21
22
|
>
|
|
22
|
-
<PanelLeft />
|
|
23
|
-
<span class="sr-only">Toggle Sidebar</span>
|
|
23
|
+
<PanelLeft :size="16" />
|
|
24
24
|
</Button>
|
|
25
25
|
</template>
|
|
@@ -34,7 +34,7 @@ export { default as SidebarTrigger } from './SidebarTrigger.vue';
|
|
|
34
34
|
export { useSidebar } from './utils';
|
|
35
35
|
|
|
36
36
|
export const sidebarMenuButtonVariants = cva(
|
|
37
|
-
'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',
|
|
37
|
+
'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center! group-data-[collapsible=icon]:p-2! group-data-[collapsible=icon]:[&>svg~span]:hidden group-data-[collapsible=icon]:[&>span~svg]:hidden group-data-[collapsible=icon]:[&>div~*]:hidden [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',
|
|
38
38
|
{
|
|
39
39
|
variants: {
|
|
40
40
|
variant: {
|
|
@@ -8,7 +8,7 @@ export const SIDEBAR_WIDTH_MOBILE = '18rem';
|
|
|
8
8
|
export const SIDEBAR_WIDTH_ICON = '3rem';
|
|
9
9
|
export const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export type SidebarContextValue = {
|
|
12
12
|
state: ComputedRef<'expanded' | 'collapsed'>;
|
|
13
13
|
open: Ref<boolean>;
|
|
14
14
|
setOpen: (value: boolean) => void;
|
|
@@ -16,4 +16,13 @@ export const [useSidebar, provideSidebarContext] = createContext<{
|
|
|
16
16
|
openMobile: Ref<boolean>;
|
|
17
17
|
setOpenMobile: (value: boolean) => void;
|
|
18
18
|
toggleSidebar: () => void;
|
|
19
|
-
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const [useSidebar, provideSidebarContext] = createContext<SidebarContextValue>('Sidebar');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Same as `useSidebar()` when inside `SidebarProvider`, otherwise `null`.
|
|
25
|
+
*/
|
|
26
|
+
export function useSidebarOptional(): SidebarContextValue | null {
|
|
27
|
+
return useSidebar(null);
|
|
28
|
+
}
|
package/src/components/index.ts
CHANGED
package/src/directives/index.ts
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { DirectiveBinding, ObjectDirective } from 'vue';
|
|
2
|
+
import type { VHoverVariant } from './vHover';
|
|
3
|
+
|
|
4
|
+
const OVERLAY_EL = Symbol('vOverlayOverlayEl');
|
|
5
|
+
|
|
6
|
+
type VOverlayBinding =
|
|
7
|
+
| VHoverVariant
|
|
8
|
+
| false
|
|
9
|
+
| null
|
|
10
|
+
| undefined
|
|
11
|
+
| {
|
|
12
|
+
variant: VHoverVariant;
|
|
13
|
+
active?: boolean;
|
|
14
|
+
hover?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type OverlayConfig = {
|
|
18
|
+
variant: VHoverVariant;
|
|
19
|
+
active: boolean;
|
|
20
|
+
hover: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function resolveConfig(binding: DirectiveBinding<VOverlayBinding>): OverlayConfig | null {
|
|
24
|
+
const value = binding.value;
|
|
25
|
+
if (value === false || value === null || value === undefined) return null;
|
|
26
|
+
|
|
27
|
+
if (typeof value === 'object' && value !== null && 'variant' in value) {
|
|
28
|
+
const { active = true, hover = false, variant } = value;
|
|
29
|
+
if (variant === 'subtle' || variant === 'default' || variant === 'strong') {
|
|
30
|
+
return { active, hover, variant };
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (value === 'subtle' || value === 'default' || value === 'strong') {
|
|
36
|
+
return { active: true, hover: false, variant: value };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function detach(el: HTMLElement): void {
|
|
43
|
+
const overlay = (el as unknown as Record<symbol, HTMLElement>)[OVERLAY_EL];
|
|
44
|
+
overlay?.remove();
|
|
45
|
+
delete (el as unknown as Record<symbol, unknown>)[OVERLAY_EL];
|
|
46
|
+
el.classList.remove('v-hover-root');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function attach(el: HTMLElement, config: OverlayConfig): void {
|
|
50
|
+
detach(el);
|
|
51
|
+
el.classList.add('v-hover-root');
|
|
52
|
+
|
|
53
|
+
const overlay = document.createElement('span');
|
|
54
|
+
overlay.className = 'v-hover-overlay';
|
|
55
|
+
overlay.setAttribute('data-v-hover-variant', config.variant);
|
|
56
|
+
overlay.setAttribute('aria-hidden', 'true');
|
|
57
|
+
overlay.style.opacity = config.active ? '1' : '';
|
|
58
|
+
|
|
59
|
+
el.prepend(overlay);
|
|
60
|
+
(el as unknown as Record<symbol, HTMLElement>)[OVERLAY_EL] = overlay;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function updateOverlay(el: HTMLElement, config: OverlayConfig): void {
|
|
64
|
+
const overlay = (el as unknown as Record<symbol, HTMLElement>)[OVERLAY_EL];
|
|
65
|
+
if (!overlay?.isConnected) {
|
|
66
|
+
attach(el, config);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
overlay.setAttribute('data-v-hover-variant', config.variant);
|
|
71
|
+
overlay.style.opacity = config.active ? '1' : '';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const vOverlay: ObjectDirective<HTMLElement, VOverlayBinding> = {
|
|
75
|
+
mounted(el, binding) {
|
|
76
|
+
const config = resolveConfig(binding);
|
|
77
|
+
if (!config || (!config.active && !config.hover)) return;
|
|
78
|
+
attach(el, config);
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
updated(el, binding) {
|
|
82
|
+
const config = resolveConfig(binding);
|
|
83
|
+
if (!config || (!config.active && !config.hover)) {
|
|
84
|
+
detach(el);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
updateOverlay(el, config);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
unmounted(el) {
|
|
92
|
+
detach(el);
|
|
93
|
+
},
|
|
94
|
+
};
|