flowbite-svelte 0.25.22 → 0.26.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/CHANGELOG.md +44 -0
- package/avatar/Avatar.svelte +4 -4
- package/dropdowns/Dropdown.svelte +19 -12
- package/dropdowns/Dropdown.svelte.d.ts +2 -3
- package/dropdowns/DropdownItem.svelte +1 -0
- package/package.json +2 -1
- package/popover/Popover.svelte +3 -3
- package/popover/Popover.svelte.d.ts +1 -0
- package/timelines/TimelineItem.svelte +6 -7
- package/timelines/TimelineItem.svelte.d.ts +1 -2
- package/timelines/TimelineItemVertical.svelte +3 -25
- package/timelines/TimelineItemVertical.svelte.d.ts +4 -5
- package/tooltips/Tooltip.svelte +7 -8
- package/tooltips/Tooltip.svelte.d.ts +3 -6
- package/utils/Popper.svelte +94 -66
- package/utils/Popper.svelte.d.ts +5 -8
- package/utils/createEventDispatcher.js +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.26.0](https://github.com/themesberg/flowbite-svelte/compare/v0.25.24...v0.26.0) (2022-08-29)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* Tooltip changed in accordance to new Popper implementation.
|
|
11
|
+
|
|
12
|
+
- Tooltip examples corrected
|
|
13
|
+
- Avatar example corrected
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* tooltips new API ([d9dacf9](https://github.com/themesberg/flowbite-svelte/commit/d9dacf9f65e85be93a3458dd5359d614a0dd12a0))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* Avatar tooltip example ([ff7c1af](https://github.com/themesberg/flowbite-svelte/commit/ff7c1af20306609f77831ff1d2632700a9f596da))
|
|
23
|
+
* docs corrections ([f208323](https://github.com/themesberg/flowbite-svelte/commit/f208323ac1457b88572aaae37531e6b3da1055de))
|
|
24
|
+
* docs corrections 2 ([5adb4d8](https://github.com/themesberg/flowbite-svelte/commit/5adb4d816591d7bc9aff2e549fc364c80e650b4b))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
* Merge branch 'jjagielka-tooltip' ([1c37601](https://github.com/themesberg/flowbite-svelte/commit/1c3760139e24569287891c1ca3f67f2e0e3b9168))
|
|
28
|
+
|
|
29
|
+
### [0.25.24](https://github.com/themesberg/flowbite-svelte/compare/v0.25.23...v0.25.24) (2022-08-28)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* popper reloaded ([a4b851e](https://github.com/themesberg/flowbite-svelte/commit/a4b851e2409356a90fd6aaae62db327b505bdcb2))
|
|
35
|
+
* popper reloaded part 2 ([2482870](https://github.com/themesberg/flowbite-svelte/commit/2482870842386c8c1e5824869ce7822b8682e8a0))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Bug Fixes
|
|
39
|
+
|
|
40
|
+
* tab page timeline ([ab598a5](https://github.com/themesberg/flowbite-svelte/commit/ab598a59a3d373f14740a42bbaec3cb276eed34b))
|
|
41
|
+
|
|
42
|
+
### [0.25.23](https://github.com/themesberg/flowbite-svelte/compare/v0.25.22...v0.25.23) (2022-08-28)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Bug Fixes
|
|
46
|
+
|
|
47
|
+
* BREAKING CHANGE for timeline components ([8b30105](https://github.com/themesberg/flowbite-svelte/commit/8b30105060d150d632ea6fbfac8e1f5639f82546))
|
|
48
|
+
|
|
5
49
|
### [0.25.22](https://github.com/themesberg/flowbite-svelte/compare/v0.25.21...v0.25.22) (2022-08-28)
|
|
6
50
|
|
|
7
51
|
|
package/avatar/Avatar.svelte
CHANGED
|
@@ -22,17 +22,17 @@ $: avatarClass = classNames(rounded ? 'rounded' : 'rounded-full', border && 'p-1
|
|
|
22
22
|
|
|
23
23
|
<Dot show={$$props.dot} {rounded} {...dot} {size} class={sizes[size]}>
|
|
24
24
|
{#if src}
|
|
25
|
-
<img
|
|
25
|
+
<img {alt} {src} {...$$restProps} class={avatarClass} />
|
|
26
26
|
{:else if $$slots.default}
|
|
27
27
|
<svelte:element
|
|
28
28
|
this={href ? 'a' : 'div'}
|
|
29
|
-
class="flex justify-center items-center text-xs font-medium {avatarClass}"
|
|
30
29
|
{href}
|
|
31
|
-
|
|
30
|
+
{...$$restProps}
|
|
31
|
+
class="flex justify-center items-center text-xs font-medium {avatarClass}">
|
|
32
32
|
<slot />
|
|
33
33
|
</svelte:element>
|
|
34
34
|
{:else}
|
|
35
|
-
<svelte:element this={href ? 'a' : 'div'} class={avatarClass}>
|
|
35
|
+
<svelte:element this={href ? 'a' : 'div'} {...$$restProps} class={avatarClass}>
|
|
36
36
|
<AvatarPlaceholder {rounded} />
|
|
37
37
|
</svelte:element>
|
|
38
38
|
{/if}
|
|
@@ -6,12 +6,15 @@ import ChevronUp from '../utils/ChevronUp.svelte';
|
|
|
6
6
|
import ChevronRight from '../utils/ChevronRight.svelte';
|
|
7
7
|
import ChevronDown from '../utils/ChevronDown.svelte';
|
|
8
8
|
import ChevronLeft from '../utils/ChevronLeft.svelte';
|
|
9
|
+
import generateId from '../utils/generateId';
|
|
9
10
|
export let label = '';
|
|
10
11
|
export let inline = false;
|
|
11
12
|
export let arrowIcon = true;
|
|
12
13
|
export let labelClass = 'flex items-center justify-between w-full py-2 pl-3 pr-4 font-medium text-gray-700 border-b border-gray-100 hover:bg-gray-50 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 md:w-auto dark:text-gray-400 dark:hover:text-white dark:focus:text-white dark:border-gray-700 dark:hover:bg-gray-700 md:dark:hover:bg-transparent';
|
|
13
14
|
export let placement = 'bottom';
|
|
14
15
|
export let open = false;
|
|
16
|
+
export let triggeredBy = undefined;
|
|
17
|
+
let id = generateId();
|
|
15
18
|
setContext('background', true);
|
|
16
19
|
const icons = {
|
|
17
20
|
top: ChevronUp,
|
|
@@ -25,18 +28,10 @@ let popoverClass;
|
|
|
25
28
|
$: popoverClass = classNames('rounded-lg shadow-sm', 'bg-white dark:bg-gray-800', 'text-gray-500 dark:text-gray-400', 'border border-gray-200 dark:border-gray-700', 'outline-none', $$props.class);
|
|
26
29
|
</script>
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
arrow={false}
|
|
31
|
-
{placement}
|
|
32
|
-
{...$$restProps}
|
|
33
|
-
class={popoverClass}
|
|
34
|
-
trigger="click"
|
|
35
|
-
on:show
|
|
36
|
-
bind:open>
|
|
37
|
-
<slot name="trigger" slot="trigger">
|
|
31
|
+
{#if label}
|
|
32
|
+
<slot name="trigger">
|
|
38
33
|
{#if inline}
|
|
39
|
-
<button class={labelClass} class:flex-row-reverse={icon == ChevronLeft}>
|
|
34
|
+
<button {id} class={labelClass} class:flex-row-reverse={icon == ChevronLeft}>
|
|
40
35
|
<slot name="label">{label}</slot>
|
|
41
36
|
{#if arrowIcon}
|
|
42
37
|
<svelte:component
|
|
@@ -45,7 +40,7 @@ $: popoverClass = classNames('rounded-lg shadow-sm', 'bg-white dark:bg-gray-800'
|
|
|
45
40
|
{/if}
|
|
46
41
|
</button>
|
|
47
42
|
{:else}
|
|
48
|
-
<Button {...$$restProps} class={icon == ChevronLeft && 'flex-row-reverse'}>
|
|
43
|
+
<Button {id} {...$$restProps} class={icon == ChevronLeft && 'flex-row-reverse'}>
|
|
49
44
|
<slot name="label">{label}</slot>
|
|
50
45
|
{#if arrowIcon}
|
|
51
46
|
<svelte:component
|
|
@@ -55,6 +50,18 @@ $: popoverClass = classNames('rounded-lg shadow-sm', 'bg-white dark:bg-gray-800'
|
|
|
55
50
|
</Button>
|
|
56
51
|
{/if}
|
|
57
52
|
</slot>
|
|
53
|
+
{/if}
|
|
54
|
+
|
|
55
|
+
<Popper
|
|
56
|
+
activeContent={true}
|
|
57
|
+
arrow={false}
|
|
58
|
+
{placement}
|
|
59
|
+
{...$$restProps}
|
|
60
|
+
class={popoverClass}
|
|
61
|
+
trigger="click"
|
|
62
|
+
on:show
|
|
63
|
+
bind:open
|
|
64
|
+
triggeredBy={triggeredBy ?? '#' + id}>
|
|
58
65
|
<slot name="content">
|
|
59
66
|
<ul class="py-1">
|
|
60
67
|
<slot />
|
|
@@ -9,6 +9,7 @@ declare const __propDef: {
|
|
|
9
9
|
labelClass?: string;
|
|
10
10
|
placement?: 'auto' | Placement;
|
|
11
11
|
open?: boolean;
|
|
12
|
+
triggeredBy?: string;
|
|
12
13
|
};
|
|
13
14
|
events: {
|
|
14
15
|
show: CustomEvent<any>;
|
|
@@ -16,9 +17,7 @@ declare const __propDef: {
|
|
|
16
17
|
[evt: string]: CustomEvent<any>;
|
|
17
18
|
};
|
|
18
19
|
slots: {
|
|
19
|
-
trigger: {
|
|
20
|
-
slot: string;
|
|
21
|
-
};
|
|
20
|
+
trigger: {};
|
|
22
21
|
label: {};
|
|
23
22
|
content: {};
|
|
24
23
|
default: {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flowbite-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Flowbite components for Svelte",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": {
|
|
@@ -244,6 +244,7 @@
|
|
|
244
244
|
"./utils/Popper.svelte": "./utils/Popper.svelte",
|
|
245
245
|
"./utils/Wrapper.svelte": "./utils/Wrapper.svelte",
|
|
246
246
|
"./utils/clickOutside": "./utils/clickOutside.js",
|
|
247
|
+
"./utils/createEventDispatcher": "./utils/createEventDispatcher.js",
|
|
247
248
|
"./utils/focusTrap": "./utils/focusTrap.js",
|
|
248
249
|
"./utils/generateId": "./utils/generateId.js"
|
|
249
250
|
},
|
package/popover/Popover.svelte
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<script>import Popper from '../utils/Popper.svelte';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
export let title = '';
|
|
4
|
+
export let triggeredBy;
|
|
4
5
|
let popoverClass;
|
|
5
6
|
$: popoverClass = classNames('rounded-lg shadow-sm', 'bg-white dark:bg-gray-800', 'text-gray-500 dark:text-gray-400', 'border border-gray-200 dark:border-gray-700', $$props.class);
|
|
6
7
|
</script>
|
|
7
8
|
|
|
8
|
-
<Popper activeContent={true} {...$$restProps} class={popoverClass} on:show>
|
|
9
|
+
<Popper activeContent={true} {triggeredBy} {...$$restProps} class={popoverClass} on:show>
|
|
9
10
|
<slot name="trigger" slot="trigger" />
|
|
10
11
|
{#if $$slots.title || title}
|
|
11
12
|
<div
|
|
12
|
-
class="py-2 px-3 bg-gray-100 rounded-t-lg border-b border-gray-200 dark:border-gray-600 dark:bg-gray-700"
|
|
13
|
-
>
|
|
13
|
+
class="py-2 px-3 bg-gray-100 rounded-t-lg border-b border-gray-200 dark:border-gray-600 dark:bg-gray-700">
|
|
14
14
|
<slot name="title">
|
|
15
15
|
<h3 class="font-semibold text-gray-900 dark:text-white">{title}</h3>
|
|
16
16
|
</slot>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script>import classNames from 'classnames';
|
|
2
2
|
import { getContext } from 'svelte';
|
|
3
|
-
export let icon;
|
|
4
3
|
export let title = '';
|
|
5
4
|
export let date = '';
|
|
6
5
|
export let customDiv = '';
|
|
@@ -49,8 +48,8 @@ const h3Class = classNames(order === 'vertical'
|
|
|
49
48
|
<slot />
|
|
50
49
|
{:else if order === 'vertical'}
|
|
51
50
|
<div class={divClasses[order]} />
|
|
52
|
-
{#if icon}
|
|
53
|
-
|
|
51
|
+
{#if $$slots.icon}
|
|
52
|
+
<slot name="icon" />
|
|
54
53
|
{:else}
|
|
55
54
|
<svg
|
|
56
55
|
aria-hidden="true"
|
|
@@ -74,8 +73,8 @@ const h3Class = classNames(order === 'vertical'
|
|
|
74
73
|
<slot />
|
|
75
74
|
{:else if order === 'horizontal'}
|
|
76
75
|
<div class={divClasses[order]} />
|
|
77
|
-
{#if icon}
|
|
78
|
-
|
|
76
|
+
{#if $$slots.icon}
|
|
77
|
+
<slot name="icon" />
|
|
79
78
|
{:else}
|
|
80
79
|
<svg
|
|
81
80
|
aria-hidden="true"
|
|
@@ -99,8 +98,8 @@ const h3Class = classNames(order === 'vertical'
|
|
|
99
98
|
<slot />
|
|
100
99
|
{:else}
|
|
101
100
|
<div class={divClasses[order]} />
|
|
102
|
-
{#if icon}
|
|
103
|
-
|
|
101
|
+
{#if $$slots.icon}
|
|
102
|
+
<slot name="icon" />
|
|
104
103
|
{:else}
|
|
105
104
|
<svg
|
|
106
105
|
aria-hidden="true"
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { SvelteComponent } from 'svelte';
|
|
3
2
|
declare const __propDef: {
|
|
4
3
|
props: {
|
|
5
|
-
icon: string | SvelteComponent;
|
|
6
4
|
title?: string;
|
|
7
5
|
date?: string;
|
|
8
6
|
customDiv?: string;
|
|
@@ -13,6 +11,7 @@ declare const __propDef: {
|
|
|
13
11
|
};
|
|
14
12
|
slots: {
|
|
15
13
|
default: {};
|
|
14
|
+
icon: {};
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
17
|
export declare type TimelineItemProps = typeof __propDef.props;
|
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
// export let timelineItems: TimelineItemVerticalType[];
|
|
3
3
|
export let title;
|
|
4
4
|
export let date;
|
|
5
|
-
export let href;
|
|
6
|
-
export let text;
|
|
7
|
-
export let linkname;
|
|
8
|
-
export let icon;
|
|
9
5
|
</script>
|
|
10
6
|
|
|
11
7
|
<li class="mb-10 ml-6">
|
|
12
8
|
<span
|
|
13
9
|
class="flex absolute -left-3 justify-center items-center w-6 h-6 bg-blue-200 rounded-full ring-8 ring-white dark:ring-gray-900 dark:bg-blue-900">
|
|
14
|
-
{#if icon}
|
|
15
|
-
|
|
10
|
+
{#if $$slots.icon}
|
|
11
|
+
<slot name="icon" />
|
|
16
12
|
{:else}
|
|
17
13
|
<svg
|
|
18
14
|
width="20"
|
|
@@ -33,23 +29,5 @@ export let icon;
|
|
|
33
29
|
</h3>
|
|
34
30
|
<time class="block mb-2 text-sm font-normal leading-none text-gray-400 dark:text-gray-500"
|
|
35
31
|
>{date}</time>
|
|
36
|
-
<
|
|
37
|
-
{text}
|
|
38
|
-
</p>
|
|
39
|
-
{#if href}
|
|
40
|
-
<a
|
|
41
|
-
{href}
|
|
42
|
-
class="inline-flex items-center py-2 px-4 text-sm font-medium text-gray-900 bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:outline-none focus:ring-gray-200 focus:text-blue-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-gray-700"
|
|
43
|
-
>{linkname}
|
|
44
|
-
<svg
|
|
45
|
-
class="ml-2 w-3 h-3"
|
|
46
|
-
fill="currentColor"
|
|
47
|
-
viewBox="0 0 20 20"
|
|
48
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
49
|
-
><path
|
|
50
|
-
fill-rule="evenodd"
|
|
51
|
-
d="M12.293 5.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-2.293-2.293a1 1 0 010-1.414z"
|
|
52
|
-
clip-rule="evenodd" /></svg
|
|
53
|
-
></a>
|
|
54
|
-
{/if}
|
|
32
|
+
<slot />
|
|
55
33
|
</li>
|
|
@@ -3,15 +3,14 @@ declare const __propDef: {
|
|
|
3
3
|
props: {
|
|
4
4
|
title: string;
|
|
5
5
|
date: string;
|
|
6
|
-
href: string;
|
|
7
|
-
text: string;
|
|
8
|
-
linkname: string;
|
|
9
|
-
icon: string;
|
|
10
6
|
};
|
|
11
7
|
events: {
|
|
12
8
|
[evt: string]: CustomEvent<any>;
|
|
13
9
|
};
|
|
14
|
-
slots: {
|
|
10
|
+
slots: {
|
|
11
|
+
icon: {};
|
|
12
|
+
default: {};
|
|
13
|
+
};
|
|
15
14
|
};
|
|
16
15
|
export declare type TimelineItemVerticalProps = typeof __propDef.props;
|
|
17
16
|
export declare type TimelineItemVerticalEvents = typeof __propDef.events;
|
package/tooltips/Tooltip.svelte
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
<script>import Popper from '../utils/Popper.svelte';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
export let
|
|
3
|
+
export let color = '';
|
|
4
4
|
export let style = 'dark';
|
|
5
|
-
export let tipColor = '';
|
|
6
5
|
export let tipClass = 'py-2 px-3 text-sm font-medium rounded-lg shadow-sm tooltip';
|
|
7
|
-
|
|
6
|
+
export let triggeredBy;
|
|
7
|
+
const colors = {
|
|
8
8
|
dark: 'border border-gray-800 bg-gray-900 text-white dark:bg-gray-700 dark:border-gray-600',
|
|
9
9
|
light: 'border border-gray-200 bg-white text-gray-900',
|
|
10
10
|
auto: 'border border-gray-200 bg-white text-gray-900 dark:bg-gray-700 dark:text-white dark:border-gray-600 ',
|
|
11
|
-
custom:
|
|
11
|
+
custom: color
|
|
12
12
|
};
|
|
13
13
|
let toolTipClass;
|
|
14
|
-
$: toolTipClass = classNames(tipClass,
|
|
14
|
+
$: toolTipClass = classNames(tipClass, colors[style], $$props.class);
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
|
-
<Popper activeContent={false} {...$$restProps} class={toolTipClass} on:show>
|
|
18
|
-
<slot
|
|
19
|
-
<slot name="content">{content}</slot>
|
|
17
|
+
<Popper activeContent={false} {triggeredBy} {...$$restProps} class={toolTipClass} on:show>
|
|
18
|
+
<slot />
|
|
20
19
|
</Popper>
|
|
@@ -2,10 +2,10 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
|
|
5
|
+
color?: string;
|
|
6
6
|
style?: 'dark' | 'light' | 'auto' | 'custom';
|
|
7
|
-
tipColor?: string;
|
|
8
7
|
tipClass?: string;
|
|
8
|
+
triggeredBy: string;
|
|
9
9
|
};
|
|
10
10
|
events: {
|
|
11
11
|
show: CustomEvent<any>;
|
|
@@ -13,10 +13,7 @@ declare const __propDef: {
|
|
|
13
13
|
[evt: string]: CustomEvent<any>;
|
|
14
14
|
};
|
|
15
15
|
slots: {
|
|
16
|
-
default: {
|
|
17
|
-
slot: string;
|
|
18
|
-
};
|
|
19
|
-
content: {};
|
|
16
|
+
default: {};
|
|
20
17
|
};
|
|
21
18
|
};
|
|
22
19
|
export declare type TooltipProps = typeof __propDef.props;
|
package/utils/Popper.svelte
CHANGED
|
@@ -1,84 +1,112 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { onMount } from 'svelte';
|
|
2
|
+
import { fade } from 'svelte/transition';
|
|
2
3
|
import { createPopper } from '@popperjs/core';
|
|
3
4
|
import classNames from 'classnames';
|
|
4
|
-
|
|
5
|
-
export let
|
|
6
|
-
export let
|
|
5
|
+
import createEventDispatcher from './createEventDispatcher';
|
|
6
|
+
export let activeContent = false;
|
|
7
|
+
export let animation = 100;
|
|
8
|
+
export let arrow = true;
|
|
7
9
|
export let offset = 8;
|
|
10
|
+
export let placement = 'top';
|
|
8
11
|
export let trigger = 'hover';
|
|
9
|
-
export let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
export let triggeredBy;
|
|
13
|
+
const dispatch = createEventDispatcher();
|
|
14
|
+
let open = false;
|
|
12
15
|
let clickable;
|
|
13
16
|
$: clickable = trigger === 'click';
|
|
14
|
-
|
|
17
|
+
$: dispatch('show', triggerEl, open);
|
|
18
|
+
let triggerEl;
|
|
19
|
+
let triggerEls = [];
|
|
20
|
+
let popper;
|
|
15
21
|
let _blocked = false; // managment of the race condition between focusin and click events
|
|
16
|
-
const block = () => ((_blocked = true), setTimeout(() => (_blocked = false),
|
|
22
|
+
const block = () => ((_blocked = true), setTimeout(() => (_blocked = false), 250));
|
|
17
23
|
const showHandler = (ev) => {
|
|
24
|
+
if (triggerEl === undefined)
|
|
25
|
+
triggerEl = ev.target;
|
|
26
|
+
else if (triggerEls.includes(ev.target) && triggerEl !== ev.target) {
|
|
27
|
+
triggerEl = ev.target;
|
|
28
|
+
block();
|
|
29
|
+
}
|
|
18
30
|
if (clickable && ev.type === 'focusin' && !open)
|
|
19
31
|
block();
|
|
20
|
-
open = ev.type === 'click' && !_blocked ? !open : true;
|
|
32
|
+
open = clickable && ev.type === 'click' && !_blocked ? !open : true;
|
|
21
33
|
};
|
|
34
|
+
// reactivity
|
|
35
|
+
$: popper && (popper.state.elements.reference = triggerEl) && popper.setOptions({ placement });
|
|
36
|
+
// typescript typeguards - poper.state.element.reference: Element|HTMLElement|VirtualElement
|
|
37
|
+
const hasHover = (el) => el.matches && el.matches(':hover');
|
|
38
|
+
const hasFocus = (el) => el.contains && el.contains(document.activeElement);
|
|
22
39
|
const hideHandler = (ev) => {
|
|
23
|
-
if (activeContent)
|
|
24
|
-
setTimeout(() =>
|
|
25
|
-
|
|
26
|
-
(
|
|
40
|
+
if (activeContent) {
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
const elements = Object.values(popper?.state.elements ?? {});
|
|
43
|
+
if (ev.type === 'mouseleave' && elements.some(hasHover))
|
|
44
|
+
return;
|
|
45
|
+
if (ev.type === 'focusout' && elements.some(hasFocus))
|
|
46
|
+
return;
|
|
47
|
+
open = false;
|
|
48
|
+
}, 100);
|
|
49
|
+
}
|
|
27
50
|
else
|
|
28
51
|
open = false;
|
|
29
52
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return modifiers;
|
|
53
|
+
function init(node, _open) {
|
|
54
|
+
popper = createPopper(triggerEl, node, {
|
|
55
|
+
placement,
|
|
56
|
+
modifiers: [
|
|
57
|
+
{ name: 'offset', options: { offset: [0, offset] } },
|
|
58
|
+
{ name: 'eventListeners', enabled: open }
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
destroy() {
|
|
63
|
+
popper.destroy();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
44
66
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
onMount(() => {
|
|
68
|
+
const events = [
|
|
69
|
+
['focusin', showHandler, true],
|
|
70
|
+
['focusout', hideHandler, true],
|
|
71
|
+
['click', showHandler, clickable],
|
|
72
|
+
['mouseenter', showHandler, !clickable],
|
|
73
|
+
['mouseleave', hideHandler, !clickable]
|
|
74
|
+
];
|
|
75
|
+
triggerEls = [...document.querySelectorAll(triggeredBy)];
|
|
76
|
+
if (!triggerEls.length)
|
|
77
|
+
console.error('no triggers given');
|
|
78
|
+
triggerEls.forEach((element) => {
|
|
79
|
+
if (element.tabIndex < 0)
|
|
80
|
+
element.tabIndex = 0; // trigger must be focusable
|
|
81
|
+
for (const [name, handler, cond] of events)
|
|
82
|
+
if (cond)
|
|
83
|
+
element.addEventListener(name, handler);
|
|
84
|
+
});
|
|
85
|
+
return () => {
|
|
86
|
+
triggerEl = undefined;
|
|
87
|
+
triggerEls.forEach((element) => {
|
|
88
|
+
if (element) {
|
|
89
|
+
for (const [name, handler] of events)
|
|
90
|
+
element.removeEventListener(name, handler);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
});
|
|
58
95
|
</script>
|
|
59
96
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
on:focusin={activeContent ? showHandler : undefined}
|
|
77
|
-
on:focusout={activeContent ? hideHandler : undefined}
|
|
78
|
-
on:mouseenter={activeContent && !clickable ? showHandler : undefined}
|
|
79
|
-
on:mouseleave={activeContent && !clickable ? hideHandler : undefined}
|
|
80
|
-
style="position: absolute;"
|
|
81
|
-
>
|
|
82
|
-
<slot />
|
|
83
|
-
{#if arrow}<div data-popper-arrow />{/if}
|
|
84
|
-
</div>
|
|
97
|
+
{#if open}
|
|
98
|
+
<div
|
|
99
|
+
use:init={open}
|
|
100
|
+
transition:fade={{ duration: animation ? animation : 0 }}
|
|
101
|
+
role="tooltip"
|
|
102
|
+
tabIndex={activeContent ? -1 : undefined}
|
|
103
|
+
class={classNames('z-10', $$props.class)}
|
|
104
|
+
on:focusin={activeContent ? showHandler : undefined}
|
|
105
|
+
on:focusout={activeContent ? hideHandler : undefined}
|
|
106
|
+
on:mouseenter={activeContent && !clickable ? showHandler : undefined}
|
|
107
|
+
on:mouseleave={activeContent && !clickable ? hideHandler : undefined}
|
|
108
|
+
style="position: absolute;">
|
|
109
|
+
<slot />
|
|
110
|
+
{#if arrow}<div data-popper-arrow />{/if}
|
|
111
|
+
</div>
|
|
112
|
+
{/if}
|
package/utils/Popper.svelte.d.ts
CHANGED
|
@@ -3,21 +3,18 @@ import type { Placement } from '@popperjs/core';
|
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
[x: string]: any;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
activeContent?: boolean;
|
|
7
|
+
animation?: false | number;
|
|
8
|
+
arrow?: boolean;
|
|
8
9
|
offset?: number;
|
|
10
|
+
placement?: Placement;
|
|
9
11
|
trigger?: 'hover' | 'click';
|
|
10
|
-
|
|
11
|
-
animation?: false | `duration-${number}`;
|
|
12
|
-
activeContent: boolean;
|
|
12
|
+
triggeredBy: string;
|
|
13
13
|
};
|
|
14
14
|
events: {
|
|
15
|
-
show: CustomEvent<any>;
|
|
16
|
-
} & {
|
|
17
15
|
[evt: string]: CustomEvent<any>;
|
|
18
16
|
};
|
|
19
17
|
slots: {
|
|
20
|
-
trigger: {};
|
|
21
18
|
default: {};
|
|
22
19
|
};
|
|
23
20
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Custom Event Dispatcher
|
|
3
|
+
|
|
4
|
+
Sets `target` in event data.
|
|
5
|
+
|
|
6
|
+
https://svelte.dev/repl/c93cbf99a8ca4f44912e662a8e3cbef7?version=3.37.0
|
|
7
|
+
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { get_current_component } from 'svelte/internal';
|
|
11
|
+
|
|
12
|
+
export default function createEventDispatcher() {
|
|
13
|
+
const component = get_current_component();
|
|
14
|
+
return (type, target, detail) => {
|
|
15
|
+
const callbacks = component.$$.callbacks[type];
|
|
16
|
+
if (callbacks) {
|
|
17
|
+
const event = new CustomEvent(type, { detail });
|
|
18
|
+
target.dispatchEvent(event);
|
|
19
|
+
callbacks.slice().forEach((fn) => {
|
|
20
|
+
fn.call(component, event);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|