flowbite-svelte 0.27.1 → 0.27.2
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 +7 -0
- package/modals/Modal.svelte +34 -46
- package/modals/Modal.svelte.d.ts +4 -3
- package/package.json +1 -1
- package/types.d.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.27.2](https://github.com/themesberg/flowbite-svelte/compare/v0.27.1...v0.27.2) (2022-09-26)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* permanent option ([cceeb1b](https://github.com/themesberg/flowbite-svelte/commit/cceeb1b21995e4b386e61fa90256c7b3a304326e))
|
|
11
|
+
|
|
5
12
|
### [0.27.1](https://github.com/themesberg/flowbite-svelte/compare/v0.27.0...v0.27.1) (2022-09-24)
|
|
6
13
|
|
|
7
14
|
|
package/modals/Modal.svelte
CHANGED
|
@@ -8,45 +8,12 @@ export let title = '';
|
|
|
8
8
|
export let size = 'md';
|
|
9
9
|
export let placement = 'center';
|
|
10
10
|
export let autoclose = true;
|
|
11
|
+
export let permanent = false;
|
|
11
12
|
export let backdropClasses = 'bg-gray-900 bg-opacity-50 dark:bg-opacity-80';
|
|
12
13
|
const dispatch = createEventDispatcher();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
e.stopPropagation();
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
function contentInit(node) {
|
|
19
|
-
function keydownHandler(e) {
|
|
20
|
-
if (open && e.key === 'Escape')
|
|
21
|
-
return hide();
|
|
22
|
-
const target = e.target;
|
|
23
|
-
if (node.contains(target))
|
|
24
|
-
return true;
|
|
25
|
-
if (e.key === 'ArrowDown' || e.key === 'ArrowUp')
|
|
26
|
-
return blockEvent(e);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
document.addEventListener('keydown', keydownHandler, { passive: false });
|
|
14
|
+
$: dispatch(open ? 'open' : 'hide');
|
|
15
|
+
function grabFocus(node) {
|
|
30
16
|
node.focus();
|
|
31
|
-
return {
|
|
32
|
-
destroy() {
|
|
33
|
-
document.removeEventListener('keydown', keydownHandler);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function init(node) {
|
|
38
|
-
function preventScroll(e) {
|
|
39
|
-
if (e.target === node)
|
|
40
|
-
return blockEvent(e);
|
|
41
|
-
}
|
|
42
|
-
node.addEventListener('wheel', preventScroll, { passive: false });
|
|
43
|
-
dispatch('show', node);
|
|
44
|
-
return {
|
|
45
|
-
destroy() {
|
|
46
|
-
node.removeEventListener('wheel', preventScroll);
|
|
47
|
-
dispatch('hide', node);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
17
|
}
|
|
51
18
|
const getPlacementClasses = () => {
|
|
52
19
|
switch (placement) {
|
|
@@ -85,23 +52,45 @@ const sizes = {
|
|
|
85
52
|
const onAutoClose = (e) => {
|
|
86
53
|
const target = e.target;
|
|
87
54
|
if (autoclose && target?.tagName === 'BUTTON')
|
|
88
|
-
open =
|
|
55
|
+
open = false;
|
|
89
56
|
};
|
|
90
57
|
const hide = () => {
|
|
91
58
|
open = false;
|
|
92
59
|
};
|
|
93
60
|
let mainClass;
|
|
94
|
-
$: mainClass = classNames('flex overflow-hidden fixed top-0 right-0 left-0 z-50 w-full md:inset-0 h-modal md:h-full', backdropClasses, getPlacementClasses()
|
|
61
|
+
$: mainClass = classNames('flex overflow-hidden fixed top-0 right-0 left-0 z-50 w-full md:inset-0 h-modal md:h-full', backdropClasses, ...getPlacementClasses(), $$props.class);
|
|
62
|
+
const isScrollable = (e) => [
|
|
63
|
+
e.scrollWidth > e.clientWidth && ['scroll', 'auto'].indexOf(getComputedStyle(e).overflowX) >= 0,
|
|
64
|
+
e.scrollHeight > e.clientHeight && ['scroll', 'auto'].indexOf(getComputedStyle(e).overflowY) >= 0
|
|
65
|
+
];
|
|
66
|
+
const isArrowKey = (e, x, y) => (x && ['ArrowLeft', 'ArrowRight'].includes(e.key)) || (y && ['ArrowDown', 'ArrowUp'].includes(e.key));
|
|
67
|
+
function preventWheelDefault(e) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
const [x, y] = isScrollable(this);
|
|
70
|
+
return x || y || e.preventDefault();
|
|
71
|
+
}
|
|
72
|
+
function stopArrowsPropagation(e) {
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
const [x, y] = isScrollable(this);
|
|
75
|
+
if (isArrowKey(e, x, y))
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
}
|
|
78
|
+
function handleKeys(e) {
|
|
79
|
+
if (e.key === 'Escape' && !permanent)
|
|
80
|
+
return hide();
|
|
81
|
+
return isArrowKey(e, true, true) ? e.preventDefault() : true;
|
|
82
|
+
}
|
|
95
83
|
</script>
|
|
96
84
|
|
|
97
|
-
<!-- Main modal -->
|
|
98
85
|
{#if open}
|
|
99
86
|
<div
|
|
100
87
|
tabindex="-1"
|
|
101
88
|
class={mainClass}
|
|
102
89
|
aria-modal="true"
|
|
103
90
|
role="dialog"
|
|
104
|
-
|
|
91
|
+
on:keydown={handleKeys}
|
|
92
|
+
on:wheel|preventDefault
|
|
93
|
+
use:grabFocus
|
|
105
94
|
use:focusTrap
|
|
106
95
|
on:click={autoclose ? onAutoClose : null}>
|
|
107
96
|
<div class="flex p-4 w-full {sizes[size]} h-full md:h-auto max-h-screen">
|
|
@@ -109,23 +98,22 @@ $: mainClass = classNames('flex overflow-hidden fixed top-0 right-0 left-0 z-50
|
|
|
109
98
|
<Frame rounded shadow class="relative flex flex-col w-full h-full md:h-auto">
|
|
110
99
|
<!-- Modal header -->
|
|
111
100
|
{#if $$slots.header || title}
|
|
112
|
-
<div
|
|
113
|
-
class="flex justify-between items-center p-4 rounded-t border-b dark:border-gray-600">
|
|
101
|
+
<div class="flex justify-between items-center p-4 rounded-t border-b dark:border-gray-600">
|
|
114
102
|
<slot name="header">
|
|
115
103
|
<h3 class="text-xl font-semibold text-gray-900 dark:text-white p-0">
|
|
116
104
|
{title}
|
|
117
105
|
</h3>
|
|
118
106
|
</slot>
|
|
119
|
-
<CloseButton name="Close modal" on:click={hide} />
|
|
107
|
+
{#if !permanent}<CloseButton name="Close modal" on:click={hide} />{/if}
|
|
120
108
|
</div>
|
|
121
|
-
{:else}
|
|
109
|
+
{:else if !permanent}
|
|
122
110
|
<CloseButton name="Close modal" class="absolute top-3 right-2.5" on:click={hide} />
|
|
123
111
|
{/if}
|
|
124
112
|
<!-- Modal body -->
|
|
125
113
|
<div
|
|
126
114
|
class="p-6 space-y-6 flex-1 overflow-y-auto overscroll-contain"
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
on:keydown={stopArrowsPropagation}
|
|
116
|
+
on:wheel|stopPropagation={preventWheelDefault}>
|
|
129
117
|
<slot />
|
|
130
118
|
</div>
|
|
131
119
|
<!-- Modal footer -->
|
package/modals/Modal.svelte.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { Size } from '../types';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
[x: string]: any;
|
|
5
6
|
open?: boolean | undefined;
|
|
6
7
|
title?: string | undefined;
|
|
7
|
-
size?:
|
|
8
|
+
size?: Size | undefined;
|
|
8
9
|
placement?: "top-left" | "top-center" | "top-right" | "center-left" | "center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right" | undefined;
|
|
9
10
|
autoclose?: boolean | undefined;
|
|
11
|
+
permanent?: boolean | undefined;
|
|
10
12
|
backdropClasses?: string | undefined;
|
|
11
13
|
};
|
|
12
14
|
events: {
|
|
13
|
-
|
|
14
|
-
hide: CustomEvent<any>;
|
|
15
|
+
wheel: WheelEvent;
|
|
15
16
|
} & {
|
|
16
17
|
[evt: string]: CustomEvent<any>;
|
|
17
18
|
};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -147,6 +147,12 @@ export interface PageType {
|
|
|
147
147
|
pageNum: number;
|
|
148
148
|
href: string;
|
|
149
149
|
}
|
|
150
|
+
export declare const xs = "xs";
|
|
151
|
+
export declare const sm = "sm";
|
|
152
|
+
export declare const md = "md";
|
|
153
|
+
export declare const lg = "lg";
|
|
154
|
+
export declare const xl = "xl";
|
|
155
|
+
export declare type Size = typeof xs | typeof sm | typeof md | typeof lg | typeof xl;
|
|
150
156
|
export interface PillTabType {
|
|
151
157
|
name: string;
|
|
152
158
|
selected: boolean;
|