@csedl/hotwire-svelte-helpers 1.1.0 → 1.1.1
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/README.md +5 -0
- package/package.json +10 -2
- package/src/lib/config.js +6 -0
- package/src/lib/utils.js +0 -1
- package/src/svelte/templates/DropdownPanel.svelte +43 -0
- package/src/svelte/templates/Modal.svelte +72 -0
package/README.md
CHANGED
|
@@ -48,6 +48,11 @@ There is a [online example app](https://hotwire-svelte-helpers.sedlmair.ch/)
|
|
|
48
48
|
</div>
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
## Svelte Dropdowns
|
|
52
|
+
|
|
53
|
+
There are some default components included, which can be used to build Svelte Dropdowns.
|
|
54
|
+
The
|
|
55
|
+
|
|
51
56
|
## What it does
|
|
52
57
|
|
|
53
58
|
- When the button is clicked, it toggles the `hide` class on the panel and places the panel using floating-ui.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csedl/hotwire-svelte-helpers",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Hotwire + Svelte helpers for Rails: Stimulus floating dropdowns/toolips + Svelte global panels/modals + RTurbo-friendly utilities. Build together with the rubygem svelte-on-rails and its npm-package.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,15 @@
|
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./index.js",
|
|
11
|
-
"./init": "./src/lib/config.js"
|
|
11
|
+
"./init": "./src/lib/config.js",
|
|
12
|
+
"./DropdownPanel.svelte": {
|
|
13
|
+
"svelte": "./src/svelte/templates/DropdownPanel.svelte",
|
|
14
|
+
"default": "./src/svelte/templates/DropdownPanel.svelte"
|
|
15
|
+
},
|
|
16
|
+
"./Modal.svelte": {
|
|
17
|
+
"svelte": "./src/svelte/templates/Modal.svelte",
|
|
18
|
+
"default": "./src/svelte/templates/Modal.svelte"
|
|
19
|
+
}
|
|
12
20
|
},
|
|
13
21
|
"repository": {
|
|
14
22
|
"type": "git",
|
package/src/lib/config.js
CHANGED
|
@@ -32,6 +32,7 @@ const HotwireSvelteHelpers = {
|
|
|
32
32
|
addArrow: true,
|
|
33
33
|
persistTooltipOnClick: false,
|
|
34
34
|
closeOnClickOutsideListenerAdded: false,
|
|
35
|
+
closeButtonSvg: null,
|
|
35
36
|
},
|
|
36
37
|
|
|
37
38
|
initializeOverlays(options = {}) {
|
|
@@ -43,6 +44,7 @@ const HotwireSvelteHelpers = {
|
|
|
43
44
|
addArrow: 'boolean',
|
|
44
45
|
persistTooltipOnClick: 'boolean',
|
|
45
46
|
closeOnClickOutsideListenerAdded: 'boolean',
|
|
47
|
+
closeButtonSvg: 'string',
|
|
46
48
|
})
|
|
47
49
|
|
|
48
50
|
const overlays = this.overlays;
|
|
@@ -67,6 +69,10 @@ const HotwireSvelteHelpers = {
|
|
|
67
69
|
overlays.persistTooltipOnClick = options.persistTooltipOnClick;
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
if (options.closeButtonSvg !== undefined) {
|
|
73
|
+
overlays.closeButtonSvg = options.closeButtonSvg;
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
window.Stimulus = Application.start()
|
|
71
77
|
|
|
72
78
|
Stimulus.register('csedl-dropdown', dc)
|
package/src/lib/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {positionPanelSelf, positionPanelByButton, positionPanel} from "./floating-ui-functions.js";
|
|
2
|
-
import {validateOptions} from "./type-validators";
|
|
3
2
|
|
|
4
3
|
// Fetch content from server based on panel's data-src attribute and update content
|
|
5
4
|
export function openDropdownPanel(buttonElement, panelElement, options = {}) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import {openDropdownPanel} from "@csedl/hotwire-svelte-helpers";
|
|
3
|
+
|
|
4
|
+
import {onMount} from "svelte";
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
title,
|
|
8
|
+
panelClass,
|
|
9
|
+
closeFunction,
|
|
10
|
+
closeButtonSvg,
|
|
11
|
+
buttonElement,
|
|
12
|
+
content,
|
|
13
|
+
} = $props()
|
|
14
|
+
let panelElement
|
|
15
|
+
|
|
16
|
+
onMount(() => {
|
|
17
|
+
openDropdownPanel(buttonElement, panelElement);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function closeFunc() {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
closeFunction()
|
|
23
|
+
}, 0)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<div class="dropdown-panel {panelClass}" bind:this={panelElement} onclose={closeFunc}>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
<div class="header">
|
|
32
|
+
<span class="title">
|
|
33
|
+
{title || 'missing title'}
|
|
34
|
+
</span>
|
|
35
|
+
<button class="close-btn"
|
|
36
|
+
onclick={closeFunction}>{@html window.HotwireSvelteHelpers.overlays.closeButtonSvg}</button>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<div class="content">
|
|
40
|
+
{@render content()}
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
</div>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import {openDropdownPanel} from "@csedl/hotwire-svelte-helpers";
|
|
3
|
+
import {onMount} from "svelte";
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
title,
|
|
7
|
+
panelClass,
|
|
8
|
+
SvelteComponent,
|
|
9
|
+
svelteComponentProps,
|
|
10
|
+
closeFunction,
|
|
11
|
+
closeButtonSvg,
|
|
12
|
+
content,
|
|
13
|
+
text,
|
|
14
|
+
actionButtonLabel,
|
|
15
|
+
actionButtonFunction,
|
|
16
|
+
} = $props()
|
|
17
|
+
let panelElement
|
|
18
|
+
|
|
19
|
+
onMount(() => {
|
|
20
|
+
//openDropdownPanel(buttonElement, panelElement);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function closeFunc() {
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
closeFunction()
|
|
26
|
+
}, 0)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<div class="modal-overlay">
|
|
32
|
+
<div class="modal-panel {panelClass}" bind:this={panelElement} onclose={closeFunc}>
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
<div class="header">
|
|
36
|
+
<span class="title">
|
|
37
|
+
{title || 'missing title'}
|
|
38
|
+
</span>
|
|
39
|
+
<button class="close-btn"
|
|
40
|
+
onclick={closeFunction}>{@html window.HotwireSvelteHelpers.overlays.closeButtonSvg}</button>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div class="content">
|
|
44
|
+
|
|
45
|
+
{#if content}
|
|
46
|
+
{@render content()}
|
|
47
|
+
{/if}
|
|
48
|
+
|
|
49
|
+
{#if SvelteComponent}
|
|
50
|
+
<SvelteComponent {...svelteComponentProps}/>
|
|
51
|
+
{/if}
|
|
52
|
+
|
|
53
|
+
{#if text}
|
|
54
|
+
{#each text as paragraph}
|
|
55
|
+
<p>{paragraph}</p>
|
|
56
|
+
{/each}
|
|
57
|
+
{/if}
|
|
58
|
+
</div>
|
|
59
|
+
<div class="footer">
|
|
60
|
+
{#if actionButtonLabel}
|
|
61
|
+
<span
|
|
62
|
+
role="button"
|
|
63
|
+
tabindex="0"
|
|
64
|
+
onkeydown={(e) => {}}
|
|
65
|
+
class="action button"
|
|
66
|
+
onclick={actionButtonFunction}>
|
|
67
|
+
{actionButtonLabel}
|
|
68
|
+
</span>
|
|
69
|
+
{/if}
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|