fluid-ui-svelte 0.1.5 → 0.1.7
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/components/Dropdown.svelte +34 -17
- package/dist/components/Dropdown.svelte.d.ts +13 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/primitives/Button.svelte +14 -3
- package/dist/primitives/Button.svelte.d.ts +3 -1
- package/dist/primitives/Container.svelte +8 -6
- package/dist/primitives/Container.svelte.d.ts +2 -1
- package/dist/primitives/Image.svelte +18 -30
- package/dist/primitives/Image.svelte.d.ts +2 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/package.json +1 -1
|
@@ -2,38 +2,55 @@
|
|
|
2
2
|
import Container from "../primitives/Container.svelte";
|
|
3
3
|
import Button from "../primitives/Button.svelte";
|
|
4
4
|
import type { Snippet } from "svelte";
|
|
5
|
-
|
|
5
|
+
import type { DropdownOptions } from "../types.js";
|
|
6
|
+
let {
|
|
6
7
|
class: className,
|
|
7
8
|
triggerClass,
|
|
8
9
|
contentClass,
|
|
9
10
|
overrideDefaultStyling = false,
|
|
11
|
+
isOpen = $bindable(false),
|
|
12
|
+
shouldCloseOnClickOutside = true,
|
|
10
13
|
dropdownTrigger,
|
|
11
|
-
|
|
14
|
+
dropdownContent,
|
|
15
|
+
triggerRawElement,
|
|
16
|
+
contentRawElement,
|
|
12
17
|
}: {
|
|
13
18
|
class?: string;
|
|
14
19
|
triggerClass?: string;
|
|
15
20
|
contentClass?: string;
|
|
16
21
|
overrideDefaultStyling?: boolean;
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
isOpen?: boolean;
|
|
23
|
+
shouldCloseOnClickOutside: boolean;
|
|
24
|
+
dropdownTrigger: Snippet<[options: { isOpen: boolean; toggleDropdown: Function }]>;
|
|
25
|
+
dropdownContent: Snippet<[options: { isOpen: boolean; toggleDropdown: Function }]>;
|
|
26
|
+
triggerRawElement: HTMLElement;
|
|
27
|
+
contentRawElement: HTMLElement;
|
|
19
28
|
} = $props();
|
|
20
29
|
|
|
21
|
-
|
|
30
|
+
const componentOptions: DropdownOptions = {
|
|
31
|
+
isOpen,
|
|
32
|
+
toggleDropdown: () => {
|
|
33
|
+
isOpen = !isOpen;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
if (shouldCloseOnClickOutside) {
|
|
37
|
+
document.addEventListener("click", (e) => {
|
|
38
|
+
if (isOpen && e.target) {
|
|
39
|
+
if (!triggerRawElement.contains(e.target as HTMLElement) && !contentRawElement.contains(e.target as HTMLElement)) {
|
|
40
|
+
isOpen = false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
22
45
|
</script>
|
|
23
46
|
|
|
24
|
-
<Container class={(overrideDefaultStyling ? "" : "fluid-dropdown") + (className ? ` ${className}` : "")} overrideDefaultStyling={true}>
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
isOpen = !isOpen;
|
|
30
|
-
}}
|
|
31
|
-
>
|
|
32
|
-
{@render dropdownTrigger(isOpen)}
|
|
33
|
-
</Button>
|
|
34
|
-
<Container overrideDefaultStyling class={(overrideDefaultStyling ? "" : "fluid-dropdown-content") + (contentClass ? ` ${contentClass}` : "")}>
|
|
47
|
+
<Container bind:rawElement={triggerRawElement} class={(overrideDefaultStyling ? "" : "fluid-dropdown") + (className ? ` ${className}` : "")} overrideDefaultStyling={true}>
|
|
48
|
+
<Container class={(overrideDefaultStyling ? "" : "fluid-dropdown-trigger") + (triggerClass ? ` ${triggerClass}` : "")} overrideDefaultStyling>
|
|
49
|
+
{@render dropdownTrigger(componentOptions)}
|
|
50
|
+
</Container>
|
|
51
|
+
<Container bind:rawElement={contentRawElement} overrideDefaultStyling class={(overrideDefaultStyling ? "" : "fluid-dropdown-content") + (contentClass ? ` ${contentClass}` : "")}>
|
|
35
52
|
{#if isOpen}
|
|
36
|
-
{@render
|
|
53
|
+
{@render dropdownContent(componentOptions)}
|
|
37
54
|
{/if}
|
|
38
55
|
</Container>
|
|
39
56
|
</Container>
|
|
@@ -4,7 +4,17 @@ declare const Dropdown: import("svelte").Component<{
|
|
|
4
4
|
triggerClass?: string;
|
|
5
5
|
contentClass?: string;
|
|
6
6
|
overrideDefaultStyling?: boolean;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
isOpen?: boolean;
|
|
8
|
+
shouldCloseOnClickOutside: boolean;
|
|
9
|
+
dropdownTrigger: Snippet<[options: {
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
toggleDropdown: Function;
|
|
12
|
+
}]>;
|
|
13
|
+
dropdownContent: Snippet<[options: {
|
|
14
|
+
isOpen: boolean;
|
|
15
|
+
toggleDropdown: Function;
|
|
16
|
+
}]>;
|
|
17
|
+
triggerRawElement: HTMLElement;
|
|
18
|
+
contentRawElement: HTMLElement;
|
|
19
|
+
}, {}, "isOpen">;
|
|
10
20
|
export default Dropdown;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
3
|
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let {
|
|
6
6
|
class: className = "",
|
|
7
7
|
buttonType = "solid",
|
|
8
8
|
buttonStyle = "primary",
|
|
9
9
|
onclick,
|
|
10
10
|
overrideDefaultStyling = false,
|
|
11
|
+
isActive = $bindable(false),
|
|
12
|
+
activeChildren,
|
|
11
13
|
children,
|
|
12
14
|
...restProps
|
|
13
15
|
}: {
|
|
@@ -16,9 +18,10 @@
|
|
|
16
18
|
buttonStyle?: "primary" | "secondary" | "tetriary" | "neutral";
|
|
17
19
|
onclick: (e: Event) => any;
|
|
18
20
|
overrideDefaultStyling?: boolean;
|
|
21
|
+
isActive?: boolean;
|
|
22
|
+
activeChildren?: Snippet;
|
|
19
23
|
children: Snippet;
|
|
20
24
|
} & Omit<HTMLButtonAttributes, "onclick"> = $props();
|
|
21
|
-
let isActive = $state(false);
|
|
22
25
|
</script>
|
|
23
26
|
|
|
24
27
|
<button
|
|
@@ -38,5 +41,13 @@
|
|
|
38
41
|
(overrideDefaultStyling ? "" : " fluid-" + buttonStyle + "-button")}
|
|
39
42
|
{...restProps}
|
|
40
43
|
>
|
|
41
|
-
{
|
|
44
|
+
{#if activeChildren}
|
|
45
|
+
{#if isActive}
|
|
46
|
+
{@render activeChildren()}
|
|
47
|
+
{:else}
|
|
48
|
+
{@render children()}
|
|
49
|
+
{/if}
|
|
50
|
+
{:else}
|
|
51
|
+
{@render children()}
|
|
52
|
+
{/if}
|
|
42
53
|
</button>
|
|
@@ -6,6 +6,8 @@ declare const Button: import("svelte").Component<{
|
|
|
6
6
|
buttonStyle?: "primary" | "secondary" | "tetriary" | "neutral";
|
|
7
7
|
onclick: (e: Event) => any;
|
|
8
8
|
overrideDefaultStyling?: boolean;
|
|
9
|
+
isActive?: boolean;
|
|
10
|
+
activeChildren?: Snippet;
|
|
9
11
|
children: Snippet;
|
|
10
|
-
} & Omit<HTMLButtonAttributes, "onclick">, {}, "">;
|
|
12
|
+
} & Omit<HTMLButtonAttributes, "onclick">, {}, "isActive">;
|
|
11
13
|
export default Button;
|
|
@@ -2,46 +2,48 @@
|
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let {
|
|
6
6
|
containerType = "div",
|
|
7
7
|
class: className = "",
|
|
8
8
|
overrideDefaultStyling = false,
|
|
9
9
|
children,
|
|
10
|
+
rawElement = $bindable(),
|
|
10
11
|
...restProps
|
|
11
12
|
}: {
|
|
12
13
|
containerType?: "div" | "section" | "aside" | "nav" | "footer";
|
|
13
14
|
class?: string;
|
|
14
15
|
overrideDefaultStyling?: boolean;
|
|
15
16
|
children?: Snippet;
|
|
17
|
+
rawElement?: HTMLElement;
|
|
16
18
|
} & HTMLAttributes<HTMLElement> = $props();
|
|
17
19
|
</script>
|
|
18
20
|
|
|
19
21
|
{#if containerType == "div"}
|
|
20
|
-
<div {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
22
|
+
<div bind:this={rawElement} {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
21
23
|
{#if children}
|
|
22
24
|
{@render children()}
|
|
23
25
|
{/if}
|
|
24
26
|
</div>
|
|
25
27
|
{:else if containerType == "section"}
|
|
26
|
-
<section {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
28
|
+
<section bind:this={rawElement} {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
27
29
|
{#if children}
|
|
28
30
|
{@render children()}
|
|
29
31
|
{/if}
|
|
30
32
|
</section>
|
|
31
33
|
{:else if containerType == "aside"}
|
|
32
|
-
<aside {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
34
|
+
<aside bind:this={rawElement} {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
33
35
|
{#if children}
|
|
34
36
|
{@render children()}
|
|
35
37
|
{/if}
|
|
36
38
|
</aside>
|
|
37
39
|
{:else if containerType == "nav"}
|
|
38
|
-
<nav {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
40
|
+
<nav bind:this={rawElement} {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
39
41
|
{#if children}
|
|
40
42
|
{@render children()}
|
|
41
43
|
{/if}
|
|
42
44
|
</nav>
|
|
43
45
|
{:else if containerType == "footer"}
|
|
44
|
-
<footer {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
46
|
+
<footer bind:this={rawElement} {...restProps} class={(overrideDefaultStyling ? "" : "fluid-container") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "")}>
|
|
45
47
|
{#if children}
|
|
46
48
|
{@render children()}
|
|
47
49
|
{/if}
|
|
@@ -5,5 +5,6 @@ declare const Container: import("svelte").Component<{
|
|
|
5
5
|
class?: string;
|
|
6
6
|
overrideDefaultStyling?: boolean;
|
|
7
7
|
children?: Snippet;
|
|
8
|
-
|
|
8
|
+
rawElement?: HTMLElement;
|
|
9
|
+
} & HTMLAttributes<HTMLElement>, {}, "rawElement">;
|
|
9
10
|
export default Container;
|
|
@@ -1,47 +1,43 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
3
|
import type { HTMLImgAttributes } from "svelte/elements";
|
|
4
|
-
|
|
4
|
+
let {
|
|
5
5
|
class: className,
|
|
6
6
|
loadingSnippet,
|
|
7
|
-
|
|
8
|
-
noPlaceholders = false,
|
|
7
|
+
placeholderSnippet,
|
|
9
8
|
overrideDefaultStyling = false,
|
|
9
|
+
rawElement,
|
|
10
10
|
...restProps
|
|
11
11
|
}: {
|
|
12
12
|
class?: string;
|
|
13
13
|
loadingSnippet?: Snippet;
|
|
14
|
-
|
|
14
|
+
placeholderSnippet?: Snippet;
|
|
15
15
|
noPlaceholders?: boolean;
|
|
16
16
|
overrideDefaultStyling?: boolean;
|
|
17
|
+
rawElement?: HTMLElement;
|
|
17
18
|
} & Omit<HTMLImgAttributes, "onerror" | "onload"> = $props();
|
|
18
19
|
|
|
19
|
-
let status = $state("loading");
|
|
20
|
+
let status: "loading" | "done" | "failed" = $state("loading");
|
|
20
21
|
</script>
|
|
21
22
|
|
|
22
|
-
{#if
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}}
|
|
33
|
-
class={(overrideDefaultStyling ? "" : "fluid-image") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "") + (status == "loading" ? " invisible" : "")}
|
|
34
|
-
/>
|
|
35
|
-
{:else if status == "loading" || status == "done"}
|
|
36
|
-
<div class={"fluid-image-loading" + (status === "done" ? " hidden" : "")}>
|
|
23
|
+
{#if status == "failed"}
|
|
24
|
+
{#if placeholderSnippet}
|
|
25
|
+
<div class="fluid-image-error">
|
|
26
|
+
{@render placeholderSnippet()}
|
|
27
|
+
</div>
|
|
28
|
+
{:else}
|
|
29
|
+
<p>Image not loaded, provide placeholder.</p>
|
|
30
|
+
{/if}
|
|
31
|
+
{:else if status == "loading" || "done"}
|
|
32
|
+
<div class={"fluid-image-loading" + status !== "loading" ? " hidden" : ""}>
|
|
37
33
|
{#if loadingSnippet}
|
|
38
34
|
{@render loadingSnippet()}
|
|
39
35
|
{:else}
|
|
40
|
-
<p>
|
|
36
|
+
<p>Image loading, provide placeholder.</p>
|
|
41
37
|
{/if}
|
|
42
38
|
</div>
|
|
43
|
-
|
|
44
39
|
<img
|
|
40
|
+
bind:this={rawElement}
|
|
45
41
|
{...restProps}
|
|
46
42
|
onerror={() => {
|
|
47
43
|
status = "failed";
|
|
@@ -53,12 +49,4 @@
|
|
|
53
49
|
}}
|
|
54
50
|
class={(overrideDefaultStyling ? "" : "fluid-image") + (className ? (overrideDefaultStyling ? `${className}` : ` ${className}`) : "") + (status == "loading" ? " invisible" : "")}
|
|
55
51
|
/>
|
|
56
|
-
{:else if status == "failed"}
|
|
57
|
-
<div class="fluid-image-error">
|
|
58
|
-
{#if errorSnippet}
|
|
59
|
-
{@render errorSnippet()}
|
|
60
|
-
{:else}
|
|
61
|
-
<p>No error snippet provided.</p>
|
|
62
|
-
{/if}
|
|
63
|
-
</div>
|
|
64
52
|
{/if}
|
|
@@ -3,8 +3,9 @@ import type { HTMLImgAttributes } from "svelte/elements";
|
|
|
3
3
|
declare const Image: import("svelte").Component<{
|
|
4
4
|
class?: string;
|
|
5
5
|
loadingSnippet?: Snippet;
|
|
6
|
-
|
|
6
|
+
placeholderSnippet?: Snippet;
|
|
7
7
|
noPlaceholders?: boolean;
|
|
8
8
|
overrideDefaultStyling?: boolean;
|
|
9
|
+
rawElement?: HTMLElement;
|
|
9
10
|
} & Omit<HTMLImgAttributes, "onload" | "onerror">, {}, "">;
|
|
10
11
|
export default Image;
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|