fluid-ui-svelte 0.1.6 → 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.
@@ -2,37 +2,53 @@
2
2
  import Container from "../primitives/Container.svelte";
3
3
  import Button from "../primitives/Button.svelte";
4
4
  import type { Snippet } from "svelte";
5
+ import type { DropdownOptions } from "../types.js";
5
6
  let {
6
7
  class: className,
7
8
  triggerClass,
8
9
  contentClass,
9
10
  overrideDefaultStyling = false,
10
11
  isOpen = $bindable(false),
12
+ shouldCloseOnClickOutside = true,
11
13
  dropdownTrigger,
12
14
  dropdownContent,
15
+ triggerRawElement,
16
+ contentRawElement,
13
17
  }: {
14
18
  class?: string;
15
19
  triggerClass?: string;
16
20
  contentClass?: string;
17
21
  overrideDefaultStyling?: boolean;
18
22
  isOpen?: boolean;
23
+ shouldCloseOnClickOutside: boolean;
19
24
  dropdownTrigger: Snippet<[options: { isOpen: boolean; toggleDropdown: Function }]>;
20
25
  dropdownContent: Snippet<[options: { isOpen: boolean; toggleDropdown: Function }]>;
26
+ triggerRawElement: HTMLElement;
27
+ contentRawElement: HTMLElement;
21
28
  } = $props();
22
29
 
23
- const componentOptions = {
30
+ const componentOptions: DropdownOptions = {
24
31
  isOpen,
25
32
  toggleDropdown: () => {
26
33
  isOpen = !isOpen;
27
34
  },
28
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
+ }
29
45
  </script>
30
46
 
31
- <Container class={(overrideDefaultStyling ? "" : "fluid-dropdown") + (className ? ` ${className}` : "")} overrideDefaultStyling={true}>
47
+ <Container bind:rawElement={triggerRawElement} class={(overrideDefaultStyling ? "" : "fluid-dropdown") + (className ? ` ${className}` : "")} overrideDefaultStyling={true}>
32
48
  <Container class={(overrideDefaultStyling ? "" : "fluid-dropdown-trigger") + (triggerClass ? ` ${triggerClass}` : "")} overrideDefaultStyling>
33
49
  {@render dropdownTrigger(componentOptions)}
34
50
  </Container>
35
- <Container overrideDefaultStyling class={(overrideDefaultStyling ? "" : "fluid-dropdown-content") + (contentClass ? ` ${contentClass}` : "")}>
51
+ <Container bind:rawElement={contentRawElement} overrideDefaultStyling class={(overrideDefaultStyling ? "" : "fluid-dropdown-content") + (contentClass ? ` ${contentClass}` : "")}>
36
52
  {#if isOpen}
37
53
  {@render dropdownContent(componentOptions)}
38
54
  {/if}
@@ -5,6 +5,7 @@ declare const Dropdown: import("svelte").Component<{
5
5
  contentClass?: string;
6
6
  overrideDefaultStyling?: boolean;
7
7
  isOpen?: boolean;
8
+ shouldCloseOnClickOutside: boolean;
8
9
  dropdownTrigger: Snippet<[options: {
9
10
  isOpen: boolean;
10
11
  toggleDropdown: Function;
@@ -13,5 +14,7 @@ declare const Dropdown: import("svelte").Component<{
13
14
  isOpen: boolean;
14
15
  toggleDropdown: Function;
15
16
  }]>;
17
+ triggerRawElement: HTMLElement;
18
+ contentRawElement: HTMLElement;
16
19
  }, {}, "isOpen">;
17
20
  export default Dropdown;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export type { DropdownOptions as DropdownOptions } from "./types.ts";
1
2
  export { default as Link } from "./primitives/Link.svelte";
2
3
  export { default as Button } from "./primitives/Button.svelte";
3
4
  export { default as Container } from "./primitives/Container.svelte";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ //Types
1
2
  // Primitives
2
3
  export { default as Link } from "./primitives/Link.svelte";
3
4
  export { default as Button } from "./primitives/Button.svelte";
@@ -2,46 +2,48 @@
2
2
  import type { Snippet } from "svelte";
3
3
  import type { HTMLAttributes } from "svelte/elements";
4
4
 
5
- const {
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
- } & HTMLAttributes<HTMLElement>, {}, "">;
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
- const {
4
+ let {
5
5
  class: className,
6
6
  loadingSnippet,
7
- errorSnippet,
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
- errorSnippet?: Snippet;
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 noPlaceholders}
23
- <img
24
- {...restProps}
25
- onerror={() => {
26
- status = "failed";
27
- console.log(status);
28
- }}
29
- onload={() => {
30
- status = "done";
31
- console.log(status);
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>No loading snippet provided.</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
- errorSnippet?: Snippet;
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;
@@ -0,0 +1,4 @@
1
+ export type DropdownOptions = {
2
+ isOpen: boolean;
3
+ toggleDropdown: Function;
4
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluid-ui-svelte",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "author": {
5
5
  "name": "Emre Ayaz",
6
6
  "email": "emreayaz@frostium.io",