@functionalcms/svelte-components 4.24.0 → 4.25.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/dist/components/dynamic/DynamicButton.d.ts +1 -0
- package/dist/components/dynamic/DynamicButton.js +10 -0
- package/dist/components/dynamic/DynamicButton.svelte +33 -0
- package/dist/components/dynamic/DynamicButton.svelte.d.ts +9 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const executeRest: (url: string, method?: "POST" | "GET" | "PUT" | "DELETE") => Promise<boolean>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const executeRest = async (url, method = "GET") => {
|
|
2
|
+
let fetchUrl = url;
|
|
3
|
+
if (!fetchUrl.startsWith('http')) {
|
|
4
|
+
fetchUrl = window.location.origin + fetchUrl;
|
|
5
|
+
}
|
|
6
|
+
const response = await fetch(fetchUrl, {
|
|
7
|
+
method: method,
|
|
8
|
+
});
|
|
9
|
+
return response.status === 200;
|
|
10
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Button, Loader } from "@functionalcms/svelte-components";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
label: string;
|
|
6
|
+
click: () => Promise<boolean>;
|
|
7
|
+
|
|
8
|
+
success?: () => void;
|
|
9
|
+
failure?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { label, click, success, failure }: Props = $props();
|
|
13
|
+
let isLoading = $derived(false);
|
|
14
|
+
|
|
15
|
+
const whenButtonIsclicked = async () => {
|
|
16
|
+
if (isLoading === false) {
|
|
17
|
+
isLoading = true;
|
|
18
|
+
|
|
19
|
+
const response = await click();
|
|
20
|
+
|
|
21
|
+
response ? success?.() : failure?.();
|
|
22
|
+
|
|
23
|
+
isLoading = false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<Button type="button" click={whenButtonIsclicked}>
|
|
29
|
+
{#if isLoading}
|
|
30
|
+
<Loader size="small" />
|
|
31
|
+
{/if}
|
|
32
|
+
{label}
|
|
33
|
+
</Button>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
label: string;
|
|
3
|
+
click: () => Promise<boolean>;
|
|
4
|
+
success?: () => void;
|
|
5
|
+
failure?: () => void;
|
|
6
|
+
}
|
|
7
|
+
declare const DynamicButton: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type DynamicButton = ReturnType<typeof DynamicButton>;
|
|
9
|
+
export default DynamicButton;
|
package/dist/index.d.ts
CHANGED
|
@@ -42,3 +42,8 @@ export { default as EasyTools } from './components/integrations/EasyTools.svelte
|
|
|
42
42
|
**/
|
|
43
43
|
export { default as Loader } from './components/indicators/Loader.svelte';
|
|
44
44
|
export { default as Spinner } from './components/indicators/Spinner.svelte';
|
|
45
|
+
/**
|
|
46
|
+
* Dynamic
|
|
47
|
+
**/
|
|
48
|
+
export { default as DynamicButton } from './components/dynamic/DynamicButton.svelte';
|
|
49
|
+
export { executeRest } from './components/dynamic/DynamicButton.js';
|
package/dist/index.js
CHANGED
|
@@ -64,3 +64,8 @@ export { default as EasyTools } from './components/integrations/EasyTools.svelte
|
|
|
64
64
|
**/
|
|
65
65
|
export { default as Loader } from './components/indicators/Loader.svelte';
|
|
66
66
|
export { default as Spinner } from './components/indicators/Spinner.svelte';
|
|
67
|
+
/**
|
|
68
|
+
* Dynamic
|
|
69
|
+
**/
|
|
70
|
+
export { default as DynamicButton } from './components/dynamic/DynamicButton.svelte';
|
|
71
|
+
export { executeRest } from './components/dynamic/DynamicButton.js';
|