@functionalcms/svelte-components 4.19.5 → 4.19.6

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.
@@ -0,0 +1,86 @@
1
+ <script lang="ts">
2
+ import { type Field, FieldType, Input } from './form.ts';
3
+ import { fade } from 'svelte/transition';
4
+
5
+ interface Props {
6
+ action: string;
7
+ css?: string;
8
+ successMessage?: string;
9
+ submitButonText?: string;
10
+ fields?: Array<Field>;
11
+ }
12
+
13
+ let {
14
+ action,
15
+ fields = [],
16
+ css = '',
17
+ submitButonText = 'Submit',
18
+ successMessage = 'Your message has been delivered'
19
+ }: Props = $props();
20
+
21
+ let form: any;
22
+ let showMessage = $state(false);
23
+ let isSendingMessage = $state(false);
24
+
25
+ const submitContactForm = async (event: Event) => {
26
+ try {
27
+ if (isSendingMessage) {
28
+ return;
29
+ }
30
+ isSendingMessage = true;
31
+ event.preventDefault();
32
+ const formData = new FormData(form);
33
+ const response = await fetch(action, {
34
+ method: 'POST',
35
+ body: formData
36
+ });
37
+ showMessage = response.status === 200;
38
+ isSendingMessage = false;
39
+ } catch (error) {
40
+ console.error('Error submitting form:', error);
41
+ }
42
+ };
43
+ </script>
44
+
45
+ {#if showMessage}
46
+ <div class="alert alert-success" transition:fade={{ duration: 2000 }}>
47
+ {successMessage}
48
+ </div>
49
+ {:else}
50
+ <form method="POST" bind:this={form} class={css}>
51
+ <fieldset>
52
+ {#each fields as field}
53
+ {#if field.type === FieldType.Input}
54
+ <Input
55
+ name={field.name}
56
+ id={field.name}
57
+ placeholder={field.placeholder}
58
+ type={field.subType}
59
+ isRequired={field.isRequired || false}
60
+ />
61
+ {:else if field.type === FieldType.Textarea}
62
+ <Input
63
+ name={field.name}
64
+ id={field.name}
65
+ placeholder={field.placeholder}
66
+ isRequired={field.isRequired || false}
67
+ />
68
+ {:else if field.type === FieldType.Radio}
69
+ <label>
70
+ <input type="radio" name={field.name} value={field.label} required={field.isRequired} />
71
+ {field.label}
72
+ </label>
73
+ {:else if field.type === FieldType.Checkbox}
74
+ <label>
75
+ <input type="checkbox" name={field.name} required={field.isRequired} />
76
+ {field.label}
77
+ </label>
78
+ {/if}
79
+ {/each}
80
+
81
+ <div class="buttons">
82
+ <button onclick={submitContactForm} class="btn btn-primary">{submitButonText}</button>
83
+ </div>
84
+ </fieldset>
85
+ </form>
86
+ {/if}
@@ -0,0 +1,11 @@
1
+ import { type Field } from './form.ts';
2
+ interface Props {
3
+ action: string;
4
+ css?: string;
5
+ successMessage?: string;
6
+ submitButonText?: string;
7
+ fields?: Array<Field>;
8
+ }
9
+ declare const SmartForm: import("svelte").Component<Props, {}, "">;
10
+ type SmartForm = ReturnType<typeof SmartForm>;
11
+ export default SmartForm;
package/dist/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export { InputType, FieldType, LabelSize, type Field } from './components/form/f
33
33
  export { default as AntiBot } from './components/form/AntiBot.svelte';
34
34
  export { default as Dropzone } from './components/form/Dropzone.svelte';
35
35
  export { default as Select } from './components/form/Select.svelte';
36
+ export { default as SmartForm } from './components/form/SmartForm.svelte';
36
37
  export { default as Markdown } from './components/content/Markdown.svelte';
37
38
  export { type BlogPost, listAllPosts, importPost } from './components/blog/blog.js';
38
39
  export { default as EasyTools } from './components/integrations/EasyTools.svelte';
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ export { InputType, FieldType, LabelSize } from './components/form/form.js';
46
46
  export { default as AntiBot } from './components/form/AntiBot.svelte';
47
47
  export { default as Dropzone } from './components/form/Dropzone.svelte';
48
48
  export { default as Select } from './components/form/Select.svelte';
49
+ export { default as SmartForm } from './components/form/SmartForm.svelte';
49
50
  /*
50
51
  * Content
51
52
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionalcms/svelte-components",
3
- "version": "4.19.5",
3
+ "version": "4.19.6",
4
4
  "watch": {
5
5
  "build": {
6
6
  "patterns": [
@@ -1,54 +0,0 @@
1
- <script lang="ts">
2
- import ChoiceInput from './ChoiceInput.svelte';
3
- import type { Field } from './form.js';
4
- import Input from './Input.svelte';
5
- import Select from './Select.svelte';
6
- import Switch from './Switch.svelte';
7
-
8
- interface Props {
9
- action: string;
10
- css?: string;
11
- successMessage?: string;
12
- submitButonText?: string;
13
- fields?: Array<Field>;
14
- }
15
-
16
- let {
17
- action,
18
- fields = [],
19
- css = '',
20
- submitButonText = 'Submit',
21
- successMessage = 'Your message has been delivered'
22
- }: Props = $props();
23
-
24
- let form: any;
25
-
26
- const showMessage = $state(false);
27
-
28
- const submitContactForm = async (event: Event) => {
29
- event.preventDefault();
30
- const formData = new FormData(form);
31
- const response = await fetch('/contact', {
32
- method: 'POST',
33
- body: formData
34
- });
35
- console.log('Form submitted', response);
36
- };
37
- </script>
38
-
39
- <form method="POST" {action} class={css}>
40
- <fieldset>
41
- {#each fields as field}
42
- <div>
43
- <Input
44
- name={field.name}
45
- id={field.name}
46
- label={field.name}
47
- type={field.subType}
48
- isRequired={field.isRequired}
49
- />
50
- </div>
51
- {/each}
52
- <button onclick={submitContactForm}>{submitButonText}</button>
53
- </fieldset>
54
- </form>
@@ -1,11 +0,0 @@
1
- import type { Field } from './form.js';
2
- interface Props {
3
- action: string;
4
- css?: string;
5
- successMessage?: string;
6
- submitButonText?: string;
7
- fields?: Array<Field>;
8
- }
9
- declare const Form: import("svelte").Component<Props, {}, "">;
10
- type Form = ReturnType<typeof Form>;
11
- export default Form;