From d483de84d8abe97a137170282e86295c6521f364 Mon Sep 17 00:00:00 2001 From: HubbeDev Date: Sat, 6 Jan 2024 22:55:48 +0100 Subject: [PATCH] rearrange shadcn-svelte to own components. --- .../src/lib/components/button/index.ts | 2 +- .../components/description/description.svelte | 13 +++ .../src/lib/components/description/index.ts | 7 ++ .../src/lib/components/form/form.svelte | 89 ------------------ .../src/lib/components/form/index.ts | 67 ++++++++++++- .../src/lib/components/form/types.ts | 3 - .../src/lib/components/index.ts | 1 - .../src/lib/components/input/index.ts | 25 +++++ .../src/lib/components/input/input.svelte | 36 +++++++ .../src/lib/components/item/index.ts | 7 ++ .../src/lib/components/item/item.svelte | 12 +++ .../src/lib/components/label/index.ts | 7 ++ .../src/lib/components/label/label.svelte | 26 +++++ .../src/lib/components/root.svelte | 94 +++++++++++++++++-- .../lib/components/ui/form/form-input.svelte | 28 ------ .../src/lib/components/ui/form/index.ts | 2 +- .../src/lib/components/validation/index.ts | 7 ++ .../components/validation/validation.svelte | 14 +++ .../src/lib/internal/types.ts | 2 +- 19 files changed, 310 insertions(+), 132 deletions(-) create mode 100644 apps/svelte-gravity-forms/src/lib/components/description/description.svelte create mode 100644 apps/svelte-gravity-forms/src/lib/components/description/index.ts delete mode 100644 apps/svelte-gravity-forms/src/lib/components/form/form.svelte delete mode 100644 apps/svelte-gravity-forms/src/lib/components/form/types.ts create mode 100644 apps/svelte-gravity-forms/src/lib/components/input/index.ts create mode 100644 apps/svelte-gravity-forms/src/lib/components/input/input.svelte create mode 100644 apps/svelte-gravity-forms/src/lib/components/item/index.ts create mode 100644 apps/svelte-gravity-forms/src/lib/components/item/item.svelte create mode 100644 apps/svelte-gravity-forms/src/lib/components/label/index.ts create mode 100644 apps/svelte-gravity-forms/src/lib/components/label/label.svelte delete mode 100644 apps/svelte-gravity-forms/src/lib/components/ui/form/form-input.svelte create mode 100644 apps/svelte-gravity-forms/src/lib/components/validation/index.ts create mode 100644 apps/svelte-gravity-forms/src/lib/components/validation/validation.svelte diff --git a/apps/svelte-gravity-forms/src/lib/components/button/index.ts b/apps/svelte-gravity-forms/src/lib/components/button/index.ts index 31667ea..dbfaded 100644 --- a/apps/svelte-gravity-forms/src/lib/components/button/index.ts +++ b/apps/svelte-gravity-forms/src/lib/components/button/index.ts @@ -52,7 +52,7 @@ export { type Events, type ButtonType, // - Root as GFButton, + Root as Button, type Props as ButtonProps, type Events as ButtonEvents, buttonVariants diff --git a/apps/svelte-gravity-forms/src/lib/components/description/description.svelte b/apps/svelte-gravity-forms/src/lib/components/description/description.svelte new file mode 100644 index 0000000..b3044ad --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/description/description.svelte @@ -0,0 +1,13 @@ + + + + + diff --git a/apps/svelte-gravity-forms/src/lib/components/description/index.ts b/apps/svelte-gravity-forms/src/lib/components/description/index.ts new file mode 100644 index 0000000..d1ea533 --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/description/index.ts @@ -0,0 +1,7 @@ +import Root from './description.svelte'; + +export { + Root, + // + Root as Description +}; diff --git a/apps/svelte-gravity-forms/src/lib/components/form/form.svelte b/apps/svelte-gravity-forms/src/lib/components/form/form.svelte deleted file mode 100644 index 19ada7b..0000000 --- a/apps/svelte-gravity-forms/src/lib/components/form/form.svelte +++ /dev/null @@ -1,89 +0,0 @@ - - -{#if !form} -

Please provide a formId

-{:else} - -
- {#if $formFields} - {#each $formFields as field, i} -
- - - {#if field.label && showFieldLabel(field.labelPlacement, 'above')} - - {field.label} - {#if field.isRequired} - {#if $formRequiredIndicator == 'asterisk'} - * - {:else if $formRequiredIndicator == 'text'} - (required) - {/if} - {/if} - - {#if field.description && field.descriptionPlacement == 'above'} - {field.description} - {/if} - - {#if field.label && showFieldLabel(field.labelPlacement, 'below')} - {field.description} - {/if} - {/if} - - - -
- {/each} - {/if} - -
-
-{/if} diff --git a/apps/svelte-gravity-forms/src/lib/components/form/index.ts b/apps/svelte-gravity-forms/src/lib/components/form/index.ts index 8184a6d..6c6be64 100644 --- a/apps/svelte-gravity-forms/src/lib/components/form/index.ts +++ b/apps/svelte-gravity-forms/src/lib/components/form/index.ts @@ -1 +1,66 @@ -export { default as Form } from './form.svelte'; +import { Form as FormPrimitive, getFormField } from 'formsnap'; +import * as RadioGroupComp from '$lib/components/ui/radio-group/index.js'; +import * as SelectComp from '$lib/components/ui/select/index.js'; +import type { Writable } from 'svelte/store'; +import { Item } from '$components/item/index.js'; +import { Input } from '$components/input/index.js'; +import { Description } from '$components/description/index.js'; +import { Label } from '$components/label/index.js'; +import { Validation } from '$components/validation/index.js'; + +import { Button } from '$components/button/index.js'; + +const Root = FormPrimitive.Root; +const Field = FormPrimitive.Field; +const Control = FormPrimitive.Control; +const RadioItem = RadioGroupComp.Item; +const NativeRadio = FormPrimitive.Radio; +const SelectContent = SelectComp.Content; +const SelectLabel = SelectComp.Label; +const SelectGroup = SelectComp.Group; +const SelectItem = SelectComp.Item; +const SelectSeparator = SelectComp.Separator; + +export type TextareaGetFormField = Omit, 'value'> & { + value: Writable; +}; + +export type Props = { + formId?: number; +}; + +export { + Root, + Field, + Control, + Item, + Input, + Label, + Button, + Validation, + RadioItem, + Description, + SelectContent, + SelectLabel, + SelectGroup, + SelectItem, + SelectSeparator, + NativeRadio, + // + Root as Form, + Field as FormField, + Control as FormControl, + Item as FormItem, + Input as FormInput, + Description as FormDescription, + Label as FormLabel, + Validation as FormValidation, + NativeRadio as FormNativeRadio, + RadioItem as FormRadioItem, + SelectContent as FormSelectContent, + SelectLabel as FormSelectLabel, + SelectGroup as FormSelectGroup, + SelectItem as FormSelectItem, + SelectSeparator as FormSelectSeparator, + Button as FormButton +}; diff --git a/apps/svelte-gravity-forms/src/lib/components/form/types.ts b/apps/svelte-gravity-forms/src/lib/components/form/types.ts deleted file mode 100644 index 2cbdd64..0000000 --- a/apps/svelte-gravity-forms/src/lib/components/form/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type Props = { - formId?: number; -}; diff --git a/apps/svelte-gravity-forms/src/lib/components/index.ts b/apps/svelte-gravity-forms/src/lib/components/index.ts index b58a198..921427e 100644 --- a/apps/svelte-gravity-forms/src/lib/components/index.ts +++ b/apps/svelte-gravity-forms/src/lib/components/index.ts @@ -1,4 +1,3 @@ -import { default as GFForm } from './form/form.svelte'; import { default as GFButton } from './button/button.svelte'; export { GFForm, GFButton }; diff --git a/apps/svelte-gravity-forms/src/lib/components/input/index.ts b/apps/svelte-gravity-forms/src/lib/components/input/index.ts new file mode 100644 index 0000000..9ba89bc --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/input/index.ts @@ -0,0 +1,25 @@ +import Root from './input.svelte'; + +type FormInputEvent = T & { + currentTarget: EventTarget & HTMLInputElement; +}; +export type InputEvents = { + blur: FormInputEvent; + change: FormInputEvent; + click: FormInputEvent; + focus: FormInputEvent; + keydown: FormInputEvent; + keypress: FormInputEvent; + keyup: FormInputEvent; + mouseover: FormInputEvent; + mouseenter: FormInputEvent; + mouseleave: FormInputEvent; + paste: FormInputEvent; + input: FormInputEvent; +}; + +export { + Root, + // + Root as Input +}; diff --git a/apps/svelte-gravity-forms/src/lib/components/input/input.svelte b/apps/svelte-gravity-forms/src/lib/components/input/input.svelte new file mode 100644 index 0000000..48828e3 --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/input/input.svelte @@ -0,0 +1,36 @@ + + + diff --git a/apps/svelte-gravity-forms/src/lib/components/item/index.ts b/apps/svelte-gravity-forms/src/lib/components/item/index.ts new file mode 100644 index 0000000..663722c --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/item/index.ts @@ -0,0 +1,7 @@ +import Root from './item.svelte'; + +export { + Root, + // + Root as Item +}; diff --git a/apps/svelte-gravity-forms/src/lib/components/item/item.svelte b/apps/svelte-gravity-forms/src/lib/components/item/item.svelte new file mode 100644 index 0000000..9435c55 --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/item/item.svelte @@ -0,0 +1,12 @@ + + +
+ +
diff --git a/apps/svelte-gravity-forms/src/lib/components/label/index.ts b/apps/svelte-gravity-forms/src/lib/components/label/index.ts new file mode 100644 index 0000000..808d141 --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/label/index.ts @@ -0,0 +1,7 @@ +import Root from './label.svelte'; + +export { + Root, + // + Root as Label +}; diff --git a/apps/svelte-gravity-forms/src/lib/components/label/label.svelte b/apps/svelte-gravity-forms/src/lib/components/label/label.svelte new file mode 100644 index 0000000..942db7b --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/label/label.svelte @@ -0,0 +1,26 @@ + + + + + diff --git a/apps/svelte-gravity-forms/src/lib/components/root.svelte b/apps/svelte-gravity-forms/src/lib/components/root.svelte index 290c57f..027293f 100644 --- a/apps/svelte-gravity-forms/src/lib/components/root.svelte +++ b/apps/svelte-gravity-forms/src/lib/components/root.svelte @@ -1,22 +1,102 @@ - +{#if !form} +

Please provide a formId

+{:else} + +
+ {#if $formFields} + {#each $formFields as field, i} +
+ + + {#if field.label && showFieldLabel(field.labelPlacement, 'above')} + + {field.label} + {#if field.isRequired} + {#if $formRequiredIndicator == 'asterisk'} + * + {:else if $formRequiredIndicator == 'text'} + (required) + {/if} + {/if} + + {#if field.description && field.descriptionPlacement == 'above'} + {field.description} + {/if} + + {#if field.label && showFieldLabel(field.labelPlacement, 'below')} + {field.description} + {/if} + {/if} + + + +
+ {/each} + {/if} + +
+
+{/if} {#if $formObject}
diff --git a/apps/svelte-gravity-forms/src/lib/components/ui/form/form-input.svelte b/apps/svelte-gravity-forms/src/lib/components/ui/form/form-input.svelte deleted file mode 100644 index 2cada46..0000000 --- a/apps/svelte-gravity-forms/src/lib/components/ui/form/form-input.svelte +++ /dev/null @@ -1,28 +0,0 @@ - - - diff --git a/apps/svelte-gravity-forms/src/lib/components/ui/form/index.ts b/apps/svelte-gravity-forms/src/lib/components/ui/form/index.ts index 6028eeb..c961067 100644 --- a/apps/svelte-gravity-forms/src/lib/components/ui/form/index.ts +++ b/apps/svelte-gravity-forms/src/lib/components/ui/form/index.ts @@ -3,7 +3,7 @@ import * as RadioGroupComp from '$lib/components/ui/radio-group/index.js'; import * as SelectComp from '$lib/components/ui/select/index.js'; import type { Writable } from 'svelte/store'; import Item from './form-item.svelte'; -import Input from './form-input.svelte'; +import { Input } from '$components/input/index.js'; import Textarea from './form-textarea.svelte'; import Description from './form-description.svelte'; import Label from './form-label.svelte'; diff --git a/apps/svelte-gravity-forms/src/lib/components/validation/index.ts b/apps/svelte-gravity-forms/src/lib/components/validation/index.ts new file mode 100644 index 0000000..7556fab --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/validation/index.ts @@ -0,0 +1,7 @@ +import Root from './validation.svelte'; + +export { + Root, + // + Root as Validation +}; diff --git a/apps/svelte-gravity-forms/src/lib/components/validation/validation.svelte b/apps/svelte-gravity-forms/src/lib/components/validation/validation.svelte new file mode 100644 index 0000000..6ca08c8 --- /dev/null +++ b/apps/svelte-gravity-forms/src/lib/components/validation/validation.svelte @@ -0,0 +1,14 @@ + + + diff --git a/apps/svelte-gravity-forms/src/lib/internal/types.ts b/apps/svelte-gravity-forms/src/lib/internal/types.ts index 62e803e..0a53b1d 100644 --- a/apps/svelte-gravity-forms/src/lib/internal/types.ts +++ b/apps/svelte-gravity-forms/src/lib/internal/types.ts @@ -29,7 +29,7 @@ export type GFFieldsProps = { choices?: string; conditionalLogic?: string; productField?: string; - layoutGridColumnSpan?: string; + layoutGridColumnSpan?: number; enablePasswordInput?: boolean; enableEnhancedUI?: number; layoutGroupId?: string;