From 9598059b8a7758119d56b308309245d62a6cbe98 Mon Sep 17 00:00:00 2001 From: paring Date: Wed, 20 Mar 2024 18:45:58 +0900 Subject: [PATCH] feat: form related components --- src/lib/components/form/Checkbox.svelte | 64 +++++++++++++++++++ src/lib/components/form/FormField.svelte | 44 +++++++++++++ src/lib/components/form/FormHint.svelte | 25 ++++++++ .../form/HorizontalFormField.svelte | 45 +++++++++++++ src/lib/components/form/InputControl.svelte | 43 +++++++++++++ .../components/form/LabeledCheckbox.svelte | 21 ++++++ src/lib/index.ts | 7 ++ src/lib/utils/translation.ts | 9 ++- src/stories/form/Checkbox.stories.svelte | 18 ++++++ src/stories/form/FormField.stories.svelte | 22 +++++++ .../form/HorizontalFormField.stories.svelte | 22 +++++++ src/stories/form/InputControl.stories.svelte | 18 ++++++ .../form/LabeledCheckbox.stories.svelte | 18 ++++++ 13 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/form/Checkbox.svelte create mode 100644 src/lib/components/form/FormField.svelte create mode 100644 src/lib/components/form/FormHint.svelte create mode 100644 src/lib/components/form/HorizontalFormField.svelte create mode 100644 src/lib/components/form/InputControl.svelte create mode 100644 src/lib/components/form/LabeledCheckbox.svelte create mode 100644 src/stories/form/Checkbox.stories.svelte create mode 100644 src/stories/form/FormField.stories.svelte create mode 100644 src/stories/form/HorizontalFormField.stories.svelte create mode 100644 src/stories/form/InputControl.stories.svelte create mode 100644 src/stories/form/LabeledCheckbox.stories.svelte diff --git a/src/lib/components/form/Checkbox.svelte b/src/lib/components/form/Checkbox.svelte new file mode 100644 index 0000000..b7545d4 --- /dev/null +++ b/src/lib/components/form/Checkbox.svelte @@ -0,0 +1,64 @@ + + + + + diff --git a/src/lib/components/form/FormField.svelte b/src/lib/components/form/FormField.svelte new file mode 100644 index 0000000..330ac7a --- /dev/null +++ b/src/lib/components/form/FormField.svelte @@ -0,0 +1,44 @@ + + +
+ + {#if error} + + + + {/if} +
+ + diff --git a/src/lib/components/form/FormHint.svelte b/src/lib/components/form/FormHint.svelte new file mode 100644 index 0000000..322080c --- /dev/null +++ b/src/lib/components/form/FormHint.svelte @@ -0,0 +1,25 @@ +
+ +
+ + diff --git a/src/lib/components/form/HorizontalFormField.svelte b/src/lib/components/form/HorizontalFormField.svelte new file mode 100644 index 0000000..32b74bb --- /dev/null +++ b/src/lib/components/form/HorizontalFormField.svelte @@ -0,0 +1,45 @@ + + +
+ + {#if error} + + + + {/if} +
+ + diff --git a/src/lib/components/form/InputControl.svelte b/src/lib/components/form/InputControl.svelte new file mode 100644 index 0000000..0c508d7 --- /dev/null +++ b/src/lib/components/form/InputControl.svelte @@ -0,0 +1,43 @@ + + +
+ +
+ + diff --git a/src/lib/components/form/LabeledCheckbox.svelte b/src/lib/components/form/LabeledCheckbox.svelte new file mode 100644 index 0000000..043786d --- /dev/null +++ b/src/lib/components/form/LabeledCheckbox.svelte @@ -0,0 +1,21 @@ + + + + + + diff --git a/src/lib/index.ts b/src/lib/index.ts index 644ee21..87856dc 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -40,3 +40,10 @@ export { default as NavAccessibilitySettings } from './components/nav/NavAccessi export { default as Footer } from './components/footer/Footer.svelte' export { default as FooterLink } from './components/footer/FooterLink.svelte' export { default as FooterSection } from './components/footer/FooterSection.svelte' + +// Form +export { default as FormField } from './components/form/FormField.svelte' +export { default as HorizontalFormField } from './components/form/HorizontalFormField.svelte' +export { default as InputControl } from './components/form/InputControl.svelte' +export { default as Checkbox } from './components/form/Checkbox.svelte' +export { default as LabeledCheckbox } from './components/form/LabeledCheckbox.svelte' diff --git a/src/lib/utils/translation.ts b/src/lib/utils/translation.ts index bbffbb8..3db6b82 100644 --- a/src/lib/utils/translation.ts +++ b/src/lib/utils/translation.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/ban-types */ + import { writable, type Readable, derived } from 'svelte/store' import langs from '../localization/langs.json' @@ -17,8 +19,11 @@ const langSections = ['common', 'footer', 'nav'] as const export type LangSection = (typeof langSections)[number] | ADOFAIGG_UI.ExtraLangSections[number] export type LangData = Record -// eslint-disable-next-line @typescript-eslint/ban-types -export type StringTranslationKey = `${LangSection}:` | (`${LangSection}:${string & {}}` & {}) +export type StringTranslationKey = + | `${LangSection}:` + | (`${LangSection}:${string & {}}` & {}) + | (`${string}:${string}` & {}) + export type ArrayTranslationKey = [LangSection, string] export type TranslationKey = StringTranslationKey | ArrayTranslationKey diff --git a/src/stories/form/Checkbox.stories.svelte b/src/stories/form/Checkbox.stories.svelte new file mode 100644 index 0000000..19f9337 --- /dev/null +++ b/src/stories/form/Checkbox.stories.svelte @@ -0,0 +1,18 @@ + + + + + + + diff --git a/src/stories/form/FormField.stories.svelte b/src/stories/form/FormField.stories.svelte new file mode 100644 index 0000000..13d06b8 --- /dev/null +++ b/src/stories/form/FormField.stories.svelte @@ -0,0 +1,22 @@ + + + + + + + + + diff --git a/src/stories/form/HorizontalFormField.stories.svelte b/src/stories/form/HorizontalFormField.stories.svelte new file mode 100644 index 0000000..90acfdd --- /dev/null +++ b/src/stories/form/HorizontalFormField.stories.svelte @@ -0,0 +1,22 @@ + + + + + + + + + diff --git a/src/stories/form/InputControl.stories.svelte b/src/stories/form/InputControl.stories.svelte new file mode 100644 index 0000000..0f9a582 --- /dev/null +++ b/src/stories/form/InputControl.stories.svelte @@ -0,0 +1,18 @@ + + + + + + + diff --git a/src/stories/form/LabeledCheckbox.stories.svelte b/src/stories/form/LabeledCheckbox.stories.svelte new file mode 100644 index 0000000..2e5522a --- /dev/null +++ b/src/stories/form/LabeledCheckbox.stories.svelte @@ -0,0 +1,18 @@ + + + + + + +