Skip to content

Commit

Permalink
feat: required prop for FormField
Browse files Browse the repository at this point in the history
  • Loading branch information
paring-chan committed Mar 21, 2024
1 parent e043b03 commit 379aeef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/components/form/FormField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
export let label: TranslationKey | null = null
export let error: TranslationKey | null = null
export let required: boolean = false
</script>

<div class="form-field">
<label class="form-field-content">
{#if label}
<p class="label">
<Translation key={label} />
{#if required}
<span class="required-sign">*</span>
{/if}
</p>
{/if}
<slot />
Expand All @@ -30,6 +34,10 @@
line-height: 16px;
}
.required-sign {
color: rgba(var(--color-red), 1);
}
.form-field {
display: flex;
flex-direction: column;
Expand Down
9 changes: 9 additions & 0 deletions src/lib/components/form/HorizontalFormField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
export let label: TranslationKey | null = null
export let error: TranslationKey | null = null
export let required: boolean = false
</script>

<div class="form-field">
<label class="form-field-content">
{#if label}
<p class="label">
<Translation key={label} />

{#if required}
<span class="required-sign">*</span>
{/if}
</p>
{/if}
<slot />
Expand All @@ -31,6 +36,10 @@
flex-grow: 1;
}
.required-sign {
color: rgba(var(--color-red), 1);
}
.form-field {
display: flex;
flex-direction: column;
Expand Down
2 changes: 2 additions & 0 deletions src/stories/form/FormField.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@

<Story name="Labeled" args={{ label: 'custom:Label' }} />

<Story name="Required" args={{ label: 'custom:Label', required: true }} />

<Story name="With Error" args={{ label: 'custom:Label', error: 'custom:Wow this is error' }} />
2 changes: 2 additions & 0 deletions src/stories/form/HorizontalFormField.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@

<Story name="Labeled" args={{ label: 'custom:Label' }} />

<Story name="Required" args={{ label: 'custom:Label', required: true }} />

<Story name="With Error" args={{ label: 'custom:Label', error: 'custom:Wow this is error' }} />

0 comments on commit 379aeef

Please sign in to comment.