Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: database forms design review #292

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/elements/forms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export { default as InputURL } from './inputURL.svelte';
export { default as InputId } from './inputId.svelte';
export { default as InputSecret } from './inputSecret.svelte';
export { default as Helper } from './helper.svelte';
export { default as Label } from './label.svelte';
9 changes: 3 additions & 6 deletions src/lib/elements/forms/inputCheckbox.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let optionalText: string | undefined = undefined;
Expand Down Expand Up @@ -27,12 +27,9 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>
<Label {required} {optionalText} hide={!showLabel} for={id}>
{label}
{#if optionalText}
<span class="optional">{optionalText}</span>
{/if}
</label>
</Label>

<div class="input-text-wrapper">
<input
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputCron.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -48,7 +48,10 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper">
<input
{id}
Expand Down
9 changes: 3 additions & 6 deletions src/lib/elements/forms/inputDateTime.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -39,12 +39,9 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>
<Label {required} {optionalText} hide={!showLabel} for={id}>
{label}
<span class:u-hide={!showLabel || !optionalText} class="optional">
{optionalText}
</span>
</label>
</Label>

<div class="input-text-wrapper" style="--amount-of-buttons:1; --button-size: 1rem">
<input
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputDomain.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -47,7 +47,10 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper">
<input
{id}
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputEmail.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -41,7 +41,10 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper">
<input
{id}
Expand Down
9 changes: 3 additions & 6 deletions src/lib/elements/forms/inputNumber.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let optionalText: string | undefined = undefined;
Expand Down Expand Up @@ -52,12 +52,9 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>
<Label {required} {optionalText} hide={!showLabel} for={id}>
{label}
{#if optionalText}
<span class="optional">{optionalText}</span>
{/if}
</label>
</Label>

<div class="input-text-wrapper">
<input
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputPassword.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let id: string;
export let label: string;
Expand Down Expand Up @@ -47,7 +47,10 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper">
{#if showInPlainText}
<input
Expand Down
6 changes: 4 additions & 2 deletions src/lib/elements/forms/inputPhone.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -46,7 +46,9 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>
<div class="input-text-wrapper">
<input
{id}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/elements/forms/inputRadio.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -40,7 +40,9 @@
bind:group
bind:this={element}
on:invalid={handleInvalid} />
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>
</div>
{#if error}
<Helper type="warning">{error}</Helper>
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputSecret.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { FormItem } from '.';
import { FormItem, Label } from '.';

export let id: string;
export let label: string;
Expand All @@ -11,7 +11,10 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper" style=" --amount-of-buttons: 1;">
{#if showInPlainText}
<div
Expand Down
9 changes: 3 additions & 6 deletions src/lib/elements/forms/inputSelect.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let id: string;
export let label: string;
Expand Down Expand Up @@ -41,12 +41,9 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>
<Label {required} {optionalText} hide={!showLabel} for={id}>
{label}
{#if optionalText}
<span class="optional">{optionalText}</span>
{/if}
</label>
</Label>

<div class="select">
<select
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputTags.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { last } from '$lib/helpers/array';
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let id: string;
export let label: string;
Expand Down Expand Up @@ -77,7 +77,10 @@
value={tags.join(',')}
{required}
on:invalid={handleInvalid} />
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper">
<div class="tags-input">
<div class="tags">
Expand Down
25 changes: 10 additions & 15 deletions src/lib/elements/forms/inputText.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import { tooltip as tooltipAction } from '$lib/actions/tooltip';
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let optionalText: string | undefined = undefined;
Expand Down Expand Up @@ -43,20 +42,9 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>
<Label {required} {tooltip} {optionalText} hide={!showLabel} for={id}>
{label}
{#if tooltip}
<span
class="icon-info"
aria-hidden="true"
use:tooltipAction={{
content: tooltip
}} />
{/if}
{#if optionalText}
<span class="optional">{optionalText}</span>
{/if}
</label>
</Label>

<div class="input-text-wrapper">
<input
Expand All @@ -72,6 +60,13 @@
bind:value
bind:this={element}
on:invalid={handleInvalid} />
{#if maxlength}
<span class="text-counter">
<span class="text-counter-count">{value?.length ?? 0}</span>
<span class="text-counter-separator" />
<span class="text-counter-max">{maxlength}</span>
</span>
{/if}
</div>
{#if error}
<Helper type="warning">{error}</Helper>
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputTextarea.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -37,7 +37,10 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper">
<textarea
{id}
Expand Down
7 changes: 5 additions & 2 deletions src/lib/elements/forms/inputURL.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { FormItem, Helper } from '.';
import { FormItem, Helper, Label } from '.';

export let label: string;
export let showLabel = true;
Expand Down Expand Up @@ -50,7 +50,10 @@
</script>

<FormItem>
<label class:u-hide={!showLabel} class="label" for={id}>{label}</label>
<Label {required} hide={!showLabel} for={id}>
{label}
</Label>

<div class="input-text-wrapper">
<input
{id}
Expand Down
33 changes: 33 additions & 0 deletions src/lib/elements/forms/label.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts">
interface $$Props extends Partial<HTMLLabelElement> {
required?: boolean;
optionalText?: string | undefined;
hide?: boolean;
tooltip?: string;
for?: string;
}

export let required: $$Props['required'] = false;
export let optionalText: $$Props['optionalText'] = undefined;
export let hide: $$Props['hide'] = false;
export let tooltip: $$Props['tooltip'] = null;
</script>

<label class:is-required={required} class:u-hide={hide} class="label" {...$$restProps}>
<slot />
</label>

{#if optionalText}
<span class="optional">{optionalText}</span>
{/if}

{#if tooltip}
<button class="tooltip" aria-label="variables info">
<span class="icon-info" aria-hidden="true" />
<span class="tooltip-popup" role="tooltip">
<p class="text">
{tooltip}
</p>
</span>
</button>
{/if}
Loading