-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add constant validation display mode
In this mode, the validation criteria are shown from the beginning. As soon as a criterion is met, it will turn green. This way, the user gets a direct feedback.
- Loading branch information
1 parent
d3a48bc
commit f3a0592
Showing
7 changed files
with
190 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/lib/components/composites/input/InputValidationCriterion.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script lang="ts"> | ||
import { cn } from "$lib/utils"; | ||
import CircleCheck from "lucide-svelte/icons/circle-check"; | ||
import CircleAlert from "lucide-svelte/icons/circle-alert"; | ||
import type { WithElementRef } from "bits-ui"; | ||
import type { HTMLAttributes } from "svelte/elements"; | ||
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & { | ||
isValid: boolean; | ||
description: string; | ||
}; | ||
let { isValid, description, class: className, ...restProps }: Props = $props(); | ||
const prettyDescription = description.substring(0, 1).toUpperCase() + description.substring(1); | ||
</script> | ||
|
||
<!-- | ||
@component | ||
Input Validation Criterion Element used to display the validation status of an input. | ||
Usage: | ||
```svelte | ||
<InputValidationCriterion {isValid} description="At least one character" /> | ||
``` | ||
--> | ||
<div | ||
class={cn( | ||
"flex flex-row gap-2 w-full px-0.5 py-0.5 text-sm items-start", | ||
isValid ? "text-green-500" : "text-red-500", | ||
className, | ||
)} | ||
{...restProps} | ||
> | ||
<div> | ||
{#if isValid} | ||
<CircleCheck class="w-5 h-5" data-testid="validation-success" /> | ||
{:else} | ||
<CircleAlert class="w-5 h-5" data-testid="validation-fail" /> | ||
{/if} | ||
</div> | ||
<p class="wrap">{prettyDescription}</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.