-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a default limit of 100 chars to short inputs (closes #120)
- Loading branch information
1 parent
3c846cf
commit c9b216c
Showing
4 changed files
with
80 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<span | ||
v-if="maxChars" | ||
class="text-xs" | ||
:class="[ | ||
hasMaxChars && charCount > maxChars | ||
? 'font-medium text-red-600' | ||
: 'text-grey-600', | ||
]" | ||
> | ||
{{ charCount }} | ||
<span v-if="hasMaxChars">/ {{ maxChars }}</span> | ||
</span> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { watch } from "vue"; | ||
import { computed, ref } from "vue"; | ||
const props = defineProps<{ | ||
text?: string; | ||
maxChars?: number; | ||
}>(); | ||
const charCount = ref<number>(props.text?.length ?? 0); | ||
const hasMaxChars = computed(() => { | ||
return props.maxChars && props.maxChars > 0; | ||
}); | ||
watch( | ||
() => props.text, | ||
() => { | ||
updateCharCount(); | ||
}, | ||
); | ||
const updateCharCount = () => { | ||
if (props.text) { | ||
charCount.value = props.text.length; | ||
} else { | ||
charCount.value = 0; | ||
} | ||
}; | ||
</script> |
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