-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add character count limit for author's message (#212)
* ✨ Add character count limit for author's message * 🎨 Update components error & hint UI using default props * ♻️ Refactor char count computed to composables * 🎨 Rename params * ♻️ Declare AUTHOR_MESSAGE_LIMIT as a constant
- Loading branch information
1 parent
3547a40
commit 2e29ed1
Showing
4 changed files
with
57 additions
and
6 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,29 @@ | ||
import { computed, Ref, ComputedRef } from 'vue' | ||
|
||
interface UseMessageCharCountReturn { | ||
messageCharCount: ComputedRef<number>; | ||
isLimitReached: ComputedRef<boolean>; | ||
} | ||
|
||
function isFullWidthChar (char: string): boolean { | ||
return char.charCodeAt(0) > 255 | ||
} | ||
|
||
export function useMessageCharCount (memo: Ref<string>, limit: number): UseMessageCharCountReturn { | ||
const messageCharCount = computed((): number => { | ||
let count = 0 | ||
for (let i = 0; i < memo.value.length; i++) { | ||
count += isFullWidthChar(memo.value[i]) ? 2 : 1 | ||
} | ||
return count | ||
}) | ||
|
||
const isLimitReached = computed((): boolean => { | ||
return messageCharCount.value > limit | ||
}) | ||
|
||
return { | ||
messageCharCount, | ||
isLimitReached | ||
} | ||
} |
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