Tags menu/muted words improvements (#3002)
* Fix translations * Handle loooong words * Truncate on desktop web, revert mobile changes * Break the words * Small enough for mobile web * Fix alignment on mobile web * Clarify
This commit is contained in:
parent
6717f8f11e
commit
978bcc1ba9
5 changed files with 53 additions and 11 deletions
|
@ -8,10 +8,27 @@ export function pluralize(n: number, base: string, plural?: string): string {
|
|||
return base + 's'
|
||||
}
|
||||
|
||||
export function enforceLen(str: string, len: number, ellipsis = false): string {
|
||||
export function enforceLen(
|
||||
str: string,
|
||||
len: number,
|
||||
ellipsis = false,
|
||||
mode: 'end' | 'middle' = 'end',
|
||||
): string {
|
||||
str = str || ''
|
||||
if (str.length > len) {
|
||||
return str.slice(0, len) + (ellipsis ? '...' : '')
|
||||
if (ellipsis) {
|
||||
if (mode === 'end') {
|
||||
return str.slice(0, len) + '…'
|
||||
} else if (mode === 'middle') {
|
||||
const half = Math.floor(len / 2)
|
||||
return str.slice(0, half) + '…' + str.slice(-half)
|
||||
} else {
|
||||
// fallback
|
||||
return str.slice(0, len)
|
||||
}
|
||||
} else {
|
||||
return str.slice(0, len)
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue