Refinment: truncate in middle
This commit is contained in:
parent
d5da853db1
commit
327cb883ee
@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { truncateMiddle } from '../../lib/textHelper';
|
||||
import ImageProxy from '../../valueObjects/ImageProxy';
|
||||
|
||||
const MAX_DISPLAY_LENGTH = 50;
|
||||
@ -71,11 +72,11 @@ export default class ImageControl extends React.Component {
|
||||
|
||||
renderImageName() {
|
||||
if (!this.state.currentImage) return null;
|
||||
if (this.state.currentImage.uri.length < MAX_DISPLAY_LENGTH) {
|
||||
return this.state.currentImage.uri;
|
||||
const { uri } = this.state.currentImage;
|
||||
if (uri.length <= MAX_DISPLAY_LENGTH) {
|
||||
return uri;
|
||||
}
|
||||
|
||||
return this.state.currentImage.uri.substring(0, MAX_DISPLAY_LENGTH) + '\u2026';
|
||||
return truncateMiddle(uri, MAX_DISPLAY_LENGTH);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
3
src/lib/textHelper.js
Normal file
3
src/lib/textHelper.js
Normal file
@ -0,0 +1,3 @@
|
||||
export function truncateMiddle(string, size) {
|
||||
return string.substring(0, size / 2) + '\u2026' + string.substring(string.length - size / 2 + 1, string.length);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user