Improve general style per design direction
This commit is contained in:
parent
d1e7c79333
commit
c322761abb
2 changed files with 24 additions and 3 deletions
|
@ -27,6 +27,7 @@ import { presentableTextForFile } from "../../../utils/FileUtils";
|
||||||
import { IMediaEventContent } from "../../../customisations/models/IMediaEventContent";
|
import { IMediaEventContent } from "../../../customisations/models/IMediaEventContent";
|
||||||
import { IBodyProps } from "./IBodyProps";
|
import { IBodyProps } from "./IBodyProps";
|
||||||
import { FileDownloader } from "../../../utils/FileDownloader";
|
import { FileDownloader } from "../../../utils/FileDownloader";
|
||||||
|
import TextWithTooltip from "../elements/TextWithTooltip";
|
||||||
|
|
||||||
export let DOWNLOAD_ICON_URL; // cached copy of the download.svg asset for the sandboxed iframe later on
|
export let DOWNLOAD_ICON_URL; // cached copy of the download.svg asset for the sandboxed iframe later on
|
||||||
|
|
||||||
|
@ -202,9 +203,12 @@ export default class MFileBody extends React.Component<IProps, IState> {
|
||||||
placeholder = (
|
placeholder = (
|
||||||
<AccessibleButton className="mx_MediaBody mx_MFileBody_info" onClick={this.onPlaceholderClick}>
|
<AccessibleButton className="mx_MediaBody mx_MFileBody_info" onClick={this.onPlaceholderClick}>
|
||||||
<span className="mx_MFileBody_info_icon" />
|
<span className="mx_MFileBody_info_icon" />
|
||||||
<span className="mx_MFileBody_info_filename">
|
<TextWithTooltip
|
||||||
{ presentableTextForFile(content, _t("Attachment"), false) }
|
className="mx_MFileBody_info_filename"
|
||||||
</span>
|
tooltip={presentableTextForFile(content, _t("Attachment"), false)}
|
||||||
|
>
|
||||||
|
{ presentableTextForFile(content, _t("Attachment"), true, true) }
|
||||||
|
</TextWithTooltip>
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,14 @@ import { _t } from '../languageHandler';
|
||||||
* @param {IMediaEventContent} content The "content" key of the matrix event.
|
* @param {IMediaEventContent} content The "content" key of the matrix event.
|
||||||
* @param {string} fallbackText The fallback text
|
* @param {string} fallbackText The fallback text
|
||||||
* @param {boolean} withSize Whether to include size information. Default true.
|
* @param {boolean} withSize Whether to include size information. Default true.
|
||||||
|
* @param {boolean} shortened Ensure the extension of the file name is visible. Default false.
|
||||||
* @return {string} the human readable link text for the attachment.
|
* @return {string} the human readable link text for the attachment.
|
||||||
*/
|
*/
|
||||||
export function presentableTextForFile(
|
export function presentableTextForFile(
|
||||||
content: IMediaEventContent,
|
content: IMediaEventContent,
|
||||||
fallbackText = _t("Attachment"),
|
fallbackText = _t("Attachment"),
|
||||||
withSize = true,
|
withSize = true,
|
||||||
|
shortened = false,
|
||||||
): string {
|
): string {
|
||||||
let text = fallbackText;
|
let text = fallbackText;
|
||||||
if (content.body && content.body.length > 0) {
|
if (content.body && content.body.length > 0) {
|
||||||
|
@ -40,6 +42,21 @@ export function presentableTextForFile(
|
||||||
text = content.body;
|
text = content.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We shorten to 15 characters somewhat arbitrarily, and assume most files
|
||||||
|
// will have a 3 character (plus full stop) extension. The goal is to knock
|
||||||
|
// the label down to 15-25 characters, not perfect accuracy.
|
||||||
|
if (shortened && text.length > 19) {
|
||||||
|
const parts = text.split('.');
|
||||||
|
let fileName = parts.slice(0, parts.length - 1).join('.').substring(0, 15);
|
||||||
|
const extension = parts[parts.length - 1];
|
||||||
|
|
||||||
|
// Trim off any full stops from the file name to avoid a case where we
|
||||||
|
// add an ellipsis that looks really funky.
|
||||||
|
fileName = fileName.replace(/\.*$/g, '');
|
||||||
|
|
||||||
|
text = `${fileName}...${extension}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (content.info && content.info.size && withSize) {
|
if (content.info && content.info.size && withSize) {
|
||||||
// If we know the size of the file then add it as human readable
|
// If we know the size of the file then add it as human readable
|
||||||
// string to the end of the link text so that the user knows how
|
// string to the end of the link text so that the user knows how
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue