UNPKG

communication-react-19

Version:

React library for building modern communication user experiences utilizing Azure Communication Services (React 19 compatible fork)

77 lines 2.65 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import React from 'react'; import { Icon } from '@fluentui/react'; import { isMessageTooLong } from './SendBoxUtils'; import { _formatString } from "../../../../acs-ui-common/src"; import { MAXIMUM_LENGTH_OF_MESSAGE } from '../utils/SendBoxUtils'; /** * @private */ export const onRenderCancelIcon = (className) => { return React.createElement(Icon, { iconName: 'EditBoxCancel', className: className }); }; /** * @private */ export const onRenderSubmitIcon = (className) => { return React.createElement(Icon, { iconName: 'EditBoxSubmit', className: className }); }; function isMessageEmpty(messageText, /* @conditional-compile-remove(file-sharing-acs) */ attachmentMetadata) { /* @conditional-compile-remove(file-sharing-acs) */ return messageText.trim().length === 0 && (attachmentMetadata === null || attachmentMetadata === void 0 ? void 0 : attachmentMetadata.length) === 0; return messageText.trim().length === 0; } /** * @private */ export function getMessageState(messageText, /* @conditional-compile-remove(file-sharing-acs) */ attachments) { return isMessageEmpty(messageText, /* @conditional-compile-remove(file-sharing-acs) */ attachments) ? 'too short' : isMessageTooLong(messageText.length) ? 'too long' : 'OK'; } /** * @private */ export const getTextValidationErrorMessage = (messageState, tooLongString, tooShortString, imageOverflow = false) => { return messageState === 'too long' || imageOverflow ? _formatString(tooLongString, { limitNumber: `${MAXIMUM_LENGTH_OF_MESSAGE}` }) : messageState === 'too short' ? tooShortString : undefined; }; /* @conditional-compile-remove(file-sharing-acs) */ /** * @private * @TODO: Remove when file-sharing feature becomes stable. */ export function getMessageWithAttachmentMetadata(message) { return message.attachments; } /* @conditional-compile-remove(file-sharing-acs) */ /** * @internal */ export const attachmentMetadataReducer = (state, action) => { switch (action.type) { case 'remove': return state.filter((v) => v.id !== action.id); default: return state; } }; /* @conditional-compile-remove(file-sharing-acs) */ /** * @internal */ export const doesMessageContainMultipleAttachments = (message) => { var _a, _b; const length = (_b = (_a = message.attachments) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0; return length > 1; }; //# sourceMappingURL=ChatMessageComponentAsEditBoxUtils.js.map