convert chat message-form component

This commit is contained in:
Ramón Souza 2021-11-02 12:26:36 +00:00
parent 1f95905dcf
commit 401ee71563
3 changed files with 99 additions and 202 deletions

View File

@ -1,13 +1,10 @@
import React, { PureComponent } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import cx from 'classnames';
import TextareaAutosize from 'react-autosize-textarea';
import deviceInfo from '/imports/utils/deviceInfo';
import PropTypes from 'prop-types';
import _ from 'lodash';
import TypingIndicatorContainer from './typing-indicator/container';
import { styles } from './styles.scss';
import Button from '../../button/component';
import Styled from './styles';
const propTypes = {
intl: PropTypes.object.isRequired,
@ -16,7 +13,6 @@ const propTypes = {
minMessageLength: PropTypes.number.isRequired,
maxMessageLength: PropTypes.number.isRequired,
chatTitle: PropTypes.string.isRequired,
className: PropTypes.string,
chatAreaId: PropTypes.string.isRequired,
handleSendMessage: PropTypes.func.isRequired,
UnsentMessagesCollection: PropTypes.objectOf(Object).isRequired,
@ -27,10 +23,6 @@ const propTypes = {
startUserTyping: PropTypes.func.isRequired,
};
const defaultProps = {
className: '',
};
const messages = defineMessages({
submitLabel: {
id: 'app.chat.submitLabel',
@ -261,7 +253,6 @@ class MessageForm extends PureComponent {
chatTitle,
title,
disabled,
className,
idChatOpen,
partnerIsLoggedOut,
} = this.props;
@ -269,14 +260,12 @@ class MessageForm extends PureComponent {
const { hasErrors, error, message } = this.state;
return CHAT_ENABLED ? (
<form
<Styled.Form
ref={(ref) => { this.form = ref; }}
className={cx(className, styles.form)}
onSubmit={this.handleSubmit}
>
<div className={styles.wrapper}>
<TextareaAutosize
className={styles.input}
<Styled.Wrapper>
<Styled.Input
id="message-input"
innerRef={(ref) => { this.textarea = ref; return this.textarea; }}
placeholder={intl.formatMessage(messages.inputPlaceholder, { 0: title })}
@ -291,10 +280,9 @@ class MessageForm extends PureComponent {
onKeyDown={this.handleMessageKeyDown}
async
/>
<Button
<Styled.SendButton
hideLabel
circle
className={styles.sendButton}
aria-label={intl.formatMessage(messages.submitLabel)}
type="submit"
disabled={disabled || partnerIsLoggedOut}
@ -304,14 +292,13 @@ class MessageForm extends PureComponent {
onClick={() => { }}
data-test="sendMessageButton"
/>
</div>
</Styled.Wrapper>
<TypingIndicatorContainer {...{ idChatOpen, error }} />
</form>
</Styled.Form>
) : null;
}
}
MessageForm.propTypes = propTypes;
MessageForm.defaultProps = defaultProps;
export default injectIntl(MessageForm);

View File

@ -0,0 +1,92 @@
import styled from 'styled-components';
import {
colorBlueLight,
colorText,
colorGrayLighter,
colorPrimary,
} from '/imports/ui/stylesheets/styled-components/palette';
import {
smPaddingX,
smPaddingY,
borderRadius,
borderSize,
} from '/imports/ui/stylesheets/styled-components/general';
import { fontSizeBase } from '/imports/ui/stylesheets/styled-components/typography';
import TextareaAutosize from 'react-autosize-textarea';
import Button from '/imports/ui/components/button/component';
const Form = styled.form`
flex-grow: 0;
flex-shrink: 0;
align-self: flex-end;
width: 100%;
position: relative;
margin-bottom: calc(-1 * ${smPaddingX});
margin-top: .2rem;
`;
const Wrapper = styled.div`
display: flex;
flex-direction: row;
`;
const Input = styled(TextareaAutosize)`
flex: 1;
background: #fff;
background-clip: padding-box;
margin: 0;
color: ${colorText};
-webkit-appearance: none;
padding: calc(${smPaddingY} * 2.5) calc(${smPaddingX} * 1.25);
resize: none;
transition: none;
border-radius: ${borderRadius};
font-size: ${fontSizeBase};
line-height: 1;
min-height: 2.5rem;
max-height: 10rem;
border: 1px solid ${colorGrayLighter};
box-shadow: 0 0 0 1px ${colorGrayLighter};
&:disabled,
&[disabled] {
cursor: not-allowed;
opacity: .75;
background-color: rgba(167,179,189,0.25);
}
&:focus {
border-radius: ${borderSize};
box-shadow: 0 0 0 ${borderSize} ${colorBlueLight}, inset 0 0 0 1px ${colorPrimary};
}
&:hover,
&:active,
&:focus {
outline: transparent;
outline-style: dotted;
outline-width: ${borderSize};
}
`;
const SendButton = styled(Button)`
margin:0 0 0 ${smPaddingX};
align-self: center;
font-size: 0.9rem;
[dir="rtl"] & {
margin: 0 ${smPaddingX} 0 0;
-webkit-transform: scale(-1, 1);
-moz-transform: scale(-1, 1);
-ms-transform: scale(-1, 1);
-o-transform: scale(-1, 1);
transform: scale(-1, 1);
}
`;
export default {
Form,
Wrapper,
Input,
SendButton,
};

View File

@ -1,182 +0,0 @@
@import "/imports/ui/stylesheets/mixins/focus";
@import "/imports/ui/stylesheets/mixins/_indicators";
@import "/imports/ui/stylesheets/variables/placeholders";
:root {
--max-chat-input-msg-height: .93rem;
}
.form {
flex-grow: 0;
flex-shrink: 0;
align-self: flex-end;
width: 100%;
position: relative;
margin-bottom: calc(-1 * var(--sm-padding-x));
margin-top: .2rem;
}
.wrapper {
display: flex;
flex-direction: row;
}
.actions {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 0;
flex-shrink: 0;
border: var(--border-size) solid var(--color-gray-lighter);
background-color: #fff;
border-radius: var(--border-radius) 0 0 var(--border-radius);
color: var(--color-gray-light);
padding: var(--sm-padding-y) var(--sm-padding-x);
cursor: pointer;
:global(.animationsEnabled) & {
transition: all .3s;
}
--bg-faded: rgba(167,179,189,0.25);
&:hover,
&:focus {
background-color: var(--bg-faded);
}
&:disabled,
&[disabled] {
cursor: not-allowed;
opacity: .75;
background-color: var(--bg-faded);
}
}
.input {
@include inputFocus(var(--color-blue-light));
flex: 1;
background: #fff;
background-clip: padding-box;
margin: 0;
color: var(--color-text);
-webkit-appearance: none;
padding: calc(var(--sm-padding-y) * 2.5) calc(var(--sm-padding-x) * 1.25);
resize: none;
transition: none;
border-radius: var(--border-radius);
font-size: var(--font-size-base);
line-height: 1;
min-height: 2.5rem;
max-height: 10rem;
border: 1px solid var(--color-gray-lighter);
box-shadow: 0 0 0 1px var(--color-gray-lighter);
&:disabled,
&[disabled] {
cursor: not-allowed;
opacity: .75;
background-color: rgba(167,179,189,0.25);
}
&:hover,
&:active,
&:focus {
@extend %highContrastOutline;
}
}
.sendButton {
margin:0 0 0 var(--sm-padding-x);
align-self: center;
font-size: 0.9rem;
[dir="rtl"] & {
margin: 0 var(--sm-padding-x) 0 0;
-webkit-transform: scale(-1, 1);
-moz-transform: scale(-1, 1);
-ms-transform: scale(-1, 1);
-o-transform: scale(-1, 1);
transform: scale(-1, 1);
}
}
.error,
.info {
font-size: calc(var(--font-size-base) * .75);
color: var(--color-gray-dark);
text-align: left;
padding: var(--border-size) 0;
position: relative;
}
.error,
.info,
.spacer {
height: var(--max-chat-input-msg-height);
max-height: var(--max-chat-input-msg-height);
}
.coupleTyper,
.singleTyper {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-weight: bold;
font-size: var(--font-size-smaller);
}
.singleTyper {
max-width: 70%;
}
.coupleTyper {
max-width: 25%;
}
.typingIndicator {
display: flex;
flex-direction: row;
> span {
display: block;
margin-right: 0.05rem;
margin-left: 0.05rem;
line-height: var(--font-size-md);
}
text-align: left;
[dir="rtl"] & {
text-align: right;
}
}
.error {
color: var(--color-danger);
}
.connectingAnimation {
margin: auto;
display: inline-block;
width: 1.5em;
&:after {
overflow: hidden;
display: inline-block;
vertical-align: bottom;
content: "\2026"; /* ascii code for the ellipsis character */
width: 0;
margin-left: 0.25em;
:global(.animationsEnabled) & {
animation: ellipsis steps(4, end) 900ms infinite;
}
}
}
@keyframes ellipsis {
to {
width: 1.5em;
}
}