import * as PropTypes from 'prop-types'; import * as React from 'react'; import * as classNames from 'classnames'; import { Button, Form, FormControl, InputGroup, OverlayTrigger, Tooltip, } from 'react-bootstrap'; import Badge from '../Badge'; import Box from '../Box'; import DirectChatToggleContactsButton from './DirectChatToggleContactsButton'; import DirectChatMessageList from './DirectChatMessageList'; import DirectChatMessage from './DirectChatMessage'; import DirectChatImage from './DirectChatImage'; import DirectChatText from './DirectChatText'; import DirectChatContactList from './DirectChatContactList'; import DirectChatContact from './DirectChatContact'; import DirectChatContactImage from './DirectChatContactImage'; import DirectChatContactInfo from './DirectChatContactInfo'; export interface Props { className?: string; messageNumber?: number; style: 'primary' | 'success' | 'warning' | 'danger'; onSubmitMessage?: (message: string) => void; title?: React.ReactNode; }; export interface State { contactsOpen: boolean; message: string; }; const propTypes = { children: PropTypes.node, className: PropTypes.string, messageNumber: PropTypes.number, style: PropTypes.oneOf(['primary', 'success', 'warning', 'danger']).isRequired, onSubmitMessage: PropTypes.func, title: PropTypes.node, }; const childContextTypes = { $adminlte_directchat: PropTypes.shape({ toggleContacts: PropTypes.func, }), }; class DirectChat extends React.Component { constructor(props) { super(props); this.state = { contactsOpen: false, message: '', }; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } static propTypes = propTypes; static childContextTypes = childContextTypes; static MessageList: typeof DirectChatMessageList; static Message: typeof DirectChatMessage; static Image: typeof DirectChatImage; static Text: typeof DirectChatText; static ContactList: typeof DirectChatContactList; static Contact: typeof DirectChatContact; static ContactImage: typeof DirectChatContactImage; static ContactInfo: typeof DirectChatContactInfo; getChildContext() { return { $adminlte_directchat: { toggleContacts: () => { this.setState((state) => { return { contactsOpen: !state.contactsOpen, }; }); }, }, }; } handleChange(e) { this.setState({ message: e.target.value, }); } handleSubmit(e) { e.preventDefault(); if (this.props.onSubmitMessage) { this.props.onSubmitMessage(this.state.message); } } renderBadge() { const { messageNumber, style } = this.props; switch (style) { case 'primary': return {messageNumber}; case 'success': return {messageNumber}; case 'warning': return {messageNumber}; case 'danger': return {messageNumber}; default: return {messageNumber}; } } render() { const classes = { 'direct-chat': true, 'direct-chat-contacts-open': this.state.contactsOpen, }; classes[`direct-chat-${this.props.style}`] = true; return ( {this.props.title} {this.props.messageNumber} New Messages } placement="top" trigger={['focus', 'hover']} > {this.renderBadge()} {this.props.children}
); } } DirectChat.MessageList = DirectChatMessageList; DirectChat.Message = DirectChatMessage; DirectChat.Image = DirectChatImage; DirectChat.Text = DirectChatText; DirectChat.ContactList = DirectChatContactList; DirectChat.Contact = DirectChatContact; DirectChat.ContactImage = DirectChatContactImage; DirectChat.ContactInfo = DirectChatContactInfo; export default DirectChat;