|
| 1 | +/* |
| 2 | +Copyright 2017 Travis Ralston |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from 'react'; |
| 18 | +import { _t, _td } from 'matrix-react-sdk/lib/languageHandler'; |
| 19 | +import sdk from 'matrix-react-sdk'; |
| 20 | + |
| 21 | +const STATUS_LABELS = { |
| 22 | + "online": _td("Online"), |
| 23 | + "unavailable": _td("Away"), |
| 24 | + "offline": _td("Appear Offline"), |
| 25 | +}; |
| 26 | + |
| 27 | +const PresenceContextMenuOption = React.createClass({ |
| 28 | + displayName: 'PresenceContextMenuOption', |
| 29 | + |
| 30 | + propTypes: { |
| 31 | + forStatus: React.PropTypes.string.isRequired, |
| 32 | + isCurrent: React.PropTypes.bool, |
| 33 | + onChange: React.PropTypes.func.isRequired, |
| 34 | + }, |
| 35 | + |
| 36 | + onClick: function() { |
| 37 | + if (this.isCurrent) return; |
| 38 | + this.props.onChange(this.props.forStatus); |
| 39 | + }, |
| 40 | + |
| 41 | + render: function() { |
| 42 | + const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); |
| 43 | + |
| 44 | + const indicatorClasses = "mx_PresenceContextMenuOption_indicator " |
| 45 | + + "mx_PresenceContextMenuOption_indicator_" + this.props.forStatus; |
| 46 | + |
| 47 | + let classNames = "mx_PresenceContextMenuOption"; |
| 48 | + if (this.props.isCurrent) classNames += " mx_PresenceContextMenuOption_current"; |
| 49 | + |
| 50 | + return ( |
| 51 | + <AccessibleButton className={classNames} element="div" onClick={this.onClick}> |
| 52 | + <div className={indicatorClasses}></div> |
| 53 | + { _t(STATUS_LABELS[this.props.forStatus]) } |
| 54 | + </AccessibleButton> |
| 55 | + ); |
| 56 | + }, |
| 57 | +}); |
| 58 | + |
| 59 | +module.exports = React.createClass({ |
| 60 | + displayName: 'PresenceContextMenu', |
| 61 | + |
| 62 | + propTypes: { |
| 63 | + // "online", "unavailable", or "offline" |
| 64 | + currentStatus: React.PropTypes.string.isRequired, |
| 65 | + |
| 66 | + // Called when the user wants to change their status. |
| 67 | + // Args: (newStatus:string) |
| 68 | + onChange: React.PropTypes.func.isRequired, |
| 69 | + |
| 70 | + // callback called when the menu is dismissed |
| 71 | + onFinished: React.PropTypes.func, |
| 72 | + }, |
| 73 | + |
| 74 | + getInitialState() { |
| 75 | + return { |
| 76 | + currentStatus: this.props.currentStatus, |
| 77 | + }; |
| 78 | + }, |
| 79 | + |
| 80 | + onChange: function(newStatus) { |
| 81 | + this.props.onChange(newStatus); |
| 82 | + this.setState({currentStatus: newStatus}); |
| 83 | + }, |
| 84 | + |
| 85 | + render: function() { |
| 86 | + const statusElements = []; |
| 87 | + for (let status of Object.keys(STATUS_LABELS)) { |
| 88 | + statusElements.push(( |
| 89 | + <PresenceContextMenuOption forStatus={status} key={status} |
| 90 | + onChange={this.onChange} |
| 91 | + isCurrent={status === this.state.currentStatus} /> |
| 92 | + )); |
| 93 | + } |
| 94 | + |
| 95 | + return ( |
| 96 | + <div> |
| 97 | + { statusElements } |
| 98 | + </div> |
| 99 | + ); |
| 100 | + }, |
| 101 | +}); |
0 commit comments