Skip to content

Commit 3e72d8d

Browse files
authored
Merge pull request element-hq#5286 from turt2live/travis/presence
CSS/components for custom presence controls
2 parents aceabd6 + 6c796cd commit 3e72d8d

7 files changed

Lines changed: 249 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
});

‎src/i18n/strings/en_EN.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
"What's New": "What's New",
6969
"Update": "Update",
7070
"What's new?": "What's new?",
71+
"Appear Offline": "Appear Offline",
72+
"Away": "Away",
7173
"A new version of Riot is available.": "A new version of Riot is available.",
7274
"To return to your account in future you need to <u>set a password</u>": "To return to your account in future you need to <u>set a password</u>",
7375
"Toolbox": "Toolbox",

‎src/skins/vector/css/_components.scss‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@import "./matrix-react-sdk/structures/_UserSettings.scss";
1616
@import "./matrix-react-sdk/structures/login/_Login.scss";
1717
@import "./matrix-react-sdk/views/avatars/_BaseAvatar.scss";
18+
@import "./matrix-react-sdk/views/avatars/_MemberPresenceAvatar.scss";
1819
@import "./matrix-react-sdk/views/dialogs/_BugReportDialog.scss";
1920
@import "./matrix-react-sdk/views/dialogs/_ChatCreateOrReuseChatDialog.scss";
2021
@import "./matrix-react-sdk/views/dialogs/_ChatInviteDialog.scss";
@@ -80,6 +81,7 @@
8081
@import "./vector-web/structures/_RoomSubList.scss";
8182
@import "./vector-web/structures/_ViewSource.scss";
8283
@import "./vector-web/views/context_menus/_MessageContextMenu.scss";
84+
@import "vector-web/views/context_menus/_PresenceContextMenuOption.scss";
8385
@import "./vector-web/views/context_menus/_RoomTileContextMenu.scss";
8486
@import "./vector-web/views/dialogs/_ChangelogDialog.scss";
8587
@import "./vector-web/views/dialogs/_DevtoolsDialog.scss";

‎src/skins/vector/css/matrix-react-sdk/structures/_ContextualMenu.scss‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,60 @@ limitations under the License.
9494
left: 1px;
9595
}
9696

97+
.mx_ContextualMenu.mx_ContextualMenu_top {
98+
top: 8px;
99+
}
100+
101+
.mx_ContextualMenu_chevron_top {
102+
position: absolute;
103+
left: 0px;
104+
top: -8px;
105+
width: 0;
106+
height: 0;
107+
border-left: 8px solid transparent;
108+
border-bottom: 8px solid $menu-border-color;
109+
border-right: 8px solid transparent;
110+
}
111+
112+
.mx_ContextualMenu_chevron_top:after{
113+
content:'';
114+
width: 0;
115+
height: 0;
116+
border-left: 7px solid transparent;
117+
border-bottom: 7px solid $menu-bg-color;
118+
border-right: 7px solid transparent;
119+
position:absolute;
120+
left: -7px;
121+
top: 1px;
122+
}
123+
124+
.mx_ContextualMenu.mx_ContextualMenu_bottom {
125+
bottom: 8px;
126+
}
127+
128+
.mx_ContextualMenu_chevron_bottom {
129+
position: absolute;
130+
left: 0px;
131+
bottom: -8px;
132+
width: 0;
133+
height: 0;
134+
border-left: 8px solid transparent;
135+
border-top: 8px solid $menu-border-color;
136+
border-right: 8px solid transparent;
137+
}
138+
139+
.mx_ContextualMenu_chevron_bottom:after{
140+
content:'';
141+
width: 0;
142+
height: 0;
143+
border-left: 7px solid transparent;
144+
border-top: 7px solid $menu-bg-color;
145+
border-right: 7px solid transparent;
146+
position:absolute;
147+
left: -7px;
148+
bottom: 1px;
149+
}
150+
97151
.mx_ContextualMenu_field {
98152
padding: 3px 6px 3px 6px;
99153
cursor: pointer;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
.mx_MemberPresenceAvatar {
18+
display: inline-block;
19+
position: relative;
20+
}
21+
22+
.mx_MemberPresenceAvatar_status {
23+
display: block;
24+
width: 10px;
25+
height: 10px;
26+
border-radius: 10px;
27+
28+
position: absolute;
29+
bottom: -2px;
30+
right: -3px;
31+
}
32+
33+
.mx_MemberPresenceAvatar_status_online {
34+
background-color: $presence-online;
35+
}
36+
37+
.mx_MemberPresenceAvatar_status_unavailable {
38+
background-color: $presence-unavailable;
39+
}
40+
41+
.mx_MemberPresenceAvatar_status_offline {
42+
background-color: $presence-offline;
43+
}

‎src/skins/vector/css/themes/_base.scss‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ $e2e-verified-color: #76cfa5; // N.B. *NOT* the same as $accent-color
135135
$e2e-unverified-color: #e8bf37;
136136
$e2e-warning-color: #ba6363;
137137

138+
// presence
139+
$presence-online: #60de00;
140+
$presence-unavailable: #deb800;
141+
$presence-offline: #b7b7b7;
142+
138143
/*** ImageView ***/
139144
$lightbox-bg-color: #454545;
140145
$lightbox-fg-color: #ffffff;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
.mx_PresenceContextMenuOption_indicator {
17+
width: 10px;
18+
height: 10px;
19+
border-radius: 10px;
20+
display: inline-block;
21+
margin-right: 5px;
22+
}
23+
24+
.mx_PresenceContextMenuOption_indicator.mx_PresenceContextMenuOption_indicator_online {
25+
background-color: $presence-online;
26+
}
27+
28+
.mx_PresenceContextMenuOption_indicator.mx_PresenceContextMenuOption_indicator_unavailable {
29+
background-color: $presence-unavailable;
30+
}
31+
32+
.mx_PresenceContextMenuOption_indicator.mx_PresenceContextMenuOption_indicator_offline {
33+
background-color: $presence-offline;
34+
}
35+
36+
.mx_PresenceContextMenuOption {
37+
padding: 2px;
38+
}
39+
40+
.mx_PresenceContextMenuOption.mx_PresenceContextMenuOption_current {
41+
font-weight: 700;
42+
}

0 commit comments

Comments
 (0)