Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Render underlines and tooltips on custom server names in auth pages #2965

Merged
merged 3 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
@import "./views/elements/_RoleButton.scss";
@import "./views/elements/_Spinner.scss";
@import "./views/elements/_SyntaxHighlight.scss";
@import "./views/elements/_TextWithTooltip.scss";
@import "./views/elements/_ToggleSwitch.scss";
@import "./views/elements/_ToolTipButton.scss";
@import "./views/elements/_Tooltip.scss";
Expand Down
4 changes: 4 additions & 0 deletions res/css/structures/auth/_Login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ limitations under the License.
.mx_Login_type_dropdown {
min-width: 200px;
}

.mx_Login_underlinedServerName {
border-bottom: 1px dashed $accent-color;
}
19 changes: 19 additions & 0 deletions res/css/views/elements/_TextWithTooltip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2019 New Vector Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_TextWithTooltip_tooltip {
display: none;
}
11 changes: 9 additions & 2 deletions src/components/structures/auth/ForgotPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,16 @@ module.exports = React.createClass({
serverName: this.props.serverConfig.hsName,
});
if (this.props.serverConfig.hsNameIsDifferent) {
// TODO: TravisR - Use tooltip to underline
const TextWithTooltip = sdk.getComponent("elements.TextWithTooltip");

yourMatrixAccountText = _t('Your Matrix account on <underlinedServerName />', {}, {
'underlinedServerName': () => <u>{this.props.serverConfig.hsName}</u>,
'underlinedServerName': () => {
return <TextWithTooltip
class="mx_Login_underlinedServerName"
tooltip={this.props.serverConfig.hsUrl}>
turt2live marked this conversation as resolved.
Show resolved Hide resolved
{this.props.serverConfig.hsName}
</TextWithTooltip>;
},
});
}

Expand Down
11 changes: 9 additions & 2 deletions src/components/views/auth/PasswordLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,16 @@ export default class PasswordLogin extends React.Component {
serverName: this.props.serverConfig.hsName,
});
if (this.props.serverConfig.hsNameIsDifferent) {
// TODO: TravisR - Use tooltip to underline
const TextWithTooltip = sdk.getComponent("elements.TextWithTooltip");

signInToText = _t('Sign in to your Matrix account on <underlinedServerName />', {}, {
'underlinedServerName': () => <u>{this.props.serverConfig.hsName}</u>,
'underlinedServerName': () => {
return <TextWithTooltip
class="mx_Login_underlinedServerName"
tooltip={this.props.serverConfig.hsUrl}>
turt2live marked this conversation as resolved.
Show resolved Hide resolved
{this.props.serverConfig.hsName}
</TextWithTooltip>;
},
});
}

Expand Down
11 changes: 9 additions & 2 deletions src/components/views/auth/RegistrationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,16 @@ module.exports = React.createClass({
serverName: this.props.serverConfig.hsName,
});
if (this.props.serverConfig.hsNameIsDifferent) {
// TODO: TravisR - Use tooltip to underline
const TextWithTooltip = sdk.getComponent("elements.TextWithTooltip");

yourMatrixAccountText = _t('Create your Matrix account on <underlinedServerName />', {}, {
'underlinedServerName': () => <u>{this.props.serverConfig.hsName}</u>,
'underlinedServerName': () => {
return <TextWithTooltip
class="mx_Login_underlinedServerName"
tooltip={this.props.serverConfig.hsUrl}>
turt2live marked this conversation as resolved.
Show resolved Hide resolved
{this.props.serverConfig.hsName}
</TextWithTooltip>;
},
});
}

Expand Down
56 changes: 56 additions & 0 deletions src/components/views/elements/TextWithTooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2019 New Vector Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import PropTypes from 'prop-types';
import sdk from '../../../index';

export default class TextWithTooltip extends React.Component {
static propTypes = {
class: PropTypes.string,
tooltip: PropTypes.string.isRequired,
};

constructor() {
super();

this.state = {
hover: false,
};
}

onMouseOver = () => {
this.setState({hover: true});
};

onMouseOut = () => {
this.setState({hover: false});
};

render() {
const Tooltip = sdk.getComponent("elements.Tooltip");

return (
<span onMouseOver={this.onMouseOver} onMouseOut={this.onMouseOut} className={this.props.class}>
{this.props.children}
<Tooltip
label={this.props.tooltip}
visible={this.state.hover}
className={"mx_TextWithTooltip_tooltip"} />
</span>
);
}
}
4 changes: 4 additions & 0 deletions src/components/views/elements/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ module.exports = React.createClass({
let offset = 0;
if (parentBox.height > MIN_TOOLTIP_HEIGHT) {
offset = Math.floor((parentBox.height - MIN_TOOLTIP_HEIGHT) / 2);
} else {
// The tooltip is larger than the parent height: figure out what offset
// we need so that we're still centered.
offset = Math.floor(parentBox.height - MIN_TOOLTIP_HEIGHT);
}
style.top = (parentBox.top - 2) + window.pageYOffset + offset;
style.left = 6 + parentBox.right + window.pageXOffset;
Expand Down