);
}
+
+ toggleAccountSwitcher() {
+ this.setState({
+ isAccountSwitcherActive: !this.state.isAccountSwitcherActive
+ });
+ }
+
+ onExpandAccountSwitcher = (event) => {
+ event.preventDefault();
+
+ this.toggleAccountSwitcher();
+ };
+
+ onBodyClick = createOnOutsideComponentClickHandler(
+ () => ReactDOM.findDOMNode(this),
+ () => this.state.isAccountSwitcherActive,
+ () => this.toggleAccountSwitcher()
+ );
+}
+
+/**
+ * Creates an event handling function to handle clicks outside the component
+ *
+ * The handler will check if current click was outside container el and if so
+ * and component isActive, it will call the callback
+ *
+ * @param {function} getEl - the function, that returns reference to container el
+ * @param {function} isActive - whether the component is active and callback may be called
+ * @param {function} callback - the callback to call, when there was a click outside el
+ * @return {function}
+ */
+function createOnOutsideComponentClickHandler(getEl, isActive, callback) {
+ // TODO: we have the same logic in LangMenu
+ // Probably we should decouple this into some helper function
+ // TODO: the name of function may be better...
+ return (event) => {
+ if (isActive()) {
+ const el = getEl();
+
+ if (!el.contains(event.target) && el !== event.taget) {
+ event.preventDefault();
+
+ // add a small delay for the case someone have alredy called toggle
+ setTimeout(() => isActive() && callback(), 0);
+ }
+ }
+ };
}
diff --git a/src/components/userbar/loggedInPanel.scss b/src/components/userbar/loggedInPanel.scss
index 54c00e6..f4b3771 100644
--- a/src/components/userbar/loggedInPanel.scss
+++ b/src/components/userbar/loggedInPanel.scss
@@ -5,15 +5,20 @@
.activeAccount {
position: relative;
+ display: inline-block;
$border: 1px solid rgba(#fff, .15);
border-left: $border;
border-right: $border;
+}
- &:hover {
- .accountSwitcherContainer {
- display: block;
- }
+.activeAccountExpanded {
+ .accountSwitcherContainer {
+ display: block;
+ }
+
+ .expandIcon {
+ transform: rotate(180deg);
}
}