From d8a3568e40b48ca293c38eb6d789a93bbc234f26 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 17 Nov 2018 14:50:08 +0200 Subject: [PATCH] Implement correct dropdown functionality --- src/components/DropDownBox/DropDownBox.scss | 3 +- src/components/DropDownBox/DropDownBox.tsx | 15 +++- .../NavbarChildLink/NavbarChildLink.scss | 2 +- .../NavbarDropdownLink.scss | 1 + .../NavbarDropdownLink/NavbarDropdownLink.tsx | 78 +++++++++++-------- src/components/Navigation/Navigation.tsx | 6 +- 6 files changed, 65 insertions(+), 40 deletions(-) diff --git a/src/components/DropDownBox/DropDownBox.scss b/src/components/DropDownBox/DropDownBox.scss index e0c0d5d..d0cb8ff 100644 --- a/src/components/DropDownBox/DropDownBox.scss +++ b/src/components/DropDownBox/DropDownBox.scss @@ -5,7 +5,8 @@ margin-top: 0.8rem; position: absolute; left: 0; - top: 20px; + top: 40px; + z-index: 10; &, & a { diff --git a/src/components/DropDownBox/DropDownBox.tsx b/src/components/DropDownBox/DropDownBox.tsx index faf4325..d2a825b 100644 --- a/src/components/DropDownBox/DropDownBox.tsx +++ b/src/components/DropDownBox/DropDownBox.tsx @@ -1,14 +1,23 @@ import * as React from "react"; import "./DropDownBox.scss"; -export interface DropDownBoxProps {} +export interface DropDownBoxProps { + onMouseEnter: () => void; + onMouseLeave: () => void; + visible: boolean; +} export interface DropDownBoxState {} class DropDownBox extends React.Component { render() { - const { children } = this.props; + const { children, onMouseEnter, onMouseLeave, visible } = this.props; return ( -
+ ); diff --git a/src/components/NavbarChildLink/NavbarChildLink.scss b/src/components/NavbarChildLink/NavbarChildLink.scss index cd4933e..cac8014 100644 --- a/src/components/NavbarChildLink/NavbarChildLink.scss +++ b/src/components/NavbarChildLink/NavbarChildLink.scss @@ -5,7 +5,7 @@ $border-width: 2px; display: block; padding: 1rem 1rem; letter-spacing: 1.5px; - margin-right: 3rem; + padding-right: 4rem; font-weight: 400; &:hover { diff --git a/src/components/NavbarDropdownLink/NavbarDropdownLink.scss b/src/components/NavbarDropdownLink/NavbarDropdownLink.scss index 124ddbe..6f48f61 100644 --- a/src/components/NavbarDropdownLink/NavbarDropdownLink.scss +++ b/src/components/NavbarDropdownLink/NavbarDropdownLink.scss @@ -8,6 +8,7 @@ $border-width: 2px; font-weight: 500; text-transform: uppercase; letter-spacing: 2px; + padding: 20px 0; } .navbar-dropdown-container { diff --git a/src/components/NavbarDropdownLink/NavbarDropdownLink.tsx b/src/components/NavbarDropdownLink/NavbarDropdownLink.tsx index cb1724c..c342bd8 100644 --- a/src/components/NavbarDropdownLink/NavbarDropdownLink.tsx +++ b/src/components/NavbarDropdownLink/NavbarDropdownLink.tsx @@ -8,53 +8,65 @@ export interface NavbarDropdownLinkProps { text: string; } export interface NavbarDropdownLinkState { - open: Boolean; + mouseOverLink: Boolean; + mouseOverBox: Boolean; } class NavbarDropdownLink extends React.Component { constructor(props) { super(props); - this.state = {open: false}; + this.state = { + mouseOverLink: false, + mouseOverBox: false, + }; } - handleOpen = () => { - this.setState({open: true}); + handleMouseEnterLink = () => { + this.setState({ + mouseOverLink: true, + }); } - handleClose = () => { - this.setState({open: false}); + handleMouseLeaveLink = () => { + this.setState({ + mouseOverLink: false, + }); + } + + handleMouseEnterBox = () => { + this.setState({ + mouseOverBox: true, + }); + } + + handleMouseLeaveBox = () => { + this.setState({ + mouseOverBox: false, + }); } render() { const { children } = this.props; - const { open } = this.state; - if (open && children) { - return ( -
- {this.props.text} - - { children } - -
- ); - } else { - return ( -
- - {this.props.text} - -
- ); - } + const { mouseOverLink, mouseOverBox } = this.state; + const open = mouseOverLink || mouseOverBox; + + return ( +
+ {this.props.text} + + {children} + +
+ ); } } diff --git a/src/components/Navigation/Navigation.tsx b/src/components/Navigation/Navigation.tsx index e9a9269..cef3f7b 100644 --- a/src/components/Navigation/Navigation.tsx +++ b/src/components/Navigation/Navigation.tsx @@ -12,14 +12,16 @@ class Navigation extends React.Component { render() { return (
- + Toiminta Fuksi Arkisto - + + Simo Höglund +