fix: Hold hover state on DocumentListItem while DocumentMenu is open

This commit is contained in:
Tom Moor
2021-01-02 20:02:57 -08:00
parent 308d4bd797
commit 68bbd9fa34
2 changed files with 25 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ import { StarredIcon, PlusIcon } from "outline-icons";
import * as React from "react"; import * as React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Link, useHistory } from "react-router-dom"; import { Link, useHistory } from "react-router-dom";
import styled, { withTheme } from "styled-components"; import styled, { css, withTheme } from "styled-components";
import Document from "models/Document"; import Document from "models/Document";
import Badge from "components/Badge"; import Badge from "components/Badge";
import Button from "components/Button"; import Button from "components/Button";
@@ -40,6 +40,7 @@ function DocumentListItem(props: Props) {
const { t } = useTranslation(); const { t } = useTranslation();
const currentUser = useCurrentUser(); const currentUser = useCurrentUser();
const history = useHistory(); const history = useHistory();
const [menuOpen, setMenuOpen] = React.useState(false);
const { const {
document, document,
showCollection, showCollection,
@@ -89,6 +90,7 @@ function DocumentListItem(props: Props) {
return ( return (
<DocumentLink <DocumentLink
menuOpen={menuOpen}
to={{ to={{
pathname: document.url, pathname: document.url,
state: { title: document.titleWithDefault }, state: { title: document.titleWithDefault },
@@ -128,7 +130,12 @@ function DocumentListItem(props: Props) {
)} )}
&nbsp; &nbsp;
<EventBoundary> <EventBoundary>
<DocumentMenu document={document} showPin={showPin} /> <DocumentMenu
document={document}
showPin={showPin}
onOpen={() => setMenuOpen(true)}
onClose={() => setMenuOpen(false)}
/>
</EventBoundary> </EventBoundary>
</SecondaryActions> </SecondaryActions>
</Heading> </Heading>
@@ -205,6 +212,20 @@ const DocumentLink = styled(Link)`
} }
} }
} }
${(props) =>
props.menuOpen &&
css`
background: ${(props) => props.theme.listItemHoverBackground};
${SecondaryActions} {
opacity: 1;
}
${StyledStar} {
opacity: 0.5;
}
`}
`; `;
const Heading = styled.h3` const Heading = styled.h3`

View File

@@ -10,6 +10,8 @@ const Button = styled.button`
line-height: 0; line-height: 0;
border: 0; border: 0;
padding: 0; padding: 0;
cursor: pointer;
user-select: none;
`; `;
export default React.forwardRef<any, typeof Button>((props, ref) => ( export default React.forwardRef<any, typeof Button>((props, ref) => (