Skip to content

Commit

Permalink
Control hover state via React
Browse files Browse the repository at this point in the history
  • Loading branch information
kudlajz committed Feb 26, 2024
1 parent c6e3d5f commit 7823d84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
height: 100%;
z-index: 2;

&:hover {
&.isHovering {
background: linear-gradient(0deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.3) 100%);

.Actions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GalleryPadding } from '@prezly/slate-types';
import classNames from 'classnames';
import type { CSSProperties } from 'react';
import React, { forwardRef } from 'react';
import React, { forwardRef, useState } from 'react';

import { Button, ImageSizeWarning, ImageWithLoadingPlaceholder } from '#components';
import { Crop, Delete } from '#icons';
Expand Down Expand Up @@ -51,6 +51,16 @@ export const GalleryTile = forwardRef<HTMLDivElement, Props>(function GalleryTil
},
ref,
) {
const [isHovering, setHovering] = useState(false);

function handleShowOverlay() {
setTimeout(() => setHovering(true), 0);
}

function handleHideOverlay() {
setHovering(false);
}

return (
<div
className={classNames(styles.GalleryTile, className, {
Expand All @@ -67,7 +77,13 @@ export const GalleryTile = forwardRef<HTMLDivElement, Props>(function GalleryTil
>
{clone && <div className={styles.Clone} />}
{!dragging && (
<div className={styles.Overlay}>
<div
className={classNames(styles.Overlay, {
[styles.isHovering]: isHovering,
})}
onMouseEnter={handleShowOverlay}
onMouseLeave={handleHideOverlay}
>
<div className={styles.Actions}>
<CropButton isSmall={withSmallButtons} onCrop={onCrop} />
<DeleteButton isSmall={withSmallButtons} onDelete={onDelete} />
Expand Down

0 comments on commit 7823d84

Please sign in to comment.