-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding hover behavior for images #4735
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3ceb5df
add hover
mirnawong1 ad515b5
update
mirnawong1 e62b36b
add widths and hover code
mirnawong1 da40805
Merge branch 'current' into mwong-hover-images
mirnawong1 5992553
Update website/blog/2023-04-17-dbt-squared.md
mirnawong1 b6de35c
Revert "Merge branch 'current' into mwong-hover-images"
mirnawong1 a6266eb
add
mirnawong1 1fc53fd
add width script
mirnawong1 4e5bac4
Merge branch 'current' into mwong-hover-images
mirnawong1 788976d
remove width attribute and add max width
mirnawong1 e3f4bcd
adjust scale
mirnawong1 2d851ed
revert
mirnawong1 75186c7
adjust css
mirnawong1 14ee386
Merge branch 'current' into mwong-hover-images
mirnawong1 9168023
Update website/src/components/lightbox/styles.module.css
mirnawong1 9fc9f97
adds scrolling varaible
mirnawong1 9914c05
Merge branch 'mwong-hover-images' of https://github.com/dbt-labs/docs…
mirnawong1 eb22883
Merge branch 'current' into mwong-hover-images
mirnawong1 84ea04e
Merge branch 'current' into mwong-hover-images
mirnawong1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,56 @@ | ||
import React from 'react'; | ||
import React, { useState, useEffect } from 'react'; | ||
import styles from './styles.module.css'; | ||
import imageCacheWrapper from '../../../functions/image-cache-wrapper'; | ||
|
||
function Lightbox({ | ||
src, | ||
src, | ||
collapsed = false, | ||
alignment = "center", | ||
alt = undefined, | ||
title = undefined, | ||
alignment = "center", | ||
alt = undefined, | ||
title = undefined, | ||
width = undefined, | ||
}) { | ||
const [isHovered, setIsHovered] = useState(false); | ||
const [expandImage, setExpandImage] = useState(false); | ||
|
||
// Set alignment class if alignment prop used | ||
let imageAlignment = '' | ||
if(alignment === "left") { | ||
imageAlignment = styles.leftAlignLightbox | ||
} else if(alignment === "right") { | ||
imageAlignment = styles.rightAlignLightbox | ||
} | ||
useEffect(() => { | ||
let timeoutId; | ||
|
||
if (isHovered) { | ||
// Delay the expansion by 5 milliseconds | ||
timeoutId = setTimeout(() => { | ||
setExpandImage(true); | ||
}, 5); | ||
} | ||
|
||
return () => { | ||
clearTimeout(timeoutId); | ||
}; | ||
}, [isHovered]); | ||
|
||
const handleMouseEnter = () => { | ||
setIsHovered(true); | ||
}; | ||
|
||
const handleMouseLeave = () => { | ||
setIsHovered(false); | ||
setExpandImage(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<link href="/css/featherlight-styles.css" type="text/css" rel="stylesheet" /> | ||
<span | ||
<div | ||
className={` | ||
${styles.docImage} | ||
${styles.docImage} | ||
${collapsed ? styles.collapsed : ''} | ||
${imageAlignment} | ||
${alignment === "left" ? styles.leftAlignLightbox : ''} | ||
${alignment === "right" ? styles.rightAlignLightbox : ''} | ||
${isHovered ? styles.hovered : ''} | ||
`} | ||
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work with these conditional checks! |
||
style={width && {maxWidth: width}} | ||
style={width && { maxWidth: width }} | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
> | ||
<span> | ||
<a href="#" data-featherlight={src}> | ||
|
@@ -37,13 +59,14 @@ function Lightbox({ | |
alt={alt ? alt : title ? title : ''} | ||
title={title ? title : ''} | ||
src={imageCacheWrapper(src)} | ||
style={expandImage ? { transform: 'scale(1.2)', transition: 'transform 0.3s ease', zIndex: '9999' } : {}} | ||
/> | ||
</a> | ||
</span> | ||
{title && ( | ||
<span className={styles.title}>{ title }</span> | ||
)} | ||
</span> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original images don't have a width attribute and this undo's a python script i ran, which added a width attribute.