-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add SponsorLogos
section above footer
#99
base: main
Are you sure you want to change the base?
Changes from 1 commit
f9fbd7c
b07bfc8
e450400
48f6b24
84dd23b
4788cf5
a4de029
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { useState } from "react"; | ||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiTitle, | ||
} from "@elastic/eui"; | ||
import { sponsors } from "../data/sponsors"; | ||
import { useIsXs, useIsS, useIsM } from "../hooks/responsive"; | ||
import loadingSpinner from '../images/sponsor-logos/loading.gif'; | ||
import useHover from "../hooks/hover"; | ||
|
||
export const SponsorLogo = ({ src, name }) => { | ||
const [logo, setLogo] = useState(loadingSpinner); | ||
if (!src.startsWith('http')) { | ||
import(`../images/sponsor-logos/${src}`).then((module) => { | ||
setLogo(module.default); | ||
}); | ||
} | ||
|
||
const [hoverRef, isHovered] = useHover(); | ||
const borderWidth = '2px'; | ||
return ( | ||
<div ref={hoverRef} style={{ | ||
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. Can we set these styles in either |
||
display: 'grid', | ||
placeItems: 'center', | ||
width: '200px', | ||
height: '150px', | ||
position: 'relative', | ||
borderWidth, | ||
borderStyle: 'solid', | ||
borderColor: isHovered ? 'var(--color-accent)' : 'transparent', | ||
transition: 'border-color .15s ease-out', | ||
overflow: 'hidden', | ||
}}> | ||
<img | ||
src={src.startsWith('http') ? src : logo} | ||
alt={name} | ||
title={name} | ||
style={{ | ||
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. same note about these styles |
||
position: 'absolute', | ||
top: '0', | ||
left: '0', | ||
width: '100%', | ||
height: '100%', | ||
objectFit: 'contain', | ||
padding: '1rem', | ||
}} | ||
/> | ||
<div style={{ | ||
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. and these |
||
position: 'absolute', | ||
bottom: '0', | ||
left: `-${borderWidth}`, | ||
width: `calc(100% + (${borderWidth} * 2))`, | ||
height: 'auto', | ||
backgroundColor: 'var(--color-accent)', | ||
border: `${borderWidth} solid var(--color-accent)`, | ||
opacity: isHovered ? 1 : 0, | ||
textDecoration: 'none', | ||
color: 'black', | ||
fontSize: '1rem', | ||
fontWeight: 600, | ||
padding: '2px 4px', | ||
transform: isHovered ? 'translateY(0%)' : 'translateY(100%)', | ||
transition: 'opacity .15s ease-out, transform .15s ease-out', | ||
}}>{name}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default function SponsorLogos() { | ||
const [isXs, isS] = [useIsXs(), useIsS(), useIsM()]; | ||
const titleSize = isXs ? "xs" : isS ? "s" : "m"; | ||
|
||
return ( | ||
<> | ||
<EuiFlexGroup | ||
className="xMargin" | ||
direction="column" | ||
> | ||
<div style={{ maxWidth: '1200px' }}> | ||
<EuiTitle size={titleSize}> | ||
<h1 style={{ marginTop: '12px', marginBottom: '24px' }} className="eui-textCenter">Featured Sponsors</h1> | ||
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. these styles too |
||
</EuiTitle> | ||
<EuiFlexItem style={{ | ||
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. also these styles should be moved to CSS file |
||
display: 'flex', | ||
flexWrap: 'wrap', | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
gap: '1rem', | ||
}}> | ||
{sponsors.map(({ name, src, href }) => { | ||
if (href?.length) { | ||
return ( | ||
<a href={href} key={name} target="_blank" rel="noreferrer" title={name}> | ||
<SponsorLogo src={src} name={name} /> | ||
</a> | ||
); | ||
} | ||
return ( | ||
<SponsorLogo src={src} name={name} /> | ||
); | ||
})} | ||
</EuiFlexItem> | ||
</div> | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export const sponsors = [ | ||
{ | ||
name: "Google", | ||
src: "https://upload.wikimedia.org/wikipedia/commons/2/2f/Google_2015_logo.svg", | ||
href: "https://www.google.com/", | ||
}, | ||
{ | ||
name: "Sponsor Name", | ||
src: "fake-logo.png", | ||
// `href` is optional, can be ommitted for unlinked sponsors | ||
}, | ||
{ | ||
name: "Sponsor Name", | ||
src: "fake-logo.png", | ||
href: "#", | ||
}, | ||
{ | ||
name: "Sponsor Name", | ||
src: "fake-logo.png", | ||
href: "#", | ||
}, | ||
{ | ||
name: "Sponsor Name", | ||
src: "fake-logo.png", | ||
href: "#", | ||
}, | ||
{ | ||
name: "Sponsor Name", | ||
src: "fake-logo.png", | ||
href: "#", | ||
}, | ||
{ | ||
name: "Sponsor Name", | ||
src: "fake-logo.png", | ||
href: "#", | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// source: https://usehooks.com/useHover/ | ||
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. @brandonmcconnell this could be that you are much more senior than me and there is a good reason for all of this, but are we sure this is really necessary for implementing the hover effect? Feel like there should be a simpler way to do it with the styles, but perhaps not actually. I will defer to you on this, but just wanted to comment and check. 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. Yes, absolutely. Using plain CSS< this will be much simpler, so I'll remove this hook when I move the styles over to pure CSS 👍🏼 |
||
import { useEffect, useState, useRef } from 'react'; | ||
|
||
export default function useHover() { | ||
const [value, setValue] = useState(false); | ||
const ref = useRef(null); | ||
const handleMouseOver = () => setValue(true); | ||
const handleMouseOut = () => setValue(false); | ||
useEffect( | ||
() => { | ||
const node = ref.current; | ||
if (node) { | ||
node.addEventListener("mouseover", handleMouseOver); | ||
node.addEventListener("mouseout", handleMouseOut); | ||
return () => { | ||
node.removeEventListener("mouseover", handleMouseOver); | ||
node.removeEventListener("mouseout", handleMouseOut); | ||
}; | ||
} | ||
}, | ||
[ref.current] | ||
); | ||
return [ref, value]; | ||
} |
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.
@bpvcode what's the reason for this change?
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.
ESLint was complaining about export an unnamed arrow function. The usage of this component should still be identical. This just resolved the ESLint warning.