-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from AdeshGhadage/Updated-Lotengdev-logo
updated Lotengdev logo according to background color
- Loading branch information
Showing
3 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,17 +1,39 @@ | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'react-router-dom'; | ||
import LogtengDevLogo from '@/assets/lotengdev-logo.svg'; | ||
import { useEffect, useState, useRef } from 'react'; | ||
import LogtengDevLogoLight from '@/assets/lotengdev-logo-light.svg'; | ||
import LogtengDevLogoDark from '@/assets/lotengdev-logo-dark.svg'; | ||
|
||
export function Brand({ url }) { | ||
const [isDarkBackground, setIsDarkBackground] = useState(false); | ||
const brandRef = useRef(null); | ||
|
||
useEffect(() => { | ||
if (brandRef.current) { | ||
const backgroundColor = window.getComputedStyle(brandRef.current).backgroundColor; | ||
const rgb = backgroundColor.match(/\d+/g); | ||
|
||
if (rgb) { | ||
const brightness = (0.299 * rgb[0]) + (0.587 * rgb[1]) + (0.114 * rgb[2]); | ||
setIsDarkBackground(brightness < 128); | ||
} | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div className="pr-10 lg:border-r border-solid border-grey"> | ||
<Link to={url}> | ||
<img className="h-7 lg:h-11" src={LogtengDevLogo} /> | ||
<img | ||
className="h-7 lg:h-11" | ||
src={isDarkBackground ? LogtengDevLogoDark : LogtengDevLogoLight} | ||
alt="LogtengDev Logo" | ||
/> | ||
</Link> | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
Brand.propTypes = { | ||
url: PropTypes.string.isRequired | ||
} | ||
url: PropTypes.string.isRequired, | ||
isDarkBackground: PropTypes.bool | ||
}; |