-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented dynamic powered by logo & added white poweredby
- Loading branch information
1 parent
ad36d08
commit 7f95837
Showing
7 changed files
with
97 additions
and
3 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.
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
41 changes: 41 additions & 0 deletions
41
apps/kyb-app/src/components/molecules/PoweredByLogo/PoweredByLogo.tsx
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getRGBColorFromElement, isColorDark } from '@/components/molecules/PoweredByLogo/helpers'; | ||
import { FunctionComponent, useEffect, useState } from 'react'; | ||
|
||
interface IPoweredByLogoProps { | ||
className?: string; | ||
sidebarRootId: string; | ||
} | ||
|
||
export const PoweredByLogo: FunctionComponent<IPoweredByLogoProps> = ({ | ||
className, | ||
sidebarRootId, | ||
}) => { | ||
const [sidebarElement, setSidebarElement] = useState<HTMLElement | null>(null); | ||
const [logoSrc, setLogoSrc] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
setSidebarElement(document.getElementById(sidebarRootId)); | ||
}, [sidebarRootId]); | ||
|
||
useEffect(() => { | ||
if (!sidebarElement) return; | ||
|
||
const rgb = getRGBColorFromElement(sidebarElement); | ||
|
||
if (rgb) { | ||
const [r, g, b] = rgb as [number, number, number]; | ||
|
||
const isDark = isColorDark(r, g, b); | ||
|
||
setLogoSrc(isDark ? '/poweredby-white.svg' : '/poweredby.svg'); | ||
} else { | ||
console.warn('Could not detect color. Default powered by logo will be used.'); | ||
|
||
setLogoSrc('/poweredby.svg'); | ||
} | ||
}, [sidebarElement]); | ||
|
||
if (!logoSrc) return null; | ||
|
||
return <img src={logoSrc} className={className} />; | ||
}; |
29 changes: 29 additions & 0 deletions
29
apps/kyb-app/src/components/molecules/PoweredByLogo/helpers.ts
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const getLuminance = (r: number, g: number, b: number) => { | ||
const a = [r, g, b].map(v => { | ||
v /= 255; | ||
|
||
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); | ||
}); | ||
|
||
return a[0]! * 0.2126 + a[1]! * 0.7152 + a[2]! * 0.0722; | ||
}; | ||
|
||
export const getRGBColorFromElement = (element: HTMLElement) => { | ||
const style = window.getComputedStyle(element); | ||
const bgColor = style.background; | ||
|
||
// Regex to extract RGB values | ||
const rgbValues = bgColor.match(/\d+/g); | ||
|
||
if (rgbValues && rgbValues.length >= 3) { | ||
return rgbValues.map(Number); // Convert strings to numbers | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export const isColorDark = (r: number, g: number, b: number) => { | ||
const luminance = getLuminance(r, g, b); | ||
|
||
return luminance < 0.5; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PoweredByLogo'; |
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