Skip to content

Commit

Permalink
feat: implemented dynamic powered by logo & added white poweredby
Browse files Browse the repository at this point in the history
  • Loading branch information
chesterkmr committed Sep 5, 2024
1 parent ad36d08 commit 7f95837
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 3 deletions.
16 changes: 16 additions & 0 deletions apps/kyb-app/public/poweredby-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ITheme } from '@/common/types/settings';
import { useUISchemasQuery } from '@/hooks/useUISchemasQuery';
import { transformThemeToInlineStyles } from '@/utils/transform-theme-to-inline-styles';
import { useLayoutEffect, useMemo } from 'react';
import defaultTheme from '../../../../theme-dark.json';
import defaultTheme from '../../../../theme.json';

interface Props {
children: React.ReactNode | React.ReactNode[];
Expand Down
5 changes: 4 additions & 1 deletion apps/kyb-app/src/components/layouts/AppShell/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ interface Props {

export const Sidebar = ({ children }: Props) => {
return (
<div className="bg-primary text-primary-foreground col-span-2 flex h-screen w-[24%] max-w-[418px] flex-col px-14 pb-4 pt-14">
<div
className="bg-primary text-primary-foreground col-span-2 flex h-screen w-[24%] max-w-[418px] flex-col px-14 pb-4 pt-14"
id="sidebar"
>
{children}
</div>
);
Expand Down
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 apps/kyb-app/src/components/molecules/PoweredByLogo/helpers.ts
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;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PoweredByLogo';
6 changes: 5 additions & 1 deletion apps/kyb-app/src/pages/CollectionFlow/CollectionFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
import { StepperProgress } from '@/common/components/atoms/StepperProgress';
import { ProgressBar } from '@/common/components/molecules/ProgressBar';
import { AppShell } from '@/components/layouts/AppShell';
import { PoweredByLogo } from '@/components/molecules/PoweredByLogo';
import { DynamicUI, State } from '@/components/organisms/DynamicUI';
import { usePageErrors } from '@/components/organisms/DynamicUI/Page/hooks/usePageErrors';
import { useStateManagerContext } from '@/components/organisms/DynamicUI/StateManager/components/StateProvider';
Expand Down Expand Up @@ -102,6 +103,7 @@ export const CollectionFlow = withSessionProtected(() => {
filteredNonEmptyErrors?.[0]?.stateName ||
context?.flowConfig?.appState ||
elements?.at(0)?.stateName;

if (!appState) return null;

return {
Expand Down Expand Up @@ -131,6 +133,7 @@ export const CollectionFlow = withSessionProtected(() => {
}, [customer?.logoImageUri]);

if (initialContext?.flowConfig?.appState === 'approved') return <Approved />;

if (initialContext?.flowConfig?.appState == 'rejected') return <Rejected />;

return definition && context ? (
Expand Down Expand Up @@ -197,7 +200,8 @@ export const CollectionFlow = withSessionProtected(() => {
}
</div>
)}
<img src={'/poweredby.svg'} className="mt-6" />
{/* <img src={'/poweredby.svg'} className="mt-6" /> */}
<PoweredByLogo className="mt-8" sidebarRootId="sidebar" />
</div>
</div>
</div>
Expand Down

0 comments on commit 7f95837

Please sign in to comment.