Skip to content

Commit

Permalink
fix: change logo
Browse files Browse the repository at this point in the history
  • Loading branch information
islxyqwe committed Aug 2, 2023
1 parent d35a77e commit 5c6a2de
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 24 deletions.
1 change: 0 additions & 1 deletion packages/graphic-walker/src/assets/kanaries-logo.svg

This file was deleted.

Binary file added packages/graphic-walker/src/assets/kanaries.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions packages/graphic-walker/src/components/timeoutImg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useRef, useState, useEffect } from 'react';

export const ImageWithFallback = (
props: React.ImgHTMLAttributes<HTMLImageElement> & { fallbackSrc: string; timeout: number }
) => {
const { src, fallbackSrc, timeout, ...rest } = props;
const [failed, setFailed] = useState(false);
const imgLoadedOnInitSrc = useRef(false);

useEffect(() => {
const timer = setTimeout(() => {
if (!imgLoadedOnInitSrc.current) setFailed(true);
}, timeout);
return () => clearTimeout(timer);
}, []);

return (
<img
{...rest}
src={failed ? src : fallbackSrc}
onError={() => {
setFailed(true);
}}
onLoad={() => {
imgLoadedOnInitSrc.current = true;
}}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const ToolbarItemContainerElement = styled.div<{ split: boolean; dark: bo
outline: none;
width: ${({ split }) => split ? 'calc(var(--height) + 10px)' : 'var(--height)'};
height: var(--height);
align-items: center;
overflow: hidden;
color: ${({ dark }) => dark ? 'var(--dark-mode-color)' : 'var(--color)'};
position: relative;
Expand Down
43 changes: 20 additions & 23 deletions packages/graphic-walker/src/visualSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import Toolbar, { ToolbarItemProps } from '../components/toolbar';
import { ButtonWithShortcut } from './menubar';
import { useCurrentMediaTheme } from '../utils/media';
import throttle from '../utils/throttle';
import KanariesLogo from '../assets/kanaries-logo.svg';
import KanariesLogo from '../assets/kanaries.png';
import { ImageWithFallback } from '../components/timeoutImg';

const Invisible = styled.div`
clip: rect(1px, 1px, 1px, 1px);
Expand Down Expand Up @@ -101,30 +102,8 @@ const VisualSettings: React.FC<IVisualSettings> = ({

const dark = useCurrentMediaTheme(darkModePreference) === 'dark';

console.log('kanaries logo', KanariesLogo);

const items = useMemo<ToolbarItemProps[]>(() => {
const builtInItems = [
{
key: 'kanaries',
label: 'kanaries',
icon: () => (
// Kanaries brand info is not allowed to be removed or changed unless you are granted with special permission.
<a href="https://kanaries.net" target="_blank">
<img
id="kanaries-logo"
className="m-1"
src="https://imagedelivery.net/tSvh1MGEu9IgUanmf58srQ/b6bc899f-a129-4c3a-d08f-d406166d0c00/public"
alt="kanaries"
onError={(e) => {
// @ts-ignore
e.target.src = KanariesLogo;
}}
/>
</a>
),
},
'-',
{
key: 'undo',
label: 'undo (Ctrl + Z)',
Expand Down Expand Up @@ -512,6 +491,24 @@ const VisualSettings: React.FC<IVisualSettings> = ({
commonStore.setShowCodeExportPanel(true);
},
},
'-',
{
key: 'kanaries',
label: 'kanaries',
icon: () => (
// Kanaries brand info is not allowed to be removed or changed unless you are granted with special permission.
<a href="https://docs.kanaries.net" target="_blank">
<ImageWithFallback
id="kanaries-logo"
className="p-1.5 opacity-70 hover:opacity-100"
src="https://imagedelivery.net/tSvh1MGEu9IgUanmf58srQ/b6bc899f-a129-4c3a-d08f-d406166d0c00/public"
fallbackSrc={KanariesLogo}
timeout={1000}
alt="kanaries"
/>
</a>
),
},
] as ToolbarItemProps[];

const items = builtInItems.filter((item) => typeof item === 'string' || !exclude.includes(item.key));
Expand Down

0 comments on commit 5c6a2de

Please sign in to comment.