Skip to content

Commit 6378570

Browse files
authored
Merge pull request #202 from lynaDev2/newpage
fixes
2 parents 30aea90 + fc47ee0 commit 6378570

File tree

7 files changed

+1615
-0
lines changed

7 files changed

+1615
-0
lines changed

apps/web/components/ChainIcon.tsx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { getChainMeta } from "./chainIcons";
2+
3+
export interface ChainIconProps {
4+
chainId: number;
5+
size?: number | string;
6+
showName?: boolean;
7+
showTooltip?: boolean;
8+
className?: string;
9+
}
10+
11+
/**
12+
* ChainIcon
13+
*
14+
* Renders the icon (and optionally name) for a given chain ID.
15+
*
16+
* @example
17+
* <ChainIcon chainId={1} size={24} showName />
18+
* <ChainIcon chainId={137} size={32} />
19+
*/
20+
export function ChainIcon({
21+
chainId,
22+
size = 24,
23+
showName = false,
24+
showTooltip = true,
25+
className = "",
26+
}: ChainIconProps) {
27+
const chain = getChainMeta(chainId);
28+
29+
return (
30+
<>
31+
<style>{`
32+
.bw-chain-icon {
33+
display: inline-flex;
34+
align-items: center;
35+
gap: 7px;
36+
vertical-align: middle;
37+
position: relative;
38+
}
39+
.bw-chain-icon__img {
40+
display: block;
41+
flex-shrink: 0;
42+
border-radius: 50%;
43+
overflow: hidden;
44+
line-height: 0;
45+
}
46+
.bw-chain-icon__img svg {
47+
display: block;
48+
width: 100%;
49+
height: 100%;
50+
}
51+
.bw-chain-icon__name {
52+
font-family: system-ui, -apple-system, sans-serif;
53+
font-size: 0.875em;
54+
font-weight: 500;
55+
color: inherit;
56+
white-space: nowrap;
57+
}
58+
.bw-chain-icon[title]:hover::after {
59+
content: attr(title);
60+
position: absolute;
61+
bottom: calc(100% + 6px);
62+
left: 50%;
63+
transform: translateX(-50%);
64+
background: #1f2937;
65+
color: #f9fafb;
66+
font-size: 11px;
67+
font-family: system-ui, sans-serif;
68+
white-space: nowrap;
69+
padding: 3px 8px;
70+
border-radius: 5px;
71+
pointer-events: none;
72+
z-index: 100;
73+
}
74+
`}</style>
75+
<span
76+
className={`bw-chain-icon ${className}`}
77+
title={showTooltip && !showName ? chain.name : undefined}
78+
role="img"
79+
aria-label={chain.name}
80+
>
81+
<span
82+
className="bw-chain-icon__img"
83+
style={{ width: size, height: size }}
84+
dangerouslySetInnerHTML={{ __html: chain.svg }}
85+
/>
86+
{showName && (
87+
<span className="bw-chain-icon__name">{chain.name}</span>
88+
)}
89+
</span>
90+
</>
91+
);
92+
}
93+
94+
export default ChainIcon;

0 commit comments

Comments
 (0)