-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathIconSpriteDefinitions.tsx
More file actions
56 lines (50 loc) · 1.55 KB
/
IconSpriteDefinitions.tsx
File metadata and controls
56 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { getIconSymbol } from '@/lib/icons/symbols';
import {
type RegisteredIconSymbol,
clearRegisteredServerIconSymbols,
getRegisteredServerIconSymbols,
} from '@gitbook/icons';
/**
* Emits the subset of icon symbols that were rendered during the current request.
*/
export async function IconSpriteDefinitions() {
const registered: Map<string, RegisteredIconSymbol> = new Map(
getRegisteredServerIconSymbols().map((symbol: RegisteredIconSymbol) => [
`${symbol.style}/${symbol.icon}`,
symbol,
])
);
if (registered.size === 0) {
return null;
}
const definitions = (
await Promise.all(
[...registered.values()].map((symbol) => {
return getIconSymbol(symbol.style, symbol.icon, symbol.symbolId);
})
)
).filter((symbol): symbol is NonNullable<typeof symbol> => !!symbol);
clearRegisteredServerIconSymbols();
if (!definitions.length) {
return null;
}
return (
<svg
id="gb-icon-sprite-root"
data-testid="icon-sprite-root"
aria-hidden="true"
focusable="false"
xmlns="http://www.w3.org/2000/svg"
style={{
position: 'absolute',
width: 0,
height: 0,
overflow: 'hidden',
pointerEvents: 'none',
}}
dangerouslySetInnerHTML={{
__html: definitions.map((symbol) => symbol.symbol).join(''),
}}
/>
);
}