diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-04-27 23:40:42 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-04-27 23:40:42 +0200 |
commit | 85a3ee2bcaf9a77b9d3751c5a18bdb6f6d20ad49 (patch) | |
tree | 19c0850d14ae6afae85515847163810ea25be711 /subprojects/frontend/src/graph/SVGIcons.tsx | |
parent | rfactor(frontend): scroll to top on initialization (diff) | |
download | refinery-85a3ee2bcaf9a77b9d3751c5a18bdb6f6d20ad49.tar.gz refinery-85a3ee2bcaf9a77b9d3751c5a18bdb6f6d20ad49.tar.zst refinery-85a3ee2bcaf9a77b9d3751c5a18bdb6f6d20ad49.zip |
refactor(frontend): fix icon placement in Safari
Also affected WebKitGTK
Diffstat (limited to 'subprojects/frontend/src/graph/SVGIcons.tsx')
-rw-r--r-- | subprojects/frontend/src/graph/SVGIcons.tsx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/subprojects/frontend/src/graph/SVGIcons.tsx b/subprojects/frontend/src/graph/SVGIcons.tsx new file mode 100644 index 00000000..fa3484b1 --- /dev/null +++ b/subprojects/frontend/src/graph/SVGIcons.tsx | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | |||
7 | import { styled } from '@mui/material/styles'; | ||
8 | import { useCallback } from 'react'; | ||
9 | |||
10 | import icons from './icons'; | ||
11 | |||
12 | export const SVG_NS = 'http://www.w3.org/2000/svg'; | ||
13 | |||
14 | const SVGIconsHolder = styled('div', { | ||
15 | name: 'SVGIcons-Holder', | ||
16 | })({ | ||
17 | position: 'absolute', | ||
18 | top: 0, | ||
19 | left: 0, | ||
20 | width: 0, | ||
21 | height: 0, | ||
22 | visibility: 'hidden', | ||
23 | }); | ||
24 | |||
25 | export default function SVGIcons(): JSX.Element { | ||
26 | const addNodes = useCallback((element: HTMLDivElement | null) => { | ||
27 | if (element === null) { | ||
28 | return; | ||
29 | } | ||
30 | const svgElement = document.createElementNS(SVG_NS, 'svg'); | ||
31 | const defs = document.createElementNS(SVG_NS, 'defs'); | ||
32 | svgElement.appendChild(defs); | ||
33 | icons.forEach((value) => { | ||
34 | const importedValue = document.importNode(value, true); | ||
35 | importedValue.id = `refinery-${importedValue.id}`; | ||
36 | defs.appendChild(importedValue); | ||
37 | }); | ||
38 | element.replaceChildren(svgElement); | ||
39 | }, []); | ||
40 | return <SVGIconsHolder ref={addNodes} />; | ||
41 | } | ||