-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaside-search.tsx
55 lines (50 loc) · 1.75 KB
/
aside-search.tsx
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
import { register } from "microfrontends";
import React from "react";
import ReactDOM from "react-dom";
import { createRoot } from "react-dom/client";
import pkg from "../package.json";
const getHTMLElement = (ref: HTMLElement | string) =>
ref instanceof HTMLElement ? ref : document.getElementById(ref);
const Search = () => (
<div className="search-wrapper">
<div className="flex flex-row gap-2 container-search px-4 outline outline-teal-300">
<svg
className="flex search-bar-icon self-center relative bottom-2"
viewBox="0 -8 24 20"
width="16"
height="24"
fill="gray"
>
<path d="M10.25 3.75c-3.59 0-6.5 2.91-6.5 6.5s2.91 6.5 6.5 6.5c1.795 0 3.419-.726 4.596-1.904 1.178-1.177 1.904-2.801 1.904-4.596 0-3.59-2.91-6.5-6.5-6.5zm-8.5 6.5c0-4.694 3.806-8.5 8.5-8.5s8.5 3.806 8.5 8.5c0 1.986-.682 3.815-1.824 5.262l4.781 4.781-1.414 1.414-4.781-4.781c-1.447 1.142-3.276 1.824-5.262 1.824-4.694 0-8.5-3.806-8.5-8.5z"></path>
</svg>
<input
type="text"
className="flex search-bar self-start grow"
placeholder="Search"
/>
</div>
</div>
);
export default register(pkg.name, "./aside-search", {
mount: (containerRef) => {
const container = getHTMLElement(containerRef);
if (container?.getAttribute("data-mf-mounted") === "true") {
return () => {
ReactDOM.unmountComponentAtNode(container!);
};
}
container?.setAttribute("data-mf-mounted", "true");
const root = createRoot(container!);
root.render(
<React.StrictMode>
<Search />
</React.StrictMode>
);
return () => {
root.unmount();
};
},
unmount: (containerRef) => {
ReactDOM.unmountComponentAtNode(getHTMLElement(containerRef)!);
},
});