CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/share/google-search.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { CSSProperties, useState } from "react";
7
import { Input } from "antd";
8
import { Icon } from "@cocalc/frontend/components/icon";
9
import { useCustomize } from "lib/customize";
10
11
export default function GoogleSearch({
12
style,
13
size,
14
}: {
15
style?: CSSProperties;
16
size?;
17
}) {
18
const [focus, setFocus] = useState<boolean>(false);
19
const { siteName } = useCustomize();
20
return (
21
<Input.Search
22
size={size}
23
onFocus={() => setFocus(true)}
24
onBlur={() => setFocus(false)}
25
style={style}
26
placeholder={`Google ${siteName} for Shared Files...`}
27
allowClear
28
enterButton={
29
<>
30
<Icon name="google" />
31
{!focus && <> Google</>}
32
</>
33
}
34
onSearch={(value) => {
35
value = value.trim();
36
if (!value) return;
37
const host = window.location.host;
38
const url = `https://www.google.com/search?q=site%3A${host}/share+${value}`;
39
// Open url in a new tab.
40
const tab = window.open(url, "_blank");
41
if (tab != null) {
42
tab.opener = null;
43
}
44
}}
45
/>
46
);
47
}
48
49