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