Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
feat: search on page (#21)
Browse files Browse the repository at this point in the history
* feat: search on page

* feat: search on page

* add styles for search

* fix styles

* chore: update LO submodule

Co-authored-by: shoom3301 <shoom3301@gmail.com>
Co-authored-by: Yaroslav Zhavoronkov <y.zhavoronkov@1inch.io>
  • Loading branch information
3 people authored Dec 23, 2021
1 parent 3de8f9f commit 06af2ca
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 3 deletions.
2 changes: 1 addition & 1 deletion git-submodules/limit-order-protocol
Submodule limit-order-protocol updated 36 files
+3 −0 .vscode/settings.json
+1 −1 contracts/LimitOrderProtocol.sol
+1 −1 contracts/OrderMixin.sol
+1 −1 contracts/OrderRFQMixin.sol
+1 −1 contracts/WethUnwrapper.sol
+1 −1 contracts/helpers/AmountCalculator.sol
+12 −15 contracts/helpers/ChainlinkCalculator.sol
+1 −1 contracts/helpers/ERC1155Proxy.sol
+1 −1 contracts/helpers/ERC721Proxy.sol
+1 −1 contracts/helpers/ERC721ProxySafe.sol
+1 −1 contracts/helpers/ImmutableOwner.sol
+1 −1 contracts/helpers/NonceManager.sol
+1 −1 contracts/helpers/PredicateHelper.sol
+1 −1 contracts/interfaces/IDaiLikePermit.sol
+1 −1 contracts/interfaces/IWithdrawable.sol
+1 −1 contracts/interfaces/InteractiveNotificationReceiver.sol
+1 −1 contracts/libraries/ArgumentsDecoder.sol
+1 −1 contracts/libraries/Permitable.sol
+1 −1 contracts/libraries/RevertReasonParser.sol
+1 −1 contracts/mocks/AggregatorMock.sol
+1 −1 contracts/mocks/TokenMock.sol
+1 −1 contracts/mocks/WrappedTokenMock.sol
+1 −1 contracts/tests/ArgumentsDecoderTest.sol
+0 −1 deploy/deploy-weth-unwrapper.js
+0 −2 deploy/deploy.js
+1 −0 deployments/avax/.chainId
+1,858 −0 deployments/avax/LimitOrderProtocol.json
+82 −0 deployments/avax/WethUnwrapper.json
+1 −0 deployments/xdai/.chainId
+1,858 −0 deployments/xdai/LimitOrderProtocol.json
+82 −0 deployments/xdai/WethUnwrapper.json
+1 −1 hardhat.config.js
+21 −53 hardhat.networks.js
+1 −1 package.json
+1 −1 test/ChainLinkExample.js
+4 −4 yarn.lock
91 changes: 90 additions & 1 deletion src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
--1inch-text-2: #6C86AD;
--1inch-text-3: #FBFBFB;
--1inch-text-4: #FBFBFB;
--1inch-text-5: rgba(251, 251, 251, 1);
--1inch-border: rgba(255, 255, 255, 0.25);
--1inch-bg-1: #000000;
--1inch-bg-2: #202835;
--1inch-bg-3: #FBFBFB;
--1inch-bg-4: rgba(6, 10, 16, 0.5);
--1inch-bg-5: #202835;
--1inch-bg-6: rgba(255, 255, 255, 0.09);
--1inch-bg-7: #202835;
--1inch-bg-card: #FFFFFF;
--1inch-bg-header: #06070A;
--1inch-bg-toggle: #202835;
--1inch-shadow-1: 0 0 4px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.25);
--1inch-shadow-2: none;
--1inch-shadow-3: 0px 0px 4px rgba(0, 0, 0, 0.1), 0px 1px 2px rgba(0, 0, 0, 0.25);
--1inch-text-2-hover: #FBFBFB;
}

Expand All @@ -35,6 +38,7 @@
--1inch-text-2: #6C86AD;
--1inch-text-3: #2F8AF5;
--1inch-text-4: #6C86AD;
--1inch-text-5: rgba(34, 34, 34, 1);
--1inch-bg-image: rgba(108, 134, 173, 0.12);
--1inch-title: #1c1e21;
--1inch-border: rgba(0, 0, 0, 0.24);
Expand All @@ -44,10 +48,12 @@
--1inch-bg-4: #ECF0F9;
--1inch-bg-5: #FFFFFF;
--1inch-bg-6: #ECF0F9;
--1inch-bg-7: #FFFFFF;
--1inch-bg-header: #FFFFFF;
--1inch-bg-toggle: #ECF0F9;
--1inch-shadow-1: 0 0 4px rgba(71, 73, 79, 0.05), 0 1px 2px rgba(71, 73, 79, 0.05);
--1inch-shadow-2: 0 0 4px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.25);
--1inch-shadow-3: 0px 0px 4px rgba(71, 73, 79, 0.1), 0px 1px 2px rgba(71, 73, 79, 0.25);
--1inch-text-2-hover: #222222;
}

Expand Down Expand Up @@ -152,7 +158,7 @@ html {

.navbar__item {
padding: 0;
margin-right: 32px;
margin-right: 24px;
align-self: stretch;
display: flex;
align-items: center;
Expand Down Expand Up @@ -393,6 +399,89 @@ html[data-theme='dark'] .swagger-ui .model-toggle:after {
}
/* swagger END */

/* search START */

.largeSearch .DocSearch-Button {
margin-top: 32px;
background: var(--1inch-bg-7) !important;
box-shadow: var(--1inch-shadow-3);
width: 275px;
height: 50px;
}

.smallSearch .DocSearch-Button {
background: var(--1inch-bg-7) !important;
box-shadow: var(--1inch-shadow-3);
width: 200px;
height: 42px;
margin-left: 32px;
}

.DocSearch-Button {
border-radius: 12px !important;
}

.DocSearch-Button:hover {
box-shadow: none;
}

.DocSearch-Search-Icon {
margin-left: 19px;
}

.DocSearch-Button-Key {
color: rgba(34, 34, 34, 1) !important;
background: #FFFFFF !important;
border-radius: 6px !important;
width: 27px !important;
height: 22px !important;
}

.navbar {
height: auto !important;
}

.DocSearch-Button-Placeholder {
color: var(--1inch-text-5);
margin-left: 16px;
}

@media (max-width: 1060px) {
.smallSearch .DocSearch-Button {
display: none;
}
}

@media (max-width: 750px) {
.largeSearch .DocSearch-Button {
width: 240px;
}

.DocSearch-Search-Icon {
margin-left: 10px;
}

.DocSearch-Button-Placeholder {
margin-left: 10px;
display: block !important;
}

.DocSearch-Button-Keys {
display: flex !important;
margin-right: 0;
}
}

@media (max-width: 400px) {
.largeSearch .DocSearch-Button {
margin-right: 0;
width: 100%;
}
}


/* search END */

/* Adaptive START */
@media (max-width: 1247px) {
.navbar__item {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import Layout from '@theme/Layout';
import styles from './index.module.css';
import HomepageFeatures from '../components/homepage-features/HomepageFeatures';
import HomepageDeveloperLinks from '../components/homepage-developer-links/HomepageDeveloperLinks';
import HomepagePreFooter from '../components/homepage-prefooter/HomepagePreFooter';
import SearchBar from '@theme/SearchBar';
import HomepageFooter from '../components/homepage-footer/HomepageFooter';
import HomePageBackgroundImage from '../../static/img/logo-background.svg'

function HomepageHeader() {
return (
<header className={styles.headerWrap}>
<h1 className={styles.mainTitle}>Documentation Portal</h1>
<SearchBar size="large"/>
</header>
);
}
Expand Down
219 changes: 219 additions & 0 deletions src/theme/SearchBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React, {useState, useRef, useCallback, useMemo} from 'react';
import {createPortal} from 'react-dom';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import {useHistory} from '@docusaurus/router';
import {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
import Link from '@docusaurus/Link';
import Head from '@docusaurus/Head';
import useSearchQuery from '@docusaurus/preset-classic/node_modules/@docusaurus/theme-search-algolia/src/theme/hooks/useSearchQuery.js';
import {isRegexpStringMatch} from '@docusaurus/theme-common';
import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react';
import useAlgoliaContextualFacetFilters from '@docusaurus/preset-classic/node_modules/@docusaurus/theme-search-algolia/src/theme/hooks/useAlgoliaContextualFacetFilters.js';
import {translate} from '@docusaurus/Translate';
import styles from './styles.module.css';

let DocSearchModal = null;

function Hit({hit, children}) {
return <Link to={hit.url}>{children}</Link>;
}

function ResultsFooter({state, onClose}) {
const {generateSearchPageLink} = useSearchQuery();

return (
<Link to={generateSearchPageLink(state.query)} onClick={onClose}>
See all {state.context.nbHits} results
</Link>
);
}

function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
const {siteMetadata} = useDocusaurusContext();

const contextualSearchFacetFilters = useAlgoliaContextualFacetFilters();

const configFacetFilters = props.searchParameters?.facetFilters ?? [];

const facetFilters = contextualSearch
? // Merge contextual search filters with config filters
[...contextualSearchFacetFilters, ...configFacetFilters]
: // ... or use config facetFilters
configFacetFilters;

// we let user override default searchParameters if he wants to
const searchParameters = {
...props.searchParameters,
facetFilters,
};

const {withBaseUrl} = useBaseUrlUtils();
const history = useHistory();
const searchContainer = useRef(null);
const searchButtonRef = useRef(null);
const [isOpen, setIsOpen] = useState(false);
const [initialQuery, setInitialQuery] = useState(null);

const importDocSearchModalIfNeeded = useCallback(() => {
if (DocSearchModal) {
return Promise.resolve();
}

return Promise.all([
import('@docsearch/react/modal'),
import('@docsearch/react/style'),
import('./styles.css'),
]).then(([{DocSearchModal: Modal}]) => {
DocSearchModal = Modal;
});
}, []);

const onOpen = useCallback(() => {
importDocSearchModalIfNeeded().then(() => {
searchContainer.current = document.createElement('div');
document.body.insertBefore(
searchContainer.current,
document.body.firstChild,
);
setIsOpen(true);
});
}, [importDocSearchModalIfNeeded, setIsOpen]);

const onClose = useCallback(() => {
setIsOpen(false);
searchContainer.current.remove();
}, [setIsOpen]);

const onInput = useCallback(
(event) => {
importDocSearchModalIfNeeded().then(() => {
setIsOpen(true);
setInitialQuery(event.key);
});
},
[importDocSearchModalIfNeeded, setIsOpen, setInitialQuery],
);

const navigator = useRef({
navigate({itemUrl}) {
// Algolia results could contain URL's from other domains which cannot
// be served through history and should navigate with window.location
if (isRegexpStringMatch(externalUrlRegex, itemUrl)) {
window.location.href = itemUrl;
} else {
history.push(itemUrl);
}
},
}).current;

const transformItems = useRef((items) => {
return items.map((item) => {
// If Algolia contains a external domain, we should navigate without relative URL
if (isRegexpStringMatch(externalUrlRegex, item.url)) {
return item;
}

// We transform the absolute URL into a relative URL.
const url = new URL(item.url);
return {
...item,
url: withBaseUrl(`${url.pathname}${url.hash}`),
};
});
}).current;

const resultsFooterComponent = useMemo(
() => (footerProps) => <ResultsFooter {...footerProps} onClose={onClose} />,
[onClose],
);

const transformSearchClient = useCallback(
(searchClient) => {
searchClient.addAlgoliaAgent(
'docusaurus',
siteMetadata.docusaurusVersion,
);

return searchClient;
},
[siteMetadata.docusaurusVersion],
);

useDocSearchKeyboardEvents({
isOpen,
onOpen,
onClose,
onInput,
searchButtonRef,
});

const translatedSearchLabel = translate({
id: 'theme.SearchBar.label',
message: 'Search',
description: 'The ARIA label and placeholder for search button',
});

return (
<>
<Head>
{/* This hints the browser that the website will load data from Algolia,
and allows it to preconnect to the DocSearch cluster. It makes the first
query faster, especially on mobile. */}
<link
rel="preconnect"
href={`https://${props.appId}-dsn.algolia.net`}
crossOrigin="anonymous"
/>
</Head>

<div className={styles.searchBox}>
<DocSearchButton
onTouchStart={importDocSearchModalIfNeeded}
onFocus={importDocSearchModalIfNeeded}
onMouseOver={importDocSearchModalIfNeeded}
onClick={onOpen}
ref={searchButtonRef}
translations={{
buttonText: translatedSearchLabel,
buttonAriaLabel: translatedSearchLabel,
}}
/>
</div>

{isOpen &&
createPortal(
<DocSearchModal
onClose={onClose}
initialScrollY={window.scrollY}
initialQuery={initialQuery}
navigator={navigator}
transformItems={transformItems}
hitComponent={Hit}
resultsFooterComponent={resultsFooterComponent}
transformSearchClient={transformSearchClient}
{...props}
searchParameters={searchParameters}
/>,
searchContainer.current,
)}
</>
);
}

function SearchBar({size}) {
const {siteConfig} = useDocusaurusContext();
return (
<div className={size === 'large' ? 'largeSearch' : 'smallSearch'}>
<DocSearch {...siteConfig.themeConfig.algolia} />
</div>
);
}

export default SearchBar;
Loading

0 comments on commit 06af2ca

Please sign in to comment.