-
-
Notifications
You must be signed in to change notification settings - Fork 69
feature DocSearch V3 #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alanpoulain
merged 10 commits into
api-platform:main
from
natacha-h:feature-DocSearch-v3
Oct 4, 2022
Merged
feature DocSearch V3 #327
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e0637a5
feature DocSearch V3
natacha-h 0454656
Update .env.gatsby
natacha-h 055c55e
Update package.json
natacha-h 2fe8c1c
Update src/components/layout/Search.js
natacha-h c72756d
Update src/components/layout/Search.js
natacha-h 6075529
fix : style of placeholder
natacha-h e276817
Update src/components/layout/Search.js
natacha-h 3c98e9c
fix typo
natacha-h e61c502
change declaration order in css
natacha-h b1544e1
Update src/styles/vendor/_docsearchcustom.scss
alanpoulain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
GATSBY_DOCSEARCH_API_KEY = 3ec989b752d176d177da4cfe814eee11 | ||
GATSBY_DOCSEARCH_API_KEY = b72f5d9b3a7c538ebfcb8fa69ba1e077 | ||
GATSBY_DOCSEARCH_INDEX_NAME = api-platform | ||
GATSBY_GOOGLE_ANALYTICS_TRACKING_ID = UA-67501746-1 | ||
GATSBY_ROOT_URL = https://api-platform.com | ||
GATSBY_BUILD_TIMEOUT=600000 | ||
GATSBY_MAPBOX_KEY = pk.eyJ1IjoiZ2luaWZpenoiLCJhIjoiY2tsZ2c3d3Z1MWs1MDJvbWpvdjM2MGg4ZSJ9.5jBAlLJbO-gf2_BQGzfZ0Q | ||
GATSBY_DOCSEARCH_APP_ID = ZQ00U6B6ML |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import scriptLoader from 'react-async-script-loader'; | ||
// import { currentVersion } from '../../../constants'; | ||
|
||
class Search extends React.Component { | ||
// eslint-disable-next-line camelcase | ||
UNSAFE_componentWillReceiveProps(nextProps) { | ||
const { isScriptLoaded } = this.props; | ||
if (nextProps.isScriptLoaded && !isScriptLoaded) { | ||
if (nextProps.isScriptLoadSucceed) { | ||
this.initDocSearch(); | ||
} | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
const { isScriptLoaded, isScriptLoadSucceed } = this.props; | ||
|
||
if (isScriptLoaded && isScriptLoadSucceed) { | ||
this.initDocSearch(); | ||
} | ||
} | ||
|
||
/* eslint-disable no-undef */ | ||
initDocSearch() { | ||
if (docsearch) { | ||
docsearch({ | ||
apiKey: process.env.GATSBY_DOCSEARCH_API_KEY, | ||
indexName: process.env.GATSBY_DOCSEARCH_INDEX_NAME, | ||
inputSelector: this.searchInput, | ||
debug: false, | ||
// algoliaOptions: { facetFilters: [`version:v${currentVersion}`] }, | ||
}); | ||
} | ||
} | ||
/* eslint-enable no-undef */ | ||
|
||
onSearchClick = () => { | ||
this.searchInput.focus(); | ||
}; | ||
|
||
render() { | ||
const { className, onFocus, onBlur } = this.props; | ||
|
||
return ( | ||
<div className={classNames('search', className)}> | ||
<button | ||
className="icon-search search__icon" | ||
type="button" | ||
onClick={this.onSearchClick} | ||
title="Search docs" | ||
aria-label="Search docs" | ||
/> | ||
<form> | ||
<input | ||
ref={(input) => { | ||
this.searchInput = input; | ||
}} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
className="search__input" | ||
type="search" | ||
placeholder="SEARCH..." | ||
/> | ||
</form> | ||
</div> | ||
); | ||
} | ||
} | ||
import { DocSearch } from '@docsearch/react'; | ||
import { currentVersion } from '../../../constants'; | ||
import '@docsearch/css'; | ||
|
||
const Search = ({ className }) => ( | ||
<div className={classNames('search', className)}> | ||
<DocSearch | ||
appId={process.env.GATSBY_DOCSEARCH_APP_ID} | ||
apiKey={process.env.GATSBY_DOCSEARCH_API_KEY} | ||
indexName={process.env.GATSBY_DOCSEARCH_INDEX_NAME} | ||
searchParameters={{ | ||
facetFilters: [`version:v${currentVersion}`], | ||
}} | ||
placeholder="Search..." | ||
/> | ||
</div> | ||
); | ||
|
||
Search.propTypes = { | ||
className: PropTypes.string, | ||
isScriptLoaded: PropTypes.bool.isRequired, | ||
isScriptLoadSucceed: PropTypes.bool.isRequired, | ||
onFocus: PropTypes.func, | ||
onBlur: PropTypes.func, | ||
}; | ||
|
||
Search.defaultProps = { | ||
className: '', | ||
onFocus: () => {}, | ||
onBlur: () => {}, | ||
}; | ||
|
||
export default scriptLoader('https://cdn.jsdelivr.net/docsearch.js/2.5/docsearch.min.js')(Search); | ||
export default Search; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
.DocSearch-Button { | ||
background-color: var(--contrast); | ||
border-radius: 0; | ||
&-Placeholder { | ||
color: var(--search-placeholder); | ||
font-size: 1.3em; | ||
font-weight: $bold; | ||
} | ||
&:focus, &:hover, &:active { | ||
outline: none; | ||
background-color: var(--focus); | ||
box-shadow: none; | ||
} | ||
.DocSearch-Search-Icon { | ||
color: $lightblue; | ||
opacity: .5; | ||
margin-right: 15px; | ||
} | ||
} | ||
|
||
.DocSearch-Modal { | ||
width: 100%; | ||
background-color: var(--bg); | ||
margin-top: calc(var(--headerH) + var(--headerMessageH)); | ||
|
||
.DocSearch-SearchBar::placeholder { | ||
color: var(--search-placeholder); | ||
} | ||
|
||
.DocSearch-Form { | ||
background: none; | ||
box-shadow: none; | ||
.DocSearch-Input { | ||
text-transform: uppercase; | ||
background-color: var(--contrast-bg); | ||
border: none; | ||
color: var(--contrast-text); | ||
font-size: 1.3em; | ||
font-weight: $bold; | ||
padding: 0 10px; | ||
line-height: 40px; | ||
height: 40px; | ||
width: 100%; | ||
|
||
&:focus { | ||
outline: none; | ||
background-color: var(--focus); | ||
} | ||
} | ||
|
||
.DocSearch-MagnifierLabel, .DocSearch-Reset { | ||
color: var(--text); | ||
} | ||
|
||
.DocSearch-MagnifierLabel { | ||
margin-right: 15px; | ||
color: $lightblue; | ||
opacity: .5; | ||
} | ||
} | ||
|
||
.DocSearch-Dropdown { | ||
font-size: $text-small; | ||
width: 100%; | ||
padding: 0 !important; | ||
|
||
.DocSearch-StartScreen, .DocSearch-Dropdown-Container, .DocSearch-NoResults { | ||
margin-top: 0 !important; | ||
padding-bottom: 20px; | ||
border-bottom: 1px solid #ddd; | ||
width: 100%; | ||
} | ||
|
||
.DocSearch-Hit { | ||
a { | ||
box-shadow: none !important; | ||
background: none; | ||
} | ||
|
||
&-title { | ||
color: var(--title); | ||
} | ||
|
||
&[aria-selected="true"] .DocSearch-Hit-action, | ||
&[aria-selected="true"] .DocSearch-Hit-icon, | ||
&[aria-selected="true"] .DocSearch-Hit-path, | ||
&[aria-selected="true"] .DocSearch-Hit-text, | ||
&[aria-selected="true"] .DocSearch-Hit-title, | ||
&[aria-selected="true"] .DocSearch-Hit-Tree, | ||
&[aria-selected="true"] mark { | ||
color: var(--title) !important; | ||
} | ||
} | ||
|
||
.DocSearch-Hits { | ||
mark { | ||
color: $blue; | ||
background-color: var(--bg); | ||
} | ||
&:before, | ||
.DocSearch-Hit-source { | ||
background: $blue !important; | ||
margin-top: 0 !important; | ||
margin-left: 0 !important; | ||
margin-right: 0 !important; | ||
color: $white !important; | ||
padding: 10px !important; | ||
text-transform: uppercase; | ||
font-weight: $bold; | ||
} | ||
} | ||
|
||
.DocSearch-Title { | ||
font-size: $text-small; | ||
color: var(--title); | ||
} | ||
|
||
@include mq($max-width: $vw-medium) { | ||
min-width: 450px!important; | ||
max-width: 450px!important; | ||
alanpoulain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.DocSearch-Hits { | ||
padding-left: 8px; | ||
padding-right: 8px; | ||
} | ||
|
||
.DocSearch-Hit-Container { | ||
padding: 0; | ||
} | ||
} | ||
} | ||
|
||
.DocSearch-Footer { | ||
background: none; | ||
margin-bottom: 10px; | ||
margin-right: 20px; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.