-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(headless): added defineSearchBox SSR controller (#3108)
- Loading branch information
1 parent
18a622f
commit 0f131c9
Showing
10 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
23 changes: 23 additions & 0 deletions
23
packages/headless/src/controllers/ssr/search-box/headless-ssr-search-box.ts
This file contains 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,23 @@ | ||
import {SearchEngine} from '../../../app/search-engine/search-engine'; | ||
import {ControllerDefinitionWithoutProps} from '../../../app/ssr-engine/types/common'; | ||
import { | ||
SearchBox, | ||
SearchBoxProps, | ||
buildSearchBox, | ||
} from '../../search-box/headless-search-box'; | ||
|
||
export type { | ||
SearchBoxOptions, | ||
SearchBoxProps, | ||
SearchBoxState, | ||
SearchBox, | ||
} from '../../search-box/headless-search-box'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const defineSearchBox = ( | ||
props?: SearchBoxProps | ||
): ControllerDefinitionWithoutProps<SearchEngine, SearchBox> => ({ | ||
build: (engine) => buildSearchBox(engine, props), | ||
}); |
This file contains 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 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 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 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 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
37 changes: 37 additions & 0 deletions
37
packages/samples/headless-ssr/src/app/generic/components/search-box.tsx
This file contains 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,37 @@ | ||
import { | ||
SearchBoxState, | ||
SearchBox as SearchBoxController, | ||
} from '@coveo/headless'; | ||
import {useEffect, useState, FunctionComponent} from 'react'; | ||
|
||
interface SearchBoxProps { | ||
ssrState: SearchBoxState; | ||
controller?: SearchBoxController; | ||
} | ||
|
||
export const SearchBox: FunctionComponent<SearchBoxProps> = ({ | ||
ssrState, | ||
controller, | ||
}) => { | ||
const [state, setState] = useState(ssrState); | ||
|
||
useEffect( | ||
() => controller?.subscribe?.(() => setState({...controller.state})), | ||
[controller] | ||
); | ||
|
||
return ( | ||
<form | ||
className="search-box" | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
controller?.submit(); | ||
}} | ||
> | ||
<input | ||
value={state.value} | ||
onChange={(e) => controller?.updateText(e.target.value)} | ||
/> | ||
</form> | ||
); | ||
}; |
This file contains 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 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 |
---|---|---|
|
@@ -130,4 +130,4 @@ | |
"editor.formatOnSave": true | ||
}, | ||
} | ||
} | ||
} |