diff --git a/packages/cra-template-coveo/README.md b/packages/cra-template-coveo/README.md new file mode 100644 index 0000000000..f38ac7d60b --- /dev/null +++ b/packages/cra-template-coveo/README.md @@ -0,0 +1,20 @@ +# cra-template-coveo + +This is the coveo template for [Create React App](https://github.com/facebook/create-react-app). + +To use this template, add `--template coveo` when creating a new app. + +For example: + +```sh +npx create-react-app my-app --template coveo + +# or + +yarn create react-app my-app --template coveo +``` + +For more information, please refer to: + +- [Getting Started](https://create-react-app.dev/docs/getting-started) – How to create a new app. +- [User Guide](https://create-react-app.dev) – How to develop apps bootstrapped with Create React App. diff --git a/packages/cra-template-coveo/package.json b/packages/cra-template-coveo/package.json new file mode 100644 index 0000000000..5425ebdee6 --- /dev/null +++ b/packages/cra-template-coveo/package.json @@ -0,0 +1,27 @@ +{ + "name": "cra-template-typescript", + "version": "1.1.1", + "keywords": [ + "react", + "create-react-app", + "template", + "typescript" + ], + "description": "The base TypeScript template for Create React App.", + "repository": { + "type": "git", + "url": "https://github.com/facebook/create-react-app.git", + "directory": "packages/cra-template-typescript" + }, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "bugs": { + "url": "https://github.com/facebook/create-react-app/issues" + }, + "files": [ + "template", + "template.json" + ] +} diff --git a/packages/cra-template-coveo/template.json b/packages/cra-template-coveo/template.json new file mode 100644 index 0000000000..11e6cce83a --- /dev/null +++ b/packages/cra-template-coveo/template.json @@ -0,0 +1,24 @@ +{ + "package": { + "dependencies": { + "@coveo/headless": "^0.1.0", + "@material-ui/core": "^4.11.3", + "@material-ui/lab": "^4.0.0-alpha.57", + "@testing-library/jest-dom": "^5.11.4", + "@testing-library/react": "^11.1.0", + "@testing-library/user-event": "^12.1.10", + "@types/node": "^12.0.0", + "@types/react": "^17.0.0", + "@types/react-dom": "^17.0.0", + "@types/jest": "^26.0.15", + "typescript": "^4.1.2", + "web-vitals": "^1.0.1" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + } + } +} \ No newline at end of file diff --git a/packages/cra-template-coveo/template/README.md b/packages/cra-template-coveo/template/README.md new file mode 100644 index 0000000000..b87cb00449 --- /dev/null +++ b/packages/cra-template-coveo/template/README.md @@ -0,0 +1,46 @@ +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.\ +You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/packages/cra-template-coveo/template/gitignore b/packages/cra-template-coveo/template/gitignore new file mode 100644 index 0000000000..4d29575de8 --- /dev/null +++ b/packages/cra-template-coveo/template/gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/packages/cra-template-coveo/template/public/favicon.ico b/packages/cra-template-coveo/template/public/favicon.ico new file mode 100644 index 0000000000..a11777cc47 Binary files /dev/null and b/packages/cra-template-coveo/template/public/favicon.ico differ diff --git a/packages/cra-template-coveo/template/public/index.html b/packages/cra-template-coveo/template/public/index.html new file mode 100644 index 0000000000..aa069f27cb --- /dev/null +++ b/packages/cra-template-coveo/template/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/packages/cra-template-coveo/template/public/logo192.png b/packages/cra-template-coveo/template/public/logo192.png new file mode 100644 index 0000000000..fc44b0a379 Binary files /dev/null and b/packages/cra-template-coveo/template/public/logo192.png differ diff --git a/packages/cra-template-coveo/template/public/logo512.png b/packages/cra-template-coveo/template/public/logo512.png new file mode 100644 index 0000000000..a4e47a6545 Binary files /dev/null and b/packages/cra-template-coveo/template/public/logo512.png differ diff --git a/packages/cra-template-coveo/template/public/manifest.json b/packages/cra-template-coveo/template/public/manifest.json new file mode 100644 index 0000000000..080d6c77ac --- /dev/null +++ b/packages/cra-template-coveo/template/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/packages/cra-template-coveo/template/public/robots.txt b/packages/cra-template-coveo/template/public/robots.txt new file mode 100644 index 0000000000..e9e57dc4d4 --- /dev/null +++ b/packages/cra-template-coveo/template/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/packages/cra-template-coveo/template/src/App.css b/packages/cra-template-coveo/template/src/App.css new file mode 100644 index 0000000000..74b5e05345 --- /dev/null +++ b/packages/cra-template-coveo/template/src/App.css @@ -0,0 +1,38 @@ +.App { + text-align: center; +} + +.App-logo { + height: 40vmin; + pointer-events: none; +} + +@media (prefers-reduced-motion: no-preference) { + .App-logo { + animation: App-logo-spin infinite 20s linear; + } +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/packages/cra-template-coveo/template/src/App.test.tsx b/packages/cra-template-coveo/template/src/App.test.tsx new file mode 100644 index 0000000000..14b01402ba --- /dev/null +++ b/packages/cra-template-coveo/template/src/App.test.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import {render, screen} from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/packages/cra-template-coveo/template/src/App.tsx b/packages/cra-template-coveo/template/src/App.tsx new file mode 100644 index 0000000000..279536081b --- /dev/null +++ b/packages/cra-template-coveo/template/src/App.tsx @@ -0,0 +1,14 @@ +import SearchPage from './Components/SearchPage'; +import Hero from './Components/Hero'; +import logo from './logo.svg'; + +function App() { + return ( +
+ + +
+ ); +} + +export default App; diff --git a/packages/cra-template-coveo/template/src/Components/Facet.css b/packages/cra-template-coveo/template/src/Components/Facet.css new file mode 100644 index 0000000000..be84d696ae --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/Facet.css @@ -0,0 +1,15 @@ +.truncate { + width: 100%; + position: relative; +} + +.inline { + display: flex; +} + +.truncate span { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + width: 100%; +} diff --git a/packages/cra-template-coveo/template/src/Components/Facet.tsx b/packages/cra-template-coveo/template/src/Components/Facet.tsx new file mode 100644 index 0000000000..dd6f97d7e3 --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/Facet.tsx @@ -0,0 +1,113 @@ +import React from 'react'; +import { + Facet as FacetType, + FacetState, + buildFacet, + FacetValue, +} from '@coveo/headless'; +import {headlessEngine} from '../Engine'; +import Button from '@material-ui/core/Button'; +import Checkbox from '@material-ui/core/Checkbox'; +import Box from '@material-ui/core/Box'; +import List from '@material-ui/core/List'; +import './Facet.css'; +import {Divider, ListItem, ListItemText, Typography} from '@material-ui/core'; + +interface IFacetProps { + title: string; + field: string; +} + +export default class Facet extends React.Component { + private headlessFacet: FacetType; + state: FacetState; + + constructor(props: any) { + super(props); + + this.headlessFacet = buildFacet(headlessEngine, { + options: { + numberOfValues: 5, + field: this.props.field, + }, + }); + + this.state = this.headlessFacet.state; + } + + componentDidMount() { + this.headlessFacet.subscribe(() => this.updateState()); + } + + componentWillUnmount() { + this.headlessFacet.subscribe(() => {}); + } + + updateState() { + this.setState(this.headlessFacet.state); + } + + toggleSelect(value: FacetValue) { + this.headlessFacet.toggleSelect(value); + } + + showMore() { + this.headlessFacet.showMoreValues(); + } + + showLess() { + this.headlessFacet.showLessValues(); + } + + render() { + return ( + + + + {this.props.title} + + + + + {this.state.values.map((value: FacetValue) => { + const labelId = `checkbox-list-label-${value}`; + + return ( + this.toggleSelect(value)} + > + + + + ); + })} + + {this.state.canShowLessValues && ( + + )} + {this.state.canShowMoreValues && ( + + )} + + ); + } +} diff --git a/packages/cra-template-coveo/template/src/Components/FacetList.tsx b/packages/cra-template-coveo/template/src/Components/FacetList.tsx new file mode 100644 index 0000000000..67a28d6727 --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/FacetList.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import Typography from '@material-ui/core/Typography'; +import Box from '@material-ui/core/Box'; +import Facet from './Facet'; + +export default class FacetList extends React.Component { + render() { + return ( + + + Refine By + + + + + + ); + } +} diff --git a/packages/cra-template-coveo/template/src/Components/Hero.css b/packages/cra-template-coveo/template/src/Components/Hero.css new file mode 100644 index 0000000000..9adce291ad --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/Hero.css @@ -0,0 +1,34 @@ +.App-logo { + height: 40vmin; + pointer-events: none; +} + +.App-header { + background-color: #333357; + min-height: 30vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + color: #e5e8e8; + font-family: Avenir, Helvetica, Arial, sans-serif; + margin-bottom: 4rem; +} + +.App-header ul { + list-style-type: none; + padding: 0; + margin-top: 0; +} +.App-header li { + display: inline-block; + margin: 0 10px; +} + +.App-header h6 { + padding-top: 2rem; +} + +.App-header a { + color: #1cebcf; +} diff --git a/packages/cra-template-coveo/template/src/Components/Hero.tsx b/packages/cra-template-coveo/template/src/Components/Hero.tsx new file mode 100644 index 0000000000..c4caf695d5 --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/Hero.tsx @@ -0,0 +1,83 @@ +import {Typography} from '@material-ui/core'; +import React from 'react'; +import './Hero.css'; + +function Anchor(props: any) { + return {props.value}; +} + +export default class Hero extends React.Component< + {logo: string; welcome: string}, + {} +> { + render() { + return ( +
+ logo + {this.props.welcome} + + This sample search page was built with{' '} + {' '} + and the{' '} + + .

+
+ + Edit{' '} + + src/App.tsx + {' '} + and save to reload. + + + + Customize your search page theme + + + You can customize your theme by modifying the{' '} + + src/theme.tsx + + . For more information about theme customization, visit{' '} + + . + + + + Essential Links + +
    +
  • + + . +
  • +
  • + + . +
  • +
  • + . +
  • +
  • + . +
  • +
+
+ ); + } +} diff --git a/packages/cra-template-coveo/template/src/Components/Pager.tsx b/packages/cra-template-coveo/template/src/Components/Pager.tsx new file mode 100644 index 0000000000..521b5e424c --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/Pager.tsx @@ -0,0 +1,57 @@ +import React from 'react'; +import {Pagination} from '@material-ui/lab'; +import Box from '@material-ui/core/Box'; +import Typography from '@material-ui/core/Typography'; +import {buildPager, PagerState, Pager as PagerType} from '@coveo/headless'; +import {headlessEngine} from '../Engine'; + +export default class Pager extends React.Component { + private headlessPager: PagerType; + state: PagerState; + + constructor(props: any) { + super(props); + + this.headlessPager = buildPager(headlessEngine, { + options: {numberOfPages: 3}, + }); + + this.state = this.headlessPager.state; + } + + componentDidMount() { + this.headlessPager.subscribe(() => this.updateState()); + } + + updateState() { + this.setState(this.headlessPager.state); + } + + setPage(pageNumber: number) { + this.headlessPager.selectPage(pageNumber); + } + + get page() { + return this.headlessPager.state.currentPage; + } + + get count() { + return this.headlessPager.state.maxPage; + } + + render() { + return ( + + Current page + this.setPage(page)} + variant="outlined" + shape="rounded" + size="small" + /> + + ); + } +} diff --git a/packages/cra-template-coveo/template/src/Components/QuerySummary.tsx b/packages/cra-template-coveo/template/src/Components/QuerySummary.tsx new file mode 100644 index 0000000000..74b5b5d67e --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/QuerySummary.tsx @@ -0,0 +1,89 @@ +import React from 'react'; +import { + buildQuerySummary, + QuerySummaryState, + QuerySummary as QuerySummaryType, +} from '@coveo/headless'; +import {headlessEngine} from '../Engine'; +import {Box, Divider} from '@material-ui/core'; + +export default class QuerySummary extends React.Component { + private headlessQuerySummary: QuerySummaryType; + state: QuerySummaryState; + + constructor(props: any) { + super(props); + + this.headlessQuerySummary = buildQuerySummary(headlessEngine); + + this.state = this.headlessQuerySummary.state; + } + + componentDidMount() { + this.headlessQuerySummary.subscribe(() => this.updateState()); + } + + updateState() { + this.setState(this.headlessQuerySummary.state); + } + + renderNoResults() { + return No results; + } + + renderBold(input: string) { + return ( + + {input} + + ); + } + + renderRange() { + return this.renderBold( + ` ${this.state.firstResult}-${this.state.lastResult}` + ); + } + + renderTotal() { + return ( + + {' '} + of {this.renderBold(this.state.total.toString())} + + ); + } + + renderQuery() { + if (this.state.hasQuery) { + return ( + for {this.renderBold(this.state.query)} + ); + } + } + + renderDuration() { + return ` in ${this.state.durationInSeconds} seconds`; + } + + renderHasResults() { + return ( + + + Results{this.renderRange()} + {this.renderTotal()} + {this.renderQuery()} + {this.renderDuration()} + + + + ); + } + + render() { + if (!this.state.hasResults) { + return this.renderNoResults(); + } + return this.renderHasResults(); + } +} diff --git a/packages/cra-template-coveo/template/src/Components/ResultList.tsx b/packages/cra-template-coveo/template/src/Components/ResultList.tsx new file mode 100644 index 0000000000..fd4baf2006 --- /dev/null +++ b/packages/cra-template-coveo/template/src/Components/ResultList.tsx @@ -0,0 +1,116 @@ +import React from 'react'; +import List from '@material-ui/core/List'; +import {ListItem, Box, Typography} from '@material-ui/core'; +import { + buildResultList, + ResultTemplatesManager, + Result, + ResultListState, + ResultList as ResultListType, + buildResultTemplatesManager, +} from '@coveo/headless'; +import {headlessEngine} from '../Engine'; + +type Template = (result: Result) => any; + +interface FieldValueInterface { + value: string; + caption: string; +} + +function ListItemLink(props: any) { + return ( + + + {props.title} + + + ); +} + +function FieldValue(props: FieldValueInterface) { + return ( + + + {props.caption}:  + + + {props.value} + + + ); +} + +export default class ResultList extends React.Component { + private headlessResultList: ResultListType; + private headlessResultTemplateManager: ResultTemplatesManager