-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add example React app to demonstrate how to use the c…
…omponents #133
- Loading branch information
1 parent
0a95979
commit 1d6c53b
Showing
15 changed files
with
190 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
node_modules/* | ||
docs/* | ||
docs-src/* | ||
rollup-config.js | ||
custom-elements.json | ||
web-dev-server.config.js | ||
build/* | ||
storybook-static/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock.json |
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,16 @@ | ||
# GenSpectrum components in React | ||
|
||
This demonstrates how to use GenSpectrum components in React. | ||
It was created using `npm create vite@latest React --template react-ts`. | ||
|
||
Install the packed version of the components: | ||
|
||
```bash | ||
npm run import-components | ||
``` | ||
|
||
Start a test server to see the components in action: | ||
|
||
```bash | ||
npm run dev | ||
``` |
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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>GenSpectrum Components with React</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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,21 @@ | ||
{ | ||
"name": "react", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"start": "vite", | ||
"import-components": "npm --prefix ../../components/ run build-and-pack && npm install ../../components/genspectrum-dashboard-components.tgz" | ||
}, | ||
"dependencies": { | ||
"@genspectrum/dashboard-components": "file:../../components/genspectrum-dashboard-components.tgz", | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.2.0" | ||
} | ||
} |
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,77 @@ | ||
import {useEffect, useState} from 'react' | ||
import '@genspectrum/dashboard-components' | ||
import '@genspectrum/dashboard-components/style.css' | ||
|
||
function App() { | ||
const [location, setLocation] = useState({ | ||
region: "Europe", | ||
country: "Switzerland" | ||
}) | ||
const [dateRange, setDateRange] = useState({ | ||
dateFrom: "2021-01-01", | ||
dateTo: "2022-01-01" | ||
}) | ||
|
||
useEffect(() => { | ||
const handleLocationChange = (event: Event) => setLocation((event as CustomEvent).detail); | ||
const handleDateRangeChange = (event: Event) => setDateRange((event as CustomEvent).detail); | ||
|
||
const locationFilter = document.querySelector('gs-location-filter'); | ||
if (locationFilter) { | ||
locationFilter.addEventListener('gs-location-changed', handleLocationChange); | ||
} | ||
|
||
const dateRangeSelector = document.querySelector('gs-date-range-selector'); | ||
if (dateRangeSelector) { | ||
dateRangeSelector.addEventListener('gs-date-range-changed', handleDateRangeChange); | ||
} | ||
|
||
return () => { | ||
if (locationFilter) { | ||
locationFilter.removeEventListener('gs-location-changed', handleLocationChange); | ||
} | ||
if (dateRangeSelector) { | ||
dateRangeSelector.removeEventListener('gs-date-range-changed', handleDateRangeChange); | ||
} | ||
}; | ||
}, []); | ||
|
||
const denominator = { | ||
...dateRange, | ||
...location, | ||
}; | ||
|
||
const numerator = { | ||
...denominator, | ||
displayName: "My variant", | ||
pangoLineage: "B.1.1.7" | ||
}; | ||
|
||
return ( | ||
<gs-app lapis="https://lapis.cov-spectrum.org/open/v1/sample"> | ||
<gs-location-filter | ||
value="Europe / Switzerland" | ||
fields='["region", "country", "division", "location"]' | ||
></gs-location-filter> | ||
<gs-date-range-selector | ||
selectedValue="last6Months" | ||
></gs-date-range-selector> | ||
<gs-prevalence-over-time | ||
numerator={JSON.stringify(numerator)} | ||
denominator={JSON.stringify(denominator)} | ||
granularity="day" | ||
smoothingWindow="7" | ||
views='["line", "table"]' | ||
></gs-prevalence-over-time> | ||
<gs-prevalence-over-time | ||
numerator={JSON.stringify(numerator)} | ||
denominator={JSON.stringify(denominator)} | ||
granularity="month" | ||
smoothingWindow="0" | ||
views='["bar", "table"]' | ||
></gs-prevalence-over-time> | ||
</gs-app> | ||
); | ||
} | ||
|
||
export default App |
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,9 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.tsx' | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
) |
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 @@ | ||
/// <reference types="vite/client" /> |
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,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"skipLibCheck": true, | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true | ||
}, | ||
"include": ["vite.config.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,7 @@ | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}) |
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