-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experiences): implement custom element (#6364)
* feat(experiences): implement custom element * build with wildcard * fix tests * only provide custom element
- Loading branch information
1 parent
1109091
commit 7eeffe6
Showing
11 changed files
with
314 additions
and
105 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
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,89 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Algolia Experiences demo</title> | ||
<link | ||
rel="stylesheet" | ||
href="/packages/instantsearch.css/themes/satellite-min.css" | ||
/> | ||
<style> | ||
body { | ||
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', | ||
Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', | ||
sans-serif; | ||
} | ||
main { | ||
max-width: 80em; | ||
margin: 0 auto; | ||
} | ||
.ais-Hits-list, | ||
.ais-TrendingItems-list { | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); | ||
gap: 1em; | ||
} | ||
.ais-TrendingItems-item, | ||
.ais-Hits-item { | ||
padding: 0; | ||
} | ||
.ais-TrendingItems-item a, | ||
.ais-Hits-item a { | ||
width: 100%; | ||
padding: 1.5em; | ||
text-decoration: none; | ||
color: inherit; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
.ais-TrendingItems-item img, | ||
.ais-Hits-item img { | ||
width: 100%; | ||
height: 10em; | ||
border-radius: 4px; | ||
object-fit: contain; | ||
} | ||
.__flex { | ||
display: flex; | ||
gap: 1em; | ||
justify-content: space-between; | ||
} | ||
.__bold { | ||
font-weight: bold; | ||
} | ||
div:has(> .ais-Pagination) { | ||
display: flex; | ||
} | ||
.ais-Pagination { | ||
margin: 1em auto; | ||
} | ||
</style> | ||
<script src="/packages/algolia-experiences/dist/algolia-experiences.development.js"></script> | ||
<meta | ||
name="algolia-configuration" | ||
content='{"appId":"F4T6CUV2AH","apiKey":"72d500963987bc97ff899d350a00f7a8"}' | ||
/> | ||
<script> | ||
let isMounted = false; | ||
function toggle() { | ||
if (isMounted) { | ||
document.querySelector('algolia-experience').remove(); | ||
isMounted = false; | ||
return; | ||
} | ||
const element = document.createElement('template'); | ||
document.querySelector('main').appendChild(element); | ||
element.outerHTML = ` | ||
<algolia-experience experience-id="category:historical" /> | ||
`; | ||
isMounted = true; | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<main> | ||
<h2>Buy historical books now!</h2> | ||
<button onclick="toggle()">Toggle</button> | ||
</main> | ||
</body> | ||
</html> |
31 changes: 31 additions & 0 deletions
31
packages/algolia-experiences/src/__tests__/get-configuration.test.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,31 @@ | ||
import { fetchConfiguration } from '../get-configuration'; | ||
|
||
describe('fetchConfiguration', () => { | ||
it('should fetch and cache the configuration', async () => { | ||
const settings = { appId: 'appId', apiKey: 'apiKey' }; | ||
|
||
// @ts-ignore | ||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
ok: true, | ||
json: () => | ||
Promise.resolve({ | ||
id: '1', | ||
name: 'name', | ||
indexName: 'indexName', | ||
blocks: [], | ||
createdAt: 'createdAt', | ||
updatedAt: 'updatedAt', | ||
}), | ||
}) | ||
); | ||
|
||
await fetchConfiguration('1', settings); | ||
|
||
expect(global.fetch).toHaveBeenCalledTimes(1); | ||
|
||
await fetchConfiguration('1', settings); | ||
|
||
expect(global.fetch).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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
Oops, something went wrong.