Skip to content
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

feat(layout): introduce Layout API #499

Open
wants to merge 26 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4c954e3
feat(theme): patch theme
francoischalifour Mar 18, 2021
52bfd97
feat: convert CSS color vars to RGB and alpha tuples
francoischalifour Mar 19, 2021
cd6facd
feat: remove capitalize on header
francoischalifour Mar 19, 2021
b8728ca
feat: rename columns CSS classes
francoischalifour Mar 19, 2021
ed288f3
fix: fix scrollable class case
francoischalifour Mar 19, 2021
7fbeec3
chore: update comments
francoischalifour Mar 19, 2021
d64ed5a
fix: rename ItemIcon CSS modifiers
francoischalifour Mar 19, 2021
9a758ea
fix: fix DetachedContainer modal CSS modifier case
francoischalifour Mar 19, 2021
17cdd21
chore: improve stylelint config
francoischalifour Mar 19, 2021
a593a79
chore: update comments
francoischalifour Mar 19, 2021
87463e1
chore: run lint
francoischalifour Mar 19, 2021
75c56ed
chore(examples): update icon class
francoischalifour Mar 19, 2021
bd7e49b
fix: remove `aa-key-shadow` var
francoischalifour Mar 24, 2021
9c26026
feat: use base `z-index` var
francoischalifour Mar 24, 2021
71c229f
refactor: update CSS vars descriptions
francoischalifour Mar 24, 2021
8041ea3
docs: update comments
francoischalifour Mar 24, 2021
5f91aff
feat(layout): introduce Layout API
francoischalifour Mar 8, 2021
afb1e2f
chore(ci): add Layouts sandbox to CodeSandbox deployments
francoischalifour Mar 25, 2021
f12ae6b
Merge branch 'next' into feat/layout-api
francoischalifour Apr 7, 2021
37cf813
docs: update example
francoischalifour Apr 7, 2021
6e0b9d1
fix(theme): update footer gradient height
francoischalifour Apr 7, 2021
f1c4e5b
feat: rely on the Component API
francoischalifour Apr 7, 2021
e4e43ca
docs: update layout docs
francoischalifour Apr 7, 2021
dad554b
docs: remove debug mode
francoischalifour Apr 7, 2021
bf6786f
feat: darkmode for keys
Shipow Apr 9, 2021
283e5c7
feat: darkmode labels
Shipow Apr 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ aliases:
mkdir -p packages/autocomplete-plugin-algolia-insights/dist
mkdir -p packages/autocomplete-plugin-recent-searches/dist
mkdir -p packages/autocomplete-plugin-query-suggestions/dist
mkdir -p packages/autocomplete-layout-classic/dist

cp -R /tmp/workspace/packages/autocomplete-shared/dist packages/autocomplete-shared
cp -R /tmp/workspace/packages/autocomplete-core/dist packages/autocomplete-core
Expand All @@ -38,6 +39,7 @@ aliases:
cp -R /tmp/workspace/packages/autocomplete-plugin-algolia-insights/dist packages/autocomplete-plugin-algolia-insights
cp -R /tmp/workspace/packages/autocomplete-plugin-recent-searches/dist packages/autocomplete-plugin-recent-searches
cp -R /tmp/workspace/packages/autocomplete-plugin-query-suggestions/dist packages/autocomplete-plugin-query-suggestions
cp -R /tmp/workspace/packages/autocomplete-layout-classic/dist packages/autocomplete-layout-classic

defaults: &defaults
working_directory: ~/autocomplete
Expand Down Expand Up @@ -82,6 +84,7 @@ jobs:
mkdir -p /tmp/workspace/packages/autocomplete-plugin-algolia-insights/dist
mkdir -p /tmp/workspace/packages/autocomplete-plugin-recent-searches/dist
mkdir -p /tmp/workspace/packages/autocomplete-plugin-query-suggestions/dist
mkdir -p /tmp/workspace/packages/autocomplete-layout-classic/dist

cp -R packages/autocomplete-shared/dist /tmp/workspace/packages/autocomplete-shared
cp -R packages/autocomplete-core/dist /tmp/workspace/packages/autocomplete-core
Expand All @@ -90,6 +93,7 @@ jobs:
cp -R packages/autocomplete-plugin-algolia-insights/dist /tmp/workspace/packages/autocomplete-plugin-algolia-insights
cp -R packages/autocomplete-plugin-recent-searches/dist /tmp/workspace/packages/autocomplete-plugin-recent-searches
cp -R packages/autocomplete-plugin-query-suggestions/dist /tmp/workspace/packages/autocomplete-plugin-query-suggestions
cp -R packages/autocomplete-layout-classic/dist /tmp/workspace/packages/autocomplete-layout-classic
- persist_to_workspace:
root: *workspace_root
paths:
Expand Down
4 changes: 3 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"rules": {
"order/properties-alphabetical-order": true,
"no-descending-specificity": null,
"selector-class-pattern": ["^aa-[A-Za-z0-9-]*$"],
"selector-class-pattern": [
"^aa-(?:[A-Z][a-z]+)+(?:--[a-z]+(?:[A-Z][a-z]+)?)?$"
],
"prettier/prettier": true,
"max-nesting-depth": null,
"rule-empty-line-before": [
Expand Down
10 changes: 9 additions & 1 deletion bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"path": "packages/autocomplete-js/dist/umd/index.production.js",
"maxSize": "14.50 kB"
"maxSize": "14.75 kB"
},
{
"path": "packages/autocomplete-preset-algolia/dist/umd/index.production.js",
Expand All @@ -23,6 +23,14 @@
{
"path": "packages/autocomplete-plugin-query-suggestions/dist/umd/index.production.js",
"maxSize": "4 kB"
},
{
"path": "packages/autocomplete-layout-classic/dist/umd/index.production.js",
"maxSize": "4 kB"
},
{
"path": "packages/autocomplete-theme-classic/dist/theme.css",
"maxSize": "4 kB"
}
]
}
2 changes: 1 addition & 1 deletion cypress/test-apps/js/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type ProductItemProps = {
function ProductItem({ hit, insights }: ProductItemProps) {
return (
<Fragment>
<div className="aa-ItemIcon aa-ItemIcon--align-top">
<div className="aa-ItemIcon aa-ItemIcon--alignTop">
<img src={hit.image} alt={hit.name} width="40" height="40" />
</div>
<div className="aa-ItemContent">
Expand Down
2 changes: 1 addition & 1 deletion cypress/test-apps/js/categoriesPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function createCategoriesPlugin({
item({ item }) {
return (
<Fragment>
<div className="aa-ItemIcon aa-ItemIcon--no-border">
<div className="aa-ItemIcon aa-ItemIcon--noBorder">
<svg
viewBox="0 0 24 24"
width="18"
Expand Down
2 changes: 1 addition & 1 deletion examples/js/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type ProductItemProps = {
function ProductItem({ hit, insights }: ProductItemProps) {
return (
<Fragment>
<div className="aa-ItemIcon aa-ItemIcon--align-top">
<div className="aa-ItemIcon aa-ItemIcon--alignTop">
<img src={hit.image} alt={hit.name} width="40" height="40" />
</div>
<div className="aa-ItemContent">
Expand Down
2 changes: 1 addition & 1 deletion examples/js/categoriesPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function createCategoriesPlugin({
item({ item }) {
return (
<Fragment>
<div className="aa-ItemIcon aa-ItemIcon--no-border">
<div className="aa-ItemIcon aa-ItemIcon--noBorder">
<svg
viewBox="0 0 24 24"
width="18"
Expand Down
Empty file added examples/layouts/README.md
Empty file.
58 changes: 58 additions & 0 deletions examples/layouts/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @jsx h */
import { autocomplete } from '@algolia/autocomplete-js';
import {
NavigationCommandsLayout,
SearchByAlgoliaLayout,
} from '@algolia/autocomplete-layout-classic';
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions';
import algoliasearch from 'algoliasearch/lite';
import { h, render } from 'preact';

import '@algolia/autocomplete-theme-classic';

const appId = 'latency';
const apiKey = '6be0576ff61c053d5f9a3225e2a90f76';
const searchClient = algoliasearch(appId, apiKey);

const querySuggestionsPlugin = createQuerySuggestionsPlugin({
searchClient,
indexName: 'instant_search_demo_query_suggestions',
getSearchParams() {
return {
hitsPerPage: 10,
};
},
});

autocomplete({
container: '#autocomplete',
placeholder: 'Search',
openOnFocus: true,
plugins: [querySuggestionsPlugin],
render({ sections, createElement, Fragment }, root) {
render(
<Fragment>
<div className="aa-PanelLayout">{sections}</div>
<footer className="aa-PanelFooter">
{NavigationCommandsLayout({
createElement,
Fragment,
translations: {
toClose: 'pour fermer',
toNavigate: 'pour naviguer',
toSelect: 'pour sélectionner',
},
})}
{SearchByAlgoliaLayout({
createElement,
Fragment,
translations: {
searchBy: 'Recherche par',
},
})}
</footer>
</Fragment>,
root
);
},
});
10 changes: 10 additions & 0 deletions examples/layouts/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as preact from 'preact';

// Parcel picks the `source` field of the monorepo packages and thus doesn't
// apply the Babel config to replace our `__DEV__` global expression.
// We therefore need to manually override it in the example app.
// See https://twitter.com/devongovett/status/1134231234605830144
(global as any).__DEV__ = process.env.NODE_ENV !== 'production';
(global as any).__TEST__ = false;
(global as any).h = preact.h;
(global as any).React = preact;
Binary file added examples/layouts/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions examples/layouts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
<link rel="stylesheet" href="style.css" />

<title>Layouts Examples</title>
</head>

<body>
<div class="container">
<div id="autocomplete"></div>
</div>

<script src="env.ts"></script>
<script src="app.tsx"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions examples/layouts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@algolia/layouts-example",
"description": "Autocomplete Layouts Sandbox",
"version": "1.0.0-alpha.44",
"private": true,
"license": "MIT",
"main": "index.html",
"scripts": {
"build": "parcel build index.html",
"start": "parcel index.html"
},
"dependencies": {
"@algolia/autocomplete-js": "1.0.0-alpha.44",
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.44",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.44",
"@algolia/autocomplete-layout-classic": "1.0.0-alpha.44",
"algoliasearch": "4.8.3",
"preact": "10.5.7"
},
"devDependencies": {
"parcel-bundler": "1.12.4"
},
"keywords": [
"algolia",
"autocomplete",
"javascript"
]
}
20 changes: 20 additions & 0 deletions examples/layouts/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
* {
box-sizing: border-box;
}

body {
background-color: rgb(244, 244, 249);
color: rgb(65, 65, 65);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
padding: 1rem;
}

.container {
margin: 0 auto;
max-width: 640px;
width: 100%;
}
2 changes: 1 addition & 1 deletion examples/query-suggestions-with-inline-categories/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const querySuggestionsPlugin = createQuerySuggestionsPlugin({
item({ item, createElement }) {
return (
<Fragment>
<div className="aa-ItemIcon aa-ItemIcon--no-border">
<div className="aa-ItemIcon aa-ItemIcon--noBorder">
<svg
viewBox="0 0 24 24"
width="18"
Expand Down
2 changes: 1 addition & 1 deletion examples/query-suggestions-with-rich-hits/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type ProductItemProps = {
function ProductItem({ hit, insights }: ProductItemProps) {
return (
<Fragment>
<div className="aa-ItemIcon aa-ItemIcon--align-top">
<div className="aa-ItemIcon aa-ItemIcon--alignTop">
<img src={hit.image} alt={hit.name} width="40" height="40" />
</div>
<div className="aa-ItemContent">
Expand Down
2 changes: 1 addition & 1 deletion examples/recently-viewed-items/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type ProductItemProps = {
function AutocompleteProductItem({ hit }: ProductItemProps) {
return (
<Fragment>
<div className="aa-ItemIcon aa-ItemIcon--align-top">
<div className="aa-ItemIcon aa-ItemIcon--alignTop">
<img src={hit.image} alt={hit.name} width="40" height="40" />
</div>
<div className="aa-ItemContent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function createLocalStorageRecentlyViewedItems<
<img src={item.image} alt={item.label} />
</div>
) : (
<div className="aa-ItemIcon aa-ItemIcon--no-border">
<div className="aa-ItemIcon aa-ItemIcon--noBorder">
<svg
viewBox="0 0 24 24"
width="18"
Expand Down
23 changes: 16 additions & 7 deletions packages/autocomplete-js/src/__tests__/render.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fireEvent, waitFor } from '@testing-library/dom';
import {
createElement as preactCreateElement,
Fragment,
Fragment as PreactFragment,
render,
} from 'preact';
Expand Down Expand Up @@ -358,16 +359,24 @@ describe('render', () => {
},
];
},
render({ createElement, children }, root) {
render({ createElement, children, sections }, root) {
expect(children).toEqual(
expect.objectContaining({
type: 'div',
type: Fragment,
props: {
className: expect.any(String),
children: expect.arrayContaining([
expect.any(Object),
expect.any(Object),
]),
children: [
expect.objectContaining({
props: {
className: 'aa-PanelLayout aa-Panel--scrollable',
children: sections,
},
}),
expect.objectContaining({
props: {
className: 'aa-GradientBottom',
},
}),
],
},
})
);
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-js/src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function autocomplete<TItem extends BaseItem>(
// results come in) so that users don't have to.
if (state.query !== prevState.query) {
const scrollablePanels = document.querySelectorAll(
'.aa-Panel--Scrollable'
'.aa-Panel--scrollable'
);
scrollablePanels.forEach((scrollablePanel) => {
if (scrollablePanel.scrollTop !== 0) {
Expand Down Expand Up @@ -272,7 +272,7 @@ export function autocomplete<TItem extends BaseItem>(

function toggleModalClassname(isActive: boolean) {
dom.value.detachedContainer.classList.toggle(
'aa-DetachedContainer--Modal',
'aa-DetachedContainer--modal',
isActive
);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/autocomplete-js/src/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ export function renderPanel<TItem extends BaseItem>(
));

const children = (
<div className="aa-PanelLayout aa-Panel--Scrollable">{sections}</div>
<Fragment>
<div className="aa-PanelLayout aa-Panel--scrollable">{sections}</div>
<div className="aa-GradientBottom" />
</Fragment>
);
const elements = sections.reduce((acc, current) => {
acc[current.props['data-autocomplete-source-id']] = current;
Expand Down
15 changes: 15 additions & 0 deletions packages/autocomplete-layout-classic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @algolia/autocomplete-layout-classic

Classic layout for Algolia Autocomplete.

## Installation

```sh
yarn add @algolia/autocomplete-layout-classic@alpha
# or
npm install @algolia/autocomplete-layout-classic@alpha
```

## Documentation

[Read documentation →](https://autocomplete.algolia.com/docs/autocomplete-layout-classic)