-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdbf309
commit e33e6ca
Showing
12 changed files
with
324 additions
and
190 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,85 @@ | ||
import { AutocompleteApi as AutocompleteCoreApi } from '@algolia/autocomplete-core'; | ||
|
||
import { resetIcon, searchIcon } from './icons'; | ||
import { AutocompleteClassNames, AutocompleteDom } from './types'; | ||
import { concatClassNames, setProperties } from './utils'; | ||
|
||
type CreateDomProps<TItem> = AutocompleteCoreApi<TItem> & { | ||
classNames: AutocompleteClassNames; | ||
}; | ||
|
||
export function createAutocompleteDom<TItem>({ | ||
getEnvironmentProps, | ||
getRootProps, | ||
getFormProps, | ||
getLabelProps, | ||
getInputProps, | ||
getPanelProps, | ||
classNames, | ||
}: CreateDomProps<TItem>): AutocompleteDom { | ||
const inputWrapper = document.createElement('div'); | ||
const input = document.createElement('input'); | ||
const root = document.createElement('div'); | ||
const form = document.createElement('form'); | ||
const label = document.createElement('label'); | ||
const resetButton = document.createElement('button'); | ||
const panel = document.createElement('div'); | ||
|
||
setProperties( | ||
window as any, | ||
getEnvironmentProps({ | ||
searchBoxElement: form, | ||
panelElement: panel, | ||
inputElement: input, | ||
}) | ||
); | ||
setProperties(root, { | ||
...getRootProps(), | ||
class: concatClassNames(['aa-Autocomplete', classNames.root]), | ||
}); | ||
const formProps = getFormProps({ inputElement: input }); | ||
setProperties(form, { | ||
...formProps, | ||
class: concatClassNames(['aa-Form', classNames.form]), | ||
}); | ||
setProperties(inputWrapper, { | ||
class: concatClassNames(['aa-InputWrapper', classNames.inputWrapper]), | ||
}); | ||
setProperties(label, { | ||
...getLabelProps(), | ||
class: concatClassNames(['aa-Label', classNames.label]), | ||
innerHTML: searchIcon, | ||
}); | ||
setProperties(input, { | ||
...getInputProps({ inputElement: input }), | ||
class: concatClassNames(['aa-Input', classNames.input]), | ||
}); | ||
setProperties(resetButton, { | ||
type: 'reset', | ||
onClick: formProps.onReset, | ||
class: concatClassNames(['aa-ResetButton', classNames.resetButton]), | ||
innerHTML: resetIcon, | ||
}); | ||
setProperties(panel, { | ||
...getPanelProps(), | ||
hidden: true, | ||
class: concatClassNames(['aa-Panel', classNames.panel]), | ||
}); | ||
|
||
inputWrapper.appendChild(input); | ||
inputWrapper.appendChild(label); | ||
inputWrapper.appendChild(resetButton); | ||
form.appendChild(inputWrapper); | ||
root.appendChild(form); | ||
root.appendChild(panel); | ||
|
||
return { | ||
inputWrapper, | ||
input, | ||
root, | ||
form, | ||
label, | ||
resetButton, | ||
panel, | ||
}; | ||
} |
Oops, something went wrong.