|
| 1 | +/** @jsx createElement */ |
| 2 | +import type { Renderer } from '../..'; |
| 3 | + |
| 4 | +export type AutocompleteSearchProps = { |
| 5 | + inputProps: Partial<React.DOMAttributes<HTMLInputElement>>; |
| 6 | + onClear: () => void; |
| 7 | + query: string; |
| 8 | +}; |
| 9 | + |
| 10 | +export function createAutocompleteSearchComponent({ createElement }: Renderer) { |
| 11 | + return function AutocompleteSearch({ |
| 12 | + inputProps, |
| 13 | + onClear, |
| 14 | + query, |
| 15 | + }: AutocompleteSearchProps) { |
| 16 | + return ( |
| 17 | + <form |
| 18 | + className="ais-AutocompleteForm" |
| 19 | + action="" |
| 20 | + noValidate |
| 21 | + role="search" |
| 22 | + onSubmit={(e) => e.preventDefault()} |
| 23 | + > |
| 24 | + <div className="ais-AutocompleteInputWrapperPrefix"> |
| 25 | + <label |
| 26 | + className="ais-AutocompleteLabel" |
| 27 | + aria-label="Submit" |
| 28 | + htmlFor="autocomplete-input" |
| 29 | + id="autocomplete-label" |
| 30 | + > |
| 31 | + <button |
| 32 | + className="ais-AutocompleteSubmitButton" |
| 33 | + type="submit" |
| 34 | + title="Submit" |
| 35 | + > |
| 36 | + <svg |
| 37 | + className="ais-AutocompleteSubmitIcon" |
| 38 | + viewBox="0 0 24 24" |
| 39 | + width="20" |
| 40 | + height="20" |
| 41 | + fill="currentColor" |
| 42 | + > |
| 43 | + <path d="M16.041 15.856c-0.034 0.026-0.067 0.055-0.099 0.087s-0.060 0.064-0.087 0.099c-1.258 1.213-2.969 1.958-4.855 1.958-1.933 0-3.682-0.782-4.95-2.050s-2.050-3.017-2.050-4.95 0.782-3.682 2.050-4.95 3.017-2.050 4.95-2.050 3.682 0.782 4.95 2.050 2.050 3.017 2.050 4.95c0 1.886-0.745 3.597-1.959 4.856zM21.707 20.293l-3.675-3.675c1.231-1.54 1.968-3.493 1.968-5.618 0-2.485-1.008-4.736-2.636-6.364s-3.879-2.636-6.364-2.636-4.736 1.008-6.364 2.636-2.636 3.879-2.636 6.364 1.008 4.736 2.636 6.364 3.879 2.636 6.364 2.636c2.125 0 4.078-0.737 5.618-1.968l3.675 3.675c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414z" /> |
| 44 | + </svg> |
| 45 | + </button> |
| 46 | + </label> |
| 47 | + <div className="ais-AutocompleteLoadingIndicator" hidden> |
| 48 | + <svg |
| 49 | + className="ais-AutocompleteLoadingIcon" |
| 50 | + viewBox="0 0 100 100" |
| 51 | + width="20" |
| 52 | + height="20" |
| 53 | + > |
| 54 | + <circle |
| 55 | + cx="50" |
| 56 | + cy="50" |
| 57 | + fill="none" |
| 58 | + r="35" |
| 59 | + stroke="currentColor" |
| 60 | + strokeDasharray="164.93361431346415 56.97787143782138" |
| 61 | + strokeWidth="6" |
| 62 | + > |
| 63 | + <animateTransform |
| 64 | + attributeName="transform" |
| 65 | + type="rotate" |
| 66 | + repeatCount="indefinite" |
| 67 | + dur="1s" |
| 68 | + values="0 50 50;90 50 50;180 50 50;360 50 50" |
| 69 | + keyTimes="0;0.40;0.65;1" |
| 70 | + ></animateTransform> |
| 71 | + </circle> |
| 72 | + </svg> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + <div className="ais-AutocompleteInputWrapper"> |
| 76 | + <input |
| 77 | + className="ais-AutocompleteInput" |
| 78 | + aria-autocomplete="both" |
| 79 | + aria-labelledby="autocomplete-label" |
| 80 | + id="autocomplete-input" |
| 81 | + autoComplete="off" |
| 82 | + autoCorrect="off" |
| 83 | + autoCapitalize="off" |
| 84 | + enterKeyHint="search" |
| 85 | + spellCheck="false" |
| 86 | + placeholder="" |
| 87 | + maxLength={512} |
| 88 | + type="search" |
| 89 | + value={query} |
| 90 | + {...inputProps} |
| 91 | + /> |
| 92 | + </div> |
| 93 | + <div className="ais-AutocompleteInputWrapperSuffix"> |
| 94 | + <button |
| 95 | + className="ais-AutocompleteClearButton" |
| 96 | + type="reset" |
| 97 | + title="Clear" |
| 98 | + hidden={!query} |
| 99 | + onClick={onClear} |
| 100 | + > |
| 101 | + <svg |
| 102 | + className="ais-AutocompleteClearIcon" |
| 103 | + viewBox="0 0 24 24" |
| 104 | + width="18" |
| 105 | + height="18" |
| 106 | + fill="currentColor" |
| 107 | + > |
| 108 | + <path d="M5.293 6.707l5.293 5.293-5.293 5.293c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0l5.293-5.293 5.293 5.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-5.293-5.293 5.293-5.293c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-5.293 5.293-5.293-5.293c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414z"></path> |
| 109 | + </svg> |
| 110 | + </button> |
| 111 | + </div> |
| 112 | + </form> |
| 113 | + ); |
| 114 | + }; |
| 115 | +} |
0 commit comments