|
| 1 | +import React from 'react'; |
| 2 | +import { |
| 3 | + AutocompleteApi, |
| 4 | + AutocompleteState, |
| 5 | +} from '@francoischalifour/autocomplete-core'; |
| 6 | + |
| 7 | +import { RecentDocSearchHit } from '../types'; |
| 8 | + |
| 9 | +interface EmptyScreenProps |
| 10 | + extends AutocompleteApi< |
| 11 | + RecentDocSearchHit, |
| 12 | + React.FormEvent, |
| 13 | + React.MouseEvent, |
| 14 | + React.KeyboardEvent |
| 15 | + > { |
| 16 | + state: AutocompleteState<RecentDocSearchHit>; |
| 17 | + hasSuggestions: boolean; |
| 18 | + onItemClick(item: RecentDocSearchHit): void; |
| 19 | + onAction(search: RecentDocSearchHit): void; |
| 20 | +} |
| 21 | + |
| 22 | +export function EmptyScreen(props: EmptyScreenProps) { |
| 23 | + if (props.state.status === 'idle' && props.hasSuggestions === false) { |
| 24 | + return ( |
| 25 | + <div> |
| 26 | + <p>Select results and your history will appear here.</p> |
| 27 | + </div> |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + return ( |
| 32 | + <div className="DocSearch-Dropdown-Container"> |
| 33 | + {props.state.suggestions.map(({ source, items }, index) => { |
| 34 | + return ( |
| 35 | + <section key={['recent', index].join(':')} className="DocSearch-Hits"> |
| 36 | + <div className="DocSearch-Hit-source">Recent</div> |
| 37 | + |
| 38 | + <ul {...props.getMenuProps()}> |
| 39 | + {items.map(item => { |
| 40 | + return ( |
| 41 | + <li |
| 42 | + key={['recent', item.objectID].join(':')} |
| 43 | + className="DocSearch-Hit" |
| 44 | + {...props.getItemProps({ |
| 45 | + item, |
| 46 | + source, |
| 47 | + onClick() { |
| 48 | + props.onItemClick(item); |
| 49 | + }, |
| 50 | + })} |
| 51 | + > |
| 52 | + <a href={item.url}> |
| 53 | + <div className="DocSearch-Hit-Container"> |
| 54 | + <div className="DocSearch-Hit-icon"> |
| 55 | + <svg width="20" height="20"> |
| 56 | + <g |
| 57 | + stroke="currentColor" |
| 58 | + strokeWidth="2" |
| 59 | + fill="none" |
| 60 | + fillRule="evenodd" |
| 61 | + strokeLinecap="round" |
| 62 | + strokeLinejoin="round" |
| 63 | + > |
| 64 | + <path d="M3.18 6.6a8.23 8.23 0 1112.93 9.94h0a8.23 8.23 0 01-11.63 0" /> |
| 65 | + <path d="M6.44 7.25H2.55V3.36M10.45 6v5.6M10.45 11.6L13 13" /> |
| 66 | + </g> |
| 67 | + </svg> |
| 68 | + </div> |
| 69 | + |
| 70 | + {item.hierarchy[item.type] && item.type === 'lvl1' && ( |
| 71 | + <div className="DocSearch-Hit-content-wrapper"> |
| 72 | + <span className="DocSearch-Hit-title"> |
| 73 | + {item.hierarchy.lvl1} |
| 74 | + </span> |
| 75 | + {item.content && ( |
| 76 | + <span className="DocSearch-Hit-path"> |
| 77 | + {item.content} |
| 78 | + </span> |
| 79 | + )} |
| 80 | + </div> |
| 81 | + )} |
| 82 | + |
| 83 | + {item.hierarchy[item.type] && |
| 84 | + (item.type === 'lvl2' || |
| 85 | + item.type === 'lvl3' || |
| 86 | + item.type === 'lvl4' || |
| 87 | + item.type === 'lvl5' || |
| 88 | + item.type === 'lvl6') && ( |
| 89 | + <div className="DocSearch-Hit-content-wrapper"> |
| 90 | + <span className="DocSearch-Hit-title"> |
| 91 | + {item.hierarchy[item.type]} |
| 92 | + </span> |
| 93 | + <span className="DocSearch-Hit-path"> |
| 94 | + {item.hierarchy.lvl1} |
| 95 | + </span> |
| 96 | + </div> |
| 97 | + )} |
| 98 | + |
| 99 | + {item.type === 'content' && ( |
| 100 | + <div className="DocSearch-Hit-content-wrapper"> |
| 101 | + <span className="DocSearch-Hit-title"> |
| 102 | + {item.content} |
| 103 | + </span> |
| 104 | + <span className="DocSearch-Hit-path"> |
| 105 | + {item.hierarchy.lvl1} |
| 106 | + </span> |
| 107 | + </div> |
| 108 | + )} |
| 109 | + |
| 110 | + <div className="DocSearch-Hit-action"> |
| 111 | + <button |
| 112 | + className="DocSearch-Hit-action-button" |
| 113 | + title="Delete this search" |
| 114 | + onClick={event => { |
| 115 | + event.preventDefault(); |
| 116 | + event.stopPropagation(); |
| 117 | + |
| 118 | + props.onAction(item); |
| 119 | + }} |
| 120 | + > |
| 121 | + <svg width="20" height="20"> |
| 122 | + <g |
| 123 | + stroke="currentColor" |
| 124 | + strokeLinecap="round" |
| 125 | + strokeLinejoin="round" |
| 126 | + strokeWidth="2" |
| 127 | + > |
| 128 | + <path |
| 129 | + d="M10,10 L15.0853291,4.91467086 L10,10 L15.0853291,15.0853291 L10,10 Z M10,10 L4.91467086,4.91467086 L10,10 L4.91467086,15.0853291 L10,10 Z" |
| 130 | + transform="translate(10.000000, 10.000000) rotate(-360.000000) translate(-10.000000, -10.000000) " |
| 131 | + ></path> |
| 132 | + </g> |
| 133 | + </svg> |
| 134 | + </button> |
| 135 | + </div> |
| 136 | + </div> |
| 137 | + </a> |
| 138 | + </li> |
| 139 | + ); |
| 140 | + })} |
| 141 | + </ul> |
| 142 | + </section> |
| 143 | + ); |
| 144 | + })} |
| 145 | + </div> |
| 146 | + ); |
| 147 | +} |
0 commit comments