PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / HelpCenter / components / knowledge-base / SearchForm.jsx

SearchForm.jsx in Extendify 2.2.0, at src/HelpCenter/components/knowledge-base/SearchForm.jsx

55 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useRef } from '@wordpress/element';
2 import { __ } from '@wordpress/i18n';
3 import { search as sIcon, Icon, closeSmall } from '@wordpress/icons';
4 import { KB_HOST } from '@constants';
5 import classNames from 'classnames';
6 import { useKnowledgeBaseStore } from '@help-center/state/knowledge-base.js';
7
8 export const SearchForm = ({ onChange }) => {
9 const { searchTerm, clearSearchTerm, reset } = useKnowledgeBaseStore();
10 const warmed = useRef(false);
11 const searchRef = useRef();
12
13 return (
14 <form
15 method="get"
16 onSubmit={(e) => e.preventDefault()}
17 className="relative h-10 w-full">
18 <label htmlFor="ext-help-center-search" className="sr-only">
19 {__('Search for articles', 'extendify-local')}
20 </label>
21 <input
22 ref={searchRef}
23 name="ext-kb-search"
24 autoFocus
25 autoCapitalize="off"
26 id="ext-help-center-search"
27 type="text"
28 value={searchTerm ?? ''}
29 onChange={(e) => onChange(e.target.value)}
30 onFocus={() => {
31 if (warmed.current) return;
32 warmed.current = true;
33 fetch(`${KB_HOST}/api/posts?boot=true`, { method: 'POST' });
34 }}
35 placeholder={__('What do you need help with?', 'extendify-local')}
36 className="input border-text-800 h-10 w-full border px-3 text-sm placeholder-gray-600"
37 />
38 <div className="absolute inset-y-5 right-2 flex items-center justify-center text-gray-400 rtl:left-2 rtl:right-auto">
39 <Icon
40 icon={!searchTerm ? sIcon : closeSmall}
41 className={classNames('fill-current', {
42 'cursor-pointer': searchTerm,
43 })}
44 onClick={() => {
45 reset();
46 clearSearchTerm();
47 searchRef.current?.focus();
48 }}
49 size={24}
50 />
51 </div>
52 </form>
53 );
54 };
55