PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 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 All 127 releases
extendify / src / HelpCenter / components / knowledge-base / SearchForm.jsx

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

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