-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from timlrx/search-improvements
Search improvements
- Loading branch information
Showing
11 changed files
with
179 additions
and
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'pliny': patch | ||
--- | ||
|
||
Improve kbar styling | ||
Simplify kbar component | ||
Add new KBarButton and AlgoliaButton wrapper which toggles their respective modals on click event |
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,11 @@ | ||
{ | ||
"mode": "pre", | ||
"tag": "beta", | ||
"initialVersions": { | ||
"@pliny/config": "0.0.0", | ||
"pliny": "0.1.0" | ||
}, | ||
"changesets": [ | ||
"gold-dingos-breathe" | ||
] | ||
} |
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,20 @@ | ||
import { DetailedHTMLProps, HTMLAttributes, useContext } from 'react' | ||
import { AlgoliaSearchContext } from './Algolia' | ||
|
||
/** | ||
* Button wrapper component that triggers the Algolia modal on click. | ||
* | ||
* @return {*} | ||
*/ | ||
export const AlgoliaButton = ({ | ||
children, | ||
...rest | ||
}: DetailedHTMLProps<HTMLAttributes<HTMLButtonElement>, HTMLButtonElement>) => { | ||
const { query } = useContext(AlgoliaSearchContext) | ||
|
||
return ( | ||
<button {...rest} onClick={() => query.toggle()}> | ||
{children} | ||
</button> | ||
) | ||
} |
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,20 @@ | ||
import { DetailedHTMLProps, HTMLAttributes } from 'react' | ||
import { useKBar } from 'kbar' | ||
|
||
/** | ||
* Button wrapper component that triggers the KBar modal on click. | ||
* | ||
* @return {*} | ||
*/ | ||
export const KBarButton = ({ | ||
children, | ||
...rest | ||
}: DetailedHTMLProps<HTMLAttributes<HTMLButtonElement>, HTMLButtonElement>) => { | ||
const { query } = useKBar() | ||
|
||
return ( | ||
<button {...rest} onClick={() => query.toggle()}> | ||
{children} | ||
</button> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,17 +1,97 @@ | ||
import { FC, ReactNode } from 'react' | ||
import { KBarProvider, Action } from 'kbar' | ||
import { Portal } from './KBarPortal' | ||
import { | ||
KBarPortal, | ||
KBarSearch, | ||
KBarAnimator, | ||
KBarPositioner, | ||
KBarResults, | ||
useMatches, | ||
Action, | ||
useRegisterActions, | ||
} from 'kbar' | ||
|
||
export const KBarModal = ({ actions, isLoading }: { actions: Action[]; isLoading: boolean }) => { | ||
useRegisterActions(actions, [actions]) | ||
|
||
export const KBarModal: FC<{ | ||
children: ReactNode | ||
actions: Action[] | ||
searchDocumentsPath: string | ||
isLoading: boolean | ||
}> = ({ actions, children, isLoading }) => { | ||
return ( | ||
<KBarProvider actions={actions}> | ||
<Portal isLoading={isLoading} /> | ||
{children} | ||
</KBarProvider> | ||
<KBarPortal> | ||
<KBarPositioner className="bg-gray-300/50 p-4 backdrop-blur backdrop-filter dark:bg-black/50"> | ||
<KBarAnimator className="w-full max-w-xl"> | ||
<div className="overflow-hidden rounded-2xl border border-gray-100 bg-gray-50 dark:border-gray-800 dark:bg-gray-900"> | ||
<div className="flex items-center space-x-4 p-4"> | ||
<span className="block w-5"> | ||
<svg | ||
className="text-gray-400 dark:text-gray-300" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" | ||
/> | ||
</svg> | ||
</span> | ||
<KBarSearch className="h-8 w-full bg-transparent text-slate-600 placeholder-slate-400 focus:outline-none dark:text-slate-200 dark:placeholder-slate-500" /> | ||
<span className="inline-block whitespace-nowrap rounded border border-slate-400/70 px-1.5 align-middle font-medium leading-4 tracking-wide text-slate-500 [font-size:10px] dark:border-slate-600 dark:text-slate-400"> | ||
ESC | ||
</span> | ||
</div> | ||
{!isLoading && <RenderResults />} | ||
{isLoading && ( | ||
<div className="block border-t border-gray-100 px-4 py-8 text-center text-gray-400 dark:border-gray-800 dark:text-gray-600"> | ||
Loading... | ||
</div> | ||
)} | ||
</div> | ||
</KBarAnimator> | ||
</KBarPositioner> | ||
</KBarPortal> | ||
) | ||
} | ||
|
||
const RenderResults = () => { | ||
const { results } = useMatches() | ||
|
||
if (results.length) { | ||
return ( | ||
<KBarResults | ||
items={results} | ||
onRender={({ item, active }) => ( | ||
<div> | ||
{typeof item === 'string' ? ( | ||
<div className="pt-3"> | ||
<div className="block border-t border-gray-100 px-4 pb-2 pt-6 text-xs font-semibold uppercase text-primary-600 dark:border-gray-800"> | ||
{item} | ||
</div> | ||
</div> | ||
) : ( | ||
<div | ||
className={`block cursor-pointer px-4 py-2 ${ | ||
active | ||
? 'bg-primary-600 text-gray-100' | ||
: 'text-gray-700 dark:text-gray-100 bg-transparent' | ||
}`} | ||
> | ||
{item.subtitle && ( | ||
<div className={`${active ? 'text-gray-200' : 'text-gray-400'} text-xs`}> | ||
{item.subtitle} | ||
</div> | ||
)} | ||
<div>{item.name}</div> | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
/> | ||
) | ||
} else { | ||
return ( | ||
<div className="block border-t border-gray-100 px-4 py-8 text-center text-gray-400 dark:border-gray-800 dark:text-gray-600"> | ||
No results for your search... | ||
</div> | ||
) | ||
} | ||
} |
Oops, something went wrong.