Skip to content

Commit

Permalink
feat(docusaurus): import DocSearch modal on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed May 14, 2020
1 parent 65a98b0 commit 4b007b6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/DocSearchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import React, { useState, useEffect } from 'react';

import { SearchIcon } from './icons/SearchIcon';

interface SearchButtonProps {
onClick(): void;
}

const ACTION_KEY_DEFAULT = 'Ctrl';
const ACTION_KEY_APPLE = '⌘';

Expand All @@ -17,7 +13,12 @@ function isAppleDevice() {
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
}

export function DocSearchButton(props: SearchButtonProps) {
export function DocSearchButton(
props: React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
>
) {
const [key, setKey] = useState(() =>
isAppleDevice() ? ACTION_KEY_APPLE : ACTION_KEY_DEFAULT
);
Expand All @@ -29,11 +30,7 @@ export function DocSearchButton(props: SearchButtonProps) {
}, []);

return (
<button
type="button"
className="DocSearch-SearchButton"
onClick={props.onClick}
>
<button type="button" className="DocSearch-SearchButton" {...props}>
<SearchIcon />
<span className="DocSearch-SearchButton-Placeholder">Search</span>
<span className="DocSearch-SearchButton-Key">{key}</span>
Expand Down

0 comments on commit 4b007b6

Please sign in to comment.