import "./index.scss"; import { Toaster } from "react-hot-toast"; import * as React from "react"; import { Switch, Route, useHistory, Redirect } from "react-router-dom"; import Layout from "./Layout"; import Home from "./Home"; import Docs from "./Docs"; import useDocsActions from "./hooks/useDocsActions"; import { useAnalytics } from "./utils"; import Blog from "./Blog"; import { ActionId, KBarAnimator, KBarProvider, KBarPortal, KBarPositioner, KBarSearch, KBarResults, createAction, useMatches, ActionImpl, useKBar, } from "../../src"; import useThemeActions from "./hooks/useThemeActions"; const searchStyle = { padding: "12px 16px", fontSize: "16px", width: "100%", boxSizing: "border-box" as React.CSSProperties["boxSizing"], outline: "none", border: "none", background: "var(--background)", color: "var(--foreground)", }; const animatorStyle = { maxWidth: "600px", width: "100%", background: "var(--background)", color: "var(--foreground)", borderRadius: "8px", overflow: "hidden", boxShadow: "var(--shadow)", }; const groupNameStyle = { padding: "8px 16px", fontSize: "10px", textTransform: "uppercase" as const, opacity: 0.5, }; const App = () => { useAnalytics(); const history = useHistory(); const initialActions = [ { id: "homeAction", name: "Home", shortcut: ["h"], keywords: "back", section: "Navigation", perform: () => history.push("/"), icon: , subtitle: "Subtitles can help add more context.", }, { id: "docsAction", name: "Docs", shortcut: ["g", "d"], keywords: "help", section: "Navigation", perform: () => history.push("/docs"), }, { id: "contactAction", name: "Contact", shortcut: ["c"], keywords: "email hello", section: "Navigation", perform: () => window.open("mailto:timchang@hey.com", "_blank"), }, { id: "twitterAction", name: "Twitter", shortcut: ["g", "t"], keywords: "social contact dm", section: "Navigation", perform: () => window.open("https://twitter.com/timcchang", "_blank"), }, createAction({ name: "Github", shortcut: ["g", "h"], keywords: "sourcecode", section: "Navigation", perform: () => window.open("https://github.com/timc1/kbar", "_blank"), }), ]; return ( ); }; function CommandBar() { useDocsActions(); useThemeActions(); return ( ); } function RenderResults() { const { results, rootActionId } = useMatches(); return ( typeof item === "string" ? (
{item}
) : ( ) } /> ); } const ResultItem = React.forwardRef( ( { action, active, currentRootActionId, }: { action: ActionImpl; active: boolean; currentRootActionId: ActionId; }, ref: React.Ref ) => { const ancestors = React.useMemo(() => { if (!currentRootActionId) return action.ancestors; const index = action.ancestors.findIndex( (ancestor) => ancestor.id === currentRootActionId ); // +1 removes the currentRootAction; e.g. // if we are on the "Set theme" parent action, // the UI should not display "Set theme… > Dark" // but rather just "Dark" return action.ancestors.slice(index + 1); }, [action.ancestors, currentRootActionId]); return (
{action.icon && action.icon}
{ancestors.length > 0 && ancestors.map((ancestor) => ( {ancestor.name} ))} {action.name}
{action.subtitle && ( {action.subtitle} )}
{action.shortcut?.length ? (
{action.shortcut.map((sc) => ( {sc} ))}
) : null}
); } ); export default App; function HomeIcon() { return ( ); }