Skip to content

Commit

Permalink
feat: Make the command bar responsive (#19411)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Dec 20, 2023
1 parent 6b9b72f commit 63d73bc
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 12 deletions.
Binary file modified frontend/__snapshots__/components-command-bar--actions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/components-command-bar--search--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/components-command-bar--shortcuts--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/components-command-bar--shortcuts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions frontend/src/lib/components/CommandBar/CommandBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const CommandBarOverlay = forwardRef<HTMLDivElement, CommandBarOverlayProps>(fun
backdropFilter: 'blur(var(--modal-backdrop-blur))',
}}
>
<div className="h-160 w-full max-w-lg">
<div className="w-full h-full max-h-160 max-w-lg overflow-hidden">
<div
data-attr="command-bar"
className={`w-full ${
barStatus === BarStatus.SHOW_SEARCH && 'h-160'
} bg-bg-3000 rounded overflow-hidden border shadow`}
barStatus === BarStatus.SHOW_SEARCH && 'h-full'
} bg-bg-3000 rounded overflow-hidden border`}
ref={ref}
>
{children}
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/lib/components/CommandBar/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LemonInput } from '@posthog/lemon-ui'
import { LemonButton, LemonInput } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { isMac } from 'lib/utils'
import { forwardRef, Ref } from 'react'
Expand All @@ -11,7 +11,7 @@ import { searchBarLogic } from './searchBarLogic'
export const SearchInput = forwardRef(function _SearchInput(_, ref: Ref<HTMLInputElement>): JSX.Element {
const { currentTeam } = useValues(teamLogic)
const { searchQuery } = useValues(searchBarLogic)
const { setSearchQuery } = useActions(searchBarLogic)
const { setSearchQuery, hideCommandBar } = useActions(searchBarLogic)

const modifierKey = isMac() ? '⌘' : '^'
const placeholder = currentTeam
Expand All @@ -25,7 +25,11 @@ export const SearchInput = forwardRef(function _SearchInput(_, ref: Ref<HTMLInpu
type="search"
className="CommandBar__input"
fullWidth
suffix={<KeyboardShortcut escape />}
suffix={
<LemonButton onClick={() => hideCommandBar()} noPadding>
<KeyboardShortcut escape />
</LemonButton>
}
placeholder={placeholder}
autoFocus
value={searchQuery}
Expand Down
24 changes: 19 additions & 5 deletions frontend/src/lib/components/CommandBar/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import clsx from 'clsx'
import { useValues } from 'kea'
import { useResizeBreakpoints } from 'lib/hooks/useResizeObserver'

import { DetectiveHog } from '../hedgehogs'
import { searchBarLogic } from './searchBarLogic'
Expand All @@ -9,8 +11,13 @@ export const SearchResults = (): JSX.Element => {
const { combinedSearchResults, combinedSearchLoading, activeResultIndex, keyboardResultIndex } =
useValues(searchBarLogic)

const { ref, size } = useResizeBreakpoints({
0: 'small',
550: 'normal',
})

return (
<div className="SearchResults grow">
<div className="SearchResults grow" ref={ref}>
{!combinedSearchLoading && combinedSearchResults?.length === 0 ? (
<div className="w-full h-full flex flex-col items-center justify-center p-3">
<h3 className="mb-0 text-xl">No results</h3>
Expand All @@ -19,7 +26,12 @@ export const SearchResults = (): JSX.Element => {
</div>
) : (
<div className="overflow-hidden overscroll-contain flex h-full">
<div className="border-r bg-bg-3000 overscroll-contain overflow-y-scroll grow-0 shrink-0 w-80">
<div
className={clsx(
'border-r bg-bg-3000 overscroll-contain overflow-y-scroll grow-0 shrink-0 w-full',
size !== 'small' && 'max-w-80'
)}
>
{combinedSearchLoading && (
<>
<SearchResultSkeleton />
Expand All @@ -38,9 +50,11 @@ export const SearchResults = (): JSX.Element => {
/>
))}
</div>
<div className="p-2 grow">
<SearchResultPreview />
</div>
{size !== 'small' ? (
<div className="p-2 grow">
<SearchResultPreview />
</div>
) : null}
</div>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/CommandBar/SearchTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type SearchTabsProps = {
export const SearchTabs = ({ inputRef }: SearchTabsProps): JSX.Element | null => {
const { tabsGrouped } = useValues(searchBarLogic)
return (
<div className="flex flex-col border-r bg-bg-light w-50 grow-0 shrink-0">
<div className="flex flex-col border-r bg-bg-light min-w-30 w-1/3 max-w-50 flex-0 overflow-y-auto">
{Object.entries(tabsGrouped).map(([group, tabs]) => (
<div key={group} className={group !== 'all' ? 'pt-1.5' : ''}>
{group !== 'all' && (
Expand Down

0 comments on commit 63d73bc

Please sign in to comment.