Skip to content

Commit

Permalink
feat: show skeleton for search input while loading data
Browse files Browse the repository at this point in the history
  • Loading branch information
isqua committed Oct 25, 2023
1 parent eb9e07a commit 12adbfd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/features/toc/ui/Menu/Filter/Filter.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import clsx from 'clsx'

import { Input } from '../../../../../components/Input'
import { useFilterInput } from '../Context/hooks'
import { Skeleton } from '../../../../../components/Skeleton'
import { useFilterInput, useIsLoading } from '../Context/hooks'

import styles from './Filter.module.css'

export function Filter(): JSX.Element {
const isLoading = useIsLoading()
const { onChange, isFiltering } = useFilterInput()

return (
<div className={styles.filter}>
<Input
onChange={onChange}
isLoading={isFiltering}
placeholder='Filter menu'
/>
<div className={clsx(styles.filter)}>
{isLoading ? (<Skeleton />) : (
<Input
onChange={onChange}
isLoading={isFiltering}
placeholder='Filter menu'
/>
)}
</div>
)
}
2 changes: 1 addition & 1 deletion src/features/toc/ui/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function Menu({ toc, activeUrl, isLoading }: MenuProps): JSX.Element {
return (
<nav className={styles.menu}>
<MenuProvider toc={toc} url={activeUrl} isLoading={isLoading}>
{!isLoading && <Filter />}
<Filter />
<List />
</MenuProvider>
</nav>
Expand Down
7 changes: 7 additions & 0 deletions src/features/toc/ui/Menu/__snapshots__/Menu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ exports[`features/toc/ui/Menu > loading > should render skeletons while the TOC
<nav
class="_menu_f33640"
>
<div
class="_filter_daddd4"
>
<span
class="_skeleton_2cc9eb _loader_daddd4"
/>
</div>
<ul
class="_list_ae4333"
>
Expand Down

0 comments on commit 12adbfd

Please sign in to comment.