Skip to content

Commit

Permalink
search tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Sep 12, 2023
1 parent 6807803 commit 8d95b0d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
9 changes: 0 additions & 9 deletions src/components/Search/Search.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
right: calc(var(--spacer) / 2);
top: calc(var(--spacer) / 3);
z-index: 10;
transform: translate3d(0, 80px, 0);
will-change: transform;
}

@media (min-width: 40rem) {
.search {
left: 0;
right: 0;
}
}

.searchInput {
Expand Down
28 changes: 2 additions & 26 deletions src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { type ReactElement, useEffect, useState, useRef } from 'react'
import { type ReactElement, useEffect, useState } from 'react'
import Fuse from 'fuse.js'
import { useStore } from '@nanostores/react'
import { isSearchOpen } from '@stores/search'
import { animate } from 'motion'
import SearchResults from './Results'
import styles from './Search.module.css'
import type { CollectionEntry } from 'astro:content'

Check failure on line 7 in src/components/Search/Search.tsx

View workflow job for this annotation

GitHub Actions / typecheck (ubuntu-latest, 18)

Cannot find module 'astro:content' or its corresponding type declarations.

Check failure on line 7 in src/components/Search/Search.tsx

View workflow job for this annotation

GitHub Actions / typecheck (macos-latest, 18)

Cannot find module 'astro:content' or its corresponding type declarations.
Expand All @@ -26,19 +25,6 @@ export default function Search(): ReactElement {
const [results, setResults] = useState<Post[]>()
const [allPosts, setAllPosts] = useState<Post[]>()

const ref = useRef(null)

// animate opening of search
useEffect(() => {
if (!$isSearchOpen || !ref?.current) return

animate(
ref.current,
{ transform: ['translate3d(0, 0, 0)'] },
{ duration: 0.2, easing: 'ease-out' }
)
}, [$isSearchOpen])

// fetch all post data on open
useEffect(() => {
if (!$isSearchOpen) return
Expand Down Expand Up @@ -67,22 +53,12 @@ export default function Search(): ReactElement {

// animate closing of search
async function toggleSearch(): Promise<void> {
ref.current &&
(await animate(
ref.current,
{
transform: $isSearchOpen
? 'translate3d(0, 80px, 0)'
: 'translate3d(0, 0, 0)'
},
{ duration: 0.2 }
).finished)
isSearchOpen.set(!$isSearchOpen)
}

return $isSearchOpen ? (
<>
<form className={styles.search} ref={ref}>
<form className={styles.search}>
<Input
className={styles.searchInput}
type="search"
Expand Down

0 comments on commit 8d95b0d

Please sign in to comment.