Skip to content

Commit

Permalink
Added the <DocumentTitle> pattern to <SearchBar>
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaydek Michels-Gualtieri committed Apr 4, 2020
1 parent 992d43d commit d469676
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 153 deletions.
19 changes: 19 additions & 0 deletions src/App/HeroiconsTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react"

// Sets the document title (uses useEffect).
const DocumentTitle = ({ title, ...props }) => {
React.useEffect(() => {
if (!title) {
// No-op
return
}
document.title = title
}, [title])
return props.children || null
}

const HeroiconsTitle = ({ title, ...props }) => {
return <DocumentTitle title={title || "Heroicons"} {...props} />
}

export default HeroiconsTitle
27 changes: 15 additions & 12 deletions src/App/SearchBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Hero from "react-heroicons"
import Context from "./Context"
import HeroiconsTitle from "./HeroiconsTitle"
import Icon from "./Icon"
import originalIcons from "./helpers/icons"
import React from "react"
Expand Down Expand Up @@ -77,19 +78,21 @@ const SearchBar = props => {
</div>

{/* Search bar */}
<div className="absolute inset-0">
<div className="h-full rounded-lg-xl dark:shadow-md transition duration-150">
<input
ref={ref}
className="w-full h-full text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-800 rounded-lg-xl outline-none shadow dark:shadow-md focus:shadow-outline transition duration-150"
type="text"
placeholder={placeholder}
value={ctx.query}
onKeyDown={handleKeyDown}
onChange={e => ctx.setQuery(e.target.value)}
/>
<HeroiconsTitle title={ctx.query && `${ctx.icons.length} results`}>
<div className="absolute inset-0">
<div className="h-full rounded-lg-xl dark:shadow-md transition duration-150">
<input
ref={ref}
className="w-full h-full text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-800 rounded-lg-xl outline-none shadow dark:shadow-md focus:shadow-outline transition duration-150"
type="text"
placeholder={placeholder}
value={ctx.query}
onKeyDown={handleKeyDown}
onChange={e => ctx.setQuery(e.target.value)}
/>
</div>
</div>
</div>
</HeroiconsTitle>

{/* End */}
<div ref={rhs} className="-mx-2 px-6 flex flex-row rounded-r-lg-xl focus:outline-none focus:shadow-outline z-10 transition duration-150">
Expand Down
1 change: 0 additions & 1 deletion src/App/helpers/SearchTrie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class SearchTrie {
constructor(dataset, key = "tags") {
const trie = {}
for (let index = 0; index < dataset.length; index++) {
// TODO: Dedupe
const tags = dataset[index][key]
for (const tag of tags) {
let ref = trie
Expand Down
Loading

0 comments on commit d469676

Please sign in to comment.