-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Search: Add dropdown with search suggestions
- [16e369c] added suggestion dropdown, listing all tags for now - [4e0688d] added single tag icon - [e803ce9] filter search for tag using .includes - [128e35b] add update and debounce back in - [e4c1a19] handle special characters in tags - [337ca13] clean up styles, add dark mode styles - [7e91ed8] tune tag search a bit - [c2f843e] fix styles for wrapping long tag names, add some padding
- Loading branch information
Showing
6 changed files
with
170 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
export default function TagIcon() { | ||
return ( | ||
<svg | ||
className="icon-tag" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
> | ||
<rect x="0" fill="none" width="24" height="24" /> | ||
<path d="M18.29,5.71v5.17l-7,7L6.12,12.71l7-7h5.17m2-2h-8L4,12a1,1,0,0,0,0,1.41L10.59,20A1,1,0,0,0,12,20l8.29-8.29v-8Zm-4.5,5.5a1,1,0,1,0-1-1A1,1,0,0,0,15.79,9.21Z" /> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.search-field { | ||
display: flex; | ||
position: relative; | ||
flex-direction: row; | ||
align-items: center; | ||
width: 100%; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import SmallSearchIcon from '../icons/search-small'; | ||
import TagIcon from '../icons/tag'; | ||
|
||
export class SearchSuggestions extends Component { | ||
static displayName = 'SearchSuggestions'; | ||
|
||
static propTypes = { | ||
onSearch: PropTypes.func.isRequired, | ||
query: PropTypes.string.isRequired, | ||
tags: PropTypes.array.isRequired, | ||
}; | ||
|
||
render() { | ||
const { query, onSearch, tags } = this.props; | ||
// const screenReaderLabel = | ||
// 'Search ' + (isTagSelected ? 'notes with tag ' : '') + placeholder; | ||
const shouldShowTagSuggestions = query.length > 2; | ||
|
||
return ( | ||
<div className="search-suggestions"> | ||
<div className="search-suggestion-row" onClick={() => onSearch(query)}> | ||
<SmallSearchIcon /> | ||
<div className="search-suggestion">{query}</div> | ||
</div> | ||
{shouldShowTagSuggestions && | ||
tags | ||
.filter(function(tag) { | ||
return tag.id.startsWith(encodeURIComponent(query)); | ||
}) | ||
.map(tag => ( | ||
<div | ||
key={tag.id} | ||
className="search-suggestion-row" | ||
onClick={() => onSearch(`tag:${tag.id}`)} | ||
> | ||
<TagIcon /> | ||
<div className="search-suggestion"> | ||
{decodeURIComponent(tag.id)} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = ({ appState: state }) => ({ | ||
tags: state.tags, | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
null | ||
)(SearchSuggestions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.search-suggestions { | ||
position: absolute; | ||
top: 32px; | ||
left: 0; | ||
z-index: 10; | ||
width: 100%; | ||
padding: 0 5px; | ||
border-radius: 5px; | ||
border: 1px solid $studio-gray-10; | ||
|
||
.search-suggestion-row { | ||
cursor: pointer; | ||
padding: 5px; | ||
position: relative; | ||
} | ||
.search-suggestion { | ||
overflow-wrap: anywhere; | ||
margin-left: 28px; | ||
} | ||
|
||
.icon-search-small, .icon-tag { | ||
position: absolute; | ||
transition: $anim-transition; | ||
width: 24px; | ||
} | ||
} | ||
|
||
.theme-light { | ||
.search-suggestions { | ||
background: $studio-white; | ||
} | ||
|
||
.search-suggestion-row { | ||
.icon-search-small, .icon-tag { | ||
fill: $studio-gray-50; | ||
} | ||
&:hover { | ||
background: $studio-blue-5; | ||
} | ||
} | ||
} | ||
|
||
.theme-dark { | ||
.search-suggestions { | ||
background: $studio-gray-90; | ||
color: $studio-white; | ||
} | ||
.search-suggestion-row { | ||
.icon-search-small, .icon-tag { | ||
fill: $studio-gray-30; | ||
} | ||
&:hover { | ||
background: $studio-gray-70; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters