-
Notifications
You must be signed in to change notification settings - Fork 0
Basics #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Basics #60
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 +1,4 @@ | ||
module.exports = { | ||
plugins: ["emotion"], | ||
presets: ["@babel/preset-env", "@babel/preset-react"] | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from "@emotion/core"; | ||
import React from "react"; | ||
|
||
export const BackIconRenderer = () => <>⬅️</>; | ||
|
||
const Header = props => { | ||
const { | ||
parents = [], | ||
onClick, | ||
title = "", | ||
getStyles, | ||
backIconRenderer: BackIcon = BackIconRenderer | ||
} = props; | ||
return ( | ||
<div css={getStyles("header", props)}> | ||
{parents.length > 0 && ( | ||
<> | ||
<span css={getStyles("headerBackIcon", props)} onClick={onClick}> | ||
<BackIcon /> | ||
</span> | ||
{parents[parents.length - 1]} | ||
</> | ||
)} | ||
{parents.length === 0 && <>{title}</>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains hidden or 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,11 @@ | ||
export const wrapperCss = () => ({ | ||
height: "40px", | ||
display: "flex", | ||
alignItems: "center", | ||
padding: "0 6px" | ||
}); | ||
|
||
export const backIconCss = () => ({ | ||
marginRight: "3px", | ||
cursor: "pointer" | ||
}); |
This file contains hidden or 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,31 @@ | ||
import { useState } from "react"; | ||
|
||
const useItemCallbacks = onSelect => { | ||
const [currentDepth, setCurrentDepth] = useState(0); | ||
const [parents, setParents] = useState([]); | ||
|
||
const onClick = (label, item, hasChild) => { | ||
if (hasChild) { | ||
setParents(parents.concat(label)); | ||
setCurrentDepth(currentDepth + 1); | ||
} else { | ||
onSelect(item); | ||
} | ||
}; | ||
|
||
const onBackClick = () => { | ||
setParents(parents.filter((parent, index) => index < parents.length - 1)); | ||
setCurrentDepth(currentDepth - 1); | ||
}; | ||
|
||
return { | ||
onClick, | ||
onBackClick, | ||
currentDepth, | ||
setCurrentDepth, | ||
parents, | ||
setParents | ||
}; | ||
}; | ||
|
||
export default useItemCallbacks; |
This file contains hidden or 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,28 @@ | ||
import { | ||
containsAllParents, | ||
filterBySearchTerm, | ||
buildLeafForItemRenderer, | ||
removeDuplicateLeafs | ||
} from "../util"; | ||
import { useState, useEffect } from "react"; | ||
|
||
const useLeavesManager = ({ structure, parents, currentDepth }) => { | ||
const [searchTerm, setSearchTerm] = useState(""); | ||
const [leaves, setLeaves] = useState([]); | ||
|
||
useEffect(() => { | ||
const leaves = structure | ||
.filter( | ||
leaf => | ||
filterBySearchTerm(leaf, searchTerm) && | ||
containsAllParents(leaf, parents) | ||
) | ||
.map(leaf => buildLeafForItemRenderer(leaf, currentDepth, searchTerm)); | ||
|
||
setLeaves(removeDuplicateLeafs(leaves)); | ||
}, [searchTerm, parents, currentDepth]); | ||
|
||
return { searchTerm, setSearchTerm, leaves }; | ||
}; | ||
|
||
export default useLeavesManager; |
This file contains hidden or 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,3 @@ | ||
import React from "react"; | ||
import Tree from "./tree"; | ||
|
||
const HelloWorld = () => <div>Hello World</div>; | ||
|
||
export default HelloWorld; | ||
export default Tree; |
This file contains hidden or 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,28 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from "@emotion/core"; | ||
import React from "react"; | ||
|
||
export const InputIconRenderer = () => <>🔍</>; | ||
|
||
const Input = props => { | ||
const { | ||
searchTerm, | ||
setSearchTerm, | ||
getStyles, | ||
inputIconRenderer: InputIcon = InputIconRenderer | ||
} = props; | ||
return ( | ||
<div css={getStyles("inputWrapper", props)}> | ||
<span css={getStyles("searchInput", props)}> | ||
<InputIcon /> | ||
</span> | ||
<input | ||
css={getStyles("input", props)} | ||
value={searchTerm} | ||
onChange={e => setSearchTerm(e.target.value)} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Input; |
This file contains hidden or 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,27 @@ | ||
export const css = () => ({ | ||
width: "100%", | ||
height: "35px", | ||
paddingLeft: "35px", | ||
border: "1px solid #cfd1d2", | ||
borderRight: "none", | ||
borderLeft: "none", | ||
backgroundColor: "#F8F9FA", | ||
|
||
"&:focus": { | ||
outline: "none !important" | ||
}, | ||
|
||
"&:active": { | ||
outline: "none !important" | ||
} | ||
}); | ||
|
||
export const searchIconCss = () => ({ | ||
position: "absolute", | ||
top: "8px", | ||
left: "8px" | ||
}); | ||
|
||
export const wrapperCss = () => ({ | ||
position: "relative" | ||
}); |
This file contains hidden or 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,7 @@ | ||
import React from "react"; | ||
|
||
const BasicItem = ({ label = "" }) => { | ||
return <span>{label}</span>; | ||
}; | ||
|
||
export default BasicItem; |
This file contains hidden or 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,54 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from "@emotion/core"; | ||
import React from "react"; | ||
|
||
import SearchedItem from "./searched_item/searched_item"; | ||
import BasicItem from "./basic_item"; | ||
|
||
export const ForwardIconRenderer = () => <>➡️</>; | ||
|
||
const ItemRenderer = props => { | ||
const { | ||
getStyles, | ||
searchTerm = "", | ||
item: { item, hasChild, currentDepth } = { | ||
item: [""], | ||
hasChild: false, | ||
currentDepth: 0 | ||
}, | ||
onClick, | ||
forwardIconRenderer: ForwardIcon = ForwardIconRenderer | ||
} = props; | ||
const searchIndex = item[item.length - 1] | ||
.toLowerCase() | ||
.indexOf(searchTerm.trim().toLowerCase()); | ||
return ( | ||
<div | ||
onClick={() => onClick(item[currentDepth], item, hasChild)} | ||
css={getStyles("item", props)} | ||
> | ||
{searchTerm !== "" && ( | ||
<SearchedItem | ||
item={item} | ||
searchIndex={searchIndex} | ||
searchTerm={searchTerm.trim()} | ||
getStyles={getStyles} | ||
/> | ||
)} | ||
{searchTerm === "" && ( | ||
<BasicItem | ||
label={item[currentDepth]} | ||
searchIndex={searchIndex} | ||
searchTerm={searchTerm.trim()} | ||
/> | ||
)} | ||
{hasChild && ( | ||
<span css={getStyles("forwardIcon", props)}> | ||
<ForwardIcon /> | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ItemRenderer; |
This file contains hidden or 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,20 @@ | ||
export const css = props => ({ | ||
orineuman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
cursor: "pointer", | ||
height: props.searchTerm !== "" ? "50px" : "30px", | ||
marginTop: "3px", | ||
padding: "0 6px", | ||
fontSize: "14px", | ||
|
||
"&:hover": { | ||
backgroundColor: "#ECEEF3" | ||
}, | ||
|
||
"&:active": { | ||
backgroundColor: "#E1E4EB" | ||
} | ||
}); | ||
|
||
export const forwardIconCss = () => ({}); |
This file contains hidden or 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,13 @@ | ||
export const initialCss = props => ({ | ||
color: "#545769" | ||
}); | ||
|
||
export const highlightCss = props => ({ | ||
fontWeight: 600, | ||
color: "#2020e1" | ||
}); | ||
|
||
export const parentsCss = props => ({ | ||
color: "#98A1B8", | ||
marginTop: "2px" | ||
}); |
This file contains hidden or 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,28 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from "@emotion/core"; | ||
import React from "react"; | ||
|
||
const SearchedItem = props => { | ||
const { item = [""], searchIndex = 0, searchTerm = "", getStyles } = props; | ||
const leaf = item[item.length - 1]; | ||
const parents = item.slice(0, item.length - 1).join(" / "); | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<span css={getStyles("searchItemInitial", props)}> | ||
{leaf.substring(0, searchIndex)} | ||
</span> | ||
<span css={getStyles("highlight", props)}> | ||
{leaf.substring(searchIndex, searchIndex + searchTerm.length)} | ||
</span> | ||
<span css={getStyles("searchItemInitial", props)}> | ||
{leaf.substring(searchIndex + searchTerm.length)} | ||
</span> | ||
</div> | ||
<div css={getStyles("parents", props)}>{parents}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchedItem; |
This file contains hidden or 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,4 @@ | ||
export default () => ({ | ||
maxHeight: "203px", | ||
overflowY: "auto" | ||
}); |
This file contains hidden or 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,15 @@ | ||
export const css = () => ({ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
marginTop: "30px" | ||
}); | ||
|
||
export const icon = () => ({ | ||
fontSize: "20px", | ||
marginBottom: "5px" | ||
}); | ||
|
||
export const text = () => ({ | ||
fontSize: "14px" | ||
}); |
This file contains hidden or 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,23 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from "@emotion/core"; | ||
import React from "react"; | ||
|
||
export const NoResultsIconRenderer = () => <>⚠️</>; | ||
|
||
const NoResults = props => { | ||
const { | ||
text, | ||
getStyles, | ||
noResultsIconRenderer: NoResultsIcon = NoResultsIconRenderer | ||
} = props; | ||
return ( | ||
<div css={getStyles("noResults", props)}> | ||
<div css={getStyles("noResultsIcon", props)}> | ||
<NoResultsIcon /> | ||
</div> | ||
<div css={getStyles("noResultsText", props)}>{text}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NoResults; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't there a clear input here at some point?