-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace slider with tree view * more redesign work * add entry for now and set interval to 5 minutes
- Loading branch information
Showing
11 changed files
with
673 additions
and
155 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
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,153 @@ | ||
import * as React from "react"; | ||
|
||
import { ContainerProps, classList } from "../util"; | ||
import { FocusList } from "./FocusList"; | ||
|
||
export interface TreeProps extends ContainerProps { | ||
role?: "tree" | "group"; | ||
} | ||
|
||
export interface TreeItemProps extends ContainerProps { | ||
role?: "treeitem"; | ||
onClick?: () => void; | ||
initiallyExpanded?: boolean; | ||
} | ||
|
||
export interface TreeItemBodyProps extends ContainerProps { | ||
} | ||
|
||
export const Tree = (props: TreeProps) => { | ||
const { | ||
children, | ||
id, | ||
className, | ||
ariaLabel, | ||
ariaHidden, | ||
ariaDescribedBy, | ||
role, | ||
} = props; | ||
|
||
if (!role || role === "tree") { | ||
return ( | ||
<FocusList | ||
className={classList("common-tree", className)} | ||
id={id} | ||
aria-label={ariaLabel} | ||
aria-hidden={ariaHidden} | ||
aria-describedby={ariaDescribedBy} | ||
role={role || "tree"} | ||
> | ||
{children} | ||
</FocusList> | ||
) | ||
} | ||
|
||
return ( | ||
<div | ||
className={classList("common-tree", "subtree", className)} | ||
id={id} | ||
aria-label={ariaLabel} | ||
aria-hidden={ariaHidden} | ||
aria-describedby={ariaDescribedBy} | ||
role={role || "tree"} | ||
> | ||
{children} | ||
</div> | ||
) | ||
}; | ||
|
||
export const TreeItem = (props: TreeItemProps) => { | ||
const { | ||
children, | ||
id, | ||
className, | ||
ariaLabel, | ||
ariaHidden, | ||
ariaDescribedBy, | ||
role, | ||
initiallyExpanded, | ||
onClick | ||
} = props; | ||
|
||
const [expanded, setExpanded] = React.useState(initiallyExpanded); | ||
const mappedChildren = React.Children.toArray(children); | ||
const hasSubtree = mappedChildren.length > 1; | ||
|
||
const subtreeContainer = React.useRef<HTMLDivElement>() | ||
|
||
React.useEffect(() => { | ||
if (!hasSubtree) return; | ||
|
||
if (expanded) { | ||
const focusable = subtreeContainer.current.querySelectorAll(`[tabindex]:not([tabindex="-1"]),[data-isfocusable]`); | ||
focusable.forEach(f => f.setAttribute("data-isfocusable", "true")); | ||
} | ||
else { | ||
const focusable = subtreeContainer.current.querySelectorAll(`[tabindex]:not([tabindex="-1"]),[data-isfocusable]`); | ||
focusable.forEach(f => f.setAttribute("data-isfocusable", "false")); | ||
} | ||
}, [expanded, hasSubtree]); | ||
|
||
const onTreeItemClick = React.useCallback(() => { | ||
if (hasSubtree) { | ||
setExpanded(!expanded); | ||
} | ||
if (onClick) { | ||
onClick(); | ||
} | ||
}, [hasSubtree, expanded]) | ||
|
||
return ( | ||
<div | ||
className="common-treeitem-container" | ||
id={id} | ||
aria-label={ariaLabel} | ||
aria-hidden={ariaHidden} | ||
aria-describedby={ariaDescribedBy} | ||
role={role || "treeitem"} | ||
|
||
> | ||
<div className={classList("common-treeitem", className)} onClick={onTreeItemClick}> | ||
{hasSubtree && | ||
<i | ||
className={classList("fas", expanded ? "fa-chevron-down" : "fa-chevron-right")} | ||
aria-hidden={true} | ||
/> | ||
} | ||
{mappedChildren[0]} | ||
</div> | ||
<div | ||
ref={subtreeContainer} | ||
style={{ display: expanded ? undefined : "none" }} | ||
> | ||
{hasSubtree ? mappedChildren[1] : undefined} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export const TreeItemBody = (props: TreeItemBodyProps) => { | ||
const { | ||
children, | ||
id, | ||
className, | ||
ariaLabel, | ||
ariaHidden, | ||
ariaDescribedBy, | ||
role, | ||
} = props; | ||
|
||
return ( | ||
<div | ||
className={classList("common-treeitembody", className)} | ||
id={id} | ||
aria-label={ariaLabel} | ||
aria-hidden={ariaHidden} | ||
aria-describedby={ariaDescribedBy} | ||
role={role} | ||
tabIndex={0} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} |
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,33 @@ | ||
.common-tree { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.common-tree.subtree .common-treeitem { | ||
// The width of the chevron is 1.81rem + 0.25rem margin | ||
padding-left: 2.06rem; | ||
} | ||
|
||
.common-treeitem { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
|
||
height: 3rem; | ||
cursor: pointer; | ||
|
||
background-color: @treeitemBackgroundColor; | ||
|
||
text-wrap: nowrap; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
} | ||
|
||
.common-treeitem:hover { | ||
filter: grayscale(.15) brightness(.85) contrast(1.3); | ||
} | ||
|
||
.common-treeitem-container { | ||
display: flex; | ||
flex-direction: column; | ||
} |
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
Oops, something went wrong.