Skip to content

Commit

Permalink
Merge pull request #10 from ccontrols/clickable-sidebar-icon
Browse files Browse the repository at this point in the history
Make Sidebar Icon Clickable
  • Loading branch information
atanasster authored Feb 14, 2021
2 parents c0f25e7 + f3a4bb5 commit 8dda340
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
60 changes: 34 additions & 26 deletions ui/components/src/Tree/Tree.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx jsx */
import { FC, useEffect, useState } from 'react';
import { jsx, Box, Flex, Text, Button, BoxProps, ButtonProps } from 'theme-ui';
import { ChevronDownIcon, ChevronRightIcon } from '@primer/octicons-react';
import { ChevronDownIcon } from '@primer/octicons-react';
import {
Keyboard,
LEFT_ARROW,
Expand Down Expand Up @@ -34,8 +34,7 @@ export const Tree: FC<TreeProps> = ({
onSelect,
onExpandCollapse,
arrowPosition = 'end',
iconExpanded = <ChevronDownIcon />,
iconCollapsed = <ChevronRightIcon />,
chevronIcon = <ChevronDownIcon />,
indentPixels = 8,
...rest
}) => {
Expand Down Expand Up @@ -105,8 +104,11 @@ export const Tree: FC<TreeProps> = ({
<Box
aria-label={isExpanded ? 'collapse items' : 'expand items'}
variant="tree.expandicon"
sx={{
transform: isExpanded ? undefined : 'rotate(-90deg)',
}}
>
{isExpanded ? iconExpanded : iconCollapsed}
{chevronIcon}
</Box>
) : null;
const content = (
Expand All @@ -133,30 +135,36 @@ export const Tree: FC<TreeProps> = ({
}
}}
>
<Box variant="tree.labelcontainer">
{arrowPosition === 'start' ? expandIcon : null}
{icon && <Box variant="tree.labelicon">{icon}</Box>}
{typeof label === 'string' ? (
<Text
variant="tree.labeltext"
sx={{
color: isActiveParent ? 'primary' : 'text',
}}
>
{itemItems ? <strong>{label}</strong> : label}
</Text>
) : typeof label === 'function' ? (
label({ isExpanded, ...item })
) : (
label
)}
</Box>
<Flex
sx={{ flexDirection: 'row', justifyContent: 'space-between' }}
>
<Box variant="tree.labelcontainer">
{arrowPosition === 'start' ? expandIcon : null}
{icon && <Box variant="tree.labelicon">{icon}</Box>}
{typeof label === 'string' ? (
<Text
variant="tree.labeltext"
sx={{
color: isActiveParent ? 'primary' : 'text',
}}
>
{itemItems ? <strong>{label}</strong> : label}
</Text>
) : typeof label === 'function' ? (
label({ isExpanded, ...item })
) : (
label
)}
</Box>
<Flex
sx={{ flexDirection: 'row', alignItems: 'center', px: 2 }}
>
{widget && <Box variant="tree.widget">{widget}</Box>}
{arrowPosition === 'end' ? expandIcon : null}
</Flex>
</Flex>
</LinkClass>
</Flex>
<Flex sx={{ flexDirection: 'row', alignItems: 'center', px: 2 }}>
{widget && <Box variant="tree.widget">{widget}</Box>}
{arrowPosition === 'end' ? expandIcon : null}
</Flex>
</Flex>
</Flex>
);
Expand Down
8 changes: 2 additions & 6 deletions ui/components/src/Tree/tree-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,10 @@ export type TreeOwnProps = {
search?: string;

/**
* custom icon when the item is expanded
* custom chevron icon
*/
iconExpanded?: ReactNode;

/**
* custom icon when the item is collapsed
*/
iconCollapsed?: ReactNode;
chevronIcon?: ReactNode;

/**
* indentation in pixels for each elevel, By default 6 pixels
Expand Down

0 comments on commit 8dda340

Please sign in to comment.