Skip to content

Commit

Permalink
**Fix:** Remove hasIconOffset, add <Example/> instead of <Example>
Browse files Browse the repository at this point in the history
Remove hasIconOffset property to fix the extra padding for trees with no children, removes misalignment
Use <Example/> instead of <Example> to fix the warning in the code example

Fixes contiamo#1321
  • Loading branch information
Rimil Dey committed Aug 1, 2020
1 parent 349ed89 commit a659624
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
4 changes: 0 additions & 4 deletions src/Tree/ChildTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type Props = TreeProps["trees"][-1] & {
searchWords?: string[]
freeze?: boolean
level: number
hasIconOffset: boolean
onMouseEnter?: (e: React.MouseEvent<HTMLDivElement>) => void
onMouseLeave?: (e: React.MouseEvent<HTMLDivElement>) => void
}
Expand Down Expand Up @@ -40,7 +39,6 @@ const ChildTree: React.SFC<Props> = ({
ignoreSearchWords,
level,
actions,
hasIconOffset,
onMouseEnter,
onMouseLeave,
strong,
Expand Down Expand Up @@ -104,7 +102,6 @@ const ChildTree: React.SFC<Props> = ({
disabled={disabled}
actions={actions}
cursor={cursor}
hasIconOffset={hasIconOffset && !hasChildren}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
strong={strong}
Expand All @@ -116,7 +113,6 @@ const ChildTree: React.SFC<Props> = ({
{hasChildren && isOpen && (
<Tree
_level={level + 1}
_hasIconOffset={Boolean(icon) || Boolean(tag)}
paddingLeft={paddingLeft}
paddingRight={paddingRight}
trees={childNodes}
Expand Down
15 changes: 5 additions & 10 deletions src/Tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ import { Tree } from "@operational/components"

```jsx
import * as React from "react"
import {
Tree,
DatabaseIcon,
WorkbenchIcon,
PhysicalTableIcon,
ColumnsIcon
} from "@operational/components"
import { Tree, DatabaseIcon, WorkbenchIcon, PhysicalTableIcon, ColumnsIcon } from "@operational/components"

const Example = () => {
const [resourceKind, setResourceKind] = React.useState("datasource")
Expand Down Expand Up @@ -187,9 +181,10 @@ const Example = () => {
],
},
]}
/>);
}
;<Example>
/>
)
}
;<Example />
```

### With higlighted search
Expand Down
4 changes: 0 additions & 4 deletions src/Tree/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export interface TreeProps {
placeholder?: React.ComponentType<DroppableStateSnapshot>
freeze?: boolean
_level?: number
_hasIconOffset?: boolean
}

const Container = styled.div`
Expand All @@ -63,7 +62,6 @@ const Container = styled.div`

const Tree: React.SFC<TreeProps> = ({
_level = 0,
_hasIconOffset = false,
paddingLeft,
paddingRight,
trees,
Expand All @@ -86,7 +84,6 @@ const Tree: React.SFC<TreeProps> = ({
paddingLeft={paddingLeft}
paddingRight={paddingRight}
level={_level}
hasIconOffset={_hasIconOffset}
key={index}
{...treeData}
searchWords={searchWords}
Expand Down Expand Up @@ -114,7 +111,6 @@ const Tree: React.SFC<TreeProps> = ({
<ChildTree
paddingLeft={paddingLeft}
paddingRight={paddingRight}
hasIconOffset={_hasIconOffset}
level={_level}
forwardRef={draggableProvided.innerRef}
searchWords={searchWords}
Expand Down
7 changes: 1 addition & 6 deletions src/Tree/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ interface TreeItemProps {
onMouseEnter?: (e: React.MouseEvent<HTMLDivElement>) => void
onMouseLeave?: (e: React.MouseEvent<HTMLDivElement>) => void
actions?: React.ReactNode
hasIconOffset?: boolean
strong?: boolean
fontSize?: number
fontColor?: string
Expand All @@ -42,7 +41,6 @@ const Header = styled.div<{
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void
cursor?: string
level: number
hasIconOffset: boolean
}>`
label: TreeItem;
width: 100%;
Expand All @@ -52,8 +50,7 @@ const Header = styled.div<{
cursor: ${({ onClick, cursor }) => cursor || (onClick ? "pointer" : "inherit")};
background: ${({ theme, highlight }) => (highlight ? getHighlightColor(theme) : "none")};
padding: ${({ theme }) => `${theme.space.base / 2}px`};
padding-left: ${({ theme, paddingLeft, level, hasIconOffset }) =>
paddingLeft + theme.space.element * level + (hasIconOffset ? theme.space.element : 0)}px;
padding-left: ${({ theme, paddingLeft, level }) => paddingLeft + theme.space.element * level}px;
padding-right: ${({ paddingRight }) => paddingRight}px;
color: ${({ theme }) => theme.color.text.dark};
color: ${({ theme }) => theme.color.text.dark};
Expand Down Expand Up @@ -148,7 +145,6 @@ const TreeItem: React.SFC<TreeItemProps> = ({
level,
cursor,
actions,
hasIconOffset,
searchWords = defaultSearch,
ignoreSearchWords,
onMouseEnter,
Expand Down Expand Up @@ -191,7 +187,6 @@ const TreeItem: React.SFC<TreeItemProps> = ({
paddingLeft={paddingLeft}
paddingRight={paddingRight}
level={level}
hasIconOffset={Boolean(hasIconOffset)}
onClick={onNodeClick}
onContextMenu={onNodeContextMenu}
onKeyDown={handleKeyDown}
Expand Down

0 comments on commit a659624

Please sign in to comment.