Skip to content

Commit 37e0785

Browse files
authored
Drop container icon props (#575)
* Allow drop container icon props * v5.0.58
1 parent a388eb5 commit 37e0785

2 files changed

Lines changed: 41 additions & 25 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/netdata-ui",
3-
"version": "5.0.57",
3+
"version": "5.0.58",
44
"description": "netdata UI kit",
55
"main": "dist/index.js",
66
"module": "dist/es6/index.js",

src/components/drops/container.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
1-
import React from "react"
1+
import React, { Fragment } from "react"
22
import Flex from "@/components/templates/flex"
33
import { Text } from "@/components/typography"
44
import { Icon } from "@/components/icon"
55

66
const rotateMap = { right: 1, bottom: 2, left: 3 }
7+
const iconAlignmentProps = { alignSelf: "center" }
78

8-
const Container = ({ children, align, margin = [1], background = "tooltip", ref, ...rest }) => (
9-
<Flex
10-
ref={ref}
11-
column={align === "top"}
12-
columnReverse={align === "bottom"}
13-
rowReverse={align === "right"}
14-
margin={margin}
15-
>
16-
<Flex background={background} padding={[1, 2]} round column {...rest}>
17-
{typeof children === "string" ? <Text color="tooltipText">{children}</Text> : children}
9+
const Container = ({
10+
children,
11+
align,
12+
margin = [1],
13+
background = "tooltip",
14+
ref,
15+
iconContainerProps = {},
16+
...rest
17+
}) => {
18+
const hasIconContainerProps = !!Object.keys(iconContainerProps)
19+
const IconContainer = hasIconContainerProps ? Flex : Fragment
20+
21+
return (
22+
<Flex
23+
ref={ref}
24+
column={align === "top"}
25+
columnReverse={align === "bottom"}
26+
rowReverse={align === "right"}
27+
margin={margin}
28+
>
29+
<Flex background={background} padding={[1, 2]} round column {...rest}>
30+
{typeof children === "string" ? <Text color="tooltipText">{children}</Text> : children}
31+
</Flex>
32+
{align && (
33+
<IconContainer {...iconAlignmentProps} {...iconContainerProps}>
34+
<Icon
35+
name="triangle"
36+
color={background}
37+
rotate={rotateMap[align]}
38+
height="8px"
39+
width="8px"
40+
data-testid="drop-arrow"
41+
{...(hasIconContainerProps ? {} : iconAlignmentProps)}
42+
/>
43+
</IconContainer>
44+
)}
1845
</Flex>
19-
{align && (
20-
<Icon
21-
name="triangle"
22-
alignSelf="center"
23-
color={background}
24-
rotate={rotateMap[align]}
25-
height="8px"
26-
width="8px"
27-
data-testid="drop-arrow"
28-
/>
29-
)}
30-
</Flex>
31-
)
46+
)
47+
}
3248

3349
export default Container

0 commit comments

Comments
 (0)