Skip to content

Commit 30ed42d

Browse files
authored
chore(icon button): add ref support to component (#401)
* chore(icon button): add ref support to component * chore(input): move input props at the end * Move input props at the end of input provided props, so they can be overwritten * v2.4.4
1 parent dcd23e4 commit 30ed42d

3 files changed

Lines changed: 43 additions & 38 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": "2.4.3",
3+
"version": "2.4.4",
44
"description": "netdata UI kit",
55
"main": "./lib/index.js",
66
"files": [
Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Button } from "./button"
1+
import React, { forwardRef } from "react"
22
import Box from "src/components/templates/box"
33
import Flex from "src/components/templates/flex"
4-
5-
import React from "react"
64
import Tooltip from "src/components/drops/tooltip"
75
import { TextSmall } from "src/components/typography"
6+
import { Button } from "./button"
87

9-
//this addition here has been done to be aligned with our current implemetation at cloud-frontend src/components/tooltips/customTooltip.js
8+
//this addition here has been done to be aligned with our current implementation at cloud-frontend src/components/tooltips/customTooltip.js
109

1110
const tooltipBackground = ["neutral", "black"]
1211

@@ -16,37 +15,43 @@ const CustomTooltipContent = ({ content }) => (
1615
</Flex>
1716
)
1817

19-
const IconButton = ({
20-
iconColor = "nodeBadgeColor",
21-
flavour = "borderless",
22-
icon,
23-
disabled,
24-
onClick,
25-
width = "20px",
26-
height = "20px",
27-
iconSize,
28-
tooltip = "",
29-
...props
30-
}) => {
31-
const isDefaultFlavour = flavour === "default"
32-
return (
33-
<Tooltip plain animation content={tooltip && <CustomTooltipContent content={tooltip} />}>
34-
<Box
35-
cursor="pointer"
36-
iconWidth={width}
37-
iconHeight={height}
38-
onClick={onClick}
39-
as={Button}
40-
flavour={flavour}
41-
disabled={disabled}
42-
icon={icon}
43-
iconColor={isDefaultFlavour ? "white" : iconColor}
44-
iconSize={iconSize}
45-
neutral={!isDefaultFlavour}
46-
{...props}
47-
></Box>
48-
</Tooltip>
49-
)
50-
}
18+
const IconButton = forwardRef(
19+
(
20+
{
21+
iconColor = "nodeBadgeColor",
22+
flavour = "borderless",
23+
icon,
24+
disabled,
25+
onClick,
26+
width = "20px",
27+
height = "20px",
28+
iconSize,
29+
tooltip = "",
30+
...props
31+
},
32+
ref
33+
) => {
34+
const isDefaultFlavour = flavour === "default"
35+
return (
36+
<Tooltip plain animation content={tooltip && <CustomTooltipContent content={tooltip} />}>
37+
<Box
38+
cursor="pointer"
39+
iconWidth={width}
40+
iconHeight={height}
41+
onClick={onClick}
42+
as={Button}
43+
flavour={flavour}
44+
disabled={disabled}
45+
icon={icon}
46+
iconColor={isDefaultFlavour ? "white" : iconColor}
47+
iconSize={iconSize}
48+
neutral={!isDefaultFlavour}
49+
ref={ref}
50+
{...props}
51+
/>
52+
</Tooltip>
53+
)
54+
}
55+
)
5156

5257
export default IconButton

src/components/input/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ export const TextInput = ({
118118
>
119119
{iconLeft && <LeftIcon icon={iconLeft} />}
120120
<StyledInput
121-
{...props}
122121
disabled={disabled}
123122
placeholder={placeholder}
124123
onBlur={handleBlur}
@@ -130,6 +129,7 @@ export const TextInput = ({
130129
type="text"
131130
value={value}
132131
ref={inputRef}
132+
{...props}
133133
/>
134134
{iconRight && <RightIcon icon={iconRight} />}
135135
{metaDisplayed && error && <RightIcon icon={<ErrorIcon name="cross_s" />} />}

0 commit comments

Comments
 (0)