Skip to content

Commit c5a86f5

Browse files
authored
Feat/change styles icon button (#392)
* fix styles at icon button * add customTooltipFor IconButton * fix typo * make tooltip optional
1 parent 2d9e2dc commit c5a86f5

4 files changed

Lines changed: 44 additions & 17 deletions

File tree

src/components/button/IconButton.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
import { Button } from "./button"
22
import Box from "src/components/templates/box"
3+
import Flex from "src/components/templates/flex"
34

45
import React from "react"
6+
import Tooltip from "src/components/drops/tooltip"
7+
import { TextSmall } from "src/components/typography"
8+
9+
//this addition here has been done to be aligned with our current implemetation at cloud-frontend src/components/tooltips/customTooltip.js
10+
11+
const tooltipBackground = ["neutral", "black"]
12+
13+
const CustomTooltipContent = ({ content }) => (
14+
<Flex padding={[1.5, 2]} margin={[2]} background={tooltipBackground} round={1} alignSelf="start">
15+
<TextSmall color="bright">{content}</TextSmall>
16+
</Flex>
17+
)
518

619
const IconButton = ({
720
iconColor = "nodeBadgeColor",
821
flavour = "borderless",
922
icon,
1023
disabled,
1124
onClick,
12-
width = "16px",
13-
height = "18px",
25+
width = "20px",
26+
height = "20px",
1427
iconSize,
28+
tooltip = "",
1529
...props
1630
}) => {
1731
const isDefaultFlavour = flavour === "default"
1832
return (
19-
<Box
20-
cursor="pointer"
21-
sx={{ width, height }}
22-
onClick={onClick}
23-
as={Button}
24-
flavour={flavour}
25-
disabled={disabled}
26-
icon={icon}
27-
iconColor={isDefaultFlavour ? "white" : iconColor}
28-
iconSize={iconSize}
29-
neutral={!isDefaultFlavour}
30-
{...props}
31-
></Box>
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>
3249
)
3350
}
3451

src/components/button/button.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const Button = forwardRef(
1616
textTransform = "firstLetter",
1717
iconColor,
1818
iconSize,
19+
iconWidth,
20+
iconHeight,
1921
...rest
2022
},
2123
ref
@@ -38,6 +40,8 @@ export const Button = forwardRef(
3840
className={iconColor ? "button-icon__color" : "button-icon"}
3941
title={icon}
4042
name={icon}
43+
width={iconWidth}
44+
height={iconHeight}
4145
/>
4246
</Flex>
4347
)}

src/components/button/button.stories.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styled from "styled-components"
55
import { action } from "@storybook/addon-actions"
66
import { text, boolean, select } from "@storybook/addon-knobs"
77
import { readmeCleanup } from "utils/readme"
8-
import { Button } from "."
8+
import { Button, IconButton } from "."
99
import readme from "./README.md"
1010
import { iconsList } from "src/components/icon"
1111

@@ -91,3 +91,9 @@ buttonStory.add(
9191
),
9292
subData
9393
)
94+
95+
buttonStory.add(
96+
"Icon Button",
97+
() => <IconButton cursor="pointer" icon="chevron_left" iconSize="small" tooltip="Previous" />,
98+
subData
99+
)

src/components/button/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface ButtonWrapperProps extends ButtonProps, MarginProps, PaddingPro
4141
type IconButtonProps = Pick<
4242
ButtonWrapperProps,
4343
"iconColor" | "flavour" | "icon" | "disabled" | "onClick" | "iconSize"
44-
> & { width?: string; height?: string }
44+
> & { width?: string; height?: string; tooltip?: string }
4545

4646
declare const Button: FC<ButtonWrapperProps>
4747
declare const IconButton: FC<IconButtonProps>

0 commit comments

Comments
 (0)