Skip to content

Commit 61b5c30

Browse files
authored
v5.4.5 (#618)
* Add flavours to tab * v5.4.5 * Update test snapshot
1 parent 7b67800 commit 61b5c30

4 files changed

Lines changed: 66 additions & 27 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.4.4",
3+
"version": "5.4.5",
44
"description": "netdata UI kit",
55
"main": "dist/index.js",
66
"module": "dist/es6/index.js",

src/components/tabs/__snapshots__/tabs.test.js.snap

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,52 @@ exports[`Tabs states * should render uncontrolled 1`] = `
3131
3232
.c3 {
3333
white-space: nowrap;
34-
border-bottom: 1px solid #42B861;
34+
border-bottom-width: 1px;
35+
border-bottom-style: solid;
3536
box-sizing: border-box;
3637
border-radius: 2px 2px 0 0;
3738
max-width: 208px;
3839
height: 32px;
3940
cursor: pointer;
4041
opacity: 1;
41-
background: #F1FFF7;
4242
pointer-events: auto;
4343
margin-bottom: -1px;
44-
}
45-
46-
.c3:hover {
47-
border-bottom: 1px solid #00AB44;
44+
border-bottom-color: #42B861;
45+
background: #F1FFF7;
4846
}
4947
5048
.c3>span {
5149
color: #00AB44;
5250
}
5351
52+
.c3:hover {
53+
border-bottom-color: #00AB44;
54+
}
55+
5456
.c4 {
5557
white-space: nowrap;
56-
border-bottom: 1px solid #E4E8E8;
58+
border-bottom-width: 1px;
59+
border-bottom-style: solid;
5760
box-sizing: border-box;
5861
border-radius: 2px 2px 0 0;
5962
max-width: 208px;
6063
height: 32px;
6164
cursor: pointer;
6265
opacity: 1;
63-
background: #F6F7F7;
6466
pointer-events: auto;
6567
margin-bottom: -1px;
66-
}
67-
68-
.c4:hover {
69-
border-bottom: 1px solid #00AB44;
68+
border-bottom-color: #E4E8E8;
69+
background: #F6F7F7;
7070
}
7171
7272
.c4>span {
7373
color: #708585;
7474
}
7575
76+
.c4:hover {
77+
border-bottom-color: #00AB44;
78+
}
79+
7680
<div
7781
class="c0"
7882
>

src/components/tabs/styled.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,57 @@ export const StyledTabs = styled(Flex).attrs(props => ({
2525
...props,
2626
}))``
2727

28+
const colorsByFlavour = {
29+
success: { background: "menuItemSelected", borderColor: "accent", color: "menuItem" },
30+
warning: { background: "warningSemi", borderColor: "warning", color: "menuItem" },
31+
error: { background: "errorSemi", borderColor: "error", color: "menuItem" },
32+
default: { background: "modalBackground", borderColor: "border", color: "menuItem" },
33+
}
34+
35+
const activeColorsByFlavour = {
36+
success: { ...colorsByFlavour.success, color: "primary" },
37+
warning: { ...colorsByFlavour.warning, color: "warning" },
38+
error: { ...colorsByFlavour.error, color: "error" },
39+
default: { background: "menuItemSelected", borderColor: "accent", color: "primary" },
40+
}
41+
42+
const hoverColorsByFlavour = {
43+
...colorsByFlavour,
44+
default: { ...colorsByFlavour.default, borderColor: "primary" },
45+
}
46+
47+
const colors = ({ theme, active, green, flavour }) => {
48+
const dictionary = active ? activeColorsByFlavour : colorsByFlavour
49+
const { background, borderColor, color } = dictionary[flavour] || dictionary.default
50+
51+
const styles = [
52+
`border-bottom-color: ${getColor(borderColor)({ theme })};`,
53+
`background: ${getColor(background)({ theme })};`,
54+
`& > span { color: ${getColor(color)({ theme })}; }`,
55+
]
56+
57+
if (!active && green) {
58+
styles.push(`border-bottom-color: ${getColor(["transparent", "full"])({ theme })};`)
59+
}
60+
61+
const hoverStyles = [
62+
`&:hover {
63+
border-bottom-color: ${getColor((hoverColorsByFlavour[flavour] || hoverColorsByFlavour.default)?.borderColor)({ theme })};
64+
}`,
65+
]
66+
67+
return [...styles, ...hoverStyles].join("")
68+
}
69+
2870
export const StyledTab = styled(Flex).attrs(props => ({
2971
small: true,
3072
padding: [0, 6],
3173
...props,
3274
}))`
3375
white-space: nowrap;
34-
border-bottom: 1px solid
35-
${({ active, green }) =>
36-
active ? getColor("accent") : green ? getColor(["transparent", "full"]) : getColor("border")};
76+
border-bottom-width: 1px;
77+
border-bottom-style: solid;
78+
3779
box-sizing: border-box;
3880
3981
border-radius: 2px 2px 0 0;
@@ -44,19 +86,12 @@ export const StyledTab = styled(Flex).attrs(props => ({
4486
4587
cursor: pointer;
4688
opacity: ${({ disabled }) => (disabled ? 0.4 : 1)};
47-
background: ${({ active }) =>
48-
active ? getColor("menuItemSelected") : getColor("modalBackground")};
89+
4990
pointer-events: ${({ disabled }) => (disabled ? "none" : "auto")};
5091
5192
margin-bottom: -1px;
5293
53-
&:hover {
54-
border-bottom: 1px solid ${getColor("primary")};
55-
}
56-
57-
& > span {
58-
color: ${({ active }) => (active ? getColor("primary") : getColor("menuItem"))};
59-
}
94+
${colors}
6095
`
6196

6297
export const StyledTabMenu = styled(Flex)`

src/components/tabs/tab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { StyledTab, StyledTabMenu } from "./styled"
33

44
export const Tab = ({ index, isMenuItem, onChange, ...rest }) => {
55
const onClick = useCallback(e => onChange && onChange(index || 0, e), [index, onChange])
6-
76
const TabComponent = isMenuItem ? StyledTabMenu : StyledTab
7+
88
return (
99
<TabComponent
1010
justifyContent="center"
1111
alignItems="center"
1212
onClick={rest.disabled ? undefined : onClick}
1313
{...rest}
1414
>
15-
{rest.label}
15+
{typeof rest.label === "function" ? rest.label({ index, isMenuItem, ...rest }) : rest.label}
1616
</TabComponent>
1717
)
1818
}

0 commit comments

Comments
 (0)