Skip to content

Commit 71aadf5

Browse files
authored
chore(netdata table): update table column menu (#414)
* chore(checkbox): update global styles * Make checkbox smaller (16px) * Add opacity to checkbox label on disabled state * refactor(checkbox): order updated props alphabetically * chore(netdata table): update columns menu for pinned columns * refactor(netdata table): order updated props alphabetically * chore(drop): update optional TS props * fix(netdata table): remove not visible columns from displayed list * v2.6.3
1 parent e71800f commit 71aadf5

File tree

11 files changed

+222
-167
lines changed

11 files changed

+222
-167
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/netdata-ui",
3-
"version": "2.6.2",
3+
"version": "2.6.3",
44
"description": "netdata UI kit",
55
"main": "./lib/index.js",
66
"files": [

src/components/checkbox/checkbox.js

+69-60
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,79 @@ import { Text } from "src/components/typography"
33
import useCheckBoxStyles from "./use-styles-checkbox"
44
import useCheckbox from "./use-checkbox"
55

6-
import { CheckboxContainer, HiddenCheckboxInput, LabelText, StyledCheckbox, StyledIcon, StyledLabel } from "./styled"
6+
import {
7+
CheckboxContainer,
8+
HiddenCheckboxInput,
9+
LabelText,
10+
StyledCheckbox,
11+
StyledIcon,
12+
StyledLabel,
13+
} from "./styled"
714

8-
export const Checkbox = forwardRef((
9-
{
10-
checked,
11-
"data-testid": testId,
12-
disabled,
13-
className,
14-
labelPosition,
15-
label,
16-
indeterminate,
17-
margin,
18-
alignSelf,
19-
iconProps,
20-
Label,
21-
...props
22-
},
15+
export const Checkbox = forwardRef(
16+
(
17+
{
18+
alignSelf,
19+
checked,
20+
className,
21+
"data-testid": testId,
22+
disabled,
23+
iconProps,
24+
indeterminate,
25+
Label,
26+
label,
27+
labelPosition,
28+
margin,
29+
...props
30+
},
2331
ref
24-
) => {
25-
const { styles } = useCheckBoxStyles({ disabled })
26-
const { getInputProps, getCheckBoxProps } = useCheckbox({
27-
disabled,
28-
checked,
29-
indeterminate,
30-
...props,
31-
})
32+
) => {
33+
const { styles } = useCheckBoxStyles({ disabled })
34+
const { getInputProps, getCheckBoxProps } = useCheckbox({
35+
checked,
36+
disabled,
37+
indeterminate,
38+
...props,
39+
})
3240

33-
return (
34-
<StyledLabel
35-
data-testid={testId}
36-
disabled={disabled}
37-
className={className}
38-
margin={margin}
39-
alignSelf={alignSelf}
40-
>
41-
{label && labelPosition === "left" && (
42-
<LabelText as={Label} left>
43-
{label}
44-
</LabelText>
45-
)}
46-
<CheckboxContainer>
47-
<HiddenCheckboxInput data-testid="checkbox-input" {...getInputProps(ref, props)} />
48-
<StyledCheckbox
49-
data-testid="styled-checkbox"
50-
{...styles.styledCheckbox}
51-
{...getCheckBoxProps()}
52-
>
53-
<StyledIcon
54-
name={indeterminate ? "checkmark_partial_s" : "checkmark_s"}
55-
disabled={disabled}
56-
{...iconProps}
57-
/>
58-
</StyledCheckbox>
59-
</CheckboxContainer>
60-
{label && labelPosition === "right" && (
61-
<LabelText as={Label} right>
62-
{label}
63-
</LabelText>
64-
)}
65-
</StyledLabel>
66-
)
67-
})
41+
return (
42+
<StyledLabel
43+
alignSelf={alignSelf}
44+
className={className}
45+
data-testid={testId}
46+
disabled={disabled}
47+
margin={margin}
48+
>
49+
{label && labelPosition === "left" && (
50+
<LabelText as={Label} disabled={disabled} left>
51+
{label}
52+
</LabelText>
53+
)}
54+
<CheckboxContainer>
55+
<HiddenCheckboxInput data-testid="checkbox-input" {...getInputProps(ref, props)} />
56+
<StyledCheckbox
57+
data-testid="styled-checkbox"
58+
{...styles.styledCheckbox}
59+
{...getCheckBoxProps()}
60+
>
61+
<StyledIcon
62+
disabled={disabled}
63+
name={indeterminate ? "checkmark_partial_s" : "checkmark_s"}
64+
{...iconProps}
65+
/>
66+
</StyledCheckbox>
67+
</CheckboxContainer>
68+
{label && labelPosition === "right" && (
69+
<LabelText as={Label} disabled={disabled} right>
70+
{label}
71+
</LabelText>
72+
)}
73+
</StyledLabel>
74+
)
75+
}
76+
)
6877

6978
Checkbox.defaultProps = {
70-
labelPosition: "right",
7179
Label: Text,
80+
labelPosition: "right",
7281
}

src/components/checkbox/styled.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import styled from "styled-components"
22
import { Icon } from "src/components/icon"
3+
import Box from "src/components/templates/box"
34
import { getSizeUnit, getValidatedControlColor } from "src/theme/utils"
45
import margin from "src/mixins/margin"
56
import alignSelf from "src/mixins/alignSelf"
67

78
import Flex from "src/components/templates/flex"
89

9-
export const CheckboxContainer = styled.div`
10-
display: block;
10+
export const CheckboxContainer = styled(Box).attrs({
11+
height: "16px",
12+
width: "16px",
13+
})`
1114
box-sizing: border-box;
12-
width: 20px;
13-
height: 20px;
1415
`
1516

16-
export const StyledIcon = styled(Icon)`
17+
export const StyledIcon = styled(Icon).attrs({
18+
height: "inherit",
19+
width: "inherit",
20+
})`
1721
flex-grow: 0;
1822
flex-shrink: 0;
1923
fill: ${getValidatedControlColor("primary", "accent")};
@@ -57,5 +61,6 @@ export const StyledLabel = styled.label`
5761

5862
export const LabelText = styled.span`
5963
${({ right, ...props }) =>
60-
right ? `margin-left: ${getSizeUnit(props)}px;` : `margin-right: ${getSizeUnit(props)}px;`}
64+
right ? `margin-left: ${getSizeUnit(props)}px;` : `margin-right: ${getSizeUnit(props)}px;`};
65+
${({ disabled }) => disabled && "opacity: 0.4;"};
6166
`

src/components/checkbox/use-styles-checkbox.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@ import { useMemo } from "react"
22

33
const makeColor = ({
44
defaultColor = "inputBorder",
5-
success = "success",
6-
error = "error",
75
disabled = "inputBorder",
6+
error = "error",
7+
success = "success",
88
}) => ({
9-
success: success,
10-
error: error,
11-
disabled: disabled,
129
default: defaultColor,
10+
disabled: disabled,
11+
error: error,
12+
success: success,
1313
})
1414
const useCheckboxStyles = ({ disabled, success, error, focused }) => {
1515
const status = success ? "success" : error ? "error" : disabled ? "disabled" : "default"
1616

17-
const styledCheckbox = useMemo(() => {
18-
return {
19-
width: "20px",
20-
height: "20px",
21-
background: disabled ? "mainBackgroundDisabled" : "mainBackground",
22-
justifyContent: "center",
17+
const styledCheckbox = useMemo(
18+
() => ({
2319
alignItems: "center",
20+
background: disabled ? "mainBackgroundDisabled" : "mainBackground",
2421
border: {
2522
size: "1px",
2623
type: "solid",
@@ -29,21 +26,25 @@ const useCheckboxStyles = ({ disabled, success, error, focused }) => {
2926
: makeColor({})[status],
3027
side: "all",
3128
},
29+
height: "inherit",
30+
justifyContent: "center",
3231
round: true,
32+
width: "inherit",
3333
_focus: {
3434
border: {
35-
size: "1px",
36-
type: "solid",
3735
color: makeColor({ defaultColor: "controlFocused" })[status],
3836
side: "all",
37+
size: "1px",
38+
type: "solid",
3939
},
4040
boxShadow: {
4141
color: makeColor({ defaultColor: "controlFocused" })[status],
4242
size: "0 0 0 1px",
4343
},
4444
},
45-
}
46-
}, [status, focused])
45+
}),
46+
[status, focused]
47+
)
4748

4849
return { styles: { styledCheckbox } }
4950
}

src/components/drops/drop/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface DropProps extends FlexProps, AlignProps, StretchProps {
66
backdropProps?: any
77
canHideTarget?: boolean
88
children: any
9-
hideShadow: boolean
9+
hideShadow?: boolean
1010
onClickOutside?: Function
1111
onEsc?: Function
1212
target: object

src/components/drops/mixins/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface AlignProps {
2-
align:
2+
align?:
33
| { top: "top" }
44
| { top: "top"; right: "left" }
55
| { top: "top"; right: "right" }

src/components/tableV2/components/actionWithDropdown.js

+34-8
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,49 @@ import BulkAction from "./bulkAction"
44
import ColumnsMenu from "./columnsMenu" //todo refactor this as right now is used only for the dropdown for column visibility
55

66
const ActionWithDropdown = ({
7+
alwaysEnabled,
8+
columnPinning = {},
9+
enableColumnPinning,
10+
handleAction,
711
id,
812
icon,
9-
handleAction,
10-
tooltipText,
11-
alwaysEnabled,
1213
isDisabled,
14+
isOpen,
1315
isVisible,
14-
testPrefix,
16+
onClose,
1517
selectedRows,
1618
table,
17-
isOpen,
18-
onClose,
19+
testPrefix,
20+
tooltipText,
1921
...rest
2022
}) => {
2123
const actionRef = useRef()
2224
const disabled = typeof isDisabled === "function" ? isDisabled() : isDisabled
2325
const visible = typeof isVisible === "function" ? isVisible() : isVisible
2426

27+
const allColumns = table.getAllLeafColumns()
28+
const allPinnedColumns = enableColumnPinning
29+
? [...(columnPinning?.left || []), ...(columnPinning?.right || [])]
30+
: []
31+
const { columns, pinnedColumns } = enableColumnPinning
32+
? allColumns.reduce(
33+
(accumulator, column) => {
34+
if (!column.getCanHide()) return accumulator
35+
36+
let key = "columns"
37+
if (allPinnedColumns.includes(column.id)) {
38+
key = "pinnedColumns"
39+
}
40+
41+
return {
42+
...accumulator,
43+
[key]: [...accumulator[key], column],
44+
}
45+
},
46+
{ columns: [], pinnedColumns: [] }
47+
)
48+
: { columns: allColumns, pinnedColumns: [] }
49+
2550
return (
2651
<>
2752
<BulkAction
@@ -38,10 +63,11 @@ const ActionWithDropdown = ({
3863
{...rest}
3964
/>
4065
<ColumnsMenu
41-
parentRef={actionRef}
66+
columns={columns}
4267
isOpen={isOpen}
43-
columns={table.getAllLeafColumns()}
4468
onClose={onClose}
69+
parentRef={actionRef}
70+
pinnedColumns={pinnedColumns}
4571
/>
4672
</>
4773
)

0 commit comments

Comments
 (0)