@canonical/react-components 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ColumnSelector/ColumnSelector.d.ts +32 -0
- package/dist/components/ColumnSelector/ColumnSelector.js +86 -0
- package/dist/components/ColumnSelector/ColumnSelector.scss +15 -0
- package/dist/components/ColumnSelector/ColumnSelector.stories.d.ts +6 -0
- package/dist/components/ColumnSelector/ColumnSelector.stories.js +48 -0
- package/dist/components/ColumnSelector/ColumnSelector.test.d.ts +1 -0
- package/dist/components/ColumnSelector/ColumnSelectorStoriesHelper.d.ts +15 -0
- package/dist/components/ColumnSelector/ColumnSelectorStoriesHelper.js +150 -0
- package/dist/components/ColumnSelector/columnSelectorHelper.d.ts +3 -0
- package/dist/components/ColumnSelector/columnSelectorHelper.js +17 -0
- package/dist/components/ColumnSelector/index.d.ts +3 -0
- package/dist/components/ColumnSelector/index.js +26 -0
- package/dist/components/CustomSelect/CustomSelect.js +1 -1
- package/dist/components/CustomSelect/CustomSelect.stories.d.ts +6 -0
- package/dist/components/CustomSelect/CustomSelect.stories.js +103 -1
- package/dist/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.d.ts +1 -0
- package/dist/components/Select/Select.d.ts +5 -1
- package/dist/components/Select/Select.js +2 -0
- package/dist/esm/components/ColumnSelector/ColumnSelector.d.ts +32 -0
- package/dist/esm/components/ColumnSelector/ColumnSelector.js +79 -0
- package/dist/esm/components/ColumnSelector/ColumnSelector.scss +15 -0
- package/dist/esm/components/ColumnSelector/ColumnSelector.stories.d.ts +6 -0
- package/dist/esm/components/ColumnSelector/ColumnSelector.stories.js +39 -0
- package/dist/esm/components/ColumnSelector/ColumnSelector.test.d.ts +1 -0
- package/dist/esm/components/ColumnSelector/ColumnSelectorStoriesHelper.d.ts +15 -0
- package/dist/esm/components/ColumnSelector/ColumnSelectorStoriesHelper.js +142 -0
- package/dist/esm/components/ColumnSelector/columnSelectorHelper.d.ts +3 -0
- package/dist/esm/components/ColumnSelector/columnSelectorHelper.js +13 -0
- package/dist/esm/components/ColumnSelector/index.d.ts +3 -0
- package/dist/esm/components/ColumnSelector/index.js +2 -0
- package/dist/esm/components/CustomSelect/CustomSelect.js +1 -1
- package/dist/esm/components/CustomSelect/CustomSelect.stories.d.ts +6 -0
- package/dist/esm/components/CustomSelect/CustomSelect.stories.js +102 -0
- package/dist/esm/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.d.ts +1 -0
- package/dist/esm/components/Select/Select.d.ts +5 -1
- package/dist/esm/components/Select/Select.js +3 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { HTMLProps } from "react";
|
|
2
|
+
import { ClassName, PropsWithSpread } from "../../types";
|
|
3
|
+
import "./ColumnSelector.scss";
|
|
4
|
+
export type Props = PropsWithSpread<{
|
|
5
|
+
/**
|
|
6
|
+
* Optional classes to add to the contextual menu.
|
|
7
|
+
*/
|
|
8
|
+
className?: ClassName;
|
|
9
|
+
/**
|
|
10
|
+
* Columns of the table that can be hidden by the user
|
|
11
|
+
*/
|
|
12
|
+
columns: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Columns of the table hidden by the user
|
|
15
|
+
*/
|
|
16
|
+
userHidden: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Columns of the table hidden because the available space is not sufficient
|
|
19
|
+
*/
|
|
20
|
+
sizeHidden: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Function that sets columns hidden by the user
|
|
23
|
+
*/
|
|
24
|
+
setUserHidden: (columns: string[]) => void;
|
|
25
|
+
}, HTMLProps<HTMLElement>>;
|
|
26
|
+
/**
|
|
27
|
+
This is a [React](https://reactjs.org/) component that extends from the Vanilla [Select](https://vanillaframework.io/docs/base/forms#select) element.
|
|
28
|
+
The aim of this component is to provide a dropdown menu to control the visibility of columns within a table.
|
|
29
|
+
This component allows users to customize their view, hiding or showing columns as needed, while also handling columns that are automatically hidden on smaller screens.
|
|
30
|
+
*/
|
|
31
|
+
declare const ColumnSelector: ({ className, columns, userHidden, sizeHidden, setUserHidden, }: Props) => React.JSX.Element;
|
|
32
|
+
export default ColumnSelector;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
var _Tooltip = _interopRequireDefault(require("../Tooltip"));
|
|
10
|
+
var _ContextualMenu = _interopRequireDefault(require("../ContextualMenu"));
|
|
11
|
+
var _Icon = _interopRequireDefault(require("../Icon"));
|
|
12
|
+
var _CheckboxInput = _interopRequireDefault(require("../CheckboxInput"));
|
|
13
|
+
require("./ColumnSelector.scss");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
/**
|
|
16
|
+
This is a [React](https://reactjs.org/) component that extends from the Vanilla [Select](https://vanillaframework.io/docs/base/forms#select) element.
|
|
17
|
+
The aim of this component is to provide a dropdown menu to control the visibility of columns within a table.
|
|
18
|
+
This component allows users to customize their view, hiding or showing columns as needed, while also handling columns that are automatically hidden on smaller screens.
|
|
19
|
+
*/
|
|
20
|
+
const ColumnSelector = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
className,
|
|
23
|
+
columns,
|
|
24
|
+
userHidden,
|
|
25
|
+
sizeHidden,
|
|
26
|
+
setUserHidden
|
|
27
|
+
} = _ref;
|
|
28
|
+
const selectedCount = columns.length - userHidden.length;
|
|
29
|
+
const toggleHiddenColumn = column => {
|
|
30
|
+
if (userHidden.includes(column)) {
|
|
31
|
+
setUserHidden(userHidden.filter(c => c !== column));
|
|
32
|
+
} else {
|
|
33
|
+
setUserHidden([...userHidden, column]);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const wrapTooltip = (element, column) => {
|
|
37
|
+
if (!sizeHidden.includes(column)) return element;
|
|
38
|
+
return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
|
|
39
|
+
message: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "Screen is too narrow to fit the column.", /*#__PURE__*/_react.default.createElement("br", null), "Disable columns above or use a bigger screen."),
|
|
40
|
+
position: "left"
|
|
41
|
+
}, element);
|
|
42
|
+
};
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement(_ContextualMenu.default, {
|
|
44
|
+
className: (0, _classnames.default)(className, "column-selector-toggle"),
|
|
45
|
+
dropdownProps: {
|
|
46
|
+
"aria-label": "columns menu"
|
|
47
|
+
},
|
|
48
|
+
position: "right",
|
|
49
|
+
toggleClassName: "has-icon",
|
|
50
|
+
toggleProps: {
|
|
51
|
+
"aria-label": "Columns selection toggle"
|
|
52
|
+
},
|
|
53
|
+
toggleLabel: /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
54
|
+
name: "settings"
|
|
55
|
+
}),
|
|
56
|
+
toggleAppearance: "base",
|
|
57
|
+
title: "Columns"
|
|
58
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
59
|
+
className: "column-selector-column-list"
|
|
60
|
+
}, /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
61
|
+
checked: userHidden.length === 0,
|
|
62
|
+
indeterminate: selectedCount > 0 && selectedCount < columns.length,
|
|
63
|
+
label: "".concat(selectedCount, " out of ").concat(columns.length, " columns selected"),
|
|
64
|
+
onChange: () => {
|
|
65
|
+
if (userHidden.length > 0) {
|
|
66
|
+
setUserHidden([]);
|
|
67
|
+
} else {
|
|
68
|
+
setUserHidden(columns);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}), /*#__PURE__*/_react.default.createElement("hr", null), columns.map(column => /*#__PURE__*/_react.default.createElement("div", {
|
|
72
|
+
key: column
|
|
73
|
+
}, wrapTooltip( /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
74
|
+
"aria-label": column,
|
|
75
|
+
labelClassName: (0, _classnames.default)({
|
|
76
|
+
"size-hidden": sizeHidden.includes(column)
|
|
77
|
+
}),
|
|
78
|
+
checked: !userHidden.includes(column),
|
|
79
|
+
label: column,
|
|
80
|
+
onChange: () => {
|
|
81
|
+
toggleHiddenColumn(column);
|
|
82
|
+
},
|
|
83
|
+
disabled: sizeHidden.includes(column)
|
|
84
|
+
}), column)))));
|
|
85
|
+
};
|
|
86
|
+
var _default = exports.default = ColumnSelector;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.Default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _ColumnSelector = _interopRequireDefault(require("./ColumnSelector"));
|
|
9
|
+
var _MainTable = _interopRequireDefault(require("../MainTable"));
|
|
10
|
+
var _ColumnSelectorStoriesHelper = require("./ColumnSelectorStoriesHelper");
|
|
11
|
+
var _columnSelectorHelper = require("./columnSelectorHelper");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
const meta = {
|
|
16
|
+
component: _ColumnSelector.default,
|
|
17
|
+
tags: ["autodocs"]
|
|
18
|
+
};
|
|
19
|
+
var _default = exports.default = meta;
|
|
20
|
+
const Default = exports.Default = {
|
|
21
|
+
render: () => {
|
|
22
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
23
|
+
const [userHidden, setUserHidden] = (0, _react.useState)([_ColumnSelectorStoriesHelper.FILESYSTEM, _ColumnSelectorStoriesHelper.SNAPSHOTS, _ColumnSelectorStoriesHelper.CLUSTER_MEMBER]);
|
|
24
|
+
const sizeHidden = [_ColumnSelectorStoriesHelper.DESCRIPTION];
|
|
25
|
+
const hiddenColumns = userHidden.concat(sizeHidden);
|
|
26
|
+
const ROWS = (0, _ColumnSelectorStoriesHelper.getRows)();
|
|
27
|
+
const setUserHiddenAndSaveInLocalStorage = columns => {
|
|
28
|
+
setUserHidden(columns);
|
|
29
|
+
};
|
|
30
|
+
const displayedRows = (0, _columnSelectorHelper.visibleRowColumns)(ROWS, hiddenColumns);
|
|
31
|
+
const displayedHeaders = (0, _columnSelectorHelper.visibleHeaderColumns)(_ColumnSelectorStoriesHelper.COLUMN_HEADERS.map(t => {
|
|
32
|
+
return {
|
|
33
|
+
content: t,
|
|
34
|
+
sortKey: t
|
|
35
|
+
};
|
|
36
|
+
}), hiddenColumns);
|
|
37
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ColumnSelector.default, {
|
|
38
|
+
columns: _ColumnSelectorStoriesHelper.USER_HIDEABLE_COLUMNS,
|
|
39
|
+
userHidden: userHidden,
|
|
40
|
+
sizeHidden: sizeHidden,
|
|
41
|
+
setUserHidden: setUserHiddenAndSaveInLocalStorage
|
|
42
|
+
}), /*#__PURE__*/_react.default.createElement(_MainTable.default, {
|
|
43
|
+
rows: displayedRows,
|
|
44
|
+
headers: displayedHeaders
|
|
45
|
+
}));
|
|
46
|
+
},
|
|
47
|
+
name: "Default"
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MainTableRow } from "../MainTable/MainTable";
|
|
2
|
+
export declare const STATUS = "Status";
|
|
3
|
+
export declare const NAME = "Name";
|
|
4
|
+
export declare const TYPE = "Type";
|
|
5
|
+
export declare const CLUSTER_MEMBER = "Cluster member";
|
|
6
|
+
export declare const DESCRIPTION = "Description";
|
|
7
|
+
export declare const MEMORY = "Memory";
|
|
8
|
+
export declare const FILESYSTEM = "Root filesystem";
|
|
9
|
+
export declare const IPV4 = "IPv4";
|
|
10
|
+
export declare const IPV6 = "IPv6";
|
|
11
|
+
export declare const SNAPSHOTS = "Snapshots";
|
|
12
|
+
export declare const PROJECT = "Project";
|
|
13
|
+
export declare const COLUMN_HEADERS: string[];
|
|
14
|
+
export declare const USER_HIDEABLE_COLUMNS: string[];
|
|
15
|
+
export declare const getRows: () => MainTableRow[];
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getRows = exports.USER_HIDEABLE_COLUMNS = exports.TYPE = exports.STATUS = exports.SNAPSHOTS = exports.PROJECT = exports.NAME = exports.MEMORY = exports.IPV6 = exports.IPV4 = exports.FILESYSTEM = exports.DESCRIPTION = exports.COLUMN_HEADERS = exports.CLUSTER_MEMBER = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
const STATUS = exports.STATUS = "Status";
|
|
10
|
+
const NAME = exports.NAME = "Name";
|
|
11
|
+
const TYPE = exports.TYPE = "Type";
|
|
12
|
+
const CLUSTER_MEMBER = exports.CLUSTER_MEMBER = "Cluster member";
|
|
13
|
+
const DESCRIPTION = exports.DESCRIPTION = "Description";
|
|
14
|
+
const MEMORY = exports.MEMORY = "Memory";
|
|
15
|
+
const FILESYSTEM = exports.FILESYSTEM = "Root filesystem";
|
|
16
|
+
const IPV4 = exports.IPV4 = "IPv4";
|
|
17
|
+
const IPV6 = exports.IPV6 = "IPv6";
|
|
18
|
+
const SNAPSHOTS = exports.SNAPSHOTS = "Snapshots";
|
|
19
|
+
const PROJECT = exports.PROJECT = "Project";
|
|
20
|
+
const COLUMN_HEADERS = exports.COLUMN_HEADERS = [NAME, TYPE, PROJECT, CLUSTER_MEMBER, MEMORY, FILESYSTEM, DESCRIPTION, IPV4, IPV6, SNAPSHOTS, STATUS];
|
|
21
|
+
|
|
22
|
+
// All columns except name and status
|
|
23
|
+
const USER_HIDEABLE_COLUMNS = exports.USER_HIDEABLE_COLUMNS = [TYPE, PROJECT, CLUSTER_MEMBER, MEMORY, FILESYSTEM, DESCRIPTION, IPV4, IPV6, SNAPSHOTS];
|
|
24
|
+
const INSTANCES = [{
|
|
25
|
+
name: "darling-bunny",
|
|
26
|
+
type: "VM",
|
|
27
|
+
project: "default",
|
|
28
|
+
clusterMember: "-",
|
|
29
|
+
memory: "1.4 GiB of 1.9 GiB",
|
|
30
|
+
fileSystem: "3.3 GiB of 9.5 GiB",
|
|
31
|
+
description: "Meet darling-bunny, a speedy little instance hopping along with your latest project. It's got the ears for listening to your commands and the nose for sniffing out the best performance. Handle with care, and remember to feed it plenty of CPU.",
|
|
32
|
+
ipv4: ["10.138.32.6"],
|
|
33
|
+
ipv6: ["fd42:6a38:859a:587d:216:3eff:fe43:167e", "fe80::216:3eff:fe43:167e", "fe80::1050:62ff:feb2:964c"],
|
|
34
|
+
status: "Running"
|
|
35
|
+
}, {
|
|
36
|
+
name: "sassy-salamander",
|
|
37
|
+
type: "VM",
|
|
38
|
+
project: "default",
|
|
39
|
+
clusterMember: "-",
|
|
40
|
+
memory: "1.4 GiB of 1.9 GiB",
|
|
41
|
+
fileSystem: "3.3 GiB of 9.5 GiB",
|
|
42
|
+
description: "sassy-salamander is a resilient and feisty instance, perfectly at home in any environment—from the scorching heat of a web server to the damp coolness of a database. Don't let its size fool you; it's quick, adaptable, and not afraid to tackle complex tasks.",
|
|
43
|
+
ipv4: ["10.138.32.6"],
|
|
44
|
+
ipv6: ["fd42:6a38:859a:587d:216:3eff:fe43:167e", "fe80::216:3eff:fe43:167e", "fe80::1050:62ff:feb2:964c"],
|
|
45
|
+
status: "Running"
|
|
46
|
+
}, {
|
|
47
|
+
name: "fun-feline",
|
|
48
|
+
type: "Container",
|
|
49
|
+
project: "default",
|
|
50
|
+
clusterMember: "-",
|
|
51
|
+
memory: "0.7 GiB of 1.9 GiB",
|
|
52
|
+
fileSystem: "1.1 GiB of 9.5 GiB",
|
|
53
|
+
description: "fun-feline is a purr-fectly agile and independent instance. It’s got nine lives for all your testing needs and a mischievous spirit for tackling the toughest tasks. Just be sure to give it enough RAM—it loves to stretch out.",
|
|
54
|
+
ipv4: ["10.138.32.6"],
|
|
55
|
+
ipv6: ["fd42:6a38:859a:587d:216:3eff:fe43:167e", "fe80::216:3eff:fe43:167e", "fe80::1050:62ff:feb2:964c"],
|
|
56
|
+
snapshots: ["1", "2"],
|
|
57
|
+
status: "Stopped"
|
|
58
|
+
}];
|
|
59
|
+
const getRows = () => {
|
|
60
|
+
const instanceRows = INSTANCES.map(instance => {
|
|
61
|
+
var _instance$snapshots$l, _instance$snapshots;
|
|
62
|
+
return {
|
|
63
|
+
key: instance.name,
|
|
64
|
+
name: instance.name,
|
|
65
|
+
columns: [{
|
|
66
|
+
content: instance.name,
|
|
67
|
+
className: "u-truncate",
|
|
68
|
+
title: "Instance ".concat(instance.name),
|
|
69
|
+
role: "rowheader",
|
|
70
|
+
"aria-label": NAME,
|
|
71
|
+
// needed
|
|
72
|
+
onClick: () => console.log("Click on instance", instance.name)
|
|
73
|
+
}, {
|
|
74
|
+
content: /*#__PURE__*/_react.default.createElement("span", null, instance.type),
|
|
75
|
+
className: "clickable-cell",
|
|
76
|
+
role: "cell",
|
|
77
|
+
"aria-label": TYPE,
|
|
78
|
+
// needed
|
|
79
|
+
onClick: () => console.log("Click on instance", instance.type)
|
|
80
|
+
}, {
|
|
81
|
+
content: /*#__PURE__*/_react.default.createElement("a", null, instance.project),
|
|
82
|
+
role: "cell",
|
|
83
|
+
"aria-label": PROJECT // needed
|
|
84
|
+
}, {
|
|
85
|
+
content: /*#__PURE__*/_react.default.createElement("a", null, instance.clusterMember),
|
|
86
|
+
role: "cell",
|
|
87
|
+
"aria-label": CLUSTER_MEMBER // needed
|
|
88
|
+
}, {
|
|
89
|
+
content: instance.memory,
|
|
90
|
+
className: "clickable-cell",
|
|
91
|
+
role: "cell",
|
|
92
|
+
"aria-label": MEMORY,
|
|
93
|
+
// needed
|
|
94
|
+
onClick: () => console.log("Click on instance", instance.memory)
|
|
95
|
+
}, {
|
|
96
|
+
content: instance.fileSystem,
|
|
97
|
+
className: "clickable-cell",
|
|
98
|
+
role: "cell",
|
|
99
|
+
"aria-label": FILESYSTEM,
|
|
100
|
+
// needed
|
|
101
|
+
onClick: () => console.log("Click on instance", instance.fileSystem)
|
|
102
|
+
}, {
|
|
103
|
+
content: /*#__PURE__*/_react.default.createElement("div", {
|
|
104
|
+
className: "u-truncate",
|
|
105
|
+
title: instance.description
|
|
106
|
+
}, instance.description),
|
|
107
|
+
className: "clickable-cell",
|
|
108
|
+
role: "cell",
|
|
109
|
+
"aria-label": DESCRIPTION,
|
|
110
|
+
// needed
|
|
111
|
+
onClick: () => console.log("Click on instance", instance.description)
|
|
112
|
+
}, {
|
|
113
|
+
key: "ipv4-".concat(instance.ipv4.length),
|
|
114
|
+
content: instance.ipv4.join(", "),
|
|
115
|
+
className: "u-align--right clickable-cell",
|
|
116
|
+
role: "cell",
|
|
117
|
+
"aria-label": IPV4,
|
|
118
|
+
// needed
|
|
119
|
+
onClick: () => console.log("Click on instance", instance.ipv4)
|
|
120
|
+
}, {
|
|
121
|
+
key: "ipv6-".concat(instance.ipv6.length),
|
|
122
|
+
content: instance.ipv6.join(", "),
|
|
123
|
+
className: "clickable-cell",
|
|
124
|
+
role: "cell",
|
|
125
|
+
"aria-label": IPV6,
|
|
126
|
+
// needed
|
|
127
|
+
onClick: () => console.log("Click on instance", instance.ipv6)
|
|
128
|
+
}, {
|
|
129
|
+
content: (_instance$snapshots$l = (_instance$snapshots = instance.snapshots) === null || _instance$snapshots === void 0 ? void 0 : _instance$snapshots.length) !== null && _instance$snapshots$l !== void 0 ? _instance$snapshots$l : "0",
|
|
130
|
+
className: "u-align--right clickable-cell",
|
|
131
|
+
role: "cell",
|
|
132
|
+
"aria-label": SNAPSHOTS,
|
|
133
|
+
// needed
|
|
134
|
+
onClick: () => {
|
|
135
|
+
var _instance$snapshots2;
|
|
136
|
+
return console.log("Click on instance", (_instance$snapshots2 = instance.snapshots) === null || _instance$snapshots2 === void 0 ? void 0 : _instance$snapshots2.length);
|
|
137
|
+
}
|
|
138
|
+
}, {
|
|
139
|
+
content: instance.status,
|
|
140
|
+
role: "cell",
|
|
141
|
+
className: "clickable-cell",
|
|
142
|
+
"aria-label": STATUS,
|
|
143
|
+
// needed
|
|
144
|
+
onClick: () => console.log("Click on instance", instance.status)
|
|
145
|
+
}]
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
return instanceRows;
|
|
149
|
+
};
|
|
150
|
+
exports.getRows = getRows;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MainTableHeader, MainTableRow } from "../MainTable/MainTable";
|
|
2
|
+
export declare const visibleRowColumns: (rows: MainTableRow[], hiddenCols: string[]) => MainTableRow[];
|
|
3
|
+
export declare const visibleHeaderColumns: (headers: MainTableHeader[], hiddenCols: string[]) => MainTableHeader[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.visibleRowColumns = exports.visibleHeaderColumns = void 0;
|
|
7
|
+
const visibleRowColumns = (rows, hiddenCols) => {
|
|
8
|
+
return rows.map(row => {
|
|
9
|
+
return {
|
|
10
|
+
...row,
|
|
11
|
+
columns: row.columns.filter(item => !hiddenCols.includes(item["aria-label"]))
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.visibleRowColumns = visibleRowColumns;
|
|
16
|
+
const visibleHeaderColumns = (headers, hiddenCols) => headers.filter(item => typeof item.content !== "string" || !hiddenCols.includes(item.content));
|
|
17
|
+
exports.visibleHeaderColumns = visibleHeaderColumns;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ColumnSelector.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "visibleHeaderColumns", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _columnSelectorHelper.visibleHeaderColumns;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "visibleRowColumns", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _columnSelectorHelper.visibleRowColumns;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _ColumnSelector = _interopRequireDefault(require("./ColumnSelector"));
|
|
25
|
+
var _columnSelectorHelper = require("./columnSelectorHelper");
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -81,7 +81,7 @@ const CustomSelect = _ref => {
|
|
|
81
81
|
const selectedOption = options.find(option => option.value === value);
|
|
82
82
|
const toggleLabel = /*#__PURE__*/_react.default.createElement("span", {
|
|
83
83
|
className: "toggle-label u-truncate"
|
|
84
|
-
}, selectedOption ? (0, _CustomSelectDropdown.getOptionText)(selectedOption) : "Select an option");
|
|
84
|
+
}, selectedOption ? selectedOption.selectedLabel || (0, _CustomSelectDropdown.getOptionText)(selectedOption) : "Select an option");
|
|
85
85
|
const handleSelect = value => {
|
|
86
86
|
var _document$getElementB3;
|
|
87
87
|
(_document$getElementB3 = document.getElementById(selectId)) === null || _document$getElementB3 === void 0 || _document$getElementB3.focus();
|
|
@@ -14,6 +14,12 @@ export declare const StandardOptions: Story;
|
|
|
14
14
|
* In this case, the `text` property for each option is required and is used for display in the toggle, search and sort functionalities.
|
|
15
15
|
*/
|
|
16
16
|
export declare const CustomOptions: Story;
|
|
17
|
+
/**
|
|
18
|
+
* If `label` is of `ReactNode` type. You can render custom content.
|
|
19
|
+
* In this case, the `selectedLabel` for each option is provided and will be displayed in the toggle instead of `text`
|
|
20
|
+
* The `text` property for each option is still required and is used for search and sort functionalities.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CustomOptionsAndSelectedLabel: Story;
|
|
17
23
|
/**
|
|
18
24
|
* For each option, if `disabled` is set to `true`, the option will be disabled.
|
|
19
25
|
*/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.StandardOptions = exports.ManualSearchable = exports.DisabledOptions = exports.CustomOptions = exports.AutoSearchable = void 0;
|
|
6
|
+
exports.default = exports.StandardOptions = exports.ManualSearchable = exports.DisabledOptions = exports.CustomOptionsAndSelectedLabel = exports.CustomOptions = exports.AutoSearchable = void 0;
|
|
7
7
|
var _CustomSelect = _interopRequireDefault(require("./CustomSelect"));
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -44,6 +44,95 @@ const generateCustomOptions = () => {
|
|
|
44
44
|
disabled: false
|
|
45
45
|
}];
|
|
46
46
|
};
|
|
47
|
+
const generateCustomOptionsWithSelectedLabel = () => {
|
|
48
|
+
const options = [{
|
|
49
|
+
type: "ovn",
|
|
50
|
+
name: "ovntest",
|
|
51
|
+
config: {
|
|
52
|
+
"security.acls": "foo,bar"
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
type: "bridge",
|
|
56
|
+
name: "lxdbr0",
|
|
57
|
+
config: {}
|
|
58
|
+
}, {
|
|
59
|
+
type: "bridge",
|
|
60
|
+
name: "microbr0",
|
|
61
|
+
config: {}
|
|
62
|
+
}, {
|
|
63
|
+
type: "macvlan",
|
|
64
|
+
name: "macvlantest",
|
|
65
|
+
config: {}
|
|
66
|
+
}].map(network => {
|
|
67
|
+
var _network$config$secur;
|
|
68
|
+
return {
|
|
69
|
+
label: /*#__PURE__*/_react.default.createElement("div", {
|
|
70
|
+
className: "label",
|
|
71
|
+
style: {
|
|
72
|
+
display: "flex",
|
|
73
|
+
gap: "5px"
|
|
74
|
+
}
|
|
75
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
76
|
+
title: network.name,
|
|
77
|
+
className: "network-option u-truncate",
|
|
78
|
+
style: {
|
|
79
|
+
width: "12rem"
|
|
80
|
+
}
|
|
81
|
+
}, network.name), /*#__PURE__*/_react.default.createElement("span", {
|
|
82
|
+
title: network.type,
|
|
83
|
+
className: "network-option u-truncate",
|
|
84
|
+
style: {
|
|
85
|
+
width: "8rem"
|
|
86
|
+
}
|
|
87
|
+
}, network.type), /*#__PURE__*/_react.default.createElement("span", {
|
|
88
|
+
title: "network ACLs",
|
|
89
|
+
className: "network-option u-truncate u-align--right",
|
|
90
|
+
style: {
|
|
91
|
+
paddingRight: "8px",
|
|
92
|
+
width: "4rem"
|
|
93
|
+
}
|
|
94
|
+
}, ((_network$config$secur = network.config["security.acls"]) === null || _network$config$secur === void 0 ? void 0 : _network$config$secur.length) || "-")),
|
|
95
|
+
value: network.name,
|
|
96
|
+
text: "".concat(network.name, " - ").concat(network.type),
|
|
97
|
+
disabled: false,
|
|
98
|
+
selectedLabel: /*#__PURE__*/_react.default.createElement("span", null, network.name, "\xA0", /*#__PURE__*/_react.default.createElement("span", {
|
|
99
|
+
className: "u-text--muted"
|
|
100
|
+
}, "(", network.type, ")"))
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
return options;
|
|
104
|
+
};
|
|
105
|
+
const getHeader = () => {
|
|
106
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
107
|
+
className: "header",
|
|
108
|
+
style: {
|
|
109
|
+
backgroundColor: "$colors--theme--background-alt",
|
|
110
|
+
display: "flex",
|
|
111
|
+
gap: "$sph--small",
|
|
112
|
+
padding: "$sph--x-small $sph--small",
|
|
113
|
+
position: "sticky",
|
|
114
|
+
top: 0
|
|
115
|
+
}
|
|
116
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
117
|
+
className: "network-option u-no-margin--bottom",
|
|
118
|
+
style: {
|
|
119
|
+
color: "$colors--theme--text-default",
|
|
120
|
+
width: "12rem"
|
|
121
|
+
}
|
|
122
|
+
}, "Name"), /*#__PURE__*/_react.default.createElement("span", {
|
|
123
|
+
className: "network-option u-no-margin--bottom",
|
|
124
|
+
style: {
|
|
125
|
+
color: "$colors--theme--text-default",
|
|
126
|
+
width: "8rem"
|
|
127
|
+
}
|
|
128
|
+
}, "Type"), /*#__PURE__*/_react.default.createElement("span", {
|
|
129
|
+
className: "network-option u-no-margin--bottom",
|
|
130
|
+
style: {
|
|
131
|
+
color: "$colors--theme--text-default",
|
|
132
|
+
width: "4rem"
|
|
133
|
+
}
|
|
134
|
+
}, "ACLs"));
|
|
135
|
+
};
|
|
47
136
|
const Template = _ref => {
|
|
48
137
|
let {
|
|
49
138
|
...props
|
|
@@ -99,6 +188,19 @@ const CustomOptions = exports.CustomOptions = {
|
|
|
99
188
|
}
|
|
100
189
|
};
|
|
101
190
|
|
|
191
|
+
/**
|
|
192
|
+
* If `label` is of `ReactNode` type. You can render custom content.
|
|
193
|
+
* In this case, the `selectedLabel` for each option is provided and will be displayed in the toggle instead of `text`
|
|
194
|
+
* The `text` property for each option is still required and is used for search and sort functionalities.
|
|
195
|
+
*/
|
|
196
|
+
const CustomOptionsAndSelectedLabel = exports.CustomOptionsAndSelectedLabel = {
|
|
197
|
+
args: {
|
|
198
|
+
options: generateCustomOptionsWithSelectedLabel(),
|
|
199
|
+
header: getHeader(),
|
|
200
|
+
dropdownClassName: "network-select-dropdown"
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
102
204
|
/**
|
|
103
205
|
* For each option, if `disabled` is set to `true`, the option will be disabled.
|
|
104
206
|
*/
|
|
@@ -22,6 +22,10 @@ export type Props = PropsWithSpread<{
|
|
|
22
22
|
* Help text to show below the field.
|
|
23
23
|
*/
|
|
24
24
|
help?: ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Optional class(es) to pass to the help text element.
|
|
27
|
+
*/
|
|
28
|
+
helpClassName?: string;
|
|
25
29
|
/**
|
|
26
30
|
* The id of the input.
|
|
27
31
|
*/
|
|
@@ -68,5 +72,5 @@ export type Props = PropsWithSpread<{
|
|
|
68
72
|
*
|
|
69
73
|
* Use the Select component to create a drop-down list.
|
|
70
74
|
*/
|
|
71
|
-
declare const Select: ({ caution, className, error, help, id, label, labelClassName, onChange, options, required, stacked, success, takeFocus, wrapperClassName, ...selectProps }: Props) => React.JSX.Element;
|
|
75
|
+
declare const Select: ({ caution, className, error, help, helpClassName, id, label, labelClassName, onChange, options, required, stacked, success, takeFocus, wrapperClassName, ...selectProps }: Props) => React.JSX.Element;
|
|
72
76
|
export default Select;
|
|
@@ -38,6 +38,7 @@ const Select = _ref2 => {
|
|
|
38
38
|
className,
|
|
39
39
|
error,
|
|
40
40
|
help,
|
|
41
|
+
helpClassName,
|
|
41
42
|
id,
|
|
42
43
|
label,
|
|
43
44
|
labelClassName,
|
|
@@ -67,6 +68,7 @@ const Select = _ref2 => {
|
|
|
67
68
|
error: error,
|
|
68
69
|
forId: selectId,
|
|
69
70
|
help: help,
|
|
71
|
+
helpClassName: helpClassName,
|
|
70
72
|
helpId: helpId,
|
|
71
73
|
isSelect: true,
|
|
72
74
|
label: label,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { HTMLProps } from "react";
|
|
2
|
+
import { ClassName, PropsWithSpread } from "../../types";
|
|
3
|
+
import "./ColumnSelector.scss";
|
|
4
|
+
export type Props = PropsWithSpread<{
|
|
5
|
+
/**
|
|
6
|
+
* Optional classes to add to the contextual menu.
|
|
7
|
+
*/
|
|
8
|
+
className?: ClassName;
|
|
9
|
+
/**
|
|
10
|
+
* Columns of the table that can be hidden by the user
|
|
11
|
+
*/
|
|
12
|
+
columns: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Columns of the table hidden by the user
|
|
15
|
+
*/
|
|
16
|
+
userHidden: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Columns of the table hidden because the available space is not sufficient
|
|
19
|
+
*/
|
|
20
|
+
sizeHidden: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Function that sets columns hidden by the user
|
|
23
|
+
*/
|
|
24
|
+
setUserHidden: (columns: string[]) => void;
|
|
25
|
+
}, HTMLProps<HTMLElement>>;
|
|
26
|
+
/**
|
|
27
|
+
This is a [React](https://reactjs.org/) component that extends from the Vanilla [Select](https://vanillaframework.io/docs/base/forms#select) element.
|
|
28
|
+
The aim of this component is to provide a dropdown menu to control the visibility of columns within a table.
|
|
29
|
+
This component allows users to customize their view, hiding or showing columns as needed, while also handling columns that are automatically hidden on smaller screens.
|
|
30
|
+
*/
|
|
31
|
+
declare const ColumnSelector: ({ className, columns, userHidden, sizeHidden, setUserHidden, }: Props) => React.JSX.Element;
|
|
32
|
+
export default ColumnSelector;
|