@canonical/react-components 3.2.0 → 3.3.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.
Files changed (37) hide show
  1. package/dist/components/ColumnSelector/ColumnSelector.d.ts +32 -0
  2. package/dist/components/ColumnSelector/ColumnSelector.js +86 -0
  3. package/dist/components/ColumnSelector/ColumnSelector.scss +15 -0
  4. package/dist/components/ColumnSelector/ColumnSelector.stories.d.ts +6 -0
  5. package/dist/components/ColumnSelector/ColumnSelector.stories.js +48 -0
  6. package/dist/components/ColumnSelector/ColumnSelector.test.d.ts +1 -0
  7. package/dist/components/ColumnSelector/ColumnSelectorStoriesHelper.d.ts +15 -0
  8. package/dist/components/ColumnSelector/ColumnSelectorStoriesHelper.js +150 -0
  9. package/dist/components/ColumnSelector/columnSelectorHelper.d.ts +3 -0
  10. package/dist/components/ColumnSelector/columnSelectorHelper.js +17 -0
  11. package/dist/components/ColumnSelector/index.d.ts +3 -0
  12. package/dist/components/ColumnSelector/index.js +26 -0
  13. package/dist/components/CustomSelect/CustomSelect.js +1 -1
  14. package/dist/components/CustomSelect/CustomSelect.stories.d.ts +6 -0
  15. package/dist/components/CustomSelect/CustomSelect.stories.js +103 -1
  16. package/dist/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.d.ts +1 -0
  17. package/dist/esm/components/ColumnSelector/ColumnSelector.d.ts +32 -0
  18. package/dist/esm/components/ColumnSelector/ColumnSelector.js +79 -0
  19. package/dist/esm/components/ColumnSelector/ColumnSelector.scss +15 -0
  20. package/dist/esm/components/ColumnSelector/ColumnSelector.stories.d.ts +6 -0
  21. package/dist/esm/components/ColumnSelector/ColumnSelector.stories.js +39 -0
  22. package/dist/esm/components/ColumnSelector/ColumnSelector.test.d.ts +1 -0
  23. package/dist/esm/components/ColumnSelector/ColumnSelectorStoriesHelper.d.ts +15 -0
  24. package/dist/esm/components/ColumnSelector/ColumnSelectorStoriesHelper.js +142 -0
  25. package/dist/esm/components/ColumnSelector/columnSelectorHelper.d.ts +3 -0
  26. package/dist/esm/components/ColumnSelector/columnSelectorHelper.js +13 -0
  27. package/dist/esm/components/ColumnSelector/index.d.ts +3 -0
  28. package/dist/esm/components/ColumnSelector/index.js +2 -0
  29. package/dist/esm/components/CustomSelect/CustomSelect.js +1 -1
  30. package/dist/esm/components/CustomSelect/CustomSelect.stories.d.ts +6 -0
  31. package/dist/esm/components/CustomSelect/CustomSelect.stories.js +102 -0
  32. package/dist/esm/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.d.ts +1 -0
  33. package/dist/esm/index.d.ts +2 -0
  34. package/dist/esm/index.js +1 -0
  35. package/dist/index.d.ts +2 -0
  36. package/dist/index.js +22 -0
  37. 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,15 @@
1
+ @import "vanilla-framework";
2
+ @include vf-b-placeholders;
3
+ @include vf-p-icon-settings;
4
+
5
+ .column-selector-column-list {
6
+ min-width: 12rem;
7
+
8
+ .p-checkbox {
9
+ margin-left: 1rem;
10
+ }
11
+
12
+ .size-hidden > * {
13
+ opacity: 0.33;
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+ import { Meta, StoryObj } from "@storybook/react";
2
+ import ColumnSelector from "./ColumnSelector";
3
+ declare const meta: Meta<typeof ColumnSelector>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof ColumnSelector>;
6
+ export declare const Default: Story;
@@ -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,3 @@
1
+ export { default } from "./ColumnSelector";
2
+ export { visibleHeaderColumns, visibleRowColumns, } from "./columnSelectorHelper";
3
+ export type { Props as ColumnSelectorProps } from "./ColumnSelector";
@@ -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
  */
@@ -4,6 +4,7 @@ export type CustomSelectOption = LiHTMLAttributes<HTMLLIElement> & {
4
4
  label: ReactNode;
5
5
  text?: string;
6
6
  disabled?: boolean;
7
+ selectedLabel?: ReactNode;
7
8
  };
8
9
  export type Props = {
9
10
  searchable?: "auto" | "always" | "never";
@@ -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,79 @@
1
+ import React from "react";
2
+ import classnames from "classnames";
3
+ import Tooltip from "../Tooltip";
4
+ import ContextualMenu from "../ContextualMenu";
5
+ import Icon from "../Icon";
6
+ import CheckboxInput from "../CheckboxInput";
7
+ import "./ColumnSelector.scss";
8
+ /**
9
+ This is a [React](https://reactjs.org/) component that extends from the Vanilla [Select](https://vanillaframework.io/docs/base/forms#select) element.
10
+ The aim of this component is to provide a dropdown menu to control the visibility of columns within a table.
11
+ 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.
12
+ */
13
+ var ColumnSelector = _ref => {
14
+ var {
15
+ className,
16
+ columns,
17
+ userHidden,
18
+ sizeHidden,
19
+ setUserHidden
20
+ } = _ref;
21
+ var selectedCount = columns.length - userHidden.length;
22
+ var toggleHiddenColumn = column => {
23
+ if (userHidden.includes(column)) {
24
+ setUserHidden(userHidden.filter(c => c !== column));
25
+ } else {
26
+ setUserHidden([...userHidden, column]);
27
+ }
28
+ };
29
+ var wrapTooltip = (element, column) => {
30
+ if (!sizeHidden.includes(column)) return element;
31
+ return /*#__PURE__*/React.createElement(Tooltip, {
32
+ message: /*#__PURE__*/React.createElement(React.Fragment, null, "Screen is too narrow to fit the column.", /*#__PURE__*/React.createElement("br", null), "Disable columns above or use a bigger screen."),
33
+ position: "left"
34
+ }, element);
35
+ };
36
+ return /*#__PURE__*/React.createElement(ContextualMenu, {
37
+ className: classnames(className, "column-selector-toggle"),
38
+ dropdownProps: {
39
+ "aria-label": "columns menu"
40
+ },
41
+ position: "right",
42
+ toggleClassName: "has-icon",
43
+ toggleProps: {
44
+ "aria-label": "Columns selection toggle"
45
+ },
46
+ toggleLabel: /*#__PURE__*/React.createElement(Icon, {
47
+ name: "settings"
48
+ }),
49
+ toggleAppearance: "base",
50
+ title: "Columns"
51
+ }, /*#__PURE__*/React.createElement("div", {
52
+ className: "column-selector-column-list"
53
+ }, /*#__PURE__*/React.createElement(CheckboxInput, {
54
+ checked: userHidden.length === 0,
55
+ indeterminate: selectedCount > 0 && selectedCount < columns.length,
56
+ label: "".concat(selectedCount, " out of ").concat(columns.length, " columns selected"),
57
+ onChange: () => {
58
+ if (userHidden.length > 0) {
59
+ setUserHidden([]);
60
+ } else {
61
+ setUserHidden(columns);
62
+ }
63
+ }
64
+ }), /*#__PURE__*/React.createElement("hr", null), columns.map(column => /*#__PURE__*/React.createElement("div", {
65
+ key: column
66
+ }, wrapTooltip( /*#__PURE__*/React.createElement(CheckboxInput, {
67
+ "aria-label": column,
68
+ labelClassName: classnames({
69
+ "size-hidden": sizeHidden.includes(column)
70
+ }),
71
+ checked: !userHidden.includes(column),
72
+ label: column,
73
+ onChange: () => {
74
+ toggleHiddenColumn(column);
75
+ },
76
+ disabled: sizeHidden.includes(column)
77
+ }), column)))));
78
+ };
79
+ export default ColumnSelector;
@@ -0,0 +1,15 @@
1
+ @import "vanilla-framework";
2
+ @include vf-b-placeholders;
3
+ @include vf-p-icon-settings;
4
+
5
+ .column-selector-column-list {
6
+ min-width: 12rem;
7
+
8
+ .p-checkbox {
9
+ margin-left: 1rem;
10
+ }
11
+
12
+ .size-hidden > * {
13
+ opacity: 0.33;
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+ import { Meta, StoryObj } from "@storybook/react";
2
+ import ColumnSelector from "./ColumnSelector";
3
+ declare const meta: Meta<typeof ColumnSelector>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof ColumnSelector>;
6
+ export declare const Default: Story;
@@ -0,0 +1,39 @@
1
+ import React, { useState } from "react";
2
+ import ColumnSelector from "./ColumnSelector";
3
+ import MainTable from "../MainTable";
4
+ import { getRows, FILESYSTEM, SNAPSHOTS, USER_HIDEABLE_COLUMNS, DESCRIPTION, CLUSTER_MEMBER, COLUMN_HEADERS } from "./ColumnSelectorStoriesHelper";
5
+ import { visibleHeaderColumns, visibleRowColumns } from "./columnSelectorHelper";
6
+ var meta = {
7
+ component: ColumnSelector,
8
+ tags: ["autodocs"]
9
+ };
10
+ export default meta;
11
+ export var Default = {
12
+ render: () => {
13
+ // eslint-disable-next-line react-hooks/rules-of-hooks
14
+ var [userHidden, setUserHidden] = useState([FILESYSTEM, SNAPSHOTS, CLUSTER_MEMBER]);
15
+ var sizeHidden = [DESCRIPTION];
16
+ var hiddenColumns = userHidden.concat(sizeHidden);
17
+ var ROWS = getRows();
18
+ var setUserHiddenAndSaveInLocalStorage = columns => {
19
+ setUserHidden(columns);
20
+ };
21
+ var displayedRows = visibleRowColumns(ROWS, hiddenColumns);
22
+ var displayedHeaders = visibleHeaderColumns(COLUMN_HEADERS.map(t => {
23
+ return {
24
+ content: t,
25
+ sortKey: t
26
+ };
27
+ }), hiddenColumns);
28
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ColumnSelector, {
29
+ columns: USER_HIDEABLE_COLUMNS,
30
+ userHidden: userHidden,
31
+ sizeHidden: sizeHidden,
32
+ setUserHidden: setUserHiddenAndSaveInLocalStorage
33
+ }), /*#__PURE__*/React.createElement(MainTable, {
34
+ rows: displayedRows,
35
+ headers: displayedHeaders
36
+ }));
37
+ },
38
+ name: "Default"
39
+ };
@@ -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,142 @@
1
+ import React from "react";
2
+ export var STATUS = "Status";
3
+ export var NAME = "Name";
4
+ export var TYPE = "Type";
5
+ export var CLUSTER_MEMBER = "Cluster member";
6
+ export var DESCRIPTION = "Description";
7
+ export var MEMORY = "Memory";
8
+ export var FILESYSTEM = "Root filesystem";
9
+ export var IPV4 = "IPv4";
10
+ export var IPV6 = "IPv6";
11
+ export var SNAPSHOTS = "Snapshots";
12
+ export var PROJECT = "Project";
13
+ export var COLUMN_HEADERS = [NAME, TYPE, PROJECT, CLUSTER_MEMBER, MEMORY, FILESYSTEM, DESCRIPTION, IPV4, IPV6, SNAPSHOTS, STATUS];
14
+
15
+ // All columns except name and status
16
+ export var USER_HIDEABLE_COLUMNS = [TYPE, PROJECT, CLUSTER_MEMBER, MEMORY, FILESYSTEM, DESCRIPTION, IPV4, IPV6, SNAPSHOTS];
17
+ var INSTANCES = [{
18
+ name: "darling-bunny",
19
+ type: "VM",
20
+ project: "default",
21
+ clusterMember: "-",
22
+ memory: "1.4 GiB of 1.9 GiB",
23
+ fileSystem: "3.3 GiB of 9.5 GiB",
24
+ 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.",
25
+ ipv4: ["10.138.32.6"],
26
+ ipv6: ["fd42:6a38:859a:587d:216:3eff:fe43:167e", "fe80::216:3eff:fe43:167e", "fe80::1050:62ff:feb2:964c"],
27
+ status: "Running"
28
+ }, {
29
+ name: "sassy-salamander",
30
+ type: "VM",
31
+ project: "default",
32
+ clusterMember: "-",
33
+ memory: "1.4 GiB of 1.9 GiB",
34
+ fileSystem: "3.3 GiB of 9.5 GiB",
35
+ 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.",
36
+ ipv4: ["10.138.32.6"],
37
+ ipv6: ["fd42:6a38:859a:587d:216:3eff:fe43:167e", "fe80::216:3eff:fe43:167e", "fe80::1050:62ff:feb2:964c"],
38
+ status: "Running"
39
+ }, {
40
+ name: "fun-feline",
41
+ type: "Container",
42
+ project: "default",
43
+ clusterMember: "-",
44
+ memory: "0.7 GiB of 1.9 GiB",
45
+ fileSystem: "1.1 GiB of 9.5 GiB",
46
+ 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.",
47
+ ipv4: ["10.138.32.6"],
48
+ ipv6: ["fd42:6a38:859a:587d:216:3eff:fe43:167e", "fe80::216:3eff:fe43:167e", "fe80::1050:62ff:feb2:964c"],
49
+ snapshots: ["1", "2"],
50
+ status: "Stopped"
51
+ }];
52
+ export var getRows = () => {
53
+ var instanceRows = INSTANCES.map(instance => {
54
+ var _instance$snapshots$l, _instance$snapshots;
55
+ return {
56
+ key: instance.name,
57
+ name: instance.name,
58
+ columns: [{
59
+ content: instance.name,
60
+ className: "u-truncate",
61
+ title: "Instance ".concat(instance.name),
62
+ role: "rowheader",
63
+ "aria-label": NAME,
64
+ // needed
65
+ onClick: () => console.log("Click on instance", instance.name)
66
+ }, {
67
+ content: /*#__PURE__*/React.createElement("span", null, instance.type),
68
+ className: "clickable-cell",
69
+ role: "cell",
70
+ "aria-label": TYPE,
71
+ // needed
72
+ onClick: () => console.log("Click on instance", instance.type)
73
+ }, {
74
+ content: /*#__PURE__*/React.createElement("a", null, instance.project),
75
+ role: "cell",
76
+ "aria-label": PROJECT // needed
77
+ }, {
78
+ content: /*#__PURE__*/React.createElement("a", null, instance.clusterMember),
79
+ role: "cell",
80
+ "aria-label": CLUSTER_MEMBER // needed
81
+ }, {
82
+ content: instance.memory,
83
+ className: "clickable-cell",
84
+ role: "cell",
85
+ "aria-label": MEMORY,
86
+ // needed
87
+ onClick: () => console.log("Click on instance", instance.memory)
88
+ }, {
89
+ content: instance.fileSystem,
90
+ className: "clickable-cell",
91
+ role: "cell",
92
+ "aria-label": FILESYSTEM,
93
+ // needed
94
+ onClick: () => console.log("Click on instance", instance.fileSystem)
95
+ }, {
96
+ content: /*#__PURE__*/React.createElement("div", {
97
+ className: "u-truncate",
98
+ title: instance.description
99
+ }, instance.description),
100
+ className: "clickable-cell",
101
+ role: "cell",
102
+ "aria-label": DESCRIPTION,
103
+ // needed
104
+ onClick: () => console.log("Click on instance", instance.description)
105
+ }, {
106
+ key: "ipv4-".concat(instance.ipv4.length),
107
+ content: instance.ipv4.join(", "),
108
+ className: "u-align--right clickable-cell",
109
+ role: "cell",
110
+ "aria-label": IPV4,
111
+ // needed
112
+ onClick: () => console.log("Click on instance", instance.ipv4)
113
+ }, {
114
+ key: "ipv6-".concat(instance.ipv6.length),
115
+ content: instance.ipv6.join(", "),
116
+ className: "clickable-cell",
117
+ role: "cell",
118
+ "aria-label": IPV6,
119
+ // needed
120
+ onClick: () => console.log("Click on instance", instance.ipv6)
121
+ }, {
122
+ 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",
123
+ className: "u-align--right clickable-cell",
124
+ role: "cell",
125
+ "aria-label": SNAPSHOTS,
126
+ // needed
127
+ onClick: () => {
128
+ var _instance$snapshots2;
129
+ return console.log("Click on instance", (_instance$snapshots2 = instance.snapshots) === null || _instance$snapshots2 === void 0 ? void 0 : _instance$snapshots2.length);
130
+ }
131
+ }, {
132
+ content: instance.status,
133
+ role: "cell",
134
+ className: "clickable-cell",
135
+ "aria-label": STATUS,
136
+ // needed
137
+ onClick: () => console.log("Click on instance", instance.status)
138
+ }]
139
+ };
140
+ });
141
+ return instanceRows;
142
+ };
@@ -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,13 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
5
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ export var visibleRowColumns = (rows, hiddenCols) => {
7
+ return rows.map(row => {
8
+ return _objectSpread(_objectSpread({}, row), {}, {
9
+ columns: row.columns.filter(item => !hiddenCols.includes(item["aria-label"]))
10
+ });
11
+ });
12
+ };
13
+ export var visibleHeaderColumns = (headers, hiddenCols) => headers.filter(item => typeof item.content !== "string" || !hiddenCols.includes(item.content));
@@ -0,0 +1,3 @@
1
+ export { default } from "./ColumnSelector";
2
+ export { visibleHeaderColumns, visibleRowColumns, } from "./columnSelectorHelper";
3
+ export type { Props as ColumnSelectorProps } from "./ColumnSelector";
@@ -0,0 +1,2 @@
1
+ export { default } from "./ColumnSelector";
2
+ export { visibleHeaderColumns, visibleRowColumns } from "./columnSelectorHelper";
@@ -75,7 +75,7 @@ var CustomSelect = _ref => {
75
75
  var selectedOption = options.find(option => option.value === value);
76
76
  var toggleLabel = /*#__PURE__*/React.createElement("span", {
77
77
  className: "toggle-label u-truncate"
78
- }, selectedOption ? getOptionText(selectedOption) : "Select an option");
78
+ }, selectedOption ? selectedOption.selectedLabel || getOptionText(selectedOption) : "Select an option");
79
79
  var handleSelect = value => {
80
80
  var _document$getElementB3;
81
81
  (_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
  */
@@ -41,6 +41,95 @@ var generateCustomOptions = () => {
41
41
  disabled: false
42
42
  }];
43
43
  };
44
+ var generateCustomOptionsWithSelectedLabel = () => {
45
+ var options = [{
46
+ type: "ovn",
47
+ name: "ovntest",
48
+ config: {
49
+ "security.acls": "foo,bar"
50
+ }
51
+ }, {
52
+ type: "bridge",
53
+ name: "lxdbr0",
54
+ config: {}
55
+ }, {
56
+ type: "bridge",
57
+ name: "microbr0",
58
+ config: {}
59
+ }, {
60
+ type: "macvlan",
61
+ name: "macvlantest",
62
+ config: {}
63
+ }].map(network => {
64
+ var _network$config$secur;
65
+ return {
66
+ label: /*#__PURE__*/React.createElement("div", {
67
+ className: "label",
68
+ style: {
69
+ display: "flex",
70
+ gap: "5px"
71
+ }
72
+ }, /*#__PURE__*/React.createElement("span", {
73
+ title: network.name,
74
+ className: "network-option u-truncate",
75
+ style: {
76
+ width: "12rem"
77
+ }
78
+ }, network.name), /*#__PURE__*/React.createElement("span", {
79
+ title: network.type,
80
+ className: "network-option u-truncate",
81
+ style: {
82
+ width: "8rem"
83
+ }
84
+ }, network.type), /*#__PURE__*/React.createElement("span", {
85
+ title: "network ACLs",
86
+ className: "network-option u-truncate u-align--right",
87
+ style: {
88
+ paddingRight: "8px",
89
+ width: "4rem"
90
+ }
91
+ }, ((_network$config$secur = network.config["security.acls"]) === null || _network$config$secur === void 0 ? void 0 : _network$config$secur.length) || "-")),
92
+ value: network.name,
93
+ text: "".concat(network.name, " - ").concat(network.type),
94
+ disabled: false,
95
+ selectedLabel: /*#__PURE__*/React.createElement("span", null, network.name, "\xA0", /*#__PURE__*/React.createElement("span", {
96
+ className: "u-text--muted"
97
+ }, "(", network.type, ")"))
98
+ };
99
+ });
100
+ return options;
101
+ };
102
+ var getHeader = () => {
103
+ return /*#__PURE__*/React.createElement("div", {
104
+ className: "header",
105
+ style: {
106
+ backgroundColor: "$colors--theme--background-alt",
107
+ display: "flex",
108
+ gap: "$sph--small",
109
+ padding: "$sph--x-small $sph--small",
110
+ position: "sticky",
111
+ top: 0
112
+ }
113
+ }, /*#__PURE__*/React.createElement("span", {
114
+ className: "network-option u-no-margin--bottom",
115
+ style: {
116
+ color: "$colors--theme--text-default",
117
+ width: "12rem"
118
+ }
119
+ }, "Name"), /*#__PURE__*/React.createElement("span", {
120
+ className: "network-option u-no-margin--bottom",
121
+ style: {
122
+ color: "$colors--theme--text-default",
123
+ width: "8rem"
124
+ }
125
+ }, "Type"), /*#__PURE__*/React.createElement("span", {
126
+ className: "network-option u-no-margin--bottom",
127
+ style: {
128
+ color: "$colors--theme--text-default",
129
+ width: "4rem"
130
+ }
131
+ }, "ACLs"));
132
+ };
44
133
  var Template = _ref => {
45
134
  var props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
46
135
  var [selected, setSelected] = useState(props.value || "");
@@ -94,6 +183,19 @@ export var CustomOptions = {
94
183
  }
95
184
  };
96
185
 
186
+ /**
187
+ * If `label` is of `ReactNode` type. You can render custom content.
188
+ * In this case, the `selectedLabel` for each option is provided and will be displayed in the toggle instead of `text`
189
+ * The `text` property for each option is still required and is used for search and sort functionalities.
190
+ */
191
+ export var CustomOptionsAndSelectedLabel = {
192
+ args: {
193
+ options: generateCustomOptionsWithSelectedLabel(),
194
+ header: getHeader(),
195
+ dropdownClassName: "network-select-dropdown"
196
+ }
197
+ };
198
+
97
199
  /**
98
200
  * For each option, if `disabled` is set to `true`, the option will be disabled.
99
201
  */
@@ -4,6 +4,7 @@ export type CustomSelectOption = LiHTMLAttributes<HTMLLIElement> & {
4
4
  label: ReactNode;
5
5
  text?: string;
6
6
  disabled?: boolean;
7
+ selectedLabel?: ReactNode;
7
8
  };
8
9
  export type Props = {
9
10
  searchable?: "auto" | "always" | "never";
@@ -16,6 +16,7 @@ export { default as Chip } from "./components/Chip";
16
16
  export { default as Code } from "./components/Code";
17
17
  export { default as CodeSnippet, CodeSnippetBlockAppearance, } from "./components/CodeSnippet";
18
18
  export { default as Col } from "./components/Col";
19
+ export { default as ColumnSelector, visibleHeaderColumns, visibleRowColumns, } from "./components/ColumnSelector";
19
20
  export { default as ConfirmationButton } from "./components/ConfirmationButton";
20
21
  export { default as ConfirmationModal } from "./components/ConfirmationModal";
21
22
  export { default as ContextualMenu } from "./components/ContextualMenu";
@@ -93,6 +94,7 @@ export type { ChipProps } from "./components/Chip";
93
94
  export type { CodeProps } from "./components/Code";
94
95
  export type { CodeSnippetProps, CodeSnippetBlockProps, CodeSnippetDropdownProps, } from "./components/CodeSnippet";
95
96
  export type { ColProps, ColSize } from "./components/Col";
97
+ export type { ColumnSelectorProps } from "./components/ColumnSelector";
96
98
  export type { ConfirmationButtonProps } from "./components/ConfirmationButton";
97
99
  export type { ConfirmationModalProps } from "./components/ConfirmationModal";
98
100
  export type { ContextualMenuProps, ContextualMenuDropdownProps, MenuLink, Position, } from "./components/ContextualMenu";
package/dist/esm/index.js CHANGED
@@ -16,6 +16,7 @@ export { default as Chip } from "./components/Chip";
16
16
  export { default as Code } from "./components/Code";
17
17
  export { default as CodeSnippet, CodeSnippetBlockAppearance } from "./components/CodeSnippet";
18
18
  export { default as Col } from "./components/Col";
19
+ export { default as ColumnSelector, visibleHeaderColumns, visibleRowColumns } from "./components/ColumnSelector";
19
20
  export { default as ConfirmationButton } from "./components/ConfirmationButton";
20
21
  export { default as ConfirmationModal } from "./components/ConfirmationModal";
21
22
  export { default as ContextualMenu } from "./components/ContextualMenu";
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export { default as Chip } from "./components/Chip";
16
16
  export { default as Code } from "./components/Code";
17
17
  export { default as CodeSnippet, CodeSnippetBlockAppearance, } from "./components/CodeSnippet";
18
18
  export { default as Col } from "./components/Col";
19
+ export { default as ColumnSelector, visibleHeaderColumns, visibleRowColumns, } from "./components/ColumnSelector";
19
20
  export { default as ConfirmationButton } from "./components/ConfirmationButton";
20
21
  export { default as ConfirmationModal } from "./components/ConfirmationModal";
21
22
  export { default as ContextualMenu } from "./components/ContextualMenu";
@@ -93,6 +94,7 @@ export type { ChipProps } from "./components/Chip";
93
94
  export type { CodeProps } from "./components/Code";
94
95
  export type { CodeSnippetProps, CodeSnippetBlockProps, CodeSnippetDropdownProps, } from "./components/CodeSnippet";
95
96
  export type { ColProps, ColSize } from "./components/Col";
97
+ export type { ColumnSelectorProps } from "./components/ColumnSelector";
96
98
  export type { ConfirmationButtonProps } from "./components/ConfirmationButton";
97
99
  export type { ConfirmationModalProps } from "./components/ConfirmationModal";
98
100
  export type { ContextualMenuProps, ContextualMenuDropdownProps, MenuLink, Position, } from "./components/ContextualMenu";
package/dist/index.js CHANGED
@@ -24,6 +24,9 @@ var _exportNames = {
24
24
  CodeSnippet: true,
25
25
  CodeSnippetBlockAppearance: true,
26
26
  Col: true,
27
+ ColumnSelector: true,
28
+ visibleHeaderColumns: true,
29
+ visibleRowColumns: true,
27
30
  ConfirmationButton: true,
28
31
  ConfirmationModal: true,
29
32
  ContextualMenu: true,
@@ -236,6 +239,12 @@ Object.defineProperty(exports, "Col", {
236
239
  return _Col.default;
237
240
  }
238
241
  });
242
+ Object.defineProperty(exports, "ColumnSelector", {
243
+ enumerable: true,
244
+ get: function () {
245
+ return _ColumnSelector.default;
246
+ }
247
+ });
239
248
  Object.defineProperty(exports, "ConfirmationButton", {
240
249
  enumerable: true,
241
250
  get: function () {
@@ -782,6 +791,18 @@ Object.defineProperty(exports, "useWindowFitment", {
782
791
  return _hooks.useWindowFitment;
783
792
  }
784
793
  });
794
+ Object.defineProperty(exports, "visibleHeaderColumns", {
795
+ enumerable: true,
796
+ get: function () {
797
+ return _ColumnSelector.visibleHeaderColumns;
798
+ }
799
+ });
800
+ Object.defineProperty(exports, "visibleRowColumns", {
801
+ enumerable: true,
802
+ get: function () {
803
+ return _ColumnSelector.visibleRowColumns;
804
+ }
805
+ });
785
806
  var _Accordion = _interopRequireDefault(require("./components/Accordion"));
786
807
  var _ActionButton = _interopRequireDefault(require("./components/ActionButton"));
787
808
  var _ArticlePagination = _interopRequireDefault(require("./components/ArticlePagination"));
@@ -800,6 +821,7 @@ var _Chip = _interopRequireDefault(require("./components/Chip"));
800
821
  var _Code = _interopRequireDefault(require("./components/Code"));
801
822
  var _CodeSnippet = _interopRequireWildcard(require("./components/CodeSnippet"));
802
823
  var _Col = _interopRequireDefault(require("./components/Col"));
824
+ var _ColumnSelector = _interopRequireWildcard(require("./components/ColumnSelector"));
803
825
  var _ConfirmationButton = _interopRequireDefault(require("./components/ConfirmationButton"));
804
826
  var _ConfirmationModal = _interopRequireDefault(require("./components/ConfirmationModal"));
805
827
  var _ContextualMenu = _interopRequireDefault(require("./components/ContextualMenu"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {