@canonical/react-components 2.14.0 → 2.15.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/ScrollableContainer/ScrollableContainer.d.ts +27 -0
- package/dist/components/ScrollableContainer/ScrollableContainer.js +51 -0
- package/dist/components/ScrollableContainer/ScrollableContainer.scss +7 -0
- package/dist/components/ScrollableContainer/ScrollableContainer.stories.d.ts +6 -0
- package/dist/components/ScrollableContainer/ScrollableContainer.stories.js +36 -0
- package/dist/components/ScrollableContainer/ScrollableContainer.test.d.ts +1 -0
- package/dist/components/ScrollableContainer/index.d.ts +2 -0
- package/dist/components/ScrollableContainer/index.js +13 -0
- package/dist/components/ScrollableTable/ScrollableTable.d.ts +27 -0
- package/dist/components/ScrollableTable/ScrollableTable.js +44 -0
- package/dist/components/ScrollableTable/ScrollableTable.scss +58 -0
- package/dist/components/ScrollableTable/ScrollableTable.stories.d.ts +6 -0
- package/dist/components/ScrollableTable/ScrollableTable.stories.js +69 -0
- package/dist/components/ScrollableTable/ScrollableTable.test.d.ts +1 -0
- package/dist/components/ScrollableTable/index.d.ts +2 -0
- package/dist/components/ScrollableTable/index.js +13 -0
- package/dist/components/SidePanel/SidePanel.js +1 -1
- package/dist/components/TablePagination/TablePagination.scss +6 -6
- package/dist/components/TablePagination/TablePagination.stories.d.ts +8 -0
- package/dist/components/TablePagination/TablePagination.stories.js +53 -1
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.js +7 -4
- package/dist/components/TablePagination/utils.d.ts +2 -1
- package/dist/components/TablePagination/utils.js +10 -3
- package/dist/esm/components/ScrollableContainer/ScrollableContainer.d.ts +27 -0
- package/dist/esm/components/ScrollableContainer/ScrollableContainer.js +43 -0
- package/dist/esm/components/ScrollableContainer/ScrollableContainer.scss +7 -0
- package/dist/esm/components/ScrollableContainer/ScrollableContainer.stories.d.ts +6 -0
- package/dist/esm/components/ScrollableContainer/ScrollableContainer.stories.js +29 -0
- package/dist/esm/components/ScrollableContainer/ScrollableContainer.test.d.ts +1 -0
- package/dist/esm/components/ScrollableContainer/index.d.ts +2 -0
- package/dist/esm/components/ScrollableContainer/index.js +1 -0
- package/dist/esm/components/ScrollableTable/ScrollableTable.d.ts +27 -0
- package/dist/esm/components/ScrollableTable/ScrollableTable.js +37 -0
- package/dist/esm/components/ScrollableTable/ScrollableTable.scss +58 -0
- package/dist/esm/components/ScrollableTable/ScrollableTable.stories.d.ts +6 -0
- package/dist/esm/components/ScrollableTable/ScrollableTable.stories.js +62 -0
- package/dist/esm/components/ScrollableTable/ScrollableTable.test.d.ts +1 -0
- package/dist/esm/components/ScrollableTable/index.d.ts +2 -0
- package/dist/esm/components/ScrollableTable/index.js +1 -0
- package/dist/esm/components/SidePanel/SidePanel.js +1 -1
- package/dist/esm/components/TablePagination/TablePagination.scss +6 -6
- package/dist/esm/components/TablePagination/TablePagination.stories.d.ts +8 -0
- package/dist/esm/components/TablePagination/TablePagination.stories.js +52 -0
- package/dist/esm/components/TablePagination/TablePaginationControls/TablePaginationControls.js +7 -4
- package/dist/esm/components/TablePagination/utils.d.ts +2 -1
- package/dist/esm/components/TablePagination/utils.js +10 -3
- package/dist/esm/hooks/useId.d.ts +1 -1
- package/dist/esm/hooks/useId.js +1 -1
- package/dist/esm/hooks/useListener.js +8 -7
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/utils.d.ts +4 -0
- package/dist/esm/utils.js +32 -1
- package/dist/hooks/useId.d.ts +1 -1
- package/dist/hooks/useId.js +1 -1
- package/dist/hooks/useListener.js +8 -7
- package/dist/index.d.ts +5 -1
- package/dist/index.js +37 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +37 -2
- package/package.json +2 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DependencyList, FC, ReactNode } from "react";
|
|
2
|
+
import "./ScrollableContainer.scss";
|
|
3
|
+
export type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* The content that should be scrollable on overflow.
|
|
6
|
+
*/
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* An array of dependencies that will trigger a re-calculation of the scrollable height when changed.
|
|
10
|
+
*/
|
|
11
|
+
dependencies: DependencyList;
|
|
12
|
+
/**
|
|
13
|
+
* An array of element IDs below the scrollable container that should be considered when calculating the height.
|
|
14
|
+
*/
|
|
15
|
+
belowIds?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Additional CSS classes to apply to the scrollable container.
|
|
18
|
+
*/
|
|
19
|
+
className?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* This is a [React](https://reactjs.org/) component for use within the [Vanilla framework](https://docs.vanillaframework.io/).
|
|
23
|
+
*
|
|
24
|
+
* It is used to make any child element scrollable by adjusting the height based on the viewport height and the heights of elements above and below it. As a result the surrounding elements are sticky and only the wrapped element contents scroll
|
|
25
|
+
*/
|
|
26
|
+
declare const ScrollableContainer: FC<Props>;
|
|
27
|
+
export default ScrollableContainer;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
require("./ScrollableContainer.scss");
|
|
10
|
+
var _utils = require("../../utils");
|
|
11
|
+
var _hooks = require("../../hooks");
|
|
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
|
+
/**
|
|
16
|
+
* This is a [React](https://reactjs.org/) component for use within the [Vanilla framework](https://docs.vanillaframework.io/).
|
|
17
|
+
*
|
|
18
|
+
* It is used to make any child element scrollable by adjusting the height based on the viewport height and the heights of elements above and below it. As a result the surrounding elements are sticky and only the wrapped element contents scroll
|
|
19
|
+
*/
|
|
20
|
+
const ScrollableContainer = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
dependencies,
|
|
23
|
+
children,
|
|
24
|
+
belowIds = ["status-bar"],
|
|
25
|
+
className
|
|
26
|
+
} = _ref;
|
|
27
|
+
const ref = (0, _react.useRef)(null);
|
|
28
|
+
const updateChildContainerHeight = () => {
|
|
29
|
+
var _ref$current;
|
|
30
|
+
const childContainer = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.children[0];
|
|
31
|
+
if (!childContainer) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const above = childContainer.getBoundingClientRect().top + 1;
|
|
35
|
+
const below = belowIds.reduce((acc, belowId) => acc + (0, _utils.getAbsoluteHeightBelowById)(belowId), 0);
|
|
36
|
+
const parentsBottomSpacing = (0, _utils.getParentsBottomSpacing)(childContainer);
|
|
37
|
+
const offset = Math.ceil(above + below + parentsBottomSpacing);
|
|
38
|
+
const style = "height: calc(100dvh - ".concat(offset, "px); min-height: calc(100dvh - ").concat(offset, "px)");
|
|
39
|
+
childContainer.setAttribute("style", style);
|
|
40
|
+
};
|
|
41
|
+
(0, _hooks.useListener)(window, updateChildContainerHeight, "resize", true);
|
|
42
|
+
(0, _react.useEffect)(updateChildContainerHeight, [dependencies, belowIds, ref]);
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
44
|
+
ref: ref,
|
|
45
|
+
className: (0, _classnames.default)("scrollable-container", className)
|
|
46
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
47
|
+
id: "content-details",
|
|
48
|
+
className: "content-details"
|
|
49
|
+
}, children));
|
|
50
|
+
};
|
|
51
|
+
var _default = exports.default = ScrollableContainer;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import ScrollableContainer from "./ScrollableContainer";
|
|
3
|
+
declare const meta: Meta<typeof ScrollableContainer>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof ScrollableContainer>;
|
|
6
|
+
export declare const Default: Story;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.Default = void 0;
|
|
7
|
+
var _ScrollableContainer = _interopRequireDefault(require("./ScrollableContainer"));
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _blocks = require("@storybook/blocks");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const meta = {
|
|
12
|
+
component: _ScrollableContainer.default,
|
|
13
|
+
tags: ["autodocs"]
|
|
14
|
+
};
|
|
15
|
+
var _default = exports.default = meta;
|
|
16
|
+
const StoryExample = args => {
|
|
17
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h1", null, "Above contents"), /*#__PURE__*/_react.default.createElement(_ScrollableContainer.default, {
|
|
18
|
+
belowIds: args.belowIds,
|
|
19
|
+
dependencies: []
|
|
20
|
+
}, /*#__PURE__*/_react.default.createElement("p", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras varius mi eu pretium vulputate. Nunc commodo sit amet nibh quis rhoncus. Aliquam rhoncus porttitor semper. Aenean faucibus consectetur neque in sodales. Sed cursus mauris id ex sollicitudin sodales. Quisque molestie rutrum odio, ornare pharetra ligula. Pellentesque ornare tristique feugiat. In a augue neque. Aenean eget arcu quis lacus tempus posuere in sit amet dui. Suspendisse faucibus sapien nisl, nec laoreet sem convallis nec."), /*#__PURE__*/_react.default.createElement("p", null, "Vestibulum sed placerat lorem. Nam luctus ex id nisi luctus, id vestibulum sem bibendum. Vivamus turpis sem, pellentesque fermentum malesuada eu, faucibus porta libero. Duis eget venenatis odio. Etiam sed volutpat magna, non tempus erat. Nunc id tortor ac quam consectetur dapibus ac ut tellus. Pellentesque ut tellus venenatis elit vehicula condimentum eget quis lorem. Ut non consectetur est, a fringilla ipsum. Nunc vitae ligula ipsum. Etiam suscipit, libero ut lacinia viverra, nunc urna consequat ex, vel eleifend eros mauris vitae ipsum. Pellentesque sed dictum augue. Ut sit amet ullamcorper mauris. Nunc congue orci mollis purus sodales facilisis ac ut arcu. Maecenas feugiat sapien ac massa mollis sodales. Donec vitae turpis eu nisi laoreet pulvinar quis at nisl. Integer volutpat, metus eget elementum dictum, lacus sapien viverra felis, consequat fermentum nisl mi ac dui."), /*#__PURE__*/_react.default.createElement("p", null, "Nullam nulla turpis, dignissim vel dapibus ut, volutpat ac dui. Donec vel elementum lacus. Mauris maximus nec felis at faucibus. Nunc faucibus gravida velit, id blandit lectus tincidunt ac. Vestibulum orci diam, elementum in congue eu, placerat id risus. Sed tempor tempus tellus, vitae iaculis turpis fringilla nec. Phasellus imperdiet facilisis velit, sit amet lobortis odio dignissim ut."), /*#__PURE__*/_react.default.createElement("p", null, "Nam placerat urna vitae ligula hendrerit, ac tincidunt lorem maximus. Mauris eu odio nisi. Nulla facilisi. Sed egestas elit sed velit rutrum, sit amet bibendum metus hendrerit. Pellentesque luctus placerat tellus, eu bibendum justo. Cras eget leo ac ex volutpat gravida. Duis vitae mollis ante. Duis a congue nunc. Aenean aliquet, sapien quis tincidunt tincidunt, odio eros consectetur lacus, vel finibus mauris tortor id velit. Donec tincidunt vitae purus eu interdum. Pellentesque scelerisque dui viverra ex ullamcorper volutpat. Vestibulum lacinia vitae arcu volutpat porta. Etiam et cursus nulla, id aliquet felis. Nam ultricies, urna id mattis pretium, velit erat viverra elit, eu maximus diam eros id nisi."), /*#__PURE__*/_react.default.createElement("p", null, "Nullam eget nisl lectus. Pellentesque eu mauris ut tortor malesuada sagittis. Cras dictum cursus est non ultricies. Duis mollis non neque at commodo. Nunc feugiat justo et consequat aliquam. Ut consectetur libero eu erat feugiat finibus. Duis varius convallis quam eu sagittis. Maecenas ac est arcu. Suspendisse at enim eget nibh ultricies dictum. Etiam aliquet tellus vel felis malesuada laoreet.")), /*#__PURE__*/_react.default.createElement("div", {
|
|
21
|
+
id: "footer"
|
|
22
|
+
}, /*#__PURE__*/_react.default.createElement("h2", {
|
|
23
|
+
className: "u-no-margin"
|
|
24
|
+
}, "Below contents"), /*#__PURE__*/_react.default.createElement("div", null, "here be dragons.")));
|
|
25
|
+
};
|
|
26
|
+
const Default = exports.Default = {
|
|
27
|
+
args: {
|
|
28
|
+
belowIds: ["footer"]
|
|
29
|
+
},
|
|
30
|
+
render: StoryExample,
|
|
31
|
+
parameters: {
|
|
32
|
+
docs: {
|
|
33
|
+
page: () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_blocks.Title, null), /*#__PURE__*/_react.default.createElement(_blocks.Subtitle, null), /*#__PURE__*/_react.default.createElement(_blocks.Description, null))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
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 _ScrollableContainer.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _ScrollableContainer = _interopRequireDefault(require("./ScrollableContainer"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DependencyList, FC, ReactNode } from "react";
|
|
2
|
+
import "./ScrollableTable.scss";
|
|
3
|
+
export type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* A MainTable that will be made scrollable.
|
|
6
|
+
*/
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* An array of dependencies that will trigger a re-calculation of the table body height when they change.
|
|
10
|
+
*/
|
|
11
|
+
dependencies: DependencyList;
|
|
12
|
+
/**
|
|
13
|
+
* The ID of the table element that contains the `<tbody>` to be made scrollable.
|
|
14
|
+
*/
|
|
15
|
+
tableId: string;
|
|
16
|
+
/**
|
|
17
|
+
* An array of element IDs below the table that should be considered when calculating the height.
|
|
18
|
+
*/
|
|
19
|
+
belowIds?: string[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* This is a [React](https://reactjs.org/) component for use within the [Vanilla framework](https://docs.vanillaframework.io/).
|
|
23
|
+
*
|
|
24
|
+
* It is used to make a table scrollable by adjusting the height of the `<tbody>` element based on the viewport height and the heights of elements above and below it. As a result the header is sticky and only the body scrolls
|
|
25
|
+
*/
|
|
26
|
+
declare const ScrollableTable: FC<Props>;
|
|
27
|
+
export default ScrollableTable;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _utils = require("../../utils");
|
|
9
|
+
require("./ScrollableTable.scss");
|
|
10
|
+
var _hooks = require("../../hooks");
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
/**
|
|
14
|
+
* This is a [React](https://reactjs.org/) component for use within the [Vanilla framework](https://docs.vanillaframework.io/).
|
|
15
|
+
*
|
|
16
|
+
* It is used to make a table scrollable by adjusting the height of the `<tbody>` element based on the viewport height and the heights of elements above and below it. As a result the header is sticky and only the body scrolls
|
|
17
|
+
*/
|
|
18
|
+
const ScrollableTable = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
dependencies,
|
|
21
|
+
children,
|
|
22
|
+
tableId,
|
|
23
|
+
belowIds = []
|
|
24
|
+
} = _ref;
|
|
25
|
+
const updateTBodyHeight = () => {
|
|
26
|
+
const table = document.getElementById(tableId);
|
|
27
|
+
if (!table || table.children.length !== 2) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const tBody = table.children[1];
|
|
31
|
+
const above = tBody.getBoundingClientRect().top + 1;
|
|
32
|
+
const below = belowIds.reduce((acc, belowId) => acc + (0, _utils.getAbsoluteHeightBelowById)(belowId), 0);
|
|
33
|
+
const parentsBottomSpacing = (0, _utils.getParentsBottomSpacing)(table);
|
|
34
|
+
const offset = Math.ceil(above + below + parentsBottomSpacing);
|
|
35
|
+
const style = "height: calc(100dvh - ".concat(offset, "px); min-height: calc(100dvh - ").concat(offset, "px)");
|
|
36
|
+
tBody.setAttribute("style", style);
|
|
37
|
+
};
|
|
38
|
+
(0, _hooks.useListener)(window, updateTBodyHeight, "resize", true);
|
|
39
|
+
(0, _react.useEffect)(updateTBodyHeight, [...dependencies, belowIds, tableId]);
|
|
40
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
41
|
+
className: "scrollable-table"
|
|
42
|
+
}, children);
|
|
43
|
+
};
|
|
44
|
+
var _default = exports.default = ScrollableTable;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
@import "vanilla-framework/scss/settings";
|
|
2
|
+
|
|
3
|
+
/* stylelint-disable selector-max-type */
|
|
4
|
+
.scrollable-table {
|
|
5
|
+
table {
|
|
6
|
+
margin-bottom: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
th,
|
|
10
|
+
td {
|
|
11
|
+
display: table-cell;
|
|
12
|
+
vertical-align: top;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
th::before {
|
|
16
|
+
content: "";
|
|
17
|
+
height: 1rem;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
thead,
|
|
21
|
+
tbody {
|
|
22
|
+
display: block;
|
|
23
|
+
overflow: hidden auto;
|
|
24
|
+
scrollbar-gutter: stable;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
tbody {
|
|
28
|
+
height: calc(100dvh - 323px);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
thead tr,
|
|
32
|
+
tbody tr {
|
|
33
|
+
display: table;
|
|
34
|
+
table-layout: fixed;
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@media screen and (max-width: $breakpoint-large) {
|
|
39
|
+
.p-table--mobile-card {
|
|
40
|
+
thead {
|
|
41
|
+
display: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
td {
|
|
45
|
+
display: block;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
tbody tr {
|
|
49
|
+
display: block;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
tbody tr:first-child {
|
|
53
|
+
margin-top: $spv--x-large;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/* stylelint-enable selector-max-type */
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.Default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _ScrollableTable = _interopRequireDefault(require("./ScrollableTable"));
|
|
9
|
+
var _index = require("../../index");
|
|
10
|
+
var _blocks = require("@storybook/blocks");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const meta = {
|
|
13
|
+
component: _ScrollableTable.default,
|
|
14
|
+
tags: ["autodocs"]
|
|
15
|
+
};
|
|
16
|
+
var _default = exports.default = meta;
|
|
17
|
+
const StoryExample = args => {
|
|
18
|
+
const headers = [{
|
|
19
|
+
content: "Fact"
|
|
20
|
+
}, {
|
|
21
|
+
content: "Relevancy score"
|
|
22
|
+
}, {
|
|
23
|
+
content: "Size"
|
|
24
|
+
}, {
|
|
25
|
+
content: "ID"
|
|
26
|
+
}, {
|
|
27
|
+
"aria-label": "Actions",
|
|
28
|
+
className: "actions"
|
|
29
|
+
}];
|
|
30
|
+
const facts = ["Dragons are mythical creatures", "They can fly", "They breathe fire", "They hoard treasure", "They are often depicted as large reptiles", "They appear in various cultures' folklore", "They can be friendly or hostile", "They are often associated with wisdom", "They can shapeshift in some legends", "They are sometimes guardians of sacred places", "They can be found in literature and movies", "They are often depicted with wings", "They can be of various colors", "They are sometimes associated with knights"];
|
|
31
|
+
const rows = facts.map(item => {
|
|
32
|
+
return {
|
|
33
|
+
columns: [{
|
|
34
|
+
content: item,
|
|
35
|
+
role: "rowheader"
|
|
36
|
+
}, {
|
|
37
|
+
content: 1
|
|
38
|
+
}, {
|
|
39
|
+
content: "1 GiB"
|
|
40
|
+
}, {
|
|
41
|
+
content: 2
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h1", null, "Above contents"), /*#__PURE__*/_react.default.createElement(_ScrollableTable.default, {
|
|
46
|
+
belowIds: args.belowIds,
|
|
47
|
+
dependencies: [headers, rows],
|
|
48
|
+
tableId: "facts-about-dragons"
|
|
49
|
+
}, /*#__PURE__*/_react.default.createElement(_index.MainTable, {
|
|
50
|
+
headers: headers,
|
|
51
|
+
rows: rows,
|
|
52
|
+
id: "facts-about-dragons"
|
|
53
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
54
|
+
id: "footer"
|
|
55
|
+
}, /*#__PURE__*/_react.default.createElement("h2", {
|
|
56
|
+
className: "u-no-margin"
|
|
57
|
+
}, "Below contents"), /*#__PURE__*/_react.default.createElement("div", null, "here be dragons.")));
|
|
58
|
+
};
|
|
59
|
+
const Default = exports.Default = {
|
|
60
|
+
args: {
|
|
61
|
+
belowIds: ["footer"]
|
|
62
|
+
},
|
|
63
|
+
render: StoryExample,
|
|
64
|
+
parameters: {
|
|
65
|
+
docs: {
|
|
66
|
+
page: () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_blocks.Title, null), /*#__PURE__*/_react.default.createElement(_blocks.Subtitle, null), /*#__PURE__*/_react.default.createElement(_blocks.Description, null))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
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 _ScrollableTable.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _ScrollableTable = _interopRequireDefault(require("./ScrollableTable"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -32,7 +32,7 @@ The sidepanel component should be used to show additional information relating t
|
|
|
32
32
|
|
|
33
33
|
* **SidePanel.HeaderControls:** To show controls in the header, such as buttons or icons for actions like closing the panel.
|
|
34
34
|
|
|
35
|
-
* **SidePanel.Sticky:** Can be wrapped around the header or footer to make them sticky when scrolling.
|
|
35
|
+
* **SidePanel.Sticky:** Can be wrapped around the header or footer to make them sticky when scrolling. The scrollbar will use the full area of the side panel, not just the content area. To limit the scrollbar to the content area, use the `ScrollableContainer` component instead of this one.
|
|
36
36
|
|
|
37
37
|
* **SidePanel.Content:** To show the main content of the side panel.
|
|
38
38
|
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
.next {
|
|
29
|
-
margin: 0 $spv--large;
|
|
29
|
+
margin: 0 $spv--large 0 0;
|
|
30
30
|
|
|
31
31
|
.p-icon--chevron-down {
|
|
32
32
|
rotate: 270deg;
|
|
@@ -34,11 +34,15 @@
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
.pagination-input {
|
|
37
|
-
margin: 0 $spv--
|
|
37
|
+
margin: 0 $spv--large;
|
|
38
38
|
min-width: 0;
|
|
39
39
|
width: 4rem;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
.pagination-item-count {
|
|
43
|
+
margin: 0 $spv--large 0 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
42
46
|
.pagination-select {
|
|
43
47
|
margin-bottom: 0;
|
|
44
48
|
margin-left: $spv--x-large;
|
|
@@ -48,10 +52,6 @@
|
|
|
48
52
|
|
|
49
53
|
@media screen and (max-width: $breakpoint-small) {
|
|
50
54
|
.back,
|
|
51
|
-
.pagination-input {
|
|
52
|
-
margin-left: 0;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
55
|
.next {
|
|
56
56
|
margin-left: 0;
|
|
57
57
|
margin-right: 0;
|
|
@@ -12,3 +12,11 @@ export declare const RenderBelow: Story;
|
|
|
12
12
|
* using the `TablePaginationControls` component.
|
|
13
13
|
*/
|
|
14
14
|
export declare const ControlsOnly: Story;
|
|
15
|
+
/** The `TablePaginationControls` component can be used when the total
|
|
16
|
+
* number of entries is unknown.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ControlsWithUnknownEntries: Story;
|
|
19
|
+
/** The `TablePaginationControls` component can be used when it is known
|
|
20
|
+
* that there are more entries than the amount displayed on the current page.
|
|
21
|
+
*/
|
|
22
|
+
export declare const ControlsWithPartiallyKnownEntries: Story;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.RenderBelow = exports.RenderAbove = exports.Default = exports.CustomPageLimit = exports.CustomDisplayTitle = exports.ControlsOnly = void 0;
|
|
6
|
+
exports.default = exports.RenderBelow = exports.RenderAbove = exports.Default = exports.CustomPageLimit = exports.CustomDisplayTitle = exports.ControlsWithUnknownEntries = exports.ControlsWithPartiallyKnownEntries = exports.ControlsOnly = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _TablePagination = _interopRequireDefault(require("./TablePagination"));
|
|
9
9
|
var _MainTable = _interopRequireDefault(require("../MainTable"));
|
|
@@ -327,4 +327,56 @@ const ControlsOnly = exports.ControlsOnly = {
|
|
|
327
327
|
visibleCount: 10
|
|
328
328
|
});
|
|
329
329
|
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/** The `TablePaginationControls` component can be used when the total
|
|
333
|
+
* number of entries is unknown.
|
|
334
|
+
*/
|
|
335
|
+
const ControlsWithUnknownEntries = exports.ControlsWithUnknownEntries = {
|
|
336
|
+
render: () => {
|
|
337
|
+
return /*#__PURE__*/_react.default.createElement(_TablePaginationControls.default, {
|
|
338
|
+
currentPage: 1,
|
|
339
|
+
itemName: "row",
|
|
340
|
+
nextButtonProps: {
|
|
341
|
+
disabled: false
|
|
342
|
+
},
|
|
343
|
+
onInputPageChange: console.log,
|
|
344
|
+
onNextPage: console.log,
|
|
345
|
+
onPageSizeChange: console.log,
|
|
346
|
+
onPreviousPage: console.log,
|
|
347
|
+
pageLimits: [10, 25, 50],
|
|
348
|
+
pageSize: 20,
|
|
349
|
+
previousButtonProps: {
|
|
350
|
+
disabled: false
|
|
351
|
+
},
|
|
352
|
+
showPageInput: true,
|
|
353
|
+
visibleCount: 10
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/** The `TablePaginationControls` component can be used when it is known
|
|
359
|
+
* that there are more entries than the amount displayed on the current page.
|
|
360
|
+
*/
|
|
361
|
+
const ControlsWithPartiallyKnownEntries = exports.ControlsWithPartiallyKnownEntries = {
|
|
362
|
+
render: () => {
|
|
363
|
+
return /*#__PURE__*/_react.default.createElement(_TablePaginationControls.default, {
|
|
364
|
+
currentPage: 3,
|
|
365
|
+
itemName: "row",
|
|
366
|
+
nextButtonProps: {
|
|
367
|
+
disabled: false
|
|
368
|
+
},
|
|
369
|
+
onInputPageChange: console.log,
|
|
370
|
+
onNextPage: console.log,
|
|
371
|
+
onPageSizeChange: console.log,
|
|
372
|
+
onPreviousPage: console.log,
|
|
373
|
+
pageLimits: [10, 25, 50],
|
|
374
|
+
pageSize: 20,
|
|
375
|
+
previousButtonProps: {
|
|
376
|
+
disabled: false
|
|
377
|
+
},
|
|
378
|
+
showPageInput: true,
|
|
379
|
+
visibleCount: 10
|
|
380
|
+
});
|
|
381
|
+
}
|
|
330
382
|
};
|
|
@@ -27,7 +27,7 @@ const TablePaginationControls = _ref => {
|
|
|
27
27
|
description,
|
|
28
28
|
displayDescription = true,
|
|
29
29
|
onInputPageChange,
|
|
30
|
-
itemName,
|
|
30
|
+
itemName = "row",
|
|
31
31
|
nextButtonProps,
|
|
32
32
|
onNextPage,
|
|
33
33
|
onPageChange,
|
|
@@ -48,7 +48,8 @@ const TablePaginationControls = _ref => {
|
|
|
48
48
|
visibleCount,
|
|
49
49
|
isSmallScreen,
|
|
50
50
|
totalItems,
|
|
51
|
-
itemName
|
|
51
|
+
itemName,
|
|
52
|
+
currentPage
|
|
52
53
|
});
|
|
53
54
|
const handleDecrementPage = currentPage => {
|
|
54
55
|
if (currentPage > 1) {
|
|
@@ -70,7 +71,7 @@ const TablePaginationControls = _ref => {
|
|
|
70
71
|
const handlePageSizeChange = e => {
|
|
71
72
|
onPageSizeChange(parseInt(e.target.value));
|
|
72
73
|
};
|
|
73
|
-
const isInputDisabled = !totalPages || totalPages == 1;
|
|
74
|
+
const isInputDisabled = typeof totalItems === "number" && (!totalPages || totalPages == 1);
|
|
74
75
|
const maxPageValue = typeof totalPages === "number" ? totalPages : 1;
|
|
75
76
|
return /*#__PURE__*/_react.default.createElement("div", _extends({
|
|
76
77
|
className: (0, _classnames.default)("pagination", className)
|
|
@@ -99,7 +100,9 @@ const TablePaginationControls = _ref => {
|
|
|
99
100
|
disabled: isInputDisabled,
|
|
100
101
|
min: 1,
|
|
101
102
|
max: maxPageValue
|
|
102
|
-
}), " ", typeof totalPages === "number" ? /*#__PURE__*/_react.default.createElement(
|
|
103
|
+
}), " ", typeof totalPages === "number" ? /*#__PURE__*/_react.default.createElement("div", {
|
|
104
|
+
className: "pagination-item-count"
|
|
105
|
+
}, "of\xA0", totalPages) : null) : null, /*#__PURE__*/_react.default.createElement(_Button.default, _extends({
|
|
103
106
|
"aria-label": Label.NEXT_PAGE,
|
|
104
107
|
className: "next",
|
|
105
108
|
appearance: "base",
|
|
@@ -17,11 +17,12 @@ export declare const generatePagingOptions: (pageLimits: number[]) => {
|
|
|
17
17
|
value: number;
|
|
18
18
|
label: string;
|
|
19
19
|
}[];
|
|
20
|
-
export declare const getDescription: ({ description, isSmallScreen, totalItems, itemName, visibleCount, }: {
|
|
20
|
+
export declare const getDescription: ({ description, isSmallScreen, totalItems, itemName, visibleCount, currentPage, }: {
|
|
21
21
|
description: ReactNode;
|
|
22
22
|
isSmallScreen: boolean;
|
|
23
23
|
totalItems: number;
|
|
24
24
|
itemName: string;
|
|
25
25
|
visibleCount: number;
|
|
26
|
+
currentPage: number;
|
|
26
27
|
}) => string | number | bigint | true | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode>>;
|
|
27
28
|
export declare const useFigureSmallScreen: () => boolean;
|
|
@@ -47,18 +47,25 @@ const getDescription = _ref => {
|
|
|
47
47
|
isSmallScreen,
|
|
48
48
|
totalItems,
|
|
49
49
|
itemName,
|
|
50
|
-
visibleCount
|
|
50
|
+
visibleCount,
|
|
51
|
+
currentPage
|
|
51
52
|
} = _ref;
|
|
52
53
|
if (description) {
|
|
53
54
|
return description;
|
|
54
55
|
}
|
|
56
|
+
let closing = "";
|
|
57
|
+
if (typeof totalItems === "number") {
|
|
58
|
+
closing = " out of ".concat(totalItems);
|
|
59
|
+
} else if (currentPage !== 1) {
|
|
60
|
+
closing = " of more than ".concat(visibleCount);
|
|
61
|
+
}
|
|
55
62
|
if (isSmallScreen) {
|
|
56
|
-
return "".concat(visibleCount
|
|
63
|
+
return "".concat(visibleCount).concat(closing);
|
|
57
64
|
}
|
|
58
65
|
if (visibleCount === totalItems && visibleCount > 1) {
|
|
59
66
|
return "Showing all ".concat(totalItems, " ").concat(itemName, "s");
|
|
60
67
|
}
|
|
61
|
-
return "Showing ".concat(visibleCount
|
|
68
|
+
return "Showing ".concat(visibleCount).concat(closing, " ").concat(itemName).concat(totalItems !== 1 ? "s" : "");
|
|
62
69
|
};
|
|
63
70
|
exports.getDescription = getDescription;
|
|
64
71
|
const useFigureSmallScreen = () => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DependencyList, FC, ReactNode } from "react";
|
|
2
|
+
import "./ScrollableContainer.scss";
|
|
3
|
+
export type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* The content that should be scrollable on overflow.
|
|
6
|
+
*/
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* An array of dependencies that will trigger a re-calculation of the scrollable height when changed.
|
|
10
|
+
*/
|
|
11
|
+
dependencies: DependencyList;
|
|
12
|
+
/**
|
|
13
|
+
* An array of element IDs below the scrollable container that should be considered when calculating the height.
|
|
14
|
+
*/
|
|
15
|
+
belowIds?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Additional CSS classes to apply to the scrollable container.
|
|
18
|
+
*/
|
|
19
|
+
className?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* This is a [React](https://reactjs.org/) component for use within the [Vanilla framework](https://docs.vanillaframework.io/).
|
|
23
|
+
*
|
|
24
|
+
* It is used to make any child element scrollable by adjusting the height based on the viewport height and the heights of elements above and below it. As a result the surrounding elements are sticky and only the wrapped element contents scroll
|
|
25
|
+
*/
|
|
26
|
+
declare const ScrollableContainer: FC<Props>;
|
|
27
|
+
export default ScrollableContainer;
|