@canonical/react-components 0.37.8 → 0.38.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.
@@ -52,10 +52,14 @@ export declare type Props = PropsWithSpread<{
52
52
  * Whether to focus on the input on initial render.
53
53
  */
54
54
  takeFocus?: boolean;
55
+ /**
56
+ * Delay takeFocus in milliseconds i.e. to let animations finish
57
+ */
58
+ takeFocusDelay?: number;
55
59
  /**
56
60
  * Optional class(es) to pass to the wrapping Field component
57
61
  */
58
62
  wrapperClassName?: string;
59
63
  }, InputHTMLAttributes<HTMLInputElement>>;
60
- declare const Input: ({ caution, className, error, help, helpClassName, id, label, labelClassName, required, stacked, success, takeFocus, type, wrapperClassName, ...inputProps }: Props) => JSX.Element;
64
+ declare const Input: ({ caution, className, error, help, helpClassName, id, label, labelClassName, required, stacked, success, takeFocus, takeFocusDelay, type, wrapperClassName, ...inputProps }: Props) => JSX.Element;
61
65
  export default Input;
@@ -19,7 +19,7 @@ var _RadioInput = _interopRequireDefault(require("../RadioInput"));
19
19
 
20
20
  var _hooks = require("../../hooks");
21
21
 
22
- var _excluded = ["caution", "className", "error", "help", "helpClassName", "id", "label", "labelClassName", "required", "stacked", "success", "takeFocus", "type", "wrapperClassName"];
22
+ var _excluded = ["caution", "className", "error", "help", "helpClassName", "id", "label", "labelClassName", "required", "stacked", "success", "takeFocus", "takeFocusDelay", "type", "wrapperClassName"];
23
23
 
24
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
25
 
@@ -52,6 +52,7 @@ var Input = function Input(_ref) {
52
52
  stacked = _ref.stacked,
53
53
  success = _ref.success,
54
54
  takeFocus = _ref.takeFocus,
55
+ takeFocusDelay = _ref.takeFocusDelay,
55
56
  type = _ref.type,
56
57
  wrapperClassName = _ref.wrapperClassName,
57
58
  inputProps = _objectWithoutProperties(_ref, _excluded);
@@ -73,7 +74,13 @@ var Input = function Input(_ref) {
73
74
 
74
75
  (0, _react.useEffect)(function () {
75
76
  if (takeFocus) {
76
- inputRef.current.focus();
77
+ if (takeFocusDelay) {
78
+ setTimeout(function () {
79
+ return inputRef.current.focus();
80
+ }, takeFocusDelay);
81
+ } else {
82
+ inputRef.current.focus();
83
+ }
77
84
  }
78
85
  }, [takeFocus]);
79
86
  var input;
@@ -61,7 +61,12 @@ var Modal = function Modal(_ref) {
61
61
  }
62
62
  };
63
63
 
64
- var keyListenersMap = new Map([["Escape", close], ["Tab", handleTabKey]]);
64
+ var handleEscKey = function handleEscKey(e) {
65
+ e.nativeEvent.stopImmediatePropagation();
66
+ close();
67
+ };
68
+
69
+ var keyListenersMap = new Map([["Escape", handleEscKey], ["Tab", handleTabKey]]);
65
70
  (0, _react.useEffect)(function () {
66
71
  modalRef.current.focus();
67
72
  }, [modalRef]);
@@ -69,7 +74,13 @@ var Modal = function Modal(_ref) {
69
74
  var _focusableModalElemen;
70
75
 
71
76
  focusableModalElements.current = modalRef.current.querySelectorAll(focusableElementSelectors);
72
- (_focusableModalElemen = focusableModalElements.current[0]) === null || _focusableModalElemen === void 0 ? void 0 : _focusableModalElemen.focus();
77
+ var focusIndex = 0; // when the close button is rendered, focus on the 2nd content element and not the close btn.
78
+
79
+ if (close && focusableModalElements.current.length > 1) {
80
+ focusIndex = 1;
81
+ }
82
+
83
+ (_focusableModalElemen = focusableModalElements.current[focusIndex]) === null || _focusableModalElemen === void 0 ? void 0 : _focusableModalElemen.focus();
73
84
  }, []);
74
85
  (0, _react.useEffect)(function () {
75
86
  var keyDown = function keyDown(e) {
@@ -19,6 +19,10 @@ export declare type Props<D extends Record<string, unknown>> = PropsWithSpread<{
19
19
  * Optional extra row to display underneath the main table content.
20
20
  */
21
21
  footer?: ReactNode;
22
+ /**
23
+ * Optional argument to make the tables be sortable and use the `useSortBy` plugin.
24
+ */
25
+ sortable?: Boolean;
22
26
  /**
23
27
  * This function is used to resolve any props needed for a particular column's header cell.
24
28
  */
@@ -33,5 +37,5 @@ export declare type Props<D extends Record<string, unknown>> = PropsWithSpread<{
33
37
  getCellProps?: (cell: Cell<D>) => Partial<TableCellProps & HTMLProps<HTMLTableCellElement>>;
34
38
  getRowId?: UseTableOptions<D>["getRowId"];
35
39
  }, HTMLProps<HTMLTableElement>>;
36
- declare function ModularTable({ data, columns, emptyMsg, footer, getHeaderProps, getRowProps, getCellProps, getRowId, ...props }: Props<Record<string, unknown>>): JSX.Element;
40
+ declare function ModularTable({ data, columns, emptyMsg, footer, sortable, getHeaderProps, getRowProps, getCellProps, getRowId, ...props }: Props<Record<string, unknown>>): JSX.Element;
37
41
  export default ModularTable;
@@ -19,7 +19,7 @@ var _TableCell = _interopRequireDefault(require("../TableCell"));
19
19
 
20
20
  var _Icon = _interopRequireDefault(require("../Icon"));
21
21
 
22
- var _excluded = ["data", "columns", "emptyMsg", "footer", "getHeaderProps", "getRowProps", "getCellProps", "getRowId"];
22
+ var _excluded = ["data", "columns", "emptyMsg", "footer", "sortable", "getHeaderProps", "getRowProps", "getCellProps", "getRowId"];
23
23
 
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
@@ -40,6 +40,7 @@ function ModularTable(_ref) {
40
40
  columns = _ref.columns,
41
41
  emptyMsg = _ref.emptyMsg,
42
42
  footer = _ref.footer,
43
+ sortable = _ref.sortable,
43
44
  getHeaderProps = _ref.getHeaderProps,
44
45
  getRowProps = _ref.getRowProps,
45
46
  getCellProps = _ref.getCellProps,
@@ -50,7 +51,7 @@ function ModularTable(_ref) {
50
51
  columns: columns,
51
52
  data: data,
52
53
  getRowId: getRowId || undefined
53
- }),
54
+ }, sortable ? _reactTable.useSortBy : undefined),
54
55
  getTableProps = _useTable.getTableProps,
55
56
  getTableBodyProps = _useTable.getTableBodyProps,
56
57
  headerGroups = _useTable.headerGroups,
@@ -60,11 +61,14 @@ function ModularTable(_ref) {
60
61
  var showEmpty = !!emptyMsg && (!rows || rows.length === 0);
61
62
  return /*#__PURE__*/_react.default.createElement(_Table.default, _extends({}, getTableProps(), props), /*#__PURE__*/_react.default.createElement("thead", null, headerGroups.map(function (headerGroup) {
62
63
  return /*#__PURE__*/_react.default.createElement(_TableRow.default, headerGroup.getHeaderGroupProps(), headerGroup.headers.map(function (column) {
63
- return /*#__PURE__*/_react.default.createElement(_TableHeader.default, column.getHeaderProps([{
64
+ return /*#__PURE__*/_react.default.createElement(_TableHeader.default, _extends({
65
+ sort: column.isSorted ? column.isSortedDesc ? "descending" : "ascending" : "none"
66
+ }, column.getHeaderProps([{
64
67
  className: column.className
65
68
  }, {
66
69
  className: column.getCellIcon ? "p-table__cell--icon-placeholder" : ""
67
- }, _objectSpread({}, getHeaderProps === null || getHeaderProps === void 0 ? void 0 : getHeaderProps(column))]), column.render("Header"));
70
+ }, _objectSpread({}, getHeaderProps === null || getHeaderProps === void 0 ? void 0 : getHeaderProps(column)), // Only call this if we want it to be sortable too.
71
+ sortable ? column.getSortByToggleProps() : {}])), column.render("Header"));
68
72
  }));
69
73
  })), /*#__PURE__*/_react.default.createElement("tbody", getTableBodyProps(), rows.map(function (row) {
70
74
  // This function is responsible for lazily preparing a row for rendering.
@@ -25,6 +25,10 @@ export declare type Props = PropsWithSpread<{
25
25
  * The number of pages at which to truncate the pagination items.
26
26
  */
27
27
  truncateThreshold?: number;
28
+ /**
29
+ * Whether or not the pagination is ceneterd on the page.
30
+ */
31
+ centered?: boolean;
28
32
  }, HTMLProps<HTMLElement>>;
29
- declare const Pagination: ({ itemsPerPage, totalItems, paginate, currentPage, scrollToTop, truncateThreshold, ...navProps }: Props) => JSX.Element;
33
+ declare const Pagination: ({ itemsPerPage, totalItems, paginate, currentPage, scrollToTop, truncateThreshold, centered, ...navProps }: Props) => JSX.Element;
30
34
  export default Pagination;
@@ -5,16 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+
8
10
  var _react = _interopRequireDefault(require("react"));
9
11
 
10
12
  var _PaginationButton = _interopRequireDefault(require("./PaginationButton"));
11
13
 
12
14
  var _PaginationItem = _interopRequireDefault(require("./PaginationItem"));
13
15
 
14
- var _excluded = ["itemsPerPage", "totalItems", "paginate", "currentPage", "scrollToTop", "truncateThreshold"];
16
+ var _excluded = ["itemsPerPage", "totalItems", "paginate", "currentPage", "scrollToTop", "truncateThreshold", "centered"];
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
20
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
+
18
22
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
19
23
 
20
24
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -121,6 +125,7 @@ var Pagination = function Pagination(_ref) {
121
125
  scrollToTop = _ref.scrollToTop,
122
126
  _ref$truncateThreshol = _ref.truncateThreshold,
123
127
  truncateThreshold = _ref$truncateThreshol === void 0 ? 10 : _ref$truncateThreshol,
128
+ centered = _ref.centered,
124
129
  navProps = _objectWithoutProperties(_ref, _excluded);
125
130
 
126
131
  // return early if no pagination is required
@@ -139,8 +144,13 @@ var Pagination = function Pagination(_ref) {
139
144
  scrollToTop && scrollTop();
140
145
  };
141
146
 
142
- return /*#__PURE__*/_react.default.createElement("nav", navProps, /*#__PURE__*/_react.default.createElement("ul", {
143
- className: "p-pagination"
147
+ return /*#__PURE__*/_react.default.createElement("nav", _extends({
148
+ className: "p-pagination",
149
+ "aria-label": "Pagination"
150
+ }, navProps), /*#__PURE__*/_react.default.createElement("ol", {
151
+ className: (0, _classnames.default)("p-pagination__items", {
152
+ "u-align--center": centered
153
+ })
144
154
  }, /*#__PURE__*/_react.default.createElement(_PaginationButton.default, {
145
155
  key: "back",
146
156
  direction: "back",
@@ -53,9 +53,11 @@ var Slider = function Slider(_ref) {
53
53
  var style = {};
54
54
 
55
55
  if ((_navigator = navigator) !== null && _navigator !== void 0 && (_navigator$userAgent = _navigator.userAgent) !== null && _navigator$userAgent !== void 0 && _navigator$userAgent.includes("AppleWebKit")) {
56
+ var _inputProps$value;
57
+
56
58
  // Range inputs on Webkit browsers don't have a built-in "filled" portion,
57
59
  // so instead it is handled here as a background.
58
- var val = inputProps.value || inputProps.defaultValue;
60
+ var val = (_inputProps$value = inputProps.value) !== null && _inputProps$value !== void 0 ? _inputProps$value : inputProps.defaultValue;
59
61
  var filledPercentage = "".concat((Number(val) - min) / (max - min) * 100, "%");
60
62
  style = {
61
63
  background: "linear-gradient(\n to right,\n ".concat(FILLED_COLOR, " 0%,\n ").concat(FILLED_COLOR, " ").concat(filledPercentage, ",\n ").concat(EMPTY_COLOR, " ").concat(filledPercentage, ",\n ").concat(EMPTY_COLOR, " 100%\n )")
@@ -1,3 +1,5 @@
1
1
  "use strict";
2
2
 
3
- require("react-table");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "0.37.8",
3
+ "version": "0.38.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "Huw Wilkins <huw.wilkins@canonical.com>",
@@ -79,7 +79,7 @@
79
79
  "ts-jest": "27.1.5",
80
80
  "tsc-alias": "1.7.0",
81
81
  "typescript": "4.7.4",
82
- "vanilla-framework": "3.8.2",
82
+ "vanilla-framework": "3.11.0",
83
83
  "wait-on": "5.3.0",
84
84
  "webpack": "5.74.0"
85
85
  },
@@ -103,7 +103,7 @@
103
103
  "peerDependencies": {
104
104
  "react": "^17.0.2 || ^18.0.0",
105
105
  "react-dom": "^17.0.2 || ^18.0.0",
106
- "vanilla-framework": "3.8.2"
106
+ "vanilla-framework": "3.11.0"
107
107
  },
108
108
  "scripts": {
109
109
  "build": "rm -rf dist && yarn build-local; yarn build-declaration",