@veracity/vui 0.5.1 → 0.6.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 (44) hide show
  1. package/core/links.d.ts +3 -2
  2. package/core/links.js +19 -15
  3. package/index.d.ts +1 -0
  4. package/index.js +1 -0
  5. package/modal/modal.d.ts +2 -2
  6. package/modal/modal.js +6 -6
  7. package/package.json +1 -1
  8. package/pagination/context.d.ts +4 -0
  9. package/pagination/context.js +23 -0
  10. package/pagination/helpers.d.ts +3 -0
  11. package/pagination/helpers.js +20 -0
  12. package/pagination/index.d.ts +13 -0
  13. package/pagination/index.js +31 -0
  14. package/pagination/pagination.d.ts +21 -0
  15. package/pagination/pagination.js +70 -0
  16. package/pagination/pagination.types.d.ts +31 -0
  17. package/pagination/pagination.types.js +2 -0
  18. package/pagination/paginationButton.d.ts +4 -0
  19. package/pagination/paginationButton.js +50 -0
  20. package/pagination/paginationEllipsis.d.ts +4 -0
  21. package/pagination/paginationEllipsis.js +40 -0
  22. package/pagination/paginationGoToPage.d.ts +4 -0
  23. package/pagination/paginationGoToPage.js +40 -0
  24. package/pagination/paginationNavigation.d.ts +4 -0
  25. package/pagination/paginationNavigation.js +68 -0
  26. package/pagination/paginationPrevNext.d.ts +4 -0
  27. package/pagination/paginationPrevNext.js +48 -0
  28. package/pagination/paginationResults.d.ts +4 -0
  29. package/pagination/paginationResults.js +41 -0
  30. package/pagination/theme.d.ts +8 -0
  31. package/pagination/theme.js +14 -0
  32. package/pagination/usePagination.d.ts +14 -0
  33. package/pagination/usePagination.js +58 -0
  34. package/pagination/usePagination.types.d.ts +12 -0
  35. package/pagination/usePagination.types.js +2 -0
  36. package/theme/components.d.ts +7 -0
  37. package/theme/components.js +20 -18
  38. package/theme/defaultTheme.d.ts +7 -0
  39. package/utils/react.d.ts +14 -0
  40. package/utils/react.js +38 -1
  41. /package/modal/{ModalBackdrop.d.ts → modalBackdrop.d.ts} +0 -0
  42. /package/modal/{ModalBackdrop.js → modalBackdrop.js} +0 -0
  43. /package/modal/{ModalContent.d.ts → modalContent.d.ts} +0 -0
  44. /package/modal/{ModalContent.js → modalContent.js} +0 -0
package/core/links.d.ts CHANGED
@@ -3,7 +3,8 @@ import { Dict, Environment } from '../utils';
3
3
  export declare type LinksDict = Dict<string>;
4
4
  declare type LinksContextType = [LinksDict, Dispatch<SetStateAction<LinksDict>>];
5
5
  /**
6
- * Adds loggedIn=1 parameter to the URL if isLoggedIn flag is true, which means the user is logged in.
6
+ * Adds loggedIn=1 parameter to the URL if 'isLoggedIn' flag is true, which means the user is logged in.
7
+ * If 'isLoggedIn' is falsy, loggedin param will be removed.
7
8
  * This is supposed to aid login flow when navigating between Veracity applications.
8
9
  */
9
10
  export declare function getLoggedInLink(link: string, isLoggedIn?: boolean): string;
@@ -14,7 +15,7 @@ export declare function LinksProvider(props: {
14
15
  export declare function useLinks(): LinksContextType;
15
16
  /**
16
17
  * Retrieves the links from CDN for the given environment and appends them with loggedin=1 parameter
17
- * if user is logged in. Links will be reloaded or updated whenever 'env' or 'isLoggedIn' change.
18
+ * if user is logged in. Links will be reloaded when 'env' changes or updated when 'isLoggedIn' changes.
18
19
  */
19
20
  export declare function useLoadLinks(env?: Environment, isLoggedIn?: boolean): void;
20
21
  export {};
package/core/links.js CHANGED
@@ -88,14 +88,19 @@ var utils_1 = require("../utils");
88
88
  var consts_1 = require("./consts");
89
89
  var LinksContext = (0, react_1.createContext)(undefined);
90
90
  /**
91
- * Adds loggedIn=1 parameter to the URL if isLoggedIn flag is true, which means the user is logged in.
91
+ * Adds loggedIn=1 parameter to the URL if 'isLoggedIn' flag is true, which means the user is logged in.
92
+ * If 'isLoggedIn' is falsy, loggedin param will be removed.
92
93
  * This is supposed to aid login flow when navigating between Veracity applications.
93
94
  */
94
95
  function getLoggedInLink(link, isLoggedIn) {
95
96
  try {
96
97
  var url = new URL(link);
97
- if (isLoggedIn)
98
+ if (isLoggedIn) {
98
99
  url.searchParams.append('loggedin', '1');
100
+ }
101
+ else {
102
+ url.searchParams.delete('loggedin');
103
+ }
99
104
  return url.toString();
100
105
  }
101
106
  catch (_a) {
@@ -120,7 +125,7 @@ function useLinks() {
120
125
  exports.useLinks = useLinks;
121
126
  /**
122
127
  * Retrieves the links from CDN for the given environment and appends them with loggedin=1 parameter
123
- * if user is logged in. Links will be reloaded or updated whenever 'env' or 'isLoggedIn' change.
128
+ * if user is logged in. Links will be reloaded when 'env' changes or updated when 'isLoggedIn' changes.
124
129
  */
125
130
  function useLoadLinks(env, isLoggedIn) {
126
131
  var _a = __read(useLinks(), 2), setLinks = _a[1];
@@ -130,17 +135,8 @@ function useLoadLinks(env, isLoggedIn) {
130
135
  loadLinks(env);
131
136
  }, [env]);
132
137
  (0, react_1.useEffect)(function () {
133
- appendLoggedInParam(isLoggedIn);
138
+ setLinks(function (links) { return updateLoggedInParam(links, isLoggedIn); });
134
139
  }, [isLoggedIn]);
135
- // Adds loggedin=1 param to each link if user is logged in.
136
- function appendLoggedInParam(isLoggedIn) {
137
- setLinks(function (state) {
138
- return Object.keys(state).reduce(function (links, key) {
139
- links[key] = getLoggedInLink(state[key], isLoggedIn);
140
- return links;
141
- }, {});
142
- });
143
- }
144
140
  // Load links from the CDN for the given environment.
145
141
  function loadLinks(env) {
146
142
  return __awaiter(this, void 0, void 0, function () {
@@ -157,8 +153,9 @@ function useLoadLinks(env, isLoggedIn) {
157
153
  return [4 /*yield*/, response.json()];
158
154
  case 2:
159
155
  data = _b.sent();
160
- if ((0, utils_1.isObject)(data))
161
- setLinks(data);
156
+ if ((0, utils_1.isObject)(data)) {
157
+ setLinks(updateLoggedInParam(data, isLoggedIn));
158
+ }
162
159
  return [3 /*break*/, 4];
163
160
  case 3:
164
161
  _a = _b.sent();
@@ -169,5 +166,12 @@ function useLoadLinks(env, isLoggedIn) {
169
166
  });
170
167
  });
171
168
  }
169
+ // Adds/removes loggedin=1 URL param for each link based on isLoggedIn arg.
170
+ function updateLoggedInParam(links, isLoggedIn) {
171
+ return Object.keys(links).reduce(function (loggedInLinks, key) {
172
+ loggedInLinks[key] = getLoggedInLink(links[key], isLoggedIn);
173
+ return loggedInLinks;
174
+ }, {});
175
+ }
172
176
  }
173
177
  exports.useLoadLinks = useLoadLinks;
package/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from './menu';
21
21
  export * from './modal';
22
22
  export * from './notification';
23
23
  export * from './p';
24
+ export * from './pagination';
24
25
  export * from './panel';
25
26
  export * from './popover';
26
27
  export * from './portal';
package/index.js CHANGED
@@ -33,6 +33,7 @@ __exportStar(require("./menu"), exports);
33
33
  __exportStar(require("./modal"), exports);
34
34
  __exportStar(require("./notification"), exports);
35
35
  __exportStar(require("./p"), exports);
36
+ __exportStar(require("./pagination"), exports);
36
37
  __exportStar(require("./panel"), exports);
37
38
  __exportStar(require("./popover"), exports);
38
39
  __exportStar(require("./portal"), exports);
package/modal/modal.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { VuiComponent } from '../core';
2
2
  import { ModalProps } from './modal.types';
3
- import ModalBackdrop from './ModalBackdrop';
4
- import ModalContent from './ModalContent';
3
+ import ModalBackdrop from './modalBackdrop';
4
+ import ModalContent from './modalContent';
5
5
  /**
6
6
  * Displays provided content on top of a dark backdrop element with fixed position.
7
7
  * By default uses Portal for content and closes when clicking backdrop or pressing 'Escape'.
package/modal/modal.js CHANGED
@@ -53,8 +53,8 @@ var portal_1 = __importDefault(require("../portal"));
53
53
  var utils_1 = require("../utils");
54
54
  var context_1 = require("./context");
55
55
  var focusLock_1 = __importDefault(require("./focusLock"));
56
- var ModalBackdrop_1 = __importDefault(require("./ModalBackdrop"));
57
- var ModalContent_1 = __importDefault(require("./ModalContent"));
56
+ var modalBackdrop_1 = __importDefault(require("./modalBackdrop"));
57
+ var modalContent_1 = __importDefault(require("./modalContent"));
58
58
  var modalManager_1 = require("./modalManager");
59
59
  /**
60
60
  * Displays provided content on top of a dark backdrop element with fixed position.
@@ -102,12 +102,12 @@ exports.Modal = (0, core_1.vui)(function (props, ref) {
102
102
  return (react_1.default.createElement(context_1.ModalProvider, { value: context },
103
103
  react_1.default.createElement(portal_1.default, { disablePortal: disablePortal },
104
104
  react_1.default.createElement(box_1.default, __assign({ className: (0, utils_1.cs)('vui-modal', className), ref: (0, utils_1.mergeRefs)(ref, modalRef) }, rest, { onKeyDown: (0, utils_1.callAll)(props.onKeyDown, onKeyDown), onMouseDown: (0, utils_1.callAll)(props.onMouseDown, onMouseDown) }),
105
- !hideBackdrop && react_1.default.createElement(ModalBackdrop_1.default, null),
105
+ !hideBackdrop && react_1.default.createElement(modalBackdrop_1.default, null),
106
106
  react_1.default.createElement(focusLock_1.default, { autoFocus: !disableAutoFocus, finalFocusRef: finalFocusRef, initialFocusRef: initialFocusRef, isDisabled: disableTrapFocus, returnFocus: !disableReturnFocus },
107
107
  react_1.default.createElement(react_remove_scroll_1.RemoveScroll, { allowPinchZoom: allowPinchZoom, enabled: !disableScrollLock, forwardProps: true, removeScrollBar: !preserveScrollBar },
108
- react_1.default.createElement(ModalContent_1.default, __assign({}, contentProps), (0, react_1.cloneElement)(children, childProps))))))));
108
+ react_1.default.createElement(modalContent_1.default, __assign({}, contentProps), (0, react_1.cloneElement)(children, childProps))))))));
109
109
  });
110
110
  exports.Modal.displayName = 'Modal';
111
- exports.Modal.Backdrop = ModalBackdrop_1.default;
112
- exports.Modal.Content = ModalContent_1.default;
111
+ exports.Modal.Backdrop = modalBackdrop_1.default;
112
+ exports.Modal.Content = modalContent_1.default;
113
113
  exports.default = exports.Modal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veracity/vui",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Veracity UI React components library based on Styled Components and @xstyled",
5
5
  "main": "index.js",
6
6
  "author": "Veracity",
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { PaginationContext } from './pagination.types';
3
+ declare const PaginationProvider: import("react").Provider<PaginationContext>, usePaginationContext: () => PaginationContext;
4
+ export { PaginationProvider, usePaginationContext };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.usePaginationContext = exports.PaginationProvider = void 0;
20
+ var utils_1 = require("../utils");
21
+ var _a = __read((0, utils_1.createContext)({ isOptional: true }), 2), PaginationProvider = _a[0], usePaginationContext = _a[1];
22
+ exports.PaginationProvider = PaginationProvider;
23
+ exports.usePaginationContext = usePaginationContext;
@@ -0,0 +1,3 @@
1
+ import { PaginationItem } from './pagination.types';
2
+ /** Returns an array describing pagination items, like page buttons, prev/next arrows or ellipsis. */
3
+ export declare function getPaginationItems(page: number, pageCount: number): PaginationItem[];
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPaginationItems = void 0;
4
+ /** Returns an array describing pagination items, like page buttons, prev/next arrows or ellipsis. */
5
+ function getPaginationItems(page, pageCount) {
6
+ var items = ['previous', 1];
7
+ if (page - 2 > 1)
8
+ items.push('ellipsisStart');
9
+ for (var i = page - 1; i <= page + 1; i++) {
10
+ if (i > 1 && i < pageCount)
11
+ items.push(i);
12
+ }
13
+ if (page + 2 < pageCount)
14
+ items.push('ellipsisEnd');
15
+ if (pageCount > 1)
16
+ items.push(pageCount);
17
+ items.push('next');
18
+ return items;
19
+ }
20
+ exports.getPaginationItems = getPaginationItems;
@@ -0,0 +1,13 @@
1
+ export * from './context';
2
+ export * from './helpers';
3
+ export * from './pagination';
4
+ export { default } from './pagination';
5
+ export * from './pagination.types';
6
+ export * from './paginationButton';
7
+ export * from './paginationEllipsis';
8
+ export * from './paginationGoToPage';
9
+ export * from './paginationNavigation';
10
+ export * from './paginationPrevNext';
11
+ export * from './paginationResults';
12
+ export { default as usePagination } from './usePagination';
13
+ export * from './usePagination.types';
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.usePagination = exports.default = void 0;
17
+ __exportStar(require("./context"), exports);
18
+ __exportStar(require("./helpers"), exports);
19
+ __exportStar(require("./pagination"), exports);
20
+ var pagination_1 = require("./pagination");
21
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(pagination_1).default; } });
22
+ __exportStar(require("./pagination.types"), exports);
23
+ __exportStar(require("./paginationButton"), exports);
24
+ __exportStar(require("./paginationEllipsis"), exports);
25
+ __exportStar(require("./paginationGoToPage"), exports);
26
+ __exportStar(require("./paginationNavigation"), exports);
27
+ __exportStar(require("./paginationPrevNext"), exports);
28
+ __exportStar(require("./paginationResults"), exports);
29
+ var usePagination_1 = require("./usePagination");
30
+ Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return __importDefault(usePagination_1).default; } });
31
+ __exportStar(require("./usePagination.types"), exports);
@@ -0,0 +1,21 @@
1
+ import { VuiComponent } from '../core';
2
+ import { PaginationProps } from './pagination.types';
3
+ import PaginationButton from './paginationButton';
4
+ import PaginationEllipsis from './paginationEllipsis';
5
+ import PaginationGoToPage from './paginationGoToPage';
6
+ import PaginationNavigation from './paginationNavigation';
7
+ import PaginationPrevNext from './paginationPrevNext';
8
+ import PaginationResults from './paginationResults';
9
+ /**
10
+ * Displays page navigation buttons together with page and item count.
11
+ * GoToPage component is shown automatically above 10 pages.
12
+ */
13
+ export declare const Pagination: VuiComponent<"div", PaginationProps> & {
14
+ Button: typeof PaginationButton;
15
+ Ellipsis: typeof PaginationEllipsis;
16
+ GoToPage: typeof PaginationGoToPage;
17
+ Navigation: typeof PaginationNavigation;
18
+ PrevNext: typeof PaginationPrevNext;
19
+ Results: typeof PaginationResults;
20
+ };
21
+ export default Pagination;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.Pagination = void 0;
29
+ var react_1 = __importDefault(require("react"));
30
+ var box_1 = __importDefault(require("../box"));
31
+ var core_1 = require("../core");
32
+ var utils_1 = require("../utils");
33
+ var context_1 = require("./context");
34
+ var paginationButton_1 = __importDefault(require("./paginationButton"));
35
+ var paginationEllipsis_1 = __importDefault(require("./paginationEllipsis"));
36
+ var paginationGoToPage_1 = __importDefault(require("./paginationGoToPage"));
37
+ var paginationNavigation_1 = __importDefault(require("./paginationNavigation"));
38
+ var paginationPrevNext_1 = __importDefault(require("./paginationPrevNext"));
39
+ var paginationResults_1 = __importDefault(require("./paginationResults"));
40
+ var usePagination_1 = __importDefault(require("./usePagination"));
41
+ /**
42
+ * Displays page navigation buttons together with page and item count.
43
+ * GoToPage component is shown automatically above 10 pages.
44
+ */
45
+ exports.Pagination = (0, core_1.vui)(function (props, ref) {
46
+ var _a;
47
+ var children = props.children, className = props.className, count = props.count, defaultPage = props.defaultPage, goToPage = props.goToPage, _b = props.items, itemsProp = _b === void 0 ? [] : _b, navigation = props.navigation, onPageChange = props.onPageChange, pageProp = props.page, pageSize = props.pageSize, results = props.results, size = props.size, variant = props.variant, rest = __rest(props, ["children", "className", "count", "defaultPage", "goToPage", "items", "navigation", "onPageChange", "page", "pageSize", "results", "size", "variant"]);
48
+ var styles = (0, core_1.useStyleConfig)('Pagination', props);
49
+ var _c = (0, usePagination_1.default)({
50
+ count: count,
51
+ defaultPage: defaultPage,
52
+ onPageChange: onPageChange,
53
+ page: pageProp,
54
+ pageSize: pageSize
55
+ }), _d = _c.items, items = _d === void 0 ? itemsProp : _d, paginationProps = __rest(_c, ["items"]);
56
+ var context = __assign(__assign({}, paginationProps), { items: items, size: size, variant: variant });
57
+ return (react_1.default.createElement(context_1.PaginationProvider, { value: context },
58
+ react_1.default.createElement(box_1.default, __assign({ centerV: true, className: (0, utils_1.cs)('vui-pagination', className), gap: 3, ref: ref, w: 1, wrap: true }, styles.container, rest), (_a = (0, utils_1.runIfFn)(children, context)) !== null && _a !== void 0 ? _a : (react_1.default.createElement(react_1.default.Fragment, null,
59
+ (0, utils_1.isJsx)(results) ? results : react_1.default.createElement(paginationResults_1.default, null),
60
+ (0, utils_1.isJsx)(navigation) ? navigation : react_1.default.createElement(paginationNavigation_1.default, { ml: "auto" }),
61
+ (0, utils_1.isJsx)(goToPage) ? goToPage : paginationProps.pageCount > 10 && react_1.default.createElement(paginationGoToPage_1.default, null))))));
62
+ });
63
+ exports.Pagination.displayName = 'Notification';
64
+ exports.Pagination.Button = paginationButton_1.default;
65
+ exports.Pagination.Ellipsis = paginationEllipsis_1.default;
66
+ exports.Pagination.GoToPage = paginationGoToPage_1.default;
67
+ exports.Pagination.Navigation = paginationNavigation_1.default;
68
+ exports.Pagination.PrevNext = paginationPrevNext_1.default;
69
+ exports.Pagination.Results = paginationResults_1.default;
70
+ exports.default = exports.Pagination;
@@ -0,0 +1,31 @@
1
+ /// <reference types="react" />
2
+ import { BoxProps } from '../box';
3
+ import { ButtonProps } from '../button';
4
+ import { ThemingProps } from '../theme';
5
+ import { RenderProps } from '../utils';
6
+ import { UsePaginationReturnType } from './usePagination';
7
+ import { UsePaginationProps } from './usePagination.types';
8
+ export declare type PaginationButtonProps = ButtonProps & {
9
+ /** Applies different styling to a button of the current page. */
10
+ isActive?: boolean;
11
+ /** Number of the page, which this button represents. */
12
+ page: number;
13
+ };
14
+ export declare type PaginationContext = UsePaginationReturnType & ThemingProps<'Pagination'>;
15
+ export declare type PaginationItem = 'ellipsisEnd' | 'ellipsisStart' | 'next' | 'previous' | number;
16
+ export declare type PaginationPrevNextProps = ButtonProps & {
17
+ /** Defines the logic of previous and next buttons. */
18
+ direction: 'previous' | 'next';
19
+ };
20
+ export declare type PaginationProps = Omit<BoxProps, 'size' | 'variant'> & ThemingProps<'Pagination'> & UsePaginationProps & {
21
+ /** Children provide render props using PaginationContext data. */
22
+ children?: RenderProps<PaginationContext>;
23
+ /** Socket for page input on the right side. */
24
+ goToPage?: JSX.Element;
25
+ /** Array describing pagination items, like page buttons, prev/next arrows or ellipsis. */
26
+ items?: PaginationItem[];
27
+ /** Socket for the main navigation elements in the middle. */
28
+ navigation?: JSX.Element;
29
+ /** Socket for numbers data on the left side. */
30
+ results?: JSX.Element;
31
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { PaginationButtonProps } from './pagination.types';
2
+ /** Displays a page navigation button within the Pagination. */
3
+ export declare const PaginationButton: import("../core").VuiComponent<"button", PaginationButtonProps>;
4
+ export default PaginationButton;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.PaginationButton = void 0;
29
+ var react_1 = __importDefault(require("react"));
30
+ var button_1 = __importDefault(require("../button"));
31
+ var core_1 = require("../core");
32
+ var context_1 = require("./context");
33
+ /** Displays a page navigation button within the Pagination. */
34
+ exports.PaginationButton = (0, core_1.vui)(function (props, ref) {
35
+ var isActiveProp = props.isActive, pageProp = props.page, rest = __rest(props, ["isActive", "page"]);
36
+ var _a = (0, context_1.usePaginationContext)(), onPageChange = _a.onPageChange, page = _a.page;
37
+ var styles = (0, core_1.useStyleConfig)('Pagination', (0, context_1.usePaginationContext)());
38
+ var isActive = isActiveProp !== null && isActiveProp !== void 0 ? isActiveProp : pageProp === page;
39
+ var activeProps = isActive
40
+ ? {
41
+ bg: 'blue.20',
42
+ color: 'blue.80',
43
+ hoverBg: 'blue.30',
44
+ activeBg: 'blue.40'
45
+ }
46
+ : {};
47
+ return (react_1.default.createElement(button_1.default, __assign({ className: "vui-paginationButton", minW: 0, onClick: function () { return onPageChange(pageProp); }, ref: ref, size: "sm", text: pageProp, variant: "text" }, styles.button, activeProps, rest)));
48
+ });
49
+ exports.PaginationButton.displayName = 'PaginationButton';
50
+ exports.default = exports.PaginationButton;
@@ -0,0 +1,4 @@
1
+ import { BoxProps } from '../box';
2
+ /** Displays '...' ellipsis for hidden pages. */
3
+ export declare const PaginationEllipsis: import("../core").VuiComponent<"span", BoxProps>;
4
+ export default PaginationEllipsis;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.PaginationEllipsis = void 0;
29
+ var react_1 = __importDefault(require("react"));
30
+ var box_1 = __importDefault(require("../box"));
31
+ var core_1 = require("../core");
32
+ var context_1 = require("./context");
33
+ /** Displays '...' ellipsis for hidden pages. */
34
+ exports.PaginationEllipsis = (0, core_1.vui)(function (props, ref) {
35
+ var children = props.children, rest = __rest(props, ["children"]);
36
+ var styles = (0, core_1.useStyleConfig)('Pagination', (0, context_1.usePaginationContext)());
37
+ return (react_1.default.createElement(box_1.default, __assign({ alignItems: "center", className: "vui-paginationEllipsis", ref: ref }, styles.ellipsis, rest), children !== null && children !== void 0 ? children : '...'));
38
+ });
39
+ exports.PaginationEllipsis.displayName = 'PaginationEllipsis';
40
+ exports.default = exports.PaginationEllipsis;
@@ -0,0 +1,4 @@
1
+ import { BoxProps } from '../box';
2
+ /** Displays a number input, which allows quickly jumping between pages. */
3
+ export declare const PaginationGoToPage: import("../core").VuiComponent<"div", BoxProps>;
4
+ export default PaginationGoToPage;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.PaginationGoToPage = void 0;
18
+ var react_1 = __importDefault(require("react"));
19
+ var box_1 = __importDefault(require("../box"));
20
+ var core_1 = require("../core");
21
+ var input_1 = __importDefault(require("../input"));
22
+ var t_1 = __importDefault(require("../t"));
23
+ var context_1 = require("./context");
24
+ /** Displays a number input, which allows quickly jumping between pages. */
25
+ exports.PaginationGoToPage = (0, core_1.vui)(function (props, ref) {
26
+ var _a = (0, context_1.usePaginationContext)(), onPageChange = _a.onPageChange, pageCount = _a.pageCount;
27
+ var styles = (0, core_1.useStyleConfig)('Pagination', (0, context_1.usePaginationContext)());
28
+ var onChange = function (e) {
29
+ var value = +e.target.value;
30
+ if (value >= 1 && value <= pageCount) {
31
+ onPageChange(Math.floor(value));
32
+ }
33
+ };
34
+ return (react_1.default.createElement(box_1.default, __assign({ centerV: true, className: "vui-paginationGoToPage", lineHeight: "normal", ref: ref }, styles.goToPage, props),
35
+ react_1.default.createElement(t_1.default, { size: "sm", weight: "medium" }, "Go to"),
36
+ react_1.default.createElement(input_1.default, { max: pageCount, min: 1, mx: 1, onChange: onChange, size: "sm", type: "number", w: 56 }),
37
+ react_1.default.createElement(t_1.default, { size: "sm", weight: "medium" }, "Page")));
38
+ });
39
+ exports.PaginationGoToPage.displayName = 'PaginationGoToPage';
40
+ exports.default = exports.PaginationGoToPage;
@@ -0,0 +1,4 @@
1
+ import { BoxProps } from '../box';
2
+ /** Displays a set of page navigation buttons. */
3
+ export declare const PaginationNavigation: import("../core").VuiComponent<"div", BoxProps>;
4
+ export default PaginationNavigation;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ var __rest = (this && this.__rest) || function (s, e) {
33
+ var t = {};
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
35
+ t[p] = s[p];
36
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
37
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
38
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
39
+ t[p[i]] = s[p[i]];
40
+ }
41
+ return t;
42
+ };
43
+ var __importDefault = (this && this.__importDefault) || function (mod) {
44
+ return (mod && mod.__esModule) ? mod : { "default": mod };
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.PaginationNavigation = void 0;
48
+ var react_1 = __importStar(require("react"));
49
+ var box_1 = __importDefault(require("../box"));
50
+ var core_1 = require("../core");
51
+ var utils_1 = require("../utils");
52
+ var context_1 = require("./context");
53
+ var paginationButton_1 = __importDefault(require("./paginationButton"));
54
+ var paginationEllipsis_1 = __importDefault(require("./paginationEllipsis"));
55
+ var paginationPrevNext_1 = __importDefault(require("./paginationPrevNext"));
56
+ /** Displays a set of page navigation buttons. */
57
+ exports.PaginationNavigation = (0, core_1.vui)(function (props, ref) {
58
+ var children = props.children, rest = __rest(props, ["children"]);
59
+ var items = (0, context_1.usePaginationContext)().items;
60
+ var styles = (0, core_1.useStyleConfig)('Pagination', (0, context_1.usePaginationContext)());
61
+ return (react_1.default.createElement(box_1.default, __assign({ className: "vui-paginationNavigation", gap: 1, ref: ref, wrap: true }, styles.navigation, rest), children !== null && children !== void 0 ? children : items.map(function (item) { return (react_1.default.createElement(react_1.Fragment, { key: item },
62
+ item === 'previous' && react_1.default.createElement(paginationPrevNext_1.default, { direction: "previous" }),
63
+ (0, utils_1.isNumber)(item) && react_1.default.createElement(paginationButton_1.default, { page: item }),
64
+ (0, utils_1.isString)(item) && item.includes('ellipsis') && react_1.default.createElement(paginationEllipsis_1.default, null),
65
+ item === 'next' && react_1.default.createElement(paginationPrevNext_1.default, { direction: "next" }))); })));
66
+ });
67
+ exports.PaginationNavigation.displayName = 'PaginationNavigation';
68
+ exports.default = exports.PaginationNavigation;
@@ -0,0 +1,4 @@
1
+ import { PaginationPrevNextProps } from './pagination.types';
2
+ /** Displays a page navigation button, which navigates forward or backward. */
3
+ export declare const PaginationPrevNext: import("../core").VuiComponent<"button", PaginationPrevNextProps>;
4
+ export default PaginationPrevNext;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.PaginationPrevNext = void 0;
29
+ var react_1 = __importDefault(require("react"));
30
+ var button_1 = __importDefault(require("../button"));
31
+ var core_1 = require("../core");
32
+ var context_1 = require("./context");
33
+ /** Displays a page navigation button, which navigates forward or backward. */
34
+ exports.PaginationPrevNext = (0, core_1.vui)(function (props, ref) {
35
+ var direction = props.direction, rest = __rest(props, ["direction"]);
36
+ var _a = (0, context_1.usePaginationContext)(), onPageChange = _a.onPageChange, page = _a.page, pageCount = _a.pageCount;
37
+ var styles = (0, core_1.useStyleConfig)('Pagination', (0, context_1.usePaginationContext)());
38
+ var isPrev = direction === 'previous';
39
+ var pageChange = isPrev ? -1 : 1;
40
+ var directionProps = {
41
+ disabled: isPrev ? page === 1 : page === pageCount,
42
+ icon: isPrev ? 'falAngleLeft' : 'falAngleRight',
43
+ onClick: function () { return onPageChange(page + pageChange); }
44
+ };
45
+ return (react_1.default.createElement(button_1.default, __assign({ className: "vui-paginationPrevNext", minW: 0, ref: ref, size: "sm", variant: "text" }, styles.prevNext, directionProps, rest)));
46
+ });
47
+ exports.PaginationPrevNext.displayName = 'PaginationPrevNext';
48
+ exports.default = exports.PaginationPrevNext;
@@ -0,0 +1,4 @@
1
+ import { TProps } from '../t';
2
+ /** Displays an action button within the Pagination. */
3
+ export declare const PaginationResults: import("../core").VuiComponent<"span", TProps>;
4
+ export default PaginationResults;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.PaginationResults = void 0;
29
+ var react_1 = __importDefault(require("react"));
30
+ var core_1 = require("../core");
31
+ var t_1 = __importDefault(require("../t"));
32
+ var context_1 = require("./context");
33
+ /** Displays an action button within the Pagination. */
34
+ exports.PaginationResults = (0, core_1.vui)(function (props, ref) {
35
+ var children = props.children, rest = __rest(props, ["children"]);
36
+ var _a = (0, context_1.usePaginationContext)(), count = _a.count, rangeEnd = _a.rangeEnd, rangeStart = _a.rangeStart;
37
+ var styles = (0, core_1.useStyleConfig)('Pagination', (0, context_1.usePaginationContext)());
38
+ return (react_1.default.createElement(t_1.default, __assign({ className: "vui-paginationResults", color: "grey.80", ref: ref, size: "sm", weight: "medium" }, styles.results, rest), children !== null && children !== void 0 ? children : "Showing " + rangeStart + " to " + rangeEnd + " of " + count + " results."));
39
+ });
40
+ exports.PaginationResults.displayName = 'PaginationResults';
41
+ exports.default = exports.PaginationResults;
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ baseStyle: {};
3
+ defaultProps: {};
4
+ parts: string[];
5
+ sizes: {};
6
+ variants: {};
7
+ };
8
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var baseStyle = {};
4
+ var defaultProps = {};
5
+ var parts = ['container', 'button', 'ellipsis', 'goToPage', 'navigation', 'prevNext', 'results'];
6
+ var sizes = {};
7
+ var variants = {};
8
+ exports.default = {
9
+ baseStyle: baseStyle,
10
+ defaultProps: defaultProps,
11
+ parts: parts,
12
+ sizes: sizes,
13
+ variants: variants
14
+ };
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { UsePaginationProps } from './usePagination.types';
3
+ /** Hook to manage pagination data and state in controlled or uncontrolled way. */
4
+ export default function usePagination(props: UsePaginationProps): {
5
+ count: number;
6
+ items: import("./pagination.types").PaginationItem[];
7
+ onPageChange: import("react").Dispatch<import("react").SetStateAction<number>>;
8
+ page: number;
9
+ pageCount: number;
10
+ pageSize: number;
11
+ rangeEnd: number;
12
+ rangeStart: number;
13
+ };
14
+ export declare type UsePaginationReturnType = ReturnType<typeof usePagination>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ var react_1 = require("react");
20
+ var utils_1 = require("../utils");
21
+ var helpers_1 = require("./helpers");
22
+ /** Hook to manage pagination data and state in controlled or uncontrolled way. */
23
+ function usePagination(props) {
24
+ var count = props.count, _a = props.defaultPage, defaultPage = _a === void 0 ? 1 : _a, onPageChangeProp = props.onPageChange, pageProp = props.page, pageSize = props.pageSize;
25
+ var _b = __read((0, utils_1.useControlled)({
26
+ defaultValue: defaultPage,
27
+ onChange: onPageChangeProp,
28
+ value: pageProp
29
+ }), 3), page = _b[0], onPageChange = _b[1], _c = _b[2], isControlled = _c.isControlled, reset = _c.reset;
30
+ // In uncontrolled mode, trigger external callback on the first render for consumer to initialize data.
31
+ (0, react_1.useEffect)(function () {
32
+ !isControlled && (onPageChangeProp === null || onPageChangeProp === void 0 ? void 0 : onPageChangeProp(defaultPage));
33
+ }, []);
34
+ /** In uncontrolled mode, reset pagination whenever pageSize changes (apart from initialization). */
35
+ (0, react_1.useEffect)(function () {
36
+ isMounted() && reset();
37
+ }, [pageSize]);
38
+ var isMounted = (0, utils_1.useIsMounted)();
39
+ /** How many pages are there in total. */
40
+ var pageCount = count > 0 && pageSize > 0 ? Math.ceil(count / pageSize) : 0;
41
+ /** Array of navigation items, like buttons or arrows. */
42
+ var items = (0, helpers_1.getPaginationItems)(page, pageCount);
43
+ /** First item displayed on the current page. */
44
+ var rangeStart = (page - 1) * pageSize + 1;
45
+ /** Last item displayed on the current page. */
46
+ var rangeEnd = page === pageCount ? count : page * pageSize;
47
+ return {
48
+ count: count,
49
+ items: items,
50
+ onPageChange: onPageChange,
51
+ page: page,
52
+ pageCount: pageCount,
53
+ pageSize: pageSize,
54
+ rangeEnd: rangeEnd,
55
+ rangeStart: rangeStart
56
+ };
57
+ }
58
+ exports.default = usePagination;
@@ -0,0 +1,12 @@
1
+ export declare type UsePaginationProps = {
2
+ /** Total amount of items being paginated. */
3
+ count: number;
4
+ /** Starting page in uncontrolled mode. */
5
+ defaultPage?: number;
6
+ /** Callback triggered by Pagination elements. */
7
+ onPageChange?: (page: number) => void;
8
+ /** Currently displayed page. */
9
+ page?: number;
10
+ /** Amount of items per page. */
11
+ pageSize: number;
12
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -679,6 +679,13 @@ declare const _default: {
679
679
  };
680
680
  variants: {};
681
681
  };
682
+ Pagination: {
683
+ baseStyle: {};
684
+ defaultProps: {};
685
+ parts: string[];
686
+ sizes: {};
687
+ variants: {};
688
+ };
682
689
  Panel: {
683
690
  baseStyle: {};
684
691
  defaultProps: {
@@ -23,15 +23,16 @@ var theme_17 = __importDefault(require("../menu/theme"));
23
23
  var theme_18 = __importDefault(require("../modal/theme"));
24
24
  var theme_19 = __importDefault(require("../notification/theme"));
25
25
  var theme_20 = __importDefault(require("../p/theme"));
26
- var theme_21 = __importDefault(require("../panel/theme"));
27
- var theme_22 = __importDefault(require("../popover/theme"));
28
- var theme_23 = __importDefault(require("../radio/theme"));
29
- var theme_24 = __importDefault(require("../skeleton/theme"));
30
- var theme_25 = __importDefault(require("../spinner/theme"));
31
- var theme_26 = __importDefault(require("../switch/theme"));
32
- var theme_27 = __importDefault(require("../t/theme"));
33
- var theme_28 = __importDefault(require("../tag/theme"));
34
- var theme_29 = __importDefault(require("../textarea/theme"));
26
+ var theme_21 = __importDefault(require("../pagination/theme"));
27
+ var theme_22 = __importDefault(require("../panel/theme"));
28
+ var theme_23 = __importDefault(require("../popover/theme"));
29
+ var theme_24 = __importDefault(require("../radio/theme"));
30
+ var theme_25 = __importDefault(require("../skeleton/theme"));
31
+ var theme_26 = __importDefault(require("../spinner/theme"));
32
+ var theme_27 = __importDefault(require("../switch/theme"));
33
+ var theme_28 = __importDefault(require("../t/theme"));
34
+ var theme_29 = __importDefault(require("../tag/theme"));
35
+ var theme_30 = __importDefault(require("../textarea/theme"));
35
36
  exports.default = {
36
37
  Avatar: theme_1.default,
37
38
  Box: theme_2.default,
@@ -53,13 +54,14 @@ exports.default = {
53
54
  Modal: theme_18.default,
54
55
  Notification: theme_19.default,
55
56
  P: theme_20.default,
56
- Panel: theme_21.default,
57
- Popover: theme_22.default,
58
- Radio: theme_23.default,
59
- Skeleton: theme_24.default,
60
- Spinner: theme_25.default,
61
- Switch: theme_26.default,
62
- T: theme_27.default,
63
- Tag: theme_28.default,
64
- Textarea: theme_29.default
57
+ Pagination: theme_21.default,
58
+ Panel: theme_22.default,
59
+ Popover: theme_23.default,
60
+ Radio: theme_24.default,
61
+ Skeleton: theme_25.default,
62
+ Spinner: theme_26.default,
63
+ Switch: theme_27.default,
64
+ T: theme_28.default,
65
+ Tag: theme_29.default,
66
+ Textarea: theme_30.default
65
67
  };
@@ -875,6 +875,13 @@ declare const defaultTheme: {
875
875
  };
876
876
  variants: {};
877
877
  };
878
+ Pagination: {
879
+ baseStyle: {};
880
+ defaultProps: {};
881
+ parts: string[];
882
+ sizes: {};
883
+ variants: {};
884
+ };
878
885
  Panel: {
879
886
  baseStyle: {};
880
887
  defaultProps: {
package/utils/react.d.ts CHANGED
@@ -20,6 +20,20 @@ export declare function useCallbackRef<T extends AnyFunction>(callback?: T): T;
20
20
  * @param events - array of events listened for (default: ['mousedown', 'touchstart'])
21
21
  */
22
22
  export declare function useClickOutside(ref: RefObject<HTMLElement | null> | RefObject<HTMLElement | null>[], callback?: (event: Event) => void, events?: string[]): void;
23
+ export declare type UseControlledProps<T> = {
24
+ value?: T;
25
+ defaultValue?: T;
26
+ onChange?: (value: T) => void;
27
+ };
28
+ /** Supports state management in components that can be controlled or uncontrolled. */
29
+ export declare function useControlled<T>(props: UseControlledProps<T>): [T, React.Dispatch<React.SetStateAction<T>>, {
30
+ isControlled: boolean;
31
+ reset: () => void;
32
+ }];
23
33
  /** Returns an array with each prefix added to the id. Useful for aria attributes in compound components. */
24
34
  export declare function useIds(id: string, prefixes: string[]): string[];
35
+ /**
36
+ * Provides a function, which can be called to check if component using the hook is mounted or unmounted.
37
+ */
38
+ export declare function useIsMounted(): () => boolean;
25
39
  export {};
package/utils/react.js CHANGED
@@ -45,9 +45,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
45
  return to.concat(ar || Array.prototype.slice.call(from));
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.useIds = exports.useClickOutside = exports.useCallbackRef = exports.mergeRefs = exports.createContext = exports.assignRef = void 0;
48
+ exports.useIsMounted = exports.useIds = exports.useControlled = exports.useClickOutside = exports.useCallbackRef = exports.mergeRefs = exports.createContext = exports.assignRef = void 0;
49
49
  var react_1 = __importStar(require("react"));
50
50
  var assertion_1 = require("./assertion");
51
+ var function_1 = require("./function");
51
52
  /**
52
53
  * Assigns given value to the provided ref.
53
54
  * Supports ref as function (e.g. useState) and classic ref (e.g. useRef).
@@ -136,8 +137,44 @@ function useClickOutside(ref, callback, events) {
136
137
  }, [eventsString, ref]);
137
138
  }
138
139
  exports.useClickOutside = useClickOutside;
140
+ // TODO: Move to ui-utils
141
+ /** Supports state management in components that can be controlled or uncontrolled. */
142
+ function useControlled(props) {
143
+ var defaultValue = props.defaultValue, onChangeProp = props.onChange, valueProp = props.value;
144
+ var _a = __read((0, react_1.useState)(defaultValue), 2), valueState = _a[0], setValue = _a[1];
145
+ var isControlled = valueProp !== undefined;
146
+ var value = isControlled ? valueProp : valueState;
147
+ /** Triggers the external callback with the new value. In uncontrolled mode, updates state. */
148
+ var onChange = useCallbackRef(function (next) {
149
+ var newValue = (0, function_1.runIfFn)(next);
150
+ if (!isControlled)
151
+ setValue(newValue);
152
+ onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(newValue);
153
+ });
154
+ /** In uncontrolled mode, sets the state to the default value. */
155
+ var reset = useCallbackRef(function () {
156
+ !isControlled && defaultValue && onChange(defaultValue);
157
+ });
158
+ return [value, onChange, { isControlled: isControlled, reset: reset }];
159
+ }
160
+ exports.useControlled = useControlled;
139
161
  /** Returns an array with each prefix added to the id. Useful for aria attributes in compound components. */
140
162
  function useIds(id, prefixes) {
141
163
  return prefixes.map(function (prefix) { return prefix + "-" + id; });
142
164
  }
143
165
  exports.useIds = useIds;
166
+ // TODO: Bring it from ui-utils
167
+ /**
168
+ * Provides a function, which can be called to check if component using the hook is mounted or unmounted.
169
+ */
170
+ function useIsMounted() {
171
+ var isMounted = (0, react_1.useRef)(false);
172
+ (0, react_1.useEffect)(function () {
173
+ isMounted.current = true;
174
+ return function () {
175
+ isMounted.current = false;
176
+ };
177
+ }, []);
178
+ return (0, react_1.useCallback)(function () { return isMounted.current; }, []);
179
+ }
180
+ exports.useIsMounted = useIsMounted;
File without changes
File without changes
File without changes