@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
108 lines (107 loc) • 5.92 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JumpToLastButton = exports.StepToNextButton = exports.StepToPreviousButton = exports.JumpToFirstButton = exports.PaginationControls = void 0;
const React = __importStar(require("react"));
const button_1 = require("@workday/canvas-kit-react/button");
const common_1 = require("@workday/canvas-kit-react/common");
const canvas_system_icons_web_1 = require("@workday/canvas-system-icons-web");
const layout_1 = require("@workday/canvas-kit-react/layout");
const useRTL_1 = require("./common/utils/useRTL");
const usePaginationModel_1 = require("./usePaginationModel");
exports.PaginationControls = (0, common_1.createComponent)('div')({
displayName: 'Pagination.Controls',
Component(elemProps, ref, Element) {
return React.createElement(layout_1.Flex, { ref: ref, as: Element, gap: "xxxs", alignItems: "center", ...elemProps });
},
});
exports.JumpToFirstButton = (0, common_1.createComponent)('button')({
displayName: 'Pagination.JumpToFirstButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage <= model.state.firstPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.firstPage);
};
const { shouldUseRTL } = (0, useRTL_1.useRTL)();
const icon = shouldUseRTL ? canvas_system_icons_web_1.chevron2xRightSmallIcon : canvas_system_icons_web_1.chevron2xLeftSmallIcon;
return (React.createElement(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: icon, onClick: handleClick, ...restProps }));
},
});
exports.StepToPreviousButton = (0, common_1.createComponent)('button')({
displayName: 'Pagination.StepToPreviousButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage <= model.state.firstPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.currentPage - 1);
};
const { shouldUseRTL } = (0, useRTL_1.useRTL)();
const icon = shouldUseRTL ? canvas_system_icons_web_1.chevronRightSmallIcon : canvas_system_icons_web_1.chevronLeftSmallIcon;
return (React.createElement(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: icon, onClick: handleClick, ...restProps }));
},
});
exports.StepToNextButton = (0, common_1.createComponent)('button')({
displayName: 'Pagination.StepToNextButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage >= model.state.lastPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.currentPage + 1);
};
const { shouldUseRTL } = (0, useRTL_1.useRTL)();
const icon = shouldUseRTL ? canvas_system_icons_web_1.chevronLeftSmallIcon : canvas_system_icons_web_1.chevronRightSmallIcon;
return (React.createElement(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: icon, onClick: handleClick, ...restProps }));
},
});
exports.JumpToLastButton = (0, common_1.createComponent)('button')({
displayName: 'Paganation.JumpToLastButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage >= model.state.lastPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.lastPage);
};
const { shouldUseRTL } = (0, useRTL_1.useRTL)();
const icon = shouldUseRTL ? canvas_system_icons_web_1.chevron2xLeftSmallIcon : canvas_system_icons_web_1.chevron2xRightSmallIcon;
return (React.createElement(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: icon, onClick: handleClick, ...restProps }));
},
});