@deque/cauldron-react 4.5.0-canary.0c764a21 → 4.5.0-canary.7f1627ef

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.
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { Placement } from '@popperjs/core';
3
+ interface Props extends React.HTMLAttributes<HTMLDivElement> {
4
+ totalItems: number;
5
+ itemsPerPage?: number;
6
+ currentPage?: number;
7
+ statusLabel?: React.ReactNode;
8
+ firstPageLabel?: string;
9
+ previousPageLabel?: string;
10
+ nextPageLabel?: string;
11
+ lastPageLabel?: string;
12
+ onNextPageClick?: () => void;
13
+ onPreviousPageClick?: () => void;
14
+ onFirstPageClick?: () => void;
15
+ onLastPageClick?: () => void;
16
+ tooltipPlacement?: Placement;
17
+ className?: string;
18
+ }
19
+ declare const Pagination: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
20
+ export default Pagination;
@@ -1,20 +1,3 @@
1
- import React from 'react';
2
- import { Placement } from '@popperjs/core';
3
- interface Props extends React.HTMLAttributes<HTMLDivElement> {
4
- totalItems: number;
5
- itemsPerPage?: number;
6
- currentPage?: number;
7
- statusLabel?: React.ReactNode;
8
- firstPageLabel?: string;
9
- previousPageLabel?: string;
10
- nextPageLabel?: string;
11
- lastPageLabel?: string;
12
- onNextPageClick?: () => void;
13
- onPreviousPageClick?: () => void;
14
- onFirstPageClick?: () => void;
15
- onLastPageClick?: () => void;
16
- tooltipPlacement?: Placement;
17
- className?: string;
18
- }
19
- declare const Pagination: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
1
+ import Pagination from './Pagination';
2
+ export { usePagination } from './usePagination';
20
3
  export default Pagination;
@@ -0,0 +1,24 @@
1
+ interface Options {
2
+ totalItems: number;
3
+ initialPageSize?: number;
4
+ initialPage?: number;
5
+ }
6
+ interface PaginationResults {
7
+ totalItems: number;
8
+ currentPage: number;
9
+ itemsPerPage: number;
10
+ onNextPageClick: () => void;
11
+ onPreviousPageClick: () => void;
12
+ onFirstPageClick: () => void;
13
+ onLastPageClick: () => void;
14
+ }
15
+ interface PageStatus {
16
+ currentPage: number;
17
+ pageStart: number;
18
+ pageEnd: number;
19
+ }
20
+ export declare const usePagination: ({ totalItems, initialPageSize, initialPage }: Options) => {
21
+ pagination: PaginationResults;
22
+ pageStatus: PageStatus;
23
+ };
24
+ export {};
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { IconType } from '../Icon';
4
+ export interface RadioItem extends React.InputHTMLAttributes<HTMLInputElement> {
5
+ label: React.ReactNode;
6
+ cardImg: JSX.Element;
7
+ cardIcon: IconType;
8
+ value?: string;
9
+ }
10
+ export interface RadioCardGroupProps {
11
+ name?: string;
12
+ className?: string;
13
+ radios: RadioItem[];
14
+ defaultValue?: string;
15
+ value?: any;
16
+ onChange: (radio: RadioItem, input: HTMLElement) => void;
17
+ }
18
+ declare const RadioCardGroup: {
19
+ ({ name, radios, defaultValue, value, onChange, className, ...other }: RadioCardGroupProps): JSX.Element;
20
+ propTypes: {
21
+ name: PropTypes.Requireable<string>;
22
+ radios: PropTypes.Validator<(PropTypes.InferProps<{
23
+ value: PropTypes.Validator<string>;
24
+ id: PropTypes.Validator<string>;
25
+ label: PropTypes.Validator<string>;
26
+ cardImg: PropTypes.Validator<PropTypes.ReactElementLike>;
27
+ cardIcon: PropTypes.Validator<string>;
28
+ }> | null | undefined)[]>;
29
+ hasLabel: (props: {
30
+ [key: string]: string;
31
+ }, propName: string, componentName: string) => Error | undefined;
32
+ className: PropTypes.Requireable<string>;
33
+ defaultValue: PropTypes.Requireable<string>;
34
+ onChange: PropTypes.Requireable<(...args: any[]) => any>;
35
+ };
36
+ displayName: string;
37
+ };
38
+ export default RadioCardGroup;
package/lib/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export { default as Loader } from './components/Loader';
25
25
  export { default as OptionsMenu, OptionsMenuList, OptionsMenuItem, OptionsMenuTrigger, OptionsMenuWrapper } from './components/OptionsMenu';
26
26
  export { default as Select, SelectOption, SelectProps } from './components/Select';
27
27
  export { default as RadioGroup } from './components/RadioGroup';
28
+ export { default as RadioCardGroup } from './components/RadioCardGroup';
28
29
  export { default as Checkbox } from './components/Checkbox';
29
30
  export { default as Tooltip, TooltipHead, TooltipContent } from './components/Tooltip';
30
31
  export { default as TooltipTabstop } from './components/TooltipTabstop';
@@ -45,7 +46,7 @@ export { default as Panel } from './components/Panel';
45
46
  export { default as IssuePanel } from './components/IssuePanel';
46
47
  export { default as ProgressBar } from './components/ProgressBar';
47
48
  export { Address, AddressLine, AddressCityStateZip } from './components/Address';
48
- export { default as Pagination } from './components/Pagination';
49
+ export { default as Pagination, usePagination } from './components/Pagination';
49
50
  export { default as FieldWrap } from './components/FieldWrap';
50
51
  export { default as Breadcrumb, BreadcrumbItem, BreadcrumbLink } from './components/Breadcrumb';
51
52
  export { default as TwoColumnPanel, ColumnHeader, ColumnGroupHeader, ColumnLeft, ColumnRight, ColumnList } from './components/TwoColumnPanel';
package/lib/index.js CHANGED
@@ -2389,6 +2389,125 @@ RadioGroup.propTypes = {
2389
2389
  };
2390
2390
  RadioGroup.displayName = 'RadioGroup';
2391
2391
 
2392
+ var Card = function (_a) {
2393
+ var className = _a.className, variant = _a.variant, other = tslib.__rest(_a, ["className", "variant"]);
2394
+ return (React__default.createElement("div", tslib.__assign({ className: classNames(className, {
2395
+ 'Card--simple': variant === 'simple',
2396
+ Card: !variant
2397
+ }) }, other)));
2398
+ };
2399
+ Card.displayName = 'Card';
2400
+ Card.propTypes = {
2401
+ className: PropTypes.string,
2402
+ variant: PropTypes.string
2403
+ };
2404
+
2405
+ var CardHeader = function (_a) {
2406
+ var className = _a.className, other = tslib.__rest(_a, ["className"]);
2407
+ return (React__default.createElement("div", tslib.__assign({ className: classNames('Card__header', className) }, other)));
2408
+ };
2409
+ CardHeader.displayName = 'CardHeader';
2410
+ CardHeader.propTypes = {
2411
+ className: PropTypes.string
2412
+ };
2413
+
2414
+ var CardContent = function (_a) {
2415
+ var className = _a.className, other = tslib.__rest(_a, ["className"]);
2416
+ return (React__default.createElement("div", tslib.__assign({ className: classNames('Card__content', className) }, other)));
2417
+ };
2418
+ CardContent.displayName = 'CardContent';
2419
+ CardContent.propTypes = {
2420
+ className: PropTypes.string
2421
+ };
2422
+
2423
+ var CardFooter = function (_a) {
2424
+ var className = _a.className, other = tslib.__rest(_a, ["className"]);
2425
+ return (React__default.createElement("div", tslib.__assign({ className: classNames('Card__footer', className) }, other)));
2426
+ };
2427
+ CardFooter.displayName = 'CardFooter';
2428
+ CardFooter.propTypes = {
2429
+ className: PropTypes.string
2430
+ };
2431
+
2432
+ var RadioCardGroup = function (_a) {
2433
+ var name = _a.name, radios = _a.radios, defaultValue = _a.defaultValue, value = _a.value,
2434
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
2435
+ _b = _a.onChange,
2436
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
2437
+ onChange = _b === void 0 ? function () { } : _b, className = _a.className, other = tslib.__rest(_a, ["name", "radios", "defaultValue", "value", "onChange", "className"]);
2438
+ var _c = tslib.__read(React.useState(value !== null && value !== void 0 ? value : defaultValue), 2), currentValue = _c[0], setCurrentValue = _c[1];
2439
+ var _d = tslib.__read(React.useState(null), 2), focusIndex = _d[0], setFocusIndex = _d[1];
2440
+ var inputs = React.useRef([]);
2441
+ var handleChange = function (value) { return setCurrentValue(value); };
2442
+ var onRadioFocus = function (index) { return setFocusIndex(index); };
2443
+ var onRadioBlur = function () { return setFocusIndex(null); };
2444
+ var onRadioClick = function (index) {
2445
+ var _a;
2446
+ var radio = (_a = inputs.current) === null || _a === void 0 ? void 0 : _a[index];
2447
+ if (!radio) {
2448
+ return;
2449
+ }
2450
+ radio.click();
2451
+ radio.focus();
2452
+ };
2453
+ React.useEffect(function () {
2454
+ if (typeof value === 'undefined') {
2455
+ return;
2456
+ }
2457
+ setCurrentValue(value);
2458
+ }, [value]);
2459
+ var radioButtons = radios.map(function (radio, index) {
2460
+ var label = radio.label, disabled = radio.disabled, radioValue = radio.value, cardImg = radio.cardImg, cardIcon = radio.cardIcon, id = radio.id, className = radio.className, other = tslib.__rest(radio, ["label", "disabled", "value", "cardImg", "cardIcon", "id", "className"]);
2461
+ var isChecked = currentValue === radioValue;
2462
+ var isFocused = focusIndex === index;
2463
+ return (React__default.createElement("div", { className: classNames('RadioCard'), key: index },
2464
+ React__default.createElement(Card, { variant: "simple", className: classNames('RadioCardGroup__Card RadioCard__overlay', {
2465
+ 'RadioCard__overlay--focused': isFocused,
2466
+ 'RadioCard__overlay--checked': isChecked,
2467
+ 'RadioCard__overlay--disabled': disabled
2468
+ }), onClick: function () { return onRadioClick(index); } },
2469
+ React__default.createElement("input", tslib.__assign({ type: "radio", name: name, value: radioValue, id: id, ref: function (input) {
2470
+ if (!input) {
2471
+ return;
2472
+ }
2473
+ inputs.current.push(input);
2474
+ }, onFocus: function () { return onRadioFocus(index); }, onBlur: function () { return onRadioBlur(); }, onChange: function () {
2475
+ var _a;
2476
+ handleChange(radioValue);
2477
+ onChange(radio, (_a = inputs.current) === null || _a === void 0 ? void 0 : _a[index]);
2478
+ }, disabled: disabled, checked: isChecked }, other)),
2479
+ React__default.createElement(CardContent, null,
2480
+ React__default.createElement("div", { className: classNames('RadioCardGroup__Checked') }, isChecked && (React__default.createElement(Icon, { className: classNames('RadioCardGroup__Icon'), type: cardIcon }))),
2481
+ React__default.createElement("div", { className: classNames('RadioCardGroup__Base') },
2482
+ React__default.createElement("div", { className: classNames('RadioCardGroup__Image') }, cardImg),
2483
+ React__default.createElement("label", { htmlFor: id, className: classNames('RadioCardGroup__Label') }, label))))));
2484
+ });
2485
+ // reset the input refs array
2486
+ // refs get clobbered every re-render anyway and this supports "dynamic" radios
2487
+ // (changing the number of radio buttons for example)
2488
+ inputs.current = [];
2489
+ return (React__default.createElement("div", tslib.__assign({ className: classNames('RadioCardGroup'), role: "radiogroup" }, other), radioButtons));
2490
+ };
2491
+ RadioCardGroup.propTypes = {
2492
+ name: PropTypes.string,
2493
+ radios: PropTypes.arrayOf(PropTypes.shape({
2494
+ value: PropTypes.string.isRequired,
2495
+ id: PropTypes.string.isRequired,
2496
+ label: PropTypes.string.isRequired,
2497
+ cardImg: PropTypes.element.isRequired,
2498
+ cardIcon: PropTypes.string.isRequired
2499
+ })).isRequired,
2500
+ hasLabel: function (props, propName, componentName) {
2501
+ if (!props['aria-label'] && !props['aria-labelledby']) {
2502
+ return new Error(componentName + " must have an \"aria-label\" or \"aria-labelledby\" prop");
2503
+ }
2504
+ },
2505
+ className: PropTypes.string,
2506
+ defaultValue: PropTypes.string,
2507
+ onChange: PropTypes.func
2508
+ };
2509
+ RadioCardGroup.displayName = 'RadioCardGroup';
2510
+
2392
2511
  var Checkbox = React.forwardRef(function (_a, ref) {
2393
2512
  var id = _a.id, label = _a.label, labelDescription = _a.labelDescription, error = _a.error, checkboxRef = _a.checkboxRef, className = _a.className, onChange = _a.onChange, ariaDescribedby = _a["aria-describedby"], _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.checked, checked = _c === void 0 ? false : _c, other = tslib.__rest(_a, ["id", "label", "labelDescription", "error", "checkboxRef", "className", "onChange", 'aria-describedby', "disabled", "checked"]);
2394
2513
  var _d = tslib.__read(React.useState(checked), 2), isChecked = _d[0], setIsChecked = _d[1];
@@ -2458,46 +2577,6 @@ function TooltipTabstop(_a) {
2458
2577
  }
2459
2578
  TooltipTabstop.displayName = 'TooltipTabstop';
2460
2579
 
2461
- var Card = function (_a) {
2462
- var className = _a.className, variant = _a.variant, other = tslib.__rest(_a, ["className", "variant"]);
2463
- return (React__default.createElement("div", tslib.__assign({ className: classNames(className, {
2464
- 'Card--simple': variant === 'simple',
2465
- Card: !variant
2466
- }) }, other)));
2467
- };
2468
- Card.displayName = 'Card';
2469
- Card.propTypes = {
2470
- className: PropTypes.string,
2471
- variant: PropTypes.string
2472
- };
2473
-
2474
- var CardHeader = function (_a) {
2475
- var className = _a.className, other = tslib.__rest(_a, ["className"]);
2476
- return (React__default.createElement("div", tslib.__assign({ className: classNames('Card__header', className) }, other)));
2477
- };
2478
- CardHeader.displayName = 'CardHeader';
2479
- CardHeader.propTypes = {
2480
- className: PropTypes.string
2481
- };
2482
-
2483
- var CardContent = function (_a) {
2484
- var className = _a.className, other = tslib.__rest(_a, ["className"]);
2485
- return (React__default.createElement("div", tslib.__assign({ className: classNames('Card__content', className) }, other)));
2486
- };
2487
- CardContent.displayName = 'CardContent';
2488
- CardContent.propTypes = {
2489
- className: PropTypes.string
2490
- };
2491
-
2492
- var CardFooter = function (_a) {
2493
- var className = _a.className, other = tslib.__rest(_a, ["className"]);
2494
- return (React__default.createElement("div", tslib.__assign({ className: classNames('Card__footer', className) }, other)));
2495
- };
2496
- CardFooter.displayName = 'CardFooter';
2497
- CardFooter.propTypes = {
2498
- className: PropTypes.string
2499
- };
2500
-
2501
2580
  var TextField = /** @class */ (function (_super) {
2502
2581
  tslib.__extends(TextField, _super);
2503
2582
  function TextField(props) {
@@ -8532,6 +8611,34 @@ Pagination.propTypes = {
8532
8611
  className: PropTypes.string
8533
8612
  };
8534
8613
 
8614
+ var usePagination = function (_a) {
8615
+ var totalItems = _a.totalItems, _b = _a.initialPageSize, initialPageSize = _b === void 0 ? 10 : _b, _c = _a.initialPage, initialPage = _c === void 0 ? 1 : _c;
8616
+ var _d = tslib.__read(React.useState(initialPage), 2), currentPage = _d[0], setCurrentPage = _d[1];
8617
+ var pageStart = currentPage * initialPageSize - initialPageSize + 1;
8618
+ var pageEnd = Math.min(pageStart + initialPageSize - 1, totalItems);
8619
+ var onFirstPageClick = function () { return setCurrentPage(1); };
8620
+ var onPreviousPageClick = function () { return setCurrentPage(currentPage - 1); };
8621
+ var onNextPageClick = function () { return setCurrentPage(currentPage + 1); };
8622
+ var onLastPageClick = function () {
8623
+ return setCurrentPage(Math.ceil(totalItems / initialPageSize));
8624
+ };
8625
+ var pagination = {
8626
+ totalItems: totalItems,
8627
+ currentPage: currentPage,
8628
+ itemsPerPage: initialPageSize,
8629
+ onFirstPageClick: onFirstPageClick,
8630
+ onPreviousPageClick: onPreviousPageClick,
8631
+ onNextPageClick: onNextPageClick,
8632
+ onLastPageClick: onLastPageClick
8633
+ };
8634
+ var pageStatus = {
8635
+ currentPage: currentPage,
8636
+ pageStart: pageStart,
8637
+ pageEnd: pageEnd
8638
+ };
8639
+ return { pagination: pagination, pageStatus: pageStatus };
8640
+ };
8641
+
8535
8642
  var FieldWrap = React__default.forwardRef(function (_a, ref) {
8536
8643
  var children = _a.children, className = _a.className, _b = _a.as, Component = _b === void 0 ? 'div' : _b, props = tslib.__rest(_a, ["children", "className", "as"]);
8537
8644
  return (React__default.createElement(Component, tslib.__assign({ ref: ref, className: classNames('Panel', className) }, props), children));
@@ -8857,6 +8964,7 @@ exports.Panel = Panel;
8857
8964
  exports.PanelTrigger = PanelTrigger$1;
8858
8965
  exports.Pointout = Pointout;
8859
8966
  exports.ProgressBar = ProgressBar;
8967
+ exports.RadioCardGroup = RadioCardGroup;
8860
8968
  exports.RadioGroup = RadioGroup;
8861
8969
  exports.Scrim = Scrim;
8862
8970
  exports.Select = Select;
@@ -8894,4 +9002,5 @@ exports.Workspace = Workspace;
8894
9002
  exports.focusableSelector = focusableSelector;
8895
9003
  exports.iconTypes = iconTypes;
8896
9004
  exports.useDidUpdate = useDidUpdate;
9005
+ exports.usePagination = usePagination;
8897
9006
  exports.useThemeContext = useThemeContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "4.5.0-canary.0c764a21",
3
+ "version": "4.5.0-canary.7f1627ef",
4
4
  "description": "Fully accessible react components library for Deque Cauldron",
5
5
  "publishConfig": {
6
6
  "access": "public"