@deque/cauldron-react 4.1.0-canary.fcf29799 → 4.2.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/README.md +6 -0
- package/lib/components/LoaderOverlay/index.d.ts +2 -0
- package/lib/index.js +46 -10
- package/lib/utils/is-browser/index.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,3 +11,9 @@ and pull in the styles:
|
|
|
11
11
|
```sh
|
|
12
12
|
$ npm install @deque/cauldron-styles --save
|
|
13
13
|
```
|
|
14
|
+
|
|
15
|
+
## server-side rendering
|
|
16
|
+
|
|
17
|
+
Avoid referencing `window` properties, such as `document`, unless you are sure the code will only be executed in a browser environment. For instance, it is safe to reference `document` in an [Effect Hook](https://reactjs.org/docs/hooks-effect.html) or a lifecycle method like `componentDidMount()`, but not in the `render()` method of a class component.
|
|
18
|
+
|
|
19
|
+
Ensuring you only reference these objects when it is safe to do so will ensure that library consumers can use Cauldron with platforms that use an SSR engine, such as GatsbyJS and NextJS.
|
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
2
2
|
interface LoaderOverlayProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
3
|
variant?: 'large' | 'small';
|
|
4
4
|
label?: string;
|
|
5
|
+
focusOnInitialRender?: boolean;
|
|
6
|
+
children?: React.ReactNode;
|
|
5
7
|
}
|
|
6
8
|
declare const LoaderOverlay: React.ForwardRefExoticComponent<LoaderOverlayProps & React.RefAttributes<HTMLDivElement>>;
|
|
7
9
|
export default LoaderOverlay;
|
package/lib/index.js
CHANGED
|
@@ -446,7 +446,18 @@ var MenuItem = /** @class */ (function (_super) {
|
|
|
446
446
|
|
|
447
447
|
var MENU_BREAKPOINT = 1024;
|
|
448
448
|
|
|
449
|
-
|
|
449
|
+
function isBrowser() {
|
|
450
|
+
return (typeof window !== 'undefined' &&
|
|
451
|
+
!!window.document &&
|
|
452
|
+
!!window.document.createElement);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
var isWide = function () {
|
|
456
|
+
if (!isBrowser()) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
return window.innerWidth >= MENU_BREAKPOINT;
|
|
460
|
+
};
|
|
450
461
|
|
|
451
462
|
var TopBar = /** @class */ (function (_super) {
|
|
452
463
|
tslib.__extends(TopBar, _super);
|
|
@@ -1282,10 +1293,11 @@ var Dialog = /** @class */ (function (_super) {
|
|
|
1282
1293
|
};
|
|
1283
1294
|
Dialog.prototype.render = function () {
|
|
1284
1295
|
var _this = this;
|
|
1285
|
-
var _a = this.props, dialogRef = _a.dialogRef, forceAction = _a.forceAction, className = _a.className, children = _a.children, closeButtonText = _a.closeButtonText, heading = _a.heading, show = _a.show,
|
|
1286
|
-
if (!show) {
|
|
1296
|
+
var _a = this.props, dialogRef = _a.dialogRef, forceAction = _a.forceAction, className = _a.className, children = _a.children, closeButtonText = _a.closeButtonText, heading = _a.heading, show = _a.show, other = tslib.__rest(_a, ["dialogRef", "forceAction", "className", "children", "closeButtonText", "heading", "show"]);
|
|
1297
|
+
if (!show || !isBrowser()) {
|
|
1287
1298
|
return null;
|
|
1288
1299
|
}
|
|
1300
|
+
var portal = this.props.portal || document.body;
|
|
1289
1301
|
var close = !forceAction ? (React__default.createElement("button", { className: "Dialog__close", type: "button", onClick: this.close },
|
|
1290
1302
|
React__default.createElement(Icon, { type: "close", "aria-hidden": "true" }),
|
|
1291
1303
|
React__default.createElement(Offscreen, null, closeButtonText))) : null;
|
|
@@ -1413,6 +1425,9 @@ var SkipLink = /** @class */ (function (_super) {
|
|
|
1413
1425
|
React__default.createElement("span", { className: "SkipLink__item--second" }, targetText))));
|
|
1414
1426
|
};
|
|
1415
1427
|
SkipLink.prototype.onClick = function () {
|
|
1428
|
+
if (!isBrowser()) {
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1416
1431
|
var element = document.querySelector(this.props.target);
|
|
1417
1432
|
if (element) {
|
|
1418
1433
|
element.tabIndex = -1;
|
|
@@ -1589,7 +1604,7 @@ function Tooltip(_a) {
|
|
|
1589
1604
|
targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association, [id, attrText].filter(Boolean).join(' '));
|
|
1590
1605
|
}
|
|
1591
1606
|
}, [targetElement, id]);
|
|
1592
|
-
return showTooltip || hideElementOnHidden
|
|
1607
|
+
return (showTooltip || hideElementOnHidden) && isBrowser()
|
|
1593
1608
|
? reactDom.createPortal(React__default.createElement("div", tslib.__assign({ id: id, className: classNames('Tooltip', "Tooltip--" + placement, className, {
|
|
1594
1609
|
TooltipInfo: variant === 'info',
|
|
1595
1610
|
'Tooltip--hidden': !showTooltip && hideElementOnHidden,
|
|
@@ -1907,10 +1922,11 @@ var Pointout = /** @class */ (function (_super) {
|
|
|
1907
1922
|
var _this = this;
|
|
1908
1923
|
var _c;
|
|
1909
1924
|
var _d = this.state, show = _d.show, style = _d.style, offscreenContentFocus = _d.offscreenContentFocus, headingId = _d.headingId;
|
|
1910
|
-
var _e = this.props, heading = _e.heading, ftpoRef = _e.ftpoRef, children = _e.children, noArrow = _e.noArrow, dismissText = _e.dismissText, previousText = _e.previousText, nextText = _e.nextText, showNext = _e.showNext, showPrevious = _e.showPrevious, arrowPosition = _e.arrowPosition, position = _e.position, className = _e.className, target = _e.target, disableOffscreenPointout = _e.disableOffscreenPointout,
|
|
1911
|
-
if (!show) {
|
|
1925
|
+
var _e = this.props, heading = _e.heading, ftpoRef = _e.ftpoRef, children = _e.children, noArrow = _e.noArrow, dismissText = _e.dismissText, previousText = _e.previousText, nextText = _e.nextText, showNext = _e.showNext, showPrevious = _e.showPrevious, arrowPosition = _e.arrowPosition, position = _e.position, className = _e.className, target = _e.target, disableOffscreenPointout = _e.disableOffscreenPointout, previousButtonProps = _e.previousButtonProps, nextButtonProps = _e.nextButtonProps, closeButtonProps = _e.closeButtonProps;
|
|
1926
|
+
if (!show || !isBrowser()) {
|
|
1912
1927
|
return null;
|
|
1913
1928
|
}
|
|
1929
|
+
var portal = this.props.portal || document.body;
|
|
1914
1930
|
var FTPO = (React__default.createElement("div", { className: classNames(className, 'Pointout', (_a = {
|
|
1915
1931
|
'Pointout--no-arrow': noArrow,
|
|
1916
1932
|
'Pointout--auto': !!target
|
|
@@ -2007,6 +2023,9 @@ var Pointout = /** @class */ (function (_super) {
|
|
|
2007
2023
|
*/
|
|
2008
2024
|
var queryAll = function (selector, context) {
|
|
2009
2025
|
if (context === void 0) { context = document; }
|
|
2026
|
+
if (!isBrowser()) {
|
|
2027
|
+
return [];
|
|
2028
|
+
}
|
|
2010
2029
|
return Array.prototype.slice.call(context.querySelectorAll(selector));
|
|
2011
2030
|
};
|
|
2012
2031
|
|
|
@@ -7979,22 +7998,39 @@ function AxeLoader() {
|
|
|
7979
7998
|
}
|
|
7980
7999
|
|
|
7981
8000
|
var LoaderOverlay = React__default.forwardRef(function (_a, ref) {
|
|
7982
|
-
var className = _a.className, variant = _a.variant, label = _a.label, other = tslib.__rest(_a, ["className", "variant", "label"]);
|
|
8001
|
+
var className = _a.className, variant = _a.variant, label = _a.label, children = _a.children, focusOnInitialRender = _a.focusOnInitialRender, other = tslib.__rest(_a, ["className", "variant", "label", "children", "focusOnInitialRender"]);
|
|
8002
|
+
var overlayRef = typeof ref === 'function' || !ref ? React.createRef() : ref;
|
|
8003
|
+
React.useEffect(function () {
|
|
8004
|
+
if (!!focusOnInitialRender && overlayRef.current) {
|
|
8005
|
+
setTimeout(function () {
|
|
8006
|
+
var _a;
|
|
8007
|
+
return (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
8008
|
+
});
|
|
8009
|
+
}
|
|
8010
|
+
return;
|
|
8011
|
+
}, [overlayRef.current]);
|
|
8012
|
+
React.useEffect(function () {
|
|
8013
|
+
if (typeof ref === 'function') {
|
|
8014
|
+
ref(overlayRef.current);
|
|
8015
|
+
}
|
|
8016
|
+
}, [ref]);
|
|
7983
8017
|
return (React__default.createElement("div", tslib.__assign({ className: classNames('Loader__overlay', className, variant === 'large'
|
|
7984
8018
|
? 'Loader__overlay--large'
|
|
7985
8019
|
: variant === 'small'
|
|
7986
8020
|
? 'Loader__overlay--small'
|
|
7987
|
-
: ''), ref:
|
|
8021
|
+
: ''), ref: overlayRef, tabIndex: -1 }, other),
|
|
7988
8022
|
React__default.createElement("div", { className: "Loader__overlay__loader" },
|
|
7989
8023
|
React__default.createElement(Loader, { variant: variant }),
|
|
7990
8024
|
React__default.createElement(AxeLoader, null)),
|
|
7991
8025
|
label ? React__default.createElement("span", { className: "Loader__overlay__label" }, label) : null,
|
|
7992
|
-
|
|
8026
|
+
children));
|
|
7993
8027
|
});
|
|
7994
8028
|
LoaderOverlay.propTypes = {
|
|
7995
8029
|
className: PropTypes.string,
|
|
7996
8030
|
variant: PropTypes.oneOf(['large', 'small']),
|
|
7997
|
-
label: PropTypes.string
|
|
8031
|
+
label: PropTypes.string,
|
|
8032
|
+
focusOnInitialRender: PropTypes.bool,
|
|
8033
|
+
children: PropTypes.node
|
|
7998
8034
|
};
|
|
7999
8035
|
LoaderOverlay.displayName = 'LoaderOverlay';
|
|
8000
8036
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBrowser(): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deque/cauldron-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Fully accessible react components library for Deque Cauldron",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -124,4 +124,4 @@
|
|
|
124
124
|
"\\.svg$": "<rootDir>/__tests__/svgMock.js"
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
}
|
|
127
|
+
}
|