@deque/cauldron-react 6.7.0-canary.2d78ed57 → 6.7.0-canary.38e18ca8
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/lib/broken-image.js +36 -0
- package/lib/components/Drawer/index.d.ts +15 -0
- package/lib/components/Icon/types.d.ts +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +184 -66
- package/lib/utils/resolveElement.d.ts +6 -0
- package/lib/utils/useEscapeKey.d.ts +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule) return e;
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n["default"] = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
24
|
+
|
|
25
|
+
var _path;
|
|
26
|
+
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); }
|
|
27
|
+
const SvgBrokenImage = props => /*#__PURE__*/React__namespace.createElement("svg", _extends({
|
|
28
|
+
viewBox: "0 0 24 24",
|
|
29
|
+
fill: "currentColor",
|
|
30
|
+
height: 24,
|
|
31
|
+
width: 24
|
|
32
|
+
}, props), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
|
|
33
|
+
d: "M22.154 0H1.846c-.49 0-.96.23-1.305.639C.195 1.049 0 1.603 0 2.182v19.636c0 .579.195 1.134.54 1.543.347.41.817.639 1.306.639h7.385a.831.831 0 0 0 .54-.206c.157-.134.274-.323.335-.54l1.712-6.065 4.22-1.994a.935.935 0 0 0 .31-.242c.088-.105.158-.23.205-.366l1.687-4.984 5.132-2.023a.952.952 0 0 0 .455-.398A1.23 1.23 0 0 0 24 6.545V2.182c0-.579-.195-1.134-.54-1.543C23.112.229 22.642 0 22.153 0ZM10.2 16.019l-1.636 5.8H1.846V18l6-7.09 3.51 4.147-.625.293a.933.933 0 0 0-.327.266c-.092.115-.16.253-.203.403Zm11.953-10.26-4.907 1.933a.908.908 0 0 0-.342.242 1.117 1.117 0 0 0-.224.388l-1.698 5.021-1.762.839-4.07-4.81c-.346-.409-.815-.638-1.305-.638s-.959.23-1.305.638l-4.695 5.542V2.182h20.308v3.577Zm1.463 4.5a.852.852 0 0 0-.4-.194.789.789 0 0 0-.432.044l-2.746 1.082a.908.908 0 0 0-.341.241 1.117 1.117 0 0 0-.224.388l-1.652 4.878-4.127 1.951a.934.934 0 0 0-.328.265 1.146 1.146 0 0 0-.204.403l-.916 3.246a1.28 1.28 0 0 0-.037.51c.021.17.078.333.163.474.086.14.198.254.329.333.13.079.274.12.42.12h9.032c.49 0 .96-.23 1.305-.639.346-.41.541-.964.541-1.543V11.145c0-.173-.035-.343-.101-.497a1.062 1.062 0 0 0-.282-.388v-.001Zm-1.463 11.56h-7.75l.374-1.33 4.098-1.937a.936.936 0 0 0 .31-.242c.088-.104.158-.229.204-.366l1.639-4.842 1.125-.443v9.16Z"
|
|
34
|
+
})));
|
|
35
|
+
|
|
36
|
+
exports["default"] = SvgBrokenImage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface DrawerProps<T extends HTMLElement = HTMLElement> extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
position: 'top' | 'bottom' | 'left' | 'right';
|
|
5
|
+
open?: boolean;
|
|
6
|
+
behavior?: 'modal' | 'non-modal';
|
|
7
|
+
focusOptions?: {
|
|
8
|
+
initialFocus?: T | React.RefObject<T> | React.MutableRefObject<T>;
|
|
9
|
+
returnFocus?: T | React.RefObject<T> | React.MutableRefObject<T>;
|
|
10
|
+
};
|
|
11
|
+
onClose?: () => void;
|
|
12
|
+
portal?: React.RefObject<HTMLElement> | HTMLElement;
|
|
13
|
+
}
|
|
14
|
+
declare const Drawer: React.ForwardRefExoticComponent<DrawerProps<HTMLElement> & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
export default Drawer;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* GENERATED CODE. DO NOT EDIT DIRECTLY!
|
|
3
3
|
*/
|
|
4
4
|
/** IconType represents each valid icon type. */
|
|
5
|
-
export type IconType = 'add-user' | 'arrow-circle-up' | 'arrow-circle-down' | 'arrow-circle-left' | 'arrow-circle-right' | 'arrow-up' | 'arrow-down' | 'arrow-left' | 'arrow-right' | 'arrows-alt' | 'bolt' | 'caution' | 'check-circle' | 'check-shield' | 'check-solid' | 'check' | 'checkbox-checked' | 'checkbox-unchecked' | 'chevron-double-up' | 'chevron-double-down' | 'chevron-double-left' | 'chevron-double-right' | 'chevron-up' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'clipboard' | 'clock' | 'close' | 'code' | 'copy' | 'download' | 'dropper' | 'exchange' | 'export-solid' | 'external-link' | 'eye' | 'filter-solid' | 'filter' | 'flag' | 'gears' | 'github' | 'grid' | 'hamburger-menu' | 'hashtag' | 'highlight' | 'images' | 'info-circle-alt' | 'info-circle' | 'info-square' | 'kabob' | 'link' | 'linkedin' | 'list' | 'lock' | 'magnifying-glass' | 'menu' | 'minus' | 'new-releases' | 'new' | 'no' | 'pencil' | 'person-running' | 'play' | 'plus' | 'question-circle-alt' | 'question-circle' | 'radio-checked' | 'radio-unchecked' | 'recycle-square' | 'recycle' | 'resend' | 'robot' | 'run-again' | 'save' | 'share-nodes' | 'share' | 'sort-triangle' | 'sort' | 'star' | 'step-back' | 'step-forward' | 'sun' | 'table-sort-ascending' | 'table-sort-descending' | 'tag' | 'target' | 'trash' | 'triangle-up' | 'triangle-down' | 'triangle-left' | 'triangle-right' | 'twitter' | 'upload';
|
|
5
|
+
export type IconType = 'add-user' | 'arrow-circle-up' | 'arrow-circle-down' | 'arrow-circle-left' | 'arrow-circle-right' | 'arrow-up' | 'arrow-down' | 'arrow-left' | 'arrow-right' | 'arrows-alt' | 'bolt' | 'broken-image' | 'caution' | 'check-circle' | 'check-shield' | 'check-solid' | 'check' | 'checkbox-checked' | 'checkbox-unchecked' | 'chevron-double-up' | 'chevron-double-down' | 'chevron-double-left' | 'chevron-double-right' | 'chevron-up' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'clipboard' | 'clock' | 'close' | 'code' | 'copy' | 'download' | 'dropper' | 'exchange' | 'export-solid' | 'external-link' | 'eye' | 'filter-solid' | 'filter' | 'flag' | 'gears' | 'github' | 'grid' | 'hamburger-menu' | 'hashtag' | 'highlight' | 'images' | 'info-circle-alt' | 'info-circle' | 'info-square' | 'kabob' | 'link' | 'linkedin' | 'list' | 'lock' | 'magnifying-glass' | 'menu' | 'minus' | 'new-releases' | 'new' | 'no' | 'pencil' | 'person-running' | 'play' | 'plus' | 'question-circle-alt' | 'question-circle' | 'radio-checked' | 'radio-unchecked' | 'recycle-square' | 'recycle' | 'resend' | 'robot' | 'run-again' | 'save' | 'share-nodes' | 'share' | 'sort-triangle' | 'sort' | 'star' | 'step-back' | 'step-forward' | 'sun' | 'table-sort-ascending' | 'table-sort-descending' | 'tag' | 'target' | 'trash' | 'triangle-up' | 'triangle-down' | 'triangle-left' | 'triangle-right' | 'twitter' | 'upload';
|
|
6
6
|
/** iconTypes holds each valid icon type. */
|
|
7
7
|
export declare const iconTypes: string[];
|
package/lib/index.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export { default as Popover } from './components/Popover';
|
|
|
59
59
|
export { default as Timeline, TimelineItem } from './components/Timeline';
|
|
60
60
|
export { default as TextEllipsis } from './components/TextEllipsis';
|
|
61
61
|
export { default as CopyButton } from './components/CopyButton';
|
|
62
|
+
export { default as Drawer } from './components/Drawer';
|
|
62
63
|
/**
|
|
63
64
|
* Helpers / Utils
|
|
64
65
|
*/
|
package/lib/index.js
CHANGED
|
@@ -114,6 +114,7 @@ var iconTypes = [
|
|
|
114
114
|
'arrow-right',
|
|
115
115
|
'arrows-alt',
|
|
116
116
|
'bolt',
|
|
117
|
+
'broken-image',
|
|
117
118
|
'caution',
|
|
118
119
|
'check-circle',
|
|
119
120
|
'check-shield',
|
|
@@ -206,6 +207,7 @@ function __variableDynamicImportRuntime0__(path) {
|
|
|
206
207
|
case './icons/arrow.svg': return Promise.resolve().then(function () { return require('./arrow.js'); });
|
|
207
208
|
case './icons/arrows-alt.svg': return Promise.resolve().then(function () { return require('./arrows-alt.js'); });
|
|
208
209
|
case './icons/bolt.svg': return Promise.resolve().then(function () { return require('./bolt.js'); });
|
|
210
|
+
case './icons/broken-image.svg': return Promise.resolve().then(function () { return require('./broken-image.js'); });
|
|
209
211
|
case './icons/caution.svg': return Promise.resolve().then(function () { return require('./caution.js'); });
|
|
210
212
|
case './icons/check-circle.svg': return Promise.resolve().then(function () { return require('./check-circle.js'); });
|
|
211
213
|
case './icons/check-shield.svg': return Promise.resolve().then(function () { return require('./check-shield.js'); });
|
|
@@ -791,6 +793,23 @@ var OptionsMenuWrapper = function (_a) {
|
|
|
791
793
|
return (React__default["default"].createElement("div", tslib.__assign({ className: classNames__default["default"]('OptionsMenu', menuAlignment(align), className) }, other)));
|
|
792
794
|
};
|
|
793
795
|
|
|
796
|
+
/**
|
|
797
|
+
* When an element can be passed as a value that is either an element or an
|
|
798
|
+
* elementRef, this will resolve the property down to the resulting element
|
|
799
|
+
*/
|
|
800
|
+
function resolveElement(elementOrRef) {
|
|
801
|
+
if (elementOrRef instanceof Element) {
|
|
802
|
+
return elementOrRef;
|
|
803
|
+
}
|
|
804
|
+
if (elementOrRef &&
|
|
805
|
+
typeof elementOrRef === 'object' &&
|
|
806
|
+
'current' in elementOrRef &&
|
|
807
|
+
elementOrRef.current instanceof Element) {
|
|
808
|
+
return elementOrRef.current;
|
|
809
|
+
}
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
|
|
794
813
|
function ClickOutsideListener(_a, ref) {
|
|
795
814
|
var children = _a.children, _b = _a.mouseEvent, mouseEvent = _b === void 0 ? 'click' : _b, _c = _a.touchEvent, touchEvent = _c === void 0 ? 'touchend' : _c, target = _a.target, _d = _a.onClickOutside, onClickOutside = _d === void 0 ? function () { return null; } : _d;
|
|
796
815
|
var childElementRef = React.useRef();
|
|
@@ -799,11 +818,9 @@ function ClickOutsideListener(_a, ref) {
|
|
|
799
818
|
return;
|
|
800
819
|
}
|
|
801
820
|
var eventTarget = event.target;
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
onClickOutside(event);
|
|
806
|
-
}
|
|
821
|
+
var elementTarget = resolveElement(target);
|
|
822
|
+
if (target && !(elementTarget === null || elementTarget === void 0 ? void 0 : elementTarget.contains(eventTarget))) {
|
|
823
|
+
onClickOutside(event);
|
|
807
824
|
// If a target is passed in via a prop, we defer to utilizing that
|
|
808
825
|
// target instead of a child element target
|
|
809
826
|
return;
|
|
@@ -1648,6 +1665,46 @@ function hasIdRef(ids, id) {
|
|
|
1648
1665
|
return idRefs(ids).has(id);
|
|
1649
1666
|
}
|
|
1650
1667
|
|
|
1668
|
+
var isEscapeKey = function (event) {
|
|
1669
|
+
return event.key === 'Escape' || event.key === 'Esc' || event.keyCode === 27;
|
|
1670
|
+
};
|
|
1671
|
+
/**
|
|
1672
|
+
* When a component needs to implement an escape handler, such as in modal
|
|
1673
|
+
* dialogs, useEscapeKey will handle the events and call the provided callback
|
|
1674
|
+
* handler when an escape key event has been fired.
|
|
1675
|
+
*
|
|
1676
|
+
* @example
|
|
1677
|
+
* useEscapeKey(() => close())
|
|
1678
|
+
*/
|
|
1679
|
+
function useEscapeKey(options, dependencies) {
|
|
1680
|
+
if (dependencies === void 0) { dependencies = []; }
|
|
1681
|
+
var callback = options.callback;
|
|
1682
|
+
var event = options.event || 'keyup';
|
|
1683
|
+
var target = resolveElement(options.target) || document.body;
|
|
1684
|
+
var active = typeof options.active === 'boolean' ? options.active : true;
|
|
1685
|
+
React.useEffect(function () {
|
|
1686
|
+
var eventListener = function (event) {
|
|
1687
|
+
if (isEscapeKey(event) &&
|
|
1688
|
+
(options.defaultPrevented ? !event.defaultPrevented : true)) {
|
|
1689
|
+
callback(event);
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
if (active) {
|
|
1693
|
+
target === null || target === void 0 ? void 0 : target.addEventListener(event, eventListener, options.capture);
|
|
1694
|
+
}
|
|
1695
|
+
return function () {
|
|
1696
|
+
target === null || target === void 0 ? void 0 : target.removeEventListener(event, eventListener, options.capture);
|
|
1697
|
+
};
|
|
1698
|
+
}, tslib.__spreadArray([
|
|
1699
|
+
active,
|
|
1700
|
+
callback,
|
|
1701
|
+
event,
|
|
1702
|
+
target,
|
|
1703
|
+
options.capture,
|
|
1704
|
+
options.defaultPrevented
|
|
1705
|
+
], tslib.__read(dependencies), false));
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1651
1708
|
var TIP_HIDE_DELAY = 100;
|
|
1652
1709
|
// fires a custom "cauldron:tooltip:show" / "cauldron:tooltip:hide" event
|
|
1653
1710
|
// to allow projects using cauldron to hook into when a tooltip is shown/hidden
|
|
@@ -1736,30 +1793,14 @@ function Tooltip(_a) {
|
|
|
1736
1793
|
attributes.popper['data-popper-placement']) ||
|
|
1737
1794
|
initialPlacement;
|
|
1738
1795
|
// Only listen to key ups when the tooltip is visible
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
};
|
|
1748
|
-
var targetElement = document.body;
|
|
1749
|
-
if (showTooltip && typeof showProp !== 'boolean') {
|
|
1750
|
-
targetElement.addEventListener('keyup', handleEscape, { capture: true });
|
|
1751
|
-
}
|
|
1752
|
-
else {
|
|
1753
|
-
targetElement.removeEventListener('keyup', handleEscape, {
|
|
1754
|
-
capture: true
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
return function () {
|
|
1758
|
-
targetElement.removeEventListener('keyup', handleEscape, {
|
|
1759
|
-
capture: true
|
|
1760
|
-
});
|
|
1761
|
-
};
|
|
1762
|
-
}, [showTooltip, showProp]);
|
|
1796
|
+
useEscapeKey({
|
|
1797
|
+
callback: function (event) {
|
|
1798
|
+
event.preventDefault();
|
|
1799
|
+
setShowTooltip(false);
|
|
1800
|
+
},
|
|
1801
|
+
capture: true,
|
|
1802
|
+
active: showTooltip && typeof showProp !== 'boolean'
|
|
1803
|
+
}, [setShowTooltip]);
|
|
1763
1804
|
// Handle hover and focus events for the targetElement
|
|
1764
1805
|
React.useEffect(function () {
|
|
1765
1806
|
if (typeof showProp !== 'boolean') {
|
|
@@ -3275,25 +3316,10 @@ var TwoColumnPanel = React.forwardRef(function (_a, ref) {
|
|
|
3275
3316
|
mediaQueryList.removeEventListener('change', listener);
|
|
3276
3317
|
};
|
|
3277
3318
|
}, []);
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
event.keyCode === 27) {
|
|
3283
|
-
setCollapsed(true);
|
|
3284
|
-
}
|
|
3285
|
-
};
|
|
3286
|
-
var targetElement = document.body;
|
|
3287
|
-
if (isFocusTrap) {
|
|
3288
|
-
targetElement.addEventListener('keyup', handleEscape);
|
|
3289
|
-
}
|
|
3290
|
-
else {
|
|
3291
|
-
targetElement.removeEventListener('keyup', handleEscape);
|
|
3292
|
-
}
|
|
3293
|
-
return function () {
|
|
3294
|
-
targetElement.removeEventListener('keyup', handleEscape);
|
|
3295
|
-
};
|
|
3296
|
-
}, [isFocusTrap]);
|
|
3319
|
+
useEscapeKey({
|
|
3320
|
+
callback: function () { return setCollapsed(true); },
|
|
3321
|
+
active: isFocusTrap
|
|
3322
|
+
}, [setCollapsed]);
|
|
3297
3323
|
var handleClickOutside = function () {
|
|
3298
3324
|
if (!isCollapsed && isFocusTrap) {
|
|
3299
3325
|
setCollapsed(true);
|
|
@@ -4076,24 +4102,6 @@ var Popover = React.forwardRef(function (_a, ref) {
|
|
|
4076
4102
|
}
|
|
4077
4103
|
targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute('aria-expanded', Boolean(show).toString());
|
|
4078
4104
|
}, [show, popoverRef.current]);
|
|
4079
|
-
React.useEffect(function () {
|
|
4080
|
-
var handleEscape = function (event) {
|
|
4081
|
-
if (event.key === 'Escape' ||
|
|
4082
|
-
event.key === 'Esc' ||
|
|
4083
|
-
event.keyCode === 27) {
|
|
4084
|
-
handleClosePopover();
|
|
4085
|
-
}
|
|
4086
|
-
};
|
|
4087
|
-
if (show) {
|
|
4088
|
-
document.body.addEventListener('keyup', handleEscape);
|
|
4089
|
-
}
|
|
4090
|
-
else {
|
|
4091
|
-
document.body.removeEventListener('keyup', handleEscape);
|
|
4092
|
-
}
|
|
4093
|
-
return function () {
|
|
4094
|
-
document.body.removeEventListener('keyup', handleEscape);
|
|
4095
|
-
};
|
|
4096
|
-
}, [show]);
|
|
4097
4105
|
React.useEffect(function () {
|
|
4098
4106
|
var attrText = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute('aria-controls');
|
|
4099
4107
|
var hasPopupAttr = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute('aria-haspopup');
|
|
@@ -4120,6 +4128,10 @@ var Popover = React.forwardRef(function (_a, ref) {
|
|
|
4120
4128
|
onClose();
|
|
4121
4129
|
}
|
|
4122
4130
|
};
|
|
4131
|
+
useEscapeKey({
|
|
4132
|
+
callback: handleClosePopover,
|
|
4133
|
+
active: show
|
|
4134
|
+
}, [show]);
|
|
4123
4135
|
if (!show || !isBrowser())
|
|
4124
4136
|
return null;
|
|
4125
4137
|
return reactDom.createPortal(React__default["default"].createElement(FocusTrap__default["default"], { focusTrapOptions: {
|
|
@@ -4197,6 +4209,111 @@ var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
|
|
|
4197
4209
|
});
|
|
4198
4210
|
TextEllipsis.displayName = 'TextEllipsis';
|
|
4199
4211
|
|
|
4212
|
+
var Drawer = React.forwardRef(function (_a, ref) {
|
|
4213
|
+
var children = _a.children, className = _a.className, position = _a.position, _b = _a.open, open = _b === void 0 ? false : _b, _c = _a.behavior, behavior = _c === void 0 ? 'modal' : _c, _d = _a.focusOptions, focusOptions = _d === void 0 ? {} : _d, portal = _a.portal, onClose = _a.onClose, style = _a.style, props = tslib.__rest(_a, ["children", "className", "position", "open", "behavior", "focusOptions", "portal", "onClose", "style"]);
|
|
4214
|
+
var drawerRef = useSharedRef(ref);
|
|
4215
|
+
var openRef = React.useRef(!!open);
|
|
4216
|
+
var previousActiveElementRef = React.useRef(null);
|
|
4217
|
+
var focusInitial = focusOptions.initialFocus, focusReturn = focusOptions.returnFocus;
|
|
4218
|
+
var _e = tslib.__read(React.useState(!!open), 2), isTransitioning = _e[0], setIsTransitioning = _e[1];
|
|
4219
|
+
var isModal = behavior === 'modal';
|
|
4220
|
+
var handleClose = React.useCallback(function () {
|
|
4221
|
+
// istanbul ignore next
|
|
4222
|
+
if (open && typeof onClose === 'function') {
|
|
4223
|
+
onClose();
|
|
4224
|
+
}
|
|
4225
|
+
}, [open, onClose]);
|
|
4226
|
+
React.useEffect(function () {
|
|
4227
|
+
// jsdom does not trigger transitionend event
|
|
4228
|
+
// istanbul ignore next
|
|
4229
|
+
var transitionEndHandler = function () { return setIsTransitioning(false); };
|
|
4230
|
+
document.addEventListener('transitionend', transitionEndHandler);
|
|
4231
|
+
return function () {
|
|
4232
|
+
document.removeEventListener('transitionend', transitionEndHandler);
|
|
4233
|
+
};
|
|
4234
|
+
}, [setIsTransitioning]);
|
|
4235
|
+
React.useEffect(function () {
|
|
4236
|
+
if (openRef.current !== open) {
|
|
4237
|
+
setIsTransitioning(true);
|
|
4238
|
+
}
|
|
4239
|
+
openRef.current = open;
|
|
4240
|
+
}, [open, setIsTransitioning]);
|
|
4241
|
+
React.useEffect(function () {
|
|
4242
|
+
if (!isModal) {
|
|
4243
|
+
return;
|
|
4244
|
+
}
|
|
4245
|
+
var isolator = new AriaIsolate(drawerRef.current);
|
|
4246
|
+
if (open) {
|
|
4247
|
+
isolator.activate();
|
|
4248
|
+
}
|
|
4249
|
+
else {
|
|
4250
|
+
isolator.deactivate();
|
|
4251
|
+
}
|
|
4252
|
+
return function () {
|
|
4253
|
+
isolator.deactivate();
|
|
4254
|
+
};
|
|
4255
|
+
}, [isModal, open]);
|
|
4256
|
+
React.useLayoutEffect(function () {
|
|
4257
|
+
var _a, _b, _c;
|
|
4258
|
+
if (open) {
|
|
4259
|
+
previousActiveElementRef.current =
|
|
4260
|
+
document.activeElement;
|
|
4261
|
+
var initialFocusElement = resolveElement(focusInitial);
|
|
4262
|
+
if (initialFocusElement) {
|
|
4263
|
+
initialFocusElement.focus();
|
|
4264
|
+
}
|
|
4265
|
+
else {
|
|
4266
|
+
var focusable = (_a = drawerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(focusableSelector);
|
|
4267
|
+
if (focusable) {
|
|
4268
|
+
focusable.focus();
|
|
4269
|
+
}
|
|
4270
|
+
else {
|
|
4271
|
+
// fallback focus
|
|
4272
|
+
(_b = drawerRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
else if (previousActiveElementRef.current) {
|
|
4277
|
+
var returnFocusElement = resolveElement(focusReturn);
|
|
4278
|
+
if (returnFocusElement) {
|
|
4279
|
+
returnFocusElement.focus();
|
|
4280
|
+
}
|
|
4281
|
+
else {
|
|
4282
|
+
// fallback focus
|
|
4283
|
+
(_c = previousActiveElementRef.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
}, [open, focusInitial, focusReturn]);
|
|
4287
|
+
useEscapeKey({ callback: handleClose, active: open, defaultPrevented: true }, [onClose]);
|
|
4288
|
+
// istanbul ignore next
|
|
4289
|
+
if (!isBrowser()) {
|
|
4290
|
+
return null;
|
|
4291
|
+
}
|
|
4292
|
+
var portalElement = resolveElement(portal);
|
|
4293
|
+
return reactDom.createPortal(React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
4294
|
+
React__default["default"].createElement(ClickOutsideListener$1, { onClickOutside: handleClose, mouseEvent: open ? undefined : false, touchEvent: open ? undefined : false, target: drawerRef },
|
|
4295
|
+
React__default["default"].createElement(FocusTrap__default["default"], { active: !!isModal && !!open, focusTrapOptions: {
|
|
4296
|
+
allowOutsideClick: true,
|
|
4297
|
+
escapeDeactivates: false,
|
|
4298
|
+
clickOutsideDeactivates: false,
|
|
4299
|
+
initialFocus: false,
|
|
4300
|
+
setReturnFocus: false,
|
|
4301
|
+
fallbackFocus: function () { return drawerRef.current; }
|
|
4302
|
+
} },
|
|
4303
|
+
React__default["default"].createElement("div", tslib.__assign({ ref: drawerRef, className: classNames__default["default"](className, 'Drawer', {
|
|
4304
|
+
'Drawer--open': !!open,
|
|
4305
|
+
'Drawer--top': position === 'top',
|
|
4306
|
+
'Drawer--bottom': position === 'bottom',
|
|
4307
|
+
'Drawer--left': position === 'left',
|
|
4308
|
+
'Drawer--right': position === 'right'
|
|
4309
|
+
}), "aria-hidden": !open || undefined, style: tslib.__assign({ visibility: !open && !isTransitioning ? 'hidden' : undefined }, style), tabIndex: open ? -1 : undefined }, props), children))),
|
|
4310
|
+
React__default["default"].createElement(Scrim, { show: !!open && !!isModal })), portalElement ||
|
|
4311
|
+
(
|
|
4312
|
+
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
|
|
4313
|
+
document === null || document === void 0 ? void 0 : document.body));
|
|
4314
|
+
});
|
|
4315
|
+
Drawer.displayName = 'Drawer';
|
|
4316
|
+
|
|
4200
4317
|
var LIGHT_THEME_CLASS = 'cauldron--theme-light';
|
|
4201
4318
|
var DARK_THEME_CLASS = 'cauldron--theme-dark';
|
|
4202
4319
|
var ThemeContext = React.createContext({
|
|
@@ -4299,6 +4416,7 @@ exports.DescriptionTerm = DescriptionTerm;
|
|
|
4299
4416
|
exports.Dialog = Dialog;
|
|
4300
4417
|
exports.DialogContent = DialogContent;
|
|
4301
4418
|
exports.DialogFooter = DialogFooter;
|
|
4419
|
+
exports.Drawer = Drawer;
|
|
4302
4420
|
exports.ExpandCollapsePanel = ExpandCollapsePanel;
|
|
4303
4421
|
exports.FieldWrap = FieldWrap;
|
|
4304
4422
|
exports.Icon = Icon;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RefObject, MutableRefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* When an element can be passed as a value that is either an element or an
|
|
4
|
+
* elementRef, this will resolve the property down to the resulting element
|
|
5
|
+
*/
|
|
6
|
+
export default function resolveElement<T extends Element = Element>(elementOrRef: T | RefObject<T> | MutableRefObject<T> | undefined): T | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* When a component needs to implement an escape handler, such as in modal
|
|
4
|
+
* dialogs, useEscapeKey will handle the events and call the provided callback
|
|
5
|
+
* handler when an escape key event has been fired.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* useEscapeKey(() => close())
|
|
9
|
+
*/
|
|
10
|
+
export default function useEscapeKey<T extends HTMLElement = HTMLElement>(options: {
|
|
11
|
+
active?: boolean;
|
|
12
|
+
callback: (event: KeyboardEvent) => void;
|
|
13
|
+
event?: 'keydown' | 'keypress' | 'keyup';
|
|
14
|
+
target?: T | React.RefObject<T> | React.MutableRefObject<T>;
|
|
15
|
+
defaultPrevented?: boolean;
|
|
16
|
+
capture?: boolean;
|
|
17
|
+
}, dependencies?: DependencyList): void;
|
package/package.json
CHANGED