@deque/cauldron-react 6.6.1-canary.cd63c05f → 6.6.1-canary.db04cb91
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 +4 -0
- package/lib/components/Code/index.d.ts +5 -0
- package/lib/index.js +121 -116
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,10 @@ yarn add @deque/cauldron-react @deque/cauldron-styles
|
|
|
22
22
|
|
|
23
23
|
To get started, follow our [usage guide](https://cauldron.dequelabs.com/#usage) that includes setup instructions and necessary dependencies. Further documentation is also available at [cauldron.dequelabs.com](https://cauldron.dequelabs.com) that includes documentation for every available Cauldron component.
|
|
24
24
|
|
|
25
|
+
## Attribution
|
|
26
|
+
|
|
27
|
+
Some Cauldron icons use Font Awesome Free and Font Awesome Pro. Their licenses can be found here: [Font Awesome Free License](https://fontawesome.com/license/free) and [Font Awesome Pro License](https://fontawesome.com/license).
|
|
28
|
+
|
|
25
29
|
## Contribute
|
|
26
30
|
|
|
27
31
|
If you're interested in contributing to Cauldron, you can check out our [contribution guide](https://github.com/dequelabs/cauldron/blob/develop/CONTRIBUTING.md) as well as our [code of conduct](https://github.com/dequelabs/cauldron/blob/develop/CODE_OF_CONDUCT.md).
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SyntaxHighlighterProps } from 'react-syntax-highlighter';
|
|
3
|
+
import type { ContentNode } from '../../types';
|
|
4
|
+
import CopyButton from '../CopyButton';
|
|
3
5
|
type Props = {
|
|
4
6
|
children: string;
|
|
5
7
|
language?: 'javascript' | 'css' | 'html' | 'yaml';
|
|
6
8
|
className?: string;
|
|
7
9
|
scrollable?: boolean;
|
|
10
|
+
label?: ContentNode;
|
|
11
|
+
allowCopy?: boolean;
|
|
12
|
+
copyButtonProps?: React.ComponentProps<typeof CopyButton>;
|
|
8
13
|
} & SyntaxHighlighterProps & React.HTMLAttributes<HTMLDivElement>;
|
|
9
14
|
declare const Code: React.ComponentType<React.PropsWithChildren<Props>>;
|
|
10
15
|
export default Code;
|
package/lib/index.js
CHANGED
|
@@ -2540,6 +2540,117 @@ var SearchField = React.forwardRef(function (_a, ref) {
|
|
|
2540
2540
|
});
|
|
2541
2541
|
SearchField.displayName = 'SearchField';
|
|
2542
2542
|
|
|
2543
|
+
/**
|
|
2544
|
+
* When a component needs to track an internal ref on a component that has a
|
|
2545
|
+
* forwarded ref, useSharedRef will return a MutableRefObject<T> that will
|
|
2546
|
+
* correctly invoke the parent ref as well providing an internal ref.
|
|
2547
|
+
*
|
|
2548
|
+
* @example
|
|
2549
|
+
* React.forwardRef(function Component({ children }, ref) {
|
|
2550
|
+
* const internalRef = useSharedRef<HTMLElement>(ref)
|
|
2551
|
+
* if (internalRef.current) {
|
|
2552
|
+
* // do something with the internal ref...
|
|
2553
|
+
* }
|
|
2554
|
+
* return (<div ref={internalRef}>...</div>)
|
|
2555
|
+
* })
|
|
2556
|
+
*/
|
|
2557
|
+
function useSharedRef(ref) {
|
|
2558
|
+
var internalRef = React.useRef();
|
|
2559
|
+
React.useEffect(function () {
|
|
2560
|
+
setRef(ref, internalRef.current);
|
|
2561
|
+
}, [ref]);
|
|
2562
|
+
return internalRef;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
function copyTextToClipboard(text) {
|
|
2566
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
2567
|
+
var copied, element, range, selection;
|
|
2568
|
+
return tslib.__generator(this, function (_a) {
|
|
2569
|
+
switch (_a.label) {
|
|
2570
|
+
case 0:
|
|
2571
|
+
copied = false;
|
|
2572
|
+
if (!('clipboard' in navigator)) return [3 /*break*/, 5];
|
|
2573
|
+
_a.label = 1;
|
|
2574
|
+
case 1:
|
|
2575
|
+
_a.trys.push([1, 3, , 4]);
|
|
2576
|
+
return [4 /*yield*/, navigator.clipboard.writeText(text)];
|
|
2577
|
+
case 2:
|
|
2578
|
+
_a.sent();
|
|
2579
|
+
copied = true;
|
|
2580
|
+
return [3 /*break*/, 4];
|
|
2581
|
+
case 3:
|
|
2582
|
+
_a.sent();
|
|
2583
|
+
return [3 /*break*/, 4];
|
|
2584
|
+
case 4: return [3 /*break*/, 6];
|
|
2585
|
+
case 5:
|
|
2586
|
+
element = document.createElement('span');
|
|
2587
|
+
element.textContent = text;
|
|
2588
|
+
element.setAttribute('aria-hidden', 'true');
|
|
2589
|
+
element.style.position = 'absolute';
|
|
2590
|
+
element.style.height = '1px';
|
|
2591
|
+
element.style.width = '1px';
|
|
2592
|
+
element.style.overflow = 'hidden';
|
|
2593
|
+
element.style.clip = 'rect(1px, 1px, 1px, 1px)';
|
|
2594
|
+
element.style.marginTop = '-1px';
|
|
2595
|
+
element.style.webkitUserSelect = 'text';
|
|
2596
|
+
element.style.userSelect = 'text';
|
|
2597
|
+
document.body.appendChild(element);
|
|
2598
|
+
range = document.createRange();
|
|
2599
|
+
selection = document.getSelection();
|
|
2600
|
+
range.selectNodeContents(element);
|
|
2601
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
|
2602
|
+
try {
|
|
2603
|
+
document.execCommand(text);
|
|
2604
|
+
copied = true;
|
|
2605
|
+
}
|
|
2606
|
+
catch (ex) {
|
|
2607
|
+
// no fallback
|
|
2608
|
+
}
|
|
2609
|
+
element.remove();
|
|
2610
|
+
_a.label = 6;
|
|
2611
|
+
case 6: return [2 /*return*/, copied];
|
|
2612
|
+
}
|
|
2613
|
+
});
|
|
2614
|
+
});
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
var NOTIFICATION_TIMEOUT_MS = 2000;
|
|
2618
|
+
var CopyButton = React.forwardRef(function (_a, ref) {
|
|
2619
|
+
var className = _a.className, value = _a.value, _b = _a.variant, variant = _b === void 0 ? 'tertiary' : _b, _c = _a.children, children = _c === void 0 ? 'Copy' : _c, _d = _a.notificationLabel, notificationLabel = _d === void 0 ? 'Copied' : _d, _e = _a.hideVisibleLabel, hideVisibleLabel = _e === void 0 ? false : _e, _f = _a.tooltipPlacement, tooltipPlacement = _f === void 0 ? 'auto' : _f, onCopy = _a.onCopy, props = tslib.__rest(_a, ["className", "value", "variant", "children", "notificationLabel", "hideVisibleLabel", "tooltipPlacement", "onCopy"]);
|
|
2620
|
+
var _g = tslib.__read(React.useState(false), 2), copied = _g[0], setCopied = _g[1];
|
|
2621
|
+
var copyButtonRef = useSharedRef(ref);
|
|
2622
|
+
var handleClick = React.useCallback(function () {
|
|
2623
|
+
copyTextToClipboard(value);
|
|
2624
|
+
setCopied(true);
|
|
2625
|
+
if (typeof onCopy === 'function') {
|
|
2626
|
+
onCopy(value);
|
|
2627
|
+
}
|
|
2628
|
+
}, [value, onCopy]);
|
|
2629
|
+
React.useEffect(function () {
|
|
2630
|
+
var timeoutId = setTimeout(function () {
|
|
2631
|
+
setCopied(false);
|
|
2632
|
+
}, NOTIFICATION_TIMEOUT_MS);
|
|
2633
|
+
return function () {
|
|
2634
|
+
clearTimeout(timeoutId);
|
|
2635
|
+
};
|
|
2636
|
+
}, [copied]);
|
|
2637
|
+
// The visibility of the tooltip only needs to be controlled
|
|
2638
|
+
// when we are visually displaying the notification label
|
|
2639
|
+
var showTooltip = hideVisibleLabel && !copied ? undefined : copied ? true : false;
|
|
2640
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
2641
|
+
React__default["default"].createElement(Button, tslib.__assign({ className: classNames__default["default"](className, {
|
|
2642
|
+
'Button--condensed': hideVisibleLabel
|
|
2643
|
+
}), ref: copyButtonRef, variant: variant, onClick: handleClick }, props),
|
|
2644
|
+
React__default["default"].createElement(Icon, { type: copied ? 'check-solid' : 'copy' }),
|
|
2645
|
+
hideVisibleLabel ? React__default["default"].createElement(Offscreen, null, children) : children),
|
|
2646
|
+
React__default["default"].createElement(Tooltip, { target: copyButtonRef, placement: tooltipPlacement, association: "none", show: showTooltip }, hideVisibleLabel && !copied ? children : notificationLabel),
|
|
2647
|
+
typeof document !== 'undefined' &&
|
|
2648
|
+
reactDom.createPortal(React__default["default"].createElement(Offscreen, { "aria-live": "polite" }, copied ? notificationLabel : ' '),
|
|
2649
|
+
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
|
|
2650
|
+
document.body)));
|
|
2651
|
+
});
|
|
2652
|
+
CopyButton.displayName = 'CopyButton';
|
|
2653
|
+
|
|
2543
2654
|
SyntaxHighlighter__default["default"].registerLanguage('javascript', js__default["default"]);
|
|
2544
2655
|
SyntaxHighlighter__default["default"].registerLanguage('css', css__default["default"]);
|
|
2545
2656
|
SyntaxHighlighter__default["default"].registerLanguage('html', xml__default["default"]);
|
|
@@ -2547,9 +2658,10 @@ SyntaxHighlighter__default["default"].registerLanguage('yaml', yaml__default["de
|
|
|
2547
2658
|
// HACK: This is a workaround for a bug in react-syntax-highlighter's types.
|
|
2548
2659
|
var Highlighter = SyntaxHighlighter__default["default"];
|
|
2549
2660
|
var Code = function (_a) {
|
|
2550
|
-
var children = _a.children, className = _a.className, _b = _a.scrollable, scrollable = _b === void 0 ? false : _b, props = tslib.__rest(_a, ["children", "className", "scrollable"]);
|
|
2661
|
+
var children = _a.children, className = _a.className, _b = _a.scrollable, scrollable = _b === void 0 ? false : _b, label = _a.label, _c = _a.allowCopy, allowCopy = _c === void 0 ? false : _c, copyButtonProps = _a.copyButtonProps, props = tslib.__rest(_a, ["children", "className", "scrollable", "label", "allowCopy", "copyButtonProps"]);
|
|
2551
2662
|
var ref = React.useRef(null);
|
|
2552
|
-
var
|
|
2663
|
+
var _d = tslib.__read(React.useState(false), 2), scrollableRegion = _d[0], setScrollableRegion = _d[1];
|
|
2664
|
+
var _e = tslib.__read(nextId.useId(1, 'code'), 1), id = _e[0];
|
|
2553
2665
|
// react-syntax-highlighter does not provide direct access to its dom elements
|
|
2554
2666
|
// via refs, but we can specify the wrapping tags to bypass this limitation
|
|
2555
2667
|
// see: https://github.com/react-syntax-highlighter/react-syntax-highlighter/issues/335
|
|
@@ -2573,9 +2685,13 @@ var Code = function (_a) {
|
|
|
2573
2685
|
setScrollableRegion(false);
|
|
2574
2686
|
};
|
|
2575
2687
|
}, [scrollable]);
|
|
2576
|
-
return (React__default["default"].createElement(
|
|
2577
|
-
|
|
2578
|
-
|
|
2688
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
2689
|
+
(label || allowCopy) && (React__default["default"].createElement("div", { className: "Code__Header" },
|
|
2690
|
+
label && React__default["default"].createElement("span", { id: "".concat(id, "-label") }, label),
|
|
2691
|
+
allowCopy && React__default["default"].createElement(CopyButton, tslib.__assign({ value: children }, copyButtonProps)))),
|
|
2692
|
+
React__default["default"].createElement(Highlighter, tslib.__assign({}, props, { PreTag: PreWithRef, useInlineStyles: false, className: classNames__default["default"]('Code', className, {
|
|
2693
|
+
'Code--scrollable': scrollable
|
|
2694
|
+
}), tabIndex: scrollableRegion ? 0 : undefined }), children)));
|
|
2579
2695
|
};
|
|
2580
2696
|
Code.displayName = 'Code';
|
|
2581
2697
|
|
|
@@ -2585,28 +2701,6 @@ function AxeLoader() {
|
|
|
2585
2701
|
React__default["default"].createElement("path", { fill: "currentColor", d: "M379 549.9h-27.6v-16.7c-7.4 13.5-22.8 20.2-39 20.2-37.1 0-58.9-28.9-58.9-61.6 0-36.5 26.4-61.4 58.9-61.4 21.1 0 34 11.2 39 20.5V434H379v115.9zm-97.8-57.4c0 14.3 10.3 35.2 35.2 35.2 15.4 0 25.5-8 30.8-18.6 2.7-5.1 4-10.5 4.4-16.2.2-5.5-.8-11.2-3.2-16.2-4.9-11-15.6-20.5-32.3-20.5-22.4 0-35 18.1-35 36.1v.2zM436.2 488.9l-39-54.8h33.3l22.6 35.6 22.6-35.6h32.9l-38.8 54.8 43.2 61h-34L453.1 510l-26.2 39.9h-33.5l42.8-61z" })));
|
|
2586
2702
|
}
|
|
2587
2703
|
|
|
2588
|
-
/**
|
|
2589
|
-
* When a component needs to track an internal ref on a component that has a
|
|
2590
|
-
* forwarded ref, useSharedRef will return a MutableRefObject<T> that will
|
|
2591
|
-
* correctly invoke the parent ref as well providing an internal ref.
|
|
2592
|
-
*
|
|
2593
|
-
* @example
|
|
2594
|
-
* React.forwardRef(function Component({ children }, ref) {
|
|
2595
|
-
* const internalRef = useSharedRef<HTMLElement>(ref)
|
|
2596
|
-
* if (internalRef.current) {
|
|
2597
|
-
* // do something with the internal ref...
|
|
2598
|
-
* }
|
|
2599
|
-
* return (<div ref={internalRef}>...</div>)
|
|
2600
|
-
* })
|
|
2601
|
-
*/
|
|
2602
|
-
function useSharedRef(ref) {
|
|
2603
|
-
var internalRef = React.useRef();
|
|
2604
|
-
React.useEffect(function () {
|
|
2605
|
-
setRef(ref, internalRef.current);
|
|
2606
|
-
}, [ref]);
|
|
2607
|
-
return internalRef;
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
2704
|
var LoaderOverlay = React.forwardRef(function (_a, ref) {
|
|
2611
2705
|
var className = _a.className, label = _a.label, children = _a.children, focusOnInitialRender = _a.focusOnInitialRender, _b = _a.focusTrap, focusTrap = _b === void 0 ? false : _b, other = tslib.__rest(_a, ["className", "label", "children", "focusOnInitialRender", "focusTrap"]);
|
|
2612
2706
|
var overlayRef = useSharedRef(ref);
|
|
@@ -4120,95 +4214,6 @@ var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
|
|
|
4120
4214
|
});
|
|
4121
4215
|
TextEllipsis.displayName = 'TextEllipsis';
|
|
4122
4216
|
|
|
4123
|
-
function copyTextToClipboard(text) {
|
|
4124
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
4125
|
-
var copied, element, range, selection;
|
|
4126
|
-
return tslib.__generator(this, function (_a) {
|
|
4127
|
-
switch (_a.label) {
|
|
4128
|
-
case 0:
|
|
4129
|
-
copied = false;
|
|
4130
|
-
if (!('clipboard' in navigator)) return [3 /*break*/, 5];
|
|
4131
|
-
_a.label = 1;
|
|
4132
|
-
case 1:
|
|
4133
|
-
_a.trys.push([1, 3, , 4]);
|
|
4134
|
-
return [4 /*yield*/, navigator.clipboard.writeText(text)];
|
|
4135
|
-
case 2:
|
|
4136
|
-
_a.sent();
|
|
4137
|
-
copied = true;
|
|
4138
|
-
return [3 /*break*/, 4];
|
|
4139
|
-
case 3:
|
|
4140
|
-
_a.sent();
|
|
4141
|
-
return [3 /*break*/, 4];
|
|
4142
|
-
case 4: return [3 /*break*/, 6];
|
|
4143
|
-
case 5:
|
|
4144
|
-
element = document.createElement('span');
|
|
4145
|
-
element.textContent = text;
|
|
4146
|
-
element.setAttribute('aria-hidden', 'true');
|
|
4147
|
-
element.style.position = 'absolute';
|
|
4148
|
-
element.style.height = '1px';
|
|
4149
|
-
element.style.width = '1px';
|
|
4150
|
-
element.style.overflow = 'hidden';
|
|
4151
|
-
element.style.clip = 'rect(1px, 1px, 1px, 1px)';
|
|
4152
|
-
element.style.marginTop = '-1px';
|
|
4153
|
-
element.style.webkitUserSelect = 'text';
|
|
4154
|
-
element.style.userSelect = 'text';
|
|
4155
|
-
document.body.appendChild(element);
|
|
4156
|
-
range = document.createRange();
|
|
4157
|
-
selection = document.getSelection();
|
|
4158
|
-
range.selectNodeContents(element);
|
|
4159
|
-
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
|
4160
|
-
try {
|
|
4161
|
-
document.execCommand(text);
|
|
4162
|
-
copied = true;
|
|
4163
|
-
}
|
|
4164
|
-
catch (ex) {
|
|
4165
|
-
// no fallback
|
|
4166
|
-
}
|
|
4167
|
-
element.remove();
|
|
4168
|
-
_a.label = 6;
|
|
4169
|
-
case 6: return [2 /*return*/, copied];
|
|
4170
|
-
}
|
|
4171
|
-
});
|
|
4172
|
-
});
|
|
4173
|
-
}
|
|
4174
|
-
|
|
4175
|
-
var NOTIFICATION_TIMEOUT_MS = 2000;
|
|
4176
|
-
var CopyButton = React.forwardRef(function (_a, ref) {
|
|
4177
|
-
var className = _a.className, value = _a.value, _b = _a.variant, variant = _b === void 0 ? 'tertiary' : _b, _c = _a.children, children = _c === void 0 ? 'Copy' : _c, _d = _a.notificationLabel, notificationLabel = _d === void 0 ? 'Copied' : _d, _e = _a.hideVisibleLabel, hideVisibleLabel = _e === void 0 ? false : _e, _f = _a.tooltipPlacement, tooltipPlacement = _f === void 0 ? 'auto' : _f, onCopy = _a.onCopy, props = tslib.__rest(_a, ["className", "value", "variant", "children", "notificationLabel", "hideVisibleLabel", "tooltipPlacement", "onCopy"]);
|
|
4178
|
-
var _g = tslib.__read(React.useState(false), 2), copied = _g[0], setCopied = _g[1];
|
|
4179
|
-
var copyButtonRef = useSharedRef(ref);
|
|
4180
|
-
var handleClick = React.useCallback(function () {
|
|
4181
|
-
copyTextToClipboard(value);
|
|
4182
|
-
setCopied(true);
|
|
4183
|
-
if (typeof onCopy === 'function') {
|
|
4184
|
-
onCopy(value);
|
|
4185
|
-
}
|
|
4186
|
-
}, [value, onCopy]);
|
|
4187
|
-
React.useEffect(function () {
|
|
4188
|
-
var timeoutId = setTimeout(function () {
|
|
4189
|
-
setCopied(false);
|
|
4190
|
-
}, NOTIFICATION_TIMEOUT_MS);
|
|
4191
|
-
return function () {
|
|
4192
|
-
clearTimeout(timeoutId);
|
|
4193
|
-
};
|
|
4194
|
-
}, [copied]);
|
|
4195
|
-
// The visibility of the tooltip only needs to be controlled
|
|
4196
|
-
// when we are visually displaying the notification label
|
|
4197
|
-
var showTooltip = hideVisibleLabel && !copied ? undefined : copied ? true : false;
|
|
4198
|
-
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
4199
|
-
React__default["default"].createElement(Button, tslib.__assign({ className: classNames__default["default"](className, {
|
|
4200
|
-
'Button--condensed': hideVisibleLabel
|
|
4201
|
-
}), ref: copyButtonRef, variant: variant, onClick: handleClick }, props),
|
|
4202
|
-
React__default["default"].createElement(Icon, { type: copied ? 'check-solid' : 'copy' }),
|
|
4203
|
-
hideVisibleLabel ? React__default["default"].createElement(Offscreen, null, children) : children),
|
|
4204
|
-
React__default["default"].createElement(Tooltip, { target: copyButtonRef, placement: tooltipPlacement, association: "none", show: showTooltip }, hideVisibleLabel && !copied ? children : notificationLabel),
|
|
4205
|
-
typeof document !== 'undefined' &&
|
|
4206
|
-
reactDom.createPortal(React__default["default"].createElement(Offscreen, { "aria-live": "polite" }, copied ? notificationLabel : ' '),
|
|
4207
|
-
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
|
|
4208
|
-
document.body)));
|
|
4209
|
-
});
|
|
4210
|
-
CopyButton.displayName = 'CopyButton';
|
|
4211
|
-
|
|
4212
4217
|
var LIGHT_THEME_CLASS = 'cauldron--theme-light';
|
|
4213
4218
|
var DARK_THEME_CLASS = 'cauldron--theme-dark';
|
|
4214
4219
|
var ThemeContext = React.createContext({
|
package/package.json
CHANGED