@deque/cauldron-react 6.2.1-canary.46b16a14 → 6.2.1-canary.595b9fbc
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/index.js +52 -22
- package/lib/utils/idRefs.d.ts +25 -0
- package/package.json +1 -1
- package/lib/utils/remove-ids/index.d.ts +0 -2
- package/lib/utils/token-list/index.d.ts +0 -5
package/lib/index.js
CHANGED
|
@@ -1601,6 +1601,43 @@ var Button = React.forwardRef(function (_a, ref) {
|
|
|
1601
1601
|
});
|
|
1602
1602
|
Button.displayName = 'Button';
|
|
1603
1603
|
|
|
1604
|
+
/**
|
|
1605
|
+
* Returns a unique set of id refs from the provided string
|
|
1606
|
+
* @param ids - string of id refs
|
|
1607
|
+
*/
|
|
1608
|
+
function idRefs(ids) {
|
|
1609
|
+
if (!ids || !ids.trim()) {
|
|
1610
|
+
return new Set();
|
|
1611
|
+
}
|
|
1612
|
+
return new Set(ids.trim().split(/\s+/));
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Returns an updated id ref string with the provided id value added
|
|
1616
|
+
* @param ids - string of id refs
|
|
1617
|
+
* @param id - id to add
|
|
1618
|
+
*/
|
|
1619
|
+
function addIdRef(ids, id) {
|
|
1620
|
+
return tslib.__spreadArray([], tslib.__read(idRefs(ids).add(id)), false).join(' ');
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Returns an updated id ref string with the provided id value removed
|
|
1624
|
+
* @param ids - string of id refs
|
|
1625
|
+
* @param id - id to remove
|
|
1626
|
+
*/
|
|
1627
|
+
function removeIdRef(_ids, id) {
|
|
1628
|
+
var ids = idRefs(_ids);
|
|
1629
|
+
ids.delete(id);
|
|
1630
|
+
return tslib.__spreadArray([], tslib.__read(ids), false).join(' ');
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Returns if an id ref string contains the provided id value
|
|
1634
|
+
* @param ids - string of id refs
|
|
1635
|
+
* @param id - id to check if it exists in the provided idRef string
|
|
1636
|
+
*/
|
|
1637
|
+
function hasIdRef(ids, id) {
|
|
1638
|
+
return idRefs(ids).has(id);
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1604
1641
|
var TIP_HIDE_DELAY = 100;
|
|
1605
1642
|
// fires a custom "cauldron:tooltip:show" / "cauldron:tooltip:hide" event
|
|
1606
1643
|
// to allow projects using cauldron to hook into when a tooltip is shown/hidden
|
|
@@ -1723,11 +1760,17 @@ function Tooltip(_a) {
|
|
|
1723
1760
|
}, [tooltipElement, show, hide]);
|
|
1724
1761
|
// Keep the target's id in sync
|
|
1725
1762
|
React.useEffect(function () {
|
|
1726
|
-
var
|
|
1727
|
-
if (!(
|
|
1728
|
-
targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association,
|
|
1763
|
+
var idRefs = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute(association);
|
|
1764
|
+
if (!hasIdRef(idRefs, id)) {
|
|
1765
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association, addIdRef(idRefs, id));
|
|
1729
1766
|
}
|
|
1730
|
-
|
|
1767
|
+
return function () {
|
|
1768
|
+
if (targetElement) {
|
|
1769
|
+
var idRefs_1 = targetElement.getAttribute(association);
|
|
1770
|
+
targetElement.setAttribute(association, removeIdRef(idRefs_1, id));
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
}, [targetElement, id, association]);
|
|
1731
1774
|
return (React__default["default"].createElement(React__default["default"].Fragment, null, (showTooltip || hideElementOnHidden) && isBrowser()
|
|
1732
1775
|
? reactDom.createPortal(React__default["default"].createElement("div", tslib.__assign({ id: id, className: classNames__default["default"]('Tooltip', "Tooltip--".concat(placement), className, {
|
|
1733
1776
|
TooltipInfo: variant === 'info',
|
|
@@ -1998,19 +2041,6 @@ var randomId = function () {
|
|
|
1998
2041
|
return "x_".concat(i++, "_").concat(num);
|
|
1999
2042
|
};
|
|
2000
2043
|
|
|
2001
|
-
/**
|
|
2002
|
-
* Adds an id to a token list attribute if its not already present in the list
|
|
2003
|
-
*/
|
|
2004
|
-
var tokenList = function (id, currentVal) {
|
|
2005
|
-
if (currentVal === void 0) { currentVal = ''; }
|
|
2006
|
-
var values = currentVal.split(' ');
|
|
2007
|
-
if (values.includes(id)) {
|
|
2008
|
-
return currentVal;
|
|
2009
|
-
}
|
|
2010
|
-
values.push(id);
|
|
2011
|
-
return values.join(' ').trim();
|
|
2012
|
-
};
|
|
2013
|
-
|
|
2014
2044
|
var Select = React__default["default"].forwardRef(function (_a, ref) {
|
|
2015
2045
|
var options = _a.options, children = _a.children, disabled = _a.disabled, label = _a.label, id = _a.id, required = _a.required, _b = _a.requiredText, requiredText = _b === void 0 ? 'Required' : _b, error = _a.error, value = _a.value, ariaDescribedby = _a["aria-describedby"], defaultValue = _a.defaultValue, onChange = _a.onChange, rest = tslib.__rest(_a, ["options", "children", "disabled", "label", "id", "required", "requiredText", "error", "value", 'aria-describedby', "defaultValue", "onChange"]);
|
|
2016
2046
|
if (options && children) {
|
|
@@ -2044,7 +2074,7 @@ var Select = React__default["default"].forwardRef(function (_a, ref) {
|
|
|
2044
2074
|
dynamicProps.defaultValue = defaultValue;
|
|
2045
2075
|
}
|
|
2046
2076
|
if (error) {
|
|
2047
|
-
dynamicProps['aria-describedby'] =
|
|
2077
|
+
dynamicProps['aria-describedby'] = addIdRef(ariaDescribedby, errorId);
|
|
2048
2078
|
}
|
|
2049
2079
|
// In order to support controlled selects, we
|
|
2050
2080
|
// have to attach an `onChange` to the select.
|
|
@@ -2260,10 +2290,10 @@ var Checkbox = React.forwardRef(function (_a, ref) {
|
|
|
2260
2290
|
}, []), errorId = _f.errorId, labelDescriptionId = _f.labelDescriptionId;
|
|
2261
2291
|
var ariaDescribedbyId = ariaDescribedby;
|
|
2262
2292
|
if (error) {
|
|
2263
|
-
ariaDescribedbyId =
|
|
2293
|
+
ariaDescribedbyId = addIdRef(ariaDescribedbyId, errorId);
|
|
2264
2294
|
}
|
|
2265
2295
|
if (labelDescription) {
|
|
2266
|
-
ariaDescribedbyId =
|
|
2296
|
+
ariaDescribedbyId = addIdRef(ariaDescribedbyId, labelDescriptionId);
|
|
2267
2297
|
}
|
|
2268
2298
|
return (React__default["default"].createElement("div", { className: "Checkbox__wrap" },
|
|
2269
2299
|
React__default["default"].createElement("div", { className: classNames__default["default"]('Checkbox is--flex-row', className) },
|
|
@@ -2349,7 +2379,7 @@ var TextField = /** @class */ (function (_super) {
|
|
|
2349
2379
|
var Field = multiline ? 'textarea' : 'input';
|
|
2350
2380
|
var inputProps = {
|
|
2351
2381
|
'aria-describedby': error
|
|
2352
|
-
?
|
|
2382
|
+
? addIdRef(ariaDescribedby, this.errorId)
|
|
2353
2383
|
: ariaDescribedby
|
|
2354
2384
|
};
|
|
2355
2385
|
return (React__default["default"].createElement("div", { className: "Field" },
|
|
@@ -3736,7 +3766,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
|
|
|
3736
3766
|
noMatchingOptions));
|
|
3737
3767
|
var errorId = "".concat(id, "-error");
|
|
3738
3768
|
var inputProps = tslib.__assign(tslib.__assign({}, props), { 'aria-describedby': error
|
|
3739
|
-
?
|
|
3769
|
+
? addIdRef(ariaDescribedby, errorId)
|
|
3740
3770
|
: ariaDescribedby });
|
|
3741
3771
|
return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', className), ref: comboboxRef },
|
|
3742
3772
|
name && React__default["default"].createElement("input", { type: "hidden", name: name, value: formValue }),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type IdRefs = string | null | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Returns a unique set of id refs from the provided string
|
|
4
|
+
* @param ids - string of id refs
|
|
5
|
+
*/
|
|
6
|
+
export default function idRefs(ids: IdRefs): Set<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Returns an updated id ref string with the provided id value added
|
|
9
|
+
* @param ids - string of id refs
|
|
10
|
+
* @param id - id to add
|
|
11
|
+
*/
|
|
12
|
+
export declare function addIdRef(ids: IdRefs, id: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Returns an updated id ref string with the provided id value removed
|
|
15
|
+
* @param ids - string of id refs
|
|
16
|
+
* @param id - id to remove
|
|
17
|
+
*/
|
|
18
|
+
export declare function removeIdRef(_ids: IdRefs, id: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns if an id ref string contains the provided id value
|
|
21
|
+
* @param ids - string of id refs
|
|
22
|
+
* @param id - id to check if it exists in the provided idRef string
|
|
23
|
+
*/
|
|
24
|
+
export declare function hasIdRef(ids: IdRefs, id: string): boolean;
|
|
25
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
declare function recursivelyRemoveIds(element: React.ReactNode): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>[] | null | undefined;
|
|
2
|
-
export default recursivelyRemoveIds;
|