@deque/cauldron-react 6.2.1 → 6.3.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.
@@ -4,8 +4,5 @@ export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>
4
4
  variant?: 'button' | 'button-secondary';
5
5
  thin?: boolean;
6
6
  }
7
- declare const Link: {
8
- ({ children, linkRef, className, variant, thin, ...other }: LinkProps): React.JSX.Element;
9
- displayName: string;
10
- };
7
+ declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
11
8
  export default Link;
@@ -0,0 +1,13 @@
1
+ import React, { ChangeEvent, InputHTMLAttributes } from 'react';
2
+ import type { ContentNode } from '../../types';
3
+ interface SearchFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
4
+ label: ContentNode;
5
+ value?: string;
6
+ defaultValue?: string;
7
+ onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
8
+ hideLabel?: boolean;
9
+ isForm?: boolean;
10
+ trailingChildren?: React.ReactNode;
11
+ }
12
+ declare const SearchField: React.ForwardRefExoticComponent<SearchFieldProps & React.RefAttributes<HTMLInputElement>>;
13
+ export default SearchField;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { type TooltipProps } from '../Tooltip';
3
+ interface TextEllipsisProps extends React.HTMLAttributes<HTMLDivElement> {
4
+ children: string;
5
+ maxLines?: number;
6
+ as?: React.ElementType;
7
+ refProp?: string;
8
+ tooltipProps?: Omit<TooltipProps, 'target' | 'association'>;
9
+ }
10
+ declare const TextEllipsis: React.ForwardRefExoticComponent<TextEllipsisProps & React.RefAttributes<HTMLElement>>;
11
+ export default TextEllipsis;
@@ -5,7 +5,7 @@ export interface TooltipProps extends React.HTMLAttributes<HTMLDivElement> {
5
5
  className?: string;
6
6
  target: React.RefObject<HTMLElement> | HTMLElement;
7
7
  variant?: 'text' | 'info' | 'big';
8
- association?: 'aria-labelledby' | 'aria-describedby';
8
+ association?: 'aria-labelledby' | 'aria-describedby' | 'none';
9
9
  show?: boolean | undefined;
10
10
  placement?: Placement;
11
11
  portal?: React.RefObject<HTMLElement> | HTMLElement;
@@ -0,0 +1,7 @@
1
+ import React, { HTMLAttributes, ReactNode } from 'react';
2
+ export interface TextFieldWrapperProps extends HTMLAttributes<HTMLDivElement> {
3
+ children: ReactNode;
4
+ className?: string;
5
+ }
6
+ declare const TextFieldWrapper: React.ForwardRefExoticComponent<TextFieldWrapperProps & React.RefAttributes<HTMLDivElement>>;
7
+ export default TextFieldWrapper;
package/lib/index.d.ts CHANGED
@@ -30,6 +30,7 @@ export { default as Checkbox } from './components/Checkbox';
30
30
  export { default as Tooltip, TooltipHead, TooltipContent } from './components/Tooltip';
31
31
  export { default as TooltipTabstop } from './components/TooltipTabstop';
32
32
  export { default as TextField } from './components/TextField';
33
+ export { default as SearchField } from './components/SearchField';
33
34
  export { default as ClickOutsideListener } from './components/ClickOutsideListener';
34
35
  export { default as ExpandCollapsePanel, PanelTrigger } from './components/ExpandCollapsePanel';
35
36
  export { default as Sidebar, SideBarItem } from './components/SideBar';
@@ -54,6 +55,7 @@ export { default as Listbox, ListboxOption, ListboxGroup } from './components/Li
54
55
  export { default as Combobox, ComboboxOption, ComboboxGroup } from './components/Combobox';
55
56
  export { default as Popover } from './components/Popover';
56
57
  export { default as Timeline, TimelineItem } from './components/Timeline';
58
+ export { default as TextEllipsis } from './components/TextEllipsis';
57
59
  /**
58
60
  * Helpers / Utils
59
61
  */
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
@@ -1622,6 +1659,7 @@ function Tooltip(_a) {
1622
1659
  var _j = tslib.__read(React.useState(null), 2), targetElement = _j[0], setTargetElement = _j[1];
1623
1660
  var _k = tslib.__read(React.useState(null), 2), tooltipElement = _k[0], setTooltipElement = _k[1];
1624
1661
  var _l = tslib.__read(React.useState(null), 2), arrowElement = _l[0], setArrowElement = _l[1];
1662
+ var hasAriaAssociation = association !== 'none';
1625
1663
  var _m = reactPopper.usePopper(targetElement, tooltipElement, {
1626
1664
  placement: initialPlacement,
1627
1665
  modifiers: [
@@ -1723,11 +1761,19 @@ function Tooltip(_a) {
1723
1761
  }, [tooltipElement, show, hide]);
1724
1762
  // Keep the target's id in sync
1725
1763
  React.useEffect(function () {
1726
- var attrText = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute(association);
1727
- if (!(attrText === null || attrText === void 0 ? void 0 : attrText.includes(id || ''))) {
1728
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association, [id, attrText].filter(Boolean).join(' '));
1764
+ if (hasAriaAssociation) {
1765
+ var idRefs = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute(association);
1766
+ if (!hasIdRef(idRefs, id)) {
1767
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association, addIdRef(idRefs, id));
1768
+ }
1729
1769
  }
1730
- }, [targetElement, id]);
1770
+ return function () {
1771
+ if (targetElement && hasAriaAssociation) {
1772
+ var idRefs = targetElement.getAttribute(association);
1773
+ targetElement.setAttribute(association, removeIdRef(idRefs, id));
1774
+ }
1775
+ };
1776
+ }, [targetElement, id, association]);
1731
1777
  return (React__default["default"].createElement(React__default["default"].Fragment, null, (showTooltip || hideElementOnHidden) && isBrowser()
1732
1778
  ? reactDom.createPortal(React__default["default"].createElement("div", tslib.__assign({ id: id, className: classNames__default["default"]('Tooltip', "Tooltip--".concat(placement), className, {
1733
1779
  TooltipInfo: variant === 'info',
@@ -1968,15 +2014,15 @@ var Toast = /** @class */ (function (_super) {
1968
2014
  return Toast;
1969
2015
  }(React__default["default"].Component));
1970
2016
 
1971
- var Link = function (_a) {
2017
+ var Link = React.forwardRef(function (_a, ref) {
1972
2018
  var children = _a.children, linkRef = _a.linkRef, className = _a.className, variant = _a.variant, thin = _a.thin, other = tslib.__rest(_a, ["children", "linkRef", "className", "variant", "thin"]);
1973
- return (React__default["default"].createElement("a", tslib.__assign({ ref: linkRef, className: classNames__default["default"](className, {
2019
+ return (React__default["default"].createElement("a", tslib.__assign({ ref: ref || linkRef, className: classNames__default["default"](className, {
1974
2020
  Link: !variant,
1975
2021
  'Button--primary': variant === 'button',
1976
2022
  'Button--secondary': variant === 'button-secondary',
1977
2023
  'Button--thin': thin
1978
2024
  }) }, other), children));
1979
- };
2025
+ });
1980
2026
  Link.displayName = 'Link';
1981
2027
 
1982
2028
  var Loader = React__default["default"].forwardRef(function (_a, ref) {
@@ -1998,19 +2044,6 @@ var randomId = function () {
1998
2044
  return "x_".concat(i++, "_").concat(num);
1999
2045
  };
2000
2046
 
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
2047
  var Select = React__default["default"].forwardRef(function (_a, ref) {
2015
2048
  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
2049
  if (options && children) {
@@ -2044,7 +2077,7 @@ var Select = React__default["default"].forwardRef(function (_a, ref) {
2044
2077
  dynamicProps.defaultValue = defaultValue;
2045
2078
  }
2046
2079
  if (error) {
2047
- dynamicProps['aria-describedby'] = tokenList(errorId, ariaDescribedby);
2080
+ dynamicProps['aria-describedby'] = addIdRef(ariaDescribedby, errorId);
2048
2081
  }
2049
2082
  // In order to support controlled selects, we
2050
2083
  // have to attach an `onChange` to the select.
@@ -2260,10 +2293,10 @@ var Checkbox = React.forwardRef(function (_a, ref) {
2260
2293
  }, []), errorId = _f.errorId, labelDescriptionId = _f.labelDescriptionId;
2261
2294
  var ariaDescribedbyId = ariaDescribedby;
2262
2295
  if (error) {
2263
- ariaDescribedbyId = tokenList(errorId, ariaDescribedbyId);
2296
+ ariaDescribedbyId = addIdRef(ariaDescribedbyId, errorId);
2264
2297
  }
2265
2298
  if (labelDescription) {
2266
- ariaDescribedbyId = tokenList(labelDescriptionId, ariaDescribedbyId);
2299
+ ariaDescribedbyId = addIdRef(ariaDescribedbyId, labelDescriptionId);
2267
2300
  }
2268
2301
  return (React__default["default"].createElement("div", { className: "Checkbox__wrap" },
2269
2302
  React__default["default"].createElement("div", { className: classNames__default["default"]('Checkbox is--flex-row', className) },
@@ -2349,7 +2382,7 @@ var TextField = /** @class */ (function (_super) {
2349
2382
  var Field = multiline ? 'textarea' : 'input';
2350
2383
  var inputProps = {
2351
2384
  'aria-describedby': error
2352
- ? tokenList(this.errorId, ariaDescribedby)
2385
+ ? addIdRef(ariaDescribedby, this.errorId)
2353
2386
  : ariaDescribedby
2354
2387
  };
2355
2388
  return (React__default["default"].createElement("div", { className: "Field" },
@@ -2396,6 +2429,44 @@ var TextField = /** @class */ (function (_super) {
2396
2429
  return TextField;
2397
2430
  }(React__default["default"].Component));
2398
2431
 
2432
+ var TextFieldWrapper = React.forwardRef(function (_a, ref) {
2433
+ var className = _a.className, children = _a.children, otherProps = tslib.__rest(_a, ["className", "children"]);
2434
+ return (React__default["default"].createElement("div", tslib.__assign({ className: classNames__default["default"]('TextFieldWrapper', className) }, otherProps, { ref: ref }), children));
2435
+ });
2436
+ TextFieldWrapper.displayName = 'TextFieldWrapper';
2437
+
2438
+ var SearchField = React.forwardRef(function (_a, ref) {
2439
+ var label = _a.label, _b = _a.defaultValue, defaultValue = _b === void 0 ? '' : _b, onChange = _a.onChange, _c = _a.hideLabel, hideLabel = _c === void 0 ? false : _c, _d = _a.placeholder, placeholder = _d === void 0 ? 'Search...' : _d, _e = _a.isForm, isForm = _e === void 0 ? true : _e, propId = _a.id, propValue = _a.value, trailingChildren = _a.trailingChildren, otherProps = tslib.__rest(_a, ["label", "defaultValue", "onChange", "hideLabel", "placeholder", "isForm", "id", "value", "trailingChildren"]);
2440
+ var isControlled = typeof propValue !== 'undefined';
2441
+ var _f = tslib.__read(React.useState(isControlled ? propValue : defaultValue), 2), value = _f[0], setValue = _f[1];
2442
+ var _g = tslib.__read(propId ? [propId] : nextId.useId(1, 'search-field'), 1), id = _g[0];
2443
+ var inputId = React.useRef(id).current;
2444
+ var handleChange = function (e) {
2445
+ var newValue = e.target.value;
2446
+ if (typeof onChange === 'function') {
2447
+ onChange(newValue, e);
2448
+ }
2449
+ if (isControlled) {
2450
+ return;
2451
+ }
2452
+ setValue(newValue);
2453
+ };
2454
+ var Field = isForm ? 'form' : 'div';
2455
+ if (typeof trailingChildren === 'string') {
2456
+ trailingChildren = React__default["default"].createElement("span", null, trailingChildren);
2457
+ }
2458
+ return (React__default["default"].createElement(Field, { role: isForm ? 'search' : undefined, className: "SearchField", "aria-labelledby": isForm ? "".concat(inputId, "-label") : undefined },
2459
+ hideLabel ? (React__default["default"].createElement(Offscreen, null,
2460
+ React__default["default"].createElement("label", { htmlFor: inputId, id: "".concat(inputId, "-label") }, label))) : (React__default["default"].createElement("label", { className: "Field__label", htmlFor: inputId, id: "".concat(inputId, "-label") }, label)),
2461
+ React__default["default"].createElement(TextFieldWrapper, { className: classNames__default["default"]({
2462
+ 'TextFieldWrapper--disabled': otherProps.disabled
2463
+ }) },
2464
+ React__default["default"].createElement(Icon, { type: "magnifying-glass", className: "SearchField__search-icon" }),
2465
+ React__default["default"].createElement("input", tslib.__assign({ id: inputId, value: value, onChange: handleChange, placeholder: placeholder, ref: ref }, otherProps, { className: classNames__default["default"](otherProps.className, 'Field__text-input'), type: "search" })),
2466
+ trailingChildren)));
2467
+ });
2468
+ SearchField.displayName = 'SearchField';
2469
+
2399
2470
  SyntaxHighlighter__default["default"].registerLanguage('javascript', js__default["default"]);
2400
2471
  SyntaxHighlighter__default["default"].registerLanguage('css', css__default["default"]);
2401
2472
  SyntaxHighlighter__default["default"].registerLanguage('html', xml__default["default"]);
@@ -3702,7 +3773,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
3702
3773
  noMatchingOptions));
3703
3774
  var errorId = "".concat(id, "-error");
3704
3775
  var inputProps = tslib.__assign(tslib.__assign({}, props), { 'aria-describedby': error
3705
- ? tokenList(errorId, ariaDescribedby)
3776
+ ? addIdRef(ariaDescribedby, errorId)
3706
3777
  : ariaDescribedby });
3707
3778
  return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', className), ref: comboboxRef },
3708
3779
  name && React__default["default"].createElement("input", { type: "hidden", name: name, value: formValue }),
@@ -3712,9 +3783,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
3712
3783
  }), id: "".concat(id, "-label"), htmlFor: "".concat(id, "-input") },
3713
3784
  React__default["default"].createElement("span", null, label),
3714
3785
  isRequired && (React__default["default"].createElement("span", { className: "Field__required-text" }, requiredText))),
3715
- React__default["default"].createElement("div", { className: classNames__default["default"]('Combobox__input', {
3716
- 'Combobox__input--error': hasError
3717
- }),
3786
+ React__default["default"].createElement(TextFieldWrapper, { className: classNames__default["default"]({ 'TextFieldWrapper--error': hasError }),
3718
3787
  // We're handling click here to open the listbox when the wrapping element is clicked,
3719
3788
  // there's already keyboard handlers to open the listbox on the input element
3720
3789
  onClick: handleInputClick },
@@ -3893,6 +3962,51 @@ function TimelineItem(_a) {
3893
3962
  React__default["default"].createElement("div", { className: "TimelineItem__details" }, children)));
3894
3963
  }
3895
3964
 
3965
+ var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
3966
+ var className = _a.className, children = _a.children, maxLines = _a.maxLines, as = _a.as, tooltipProps = _a.tooltipProps, props = tslib.__rest(_a, ["className", "children", "maxLines", "as", "tooltipProps"]);
3967
+ var Element = 'div';
3968
+ var sharedRef = useSharedRef(ref);
3969
+ var _b = tslib.__read(React.useState(false), 2), showTooltip = _b[0], setShowTooltip = _b[1];
3970
+ if (as) {
3971
+ Element = as;
3972
+ }
3973
+ else if (showTooltip) {
3974
+ props = Object.assign({
3975
+ role: 'button',
3976
+ 'aria-disabled': true,
3977
+ tabIndex: 0
3978
+ }, props);
3979
+ }
3980
+ if (typeof maxLines === 'number') {
3981
+ props.style = tslib.__assign({ WebkitLineClamp: maxLines || 2 }, props.style);
3982
+ }
3983
+ React.useEffect(function () {
3984
+ var listener = function () {
3985
+ requestAnimationFrame(function () {
3986
+ var overflowElement = sharedRef.current;
3987
+ if (!overflowElement) {
3988
+ return;
3989
+ }
3990
+ var hasOverflow = typeof maxLines === 'number'
3991
+ ? overflowElement.clientHeight < overflowElement.scrollHeight
3992
+ : overflowElement.clientWidth < overflowElement.scrollWidth;
3993
+ setShowTooltip(hasOverflow);
3994
+ });
3995
+ };
3996
+ var observer = new ResizeObserver(listener);
3997
+ observer.observe(sharedRef.current);
3998
+ return function () {
3999
+ observer === null || observer === void 0 ? void 0 : observer.disconnect();
4000
+ };
4001
+ }, []);
4002
+ return (React__default["default"].createElement(React__default["default"].Fragment, null,
4003
+ React__default["default"].createElement(Element, tslib.__assign({ className: classNames__default["default"]('TextEllipsis', className, {
4004
+ 'TextEllipsis--multiline': !!maxLines
4005
+ }), ref: sharedRef }, props), children),
4006
+ showTooltip && (React__default["default"].createElement(Tooltip, tslib.__assign({ target: sharedRef, association: "none" }, tooltipProps), children))));
4007
+ });
4008
+ TextEllipsis.displayName = 'TextEllipsis';
4009
+
3896
4010
  var LIGHT_THEME_CLASS = 'cauldron--theme-light';
3897
4011
  var DARK_THEME_CLASS = 'cauldron--theme-dark';
3898
4012
  var ThemeContext = React.createContext({
@@ -4029,6 +4143,7 @@ exports.ProgressBar = ProgressBar;
4029
4143
  exports.RadioCardGroup = RadioCardGroup;
4030
4144
  exports.RadioGroup = RadioGroup;
4031
4145
  exports.Scrim = Scrim;
4146
+ exports.SearchField = SearchField;
4032
4147
  exports.Select = Select;
4033
4148
  exports.SideBar = SideBar;
4034
4149
  exports.SideBarItem = SideBarItem;
@@ -4049,6 +4164,7 @@ exports.Tabs = Tabs;
4049
4164
  exports.Tag = Tag;
4050
4165
  exports.TagButton = TagButton;
4051
4166
  exports.TagLabel = TagLabel;
4167
+ exports.TextEllipsis = TextEllipsis;
4052
4168
  exports.TextField = TextField;
4053
4169
  exports.ThemeContext = ThemeContext;
4054
4170
  exports.ThemeProvider = ThemeProvider;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "6.2.1",
3
+ "version": "6.3.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Fully accessible react components library for Deque Cauldron",
6
6
  "homepage": "https://cauldron.dequelabs.com/",
@@ -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;
@@ -1,5 +0,0 @@
1
- /**
2
- * Adds an id to a token list attribute if its not already present in the list
3
- */
4
- declare const tokenList: (id: string, currentVal?: string) => string;
5
- export default tokenList;