@deque/cauldron-react 3.0.1-canary.03388cec → 3.0.1-canary.41ff0487

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.
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ interface AddressProps extends React.HTMLAttributes<HTMLElement> {
4
+ children: React.ReactNode;
5
+ }
6
+ export declare const Address: {
7
+ ({ children, className, ...other }: AddressProps): JSX.Element;
8
+ displayName: string;
9
+ propTypes: {
10
+ children: PropTypes.Validator<string | number | boolean | {} | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
11
+ className: PropTypes.Requireable<string>;
12
+ };
13
+ };
14
+ declare type AddressLineProps = React.HTMLAttributes<HTMLElement>;
15
+ export declare const AddressLine: {
16
+ ({ children, className, ...other }: AddressLineProps): JSX.Element | null;
17
+ displayName: string;
18
+ propTypes: {
19
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
20
+ className: PropTypes.Requireable<string>;
21
+ };
22
+ };
23
+ interface AddressCityStateZipProps extends React.HTMLAttributes<HTMLElement> {
24
+ city: React.ReactNode;
25
+ state: React.ReactNode;
26
+ zip: React.ReactNode;
27
+ }
28
+ export declare const AddressCityStateZip: {
29
+ ({ city, state, zip, className, ...other }: AddressCityStateZipProps): JSX.Element | null;
30
+ displayName: string;
31
+ propTypes: {
32
+ city: PropTypes.Requireable<PropTypes.ReactNodeLike>;
33
+ state: PropTypes.Requireable<PropTypes.ReactNodeLike>;
34
+ zip: PropTypes.Requireable<PropTypes.ReactNodeLike>;
35
+ className: PropTypes.Requireable<string>;
36
+ };
37
+ };
38
+ export {};
@@ -1,7 +1,7 @@
1
- import React from 'react';
1
+ import * as Polymorphic from '../../utils/polymorphic-type';
2
2
  import { IconType } from '../Icon';
3
3
  import { TooltipProps } from '../Tooltip';
4
- export interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
4
+ export interface IconButtonOwnProps {
5
5
  icon: IconType;
6
6
  label: string;
7
7
  tooltipPlacement?: TooltipProps['placement'];
@@ -9,5 +9,12 @@ export interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonEl
9
9
  tooltipPortal?: TooltipProps['portal'];
10
10
  variant?: 'primary' | 'secondary' | 'error';
11
11
  }
12
- declare const IconButton: React.ForwardRefExoticComponent<IconButtonProps & React.RefAttributes<HTMLButtonElement>>;
12
+ declare type PolymorphicIconButton = Polymorphic.ForwardRefComponent<'button', IconButtonOwnProps>;
13
+ /**
14
+ * Unfortunately, eslint does not recognize that this Polymorphic component has a displayName set
15
+ *
16
+ * We might be able to remove this if we upgrade eslint and associated plugins
17
+ * See: https://github.com/dequelabs/cauldron/issues/451
18
+ */
19
+ declare const IconButton: PolymorphicIconButton;
13
20
  export default IconButton;
@@ -5,7 +5,7 @@ declare const Panel: {
5
5
  ({ className, title, actions, children }: {
6
6
  className?: string | undefined;
7
7
  title?: string | undefined;
8
- actions?: React.ForwardRefExoticComponent<import("../IconButton").IconButtonProps & React.RefAttributes<HTMLButtonElement>>[] | undefined;
8
+ actions?: import("../../utils/polymorphic-type").ForwardRefComponent<"button", import("../IconButton").IconButtonOwnProps>[] | undefined;
9
9
  children: React.ReactNode;
10
10
  }): JSX.Element;
11
11
  displayName: string;
@@ -9,6 +9,7 @@ interface StepWithChildren extends BaseStepProps {
9
9
  }
10
10
  interface StepWithTooltip extends BaseStepProps {
11
11
  tooltip: React.ReactNode;
12
+ tooltipText: string;
12
13
  }
13
14
  declare type StepProps = StepWithChildren | StepWithTooltip;
14
15
  export declare const Step: {
@@ -17,6 +18,7 @@ export declare const Step: {
17
18
  propTypes: {
18
19
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
19
20
  tooltip: PropTypes.Requireable<PropTypes.ReactNodeLike>;
21
+ tooltipText: PropTypes.Requireable<string>;
20
22
  className: PropTypes.Requireable<string>;
21
23
  };
22
24
  };
@@ -1,6 +1,6 @@
1
- import React from 'react';
1
+ import React, { TdHTMLAttributes } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- interface TableCellProps {
3
+ interface TableCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
4
4
  children: React.ReactNode;
5
5
  className?: string;
6
6
  }
@@ -1,6 +1,6 @@
1
- import React from 'react';
1
+ import React, { ThHTMLAttributes } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- interface TableHeaderProps {
3
+ interface TableHeaderProps extends ThHTMLAttributes<HTMLTableCellElement> {
4
4
  children: React.ReactNode;
5
5
  className?: string;
6
6
  }
@@ -11,7 +11,7 @@ export interface TooltipProps extends React.HTMLAttributes<HTMLDivElement> {
11
11
  portal?: React.RefObject<HTMLElement> | HTMLElement;
12
12
  hideElementOnHidden?: boolean;
13
13
  }
14
- declare function Tooltip({ id: propId, placement: initialPlacement, children, portal, target, association, variant, show: showProp, hideElementOnHidden, ...props }: TooltipProps): React.ReactPortal | null;
14
+ declare function Tooltip({ id: propId, placement: initialPlacement, children, portal, target, association, variant, show: showProp, hideElementOnHidden, className, ...props }: TooltipProps): React.ReactPortal | null;
15
15
  declare namespace Tooltip {
16
16
  var displayName: string;
17
17
  var propTypes: {
package/lib/index.d.ts CHANGED
@@ -43,6 +43,7 @@ export { DescriptionList, DescriptionListItem, DescriptionTerm, DescriptionDetai
43
43
  export { default as Stepper, Step } from './components/Stepper';
44
44
  export { default as Panel } from './components/Panel';
45
45
  export { default as ProgressBar } from './components/ProgressBar';
46
+ export { Address, AddressLine, AddressCityStateZip } from './components/Address';
46
47
  /**
47
48
  * Helpers / Utils
48
49
  */
package/lib/index.js CHANGED
@@ -1467,7 +1467,7 @@ var fireCustomEvent = function (show, button) {
1467
1467
  };
1468
1468
  function Tooltip(_a) {
1469
1469
  var _this = this;
1470
- var propId = _a.id, _b = _a.placement, initialPlacement = _b === void 0 ? 'auto' : _b, children = _a.children, portal = _a.portal, target = _a.target, _c = _a.association, association = _c === void 0 ? 'aria-describedby' : _c, _d = _a.variant, variant = _d === void 0 ? 'text' : _d, _e = _a.show, showProp = _e === void 0 ? false : _e, _f = _a.hideElementOnHidden, hideElementOnHidden = _f === void 0 ? false : _f, props = tslib.__rest(_a, ["id", "placement", "children", "portal", "target", "association", "variant", "show", "hideElementOnHidden"]);
1470
+ var propId = _a.id, _b = _a.placement, initialPlacement = _b === void 0 ? 'auto' : _b, children = _a.children, portal = _a.portal, target = _a.target, _c = _a.association, association = _c === void 0 ? 'aria-describedby' : _c, _d = _a.variant, variant = _d === void 0 ? 'text' : _d, _e = _a.show, showProp = _e === void 0 ? false : _e, _f = _a.hideElementOnHidden, hideElementOnHidden = _f === void 0 ? false : _f, className = _a.className, props = tslib.__rest(_a, ["id", "placement", "children", "portal", "target", "association", "variant", "show", "hideElementOnHidden", "className"]);
1471
1471
  var id = (propId ? [propId] : nextId.useId(1, 'tooltip'))[0];
1472
1472
  var hovering = React.useRef(false);
1473
1473
  var _g = React.useState(initialPlacement), placement = _g[0], setPlacement = _g[1];
@@ -1588,7 +1588,7 @@ function Tooltip(_a) {
1588
1588
  }
1589
1589
  }, [targetElement, id]);
1590
1590
  return showTooltip || hideElementOnHidden
1591
- ? reactDom.createPortal(React__default.createElement("div", tslib.__assign({ id: id, className: classNames('Tooltip', "Tooltip--" + placement, {
1591
+ ? reactDom.createPortal(React__default.createElement("div", tslib.__assign({ id: id, className: classNames('Tooltip', "Tooltip--" + placement, className, {
1592
1592
  TooltipInfo: variant === 'info',
1593
1593
  'Tooltip--hidden': !showTooltip && hideElementOnHidden,
1594
1594
  'Tooltip--big': variant === 'big'
@@ -1617,21 +1617,45 @@ var TooltipContent = function (_a) {
1617
1617
  return (React__default.createElement("div", tslib.__assign({ className: classNames('TooltipContent', className) }, other)));
1618
1618
  };
1619
1619
 
1620
+ /**
1621
+ * Unfortunately, eslint does not recognize that this Polymorphic component has a displayName set
1622
+ *
1623
+ * We might be able to remove this if we upgrade eslint and associated plugins
1624
+ * See: https://github.com/dequelabs/cauldron/issues/451
1625
+ */
1626
+ // eslint-disable-next-line react/display-name
1620
1627
  var IconButton = React.forwardRef(function (_a, ref) {
1621
- var icon = _a.icon, label = _a.label, _b = _a.tooltipPlacement, tooltipPlacement = _b === void 0 ? 'auto' : _b, tooltipVariant = _a.tooltipVariant, tooltipPortal = _a.tooltipPortal, className = _a.className, _c = _a.variant, variant = _c === void 0 ? 'secondary' : _c, disabled = _a.disabled, other = tslib.__rest(_a, ["icon", "label", "tooltipPlacement", "tooltipVariant", "tooltipPortal", "className", "variant", "disabled"]);
1622
- var buttonRef = React.useRef();
1623
- React.useImperativeHandle(ref, function () { return buttonRef.current; });
1628
+ var _b = _a.as, Component = _b === void 0 ? 'button' : _b, icon = _a.icon, label = _a.label, _c = _a.tooltipPlacement, tooltipPlacement = _c === void 0 ? 'auto' : _c, tooltipVariant = _a.tooltipVariant, tooltipPortal = _a.tooltipPortal, className = _a.className, _d = _a.variant, variant = _d === void 0 ? 'secondary' : _d, disabled = _a.disabled, _e = _a.tabIndex, tabIndex = _e === void 0 ? 0 : _e, other = tslib.__rest(_a, ["as", "icon", "label", "tooltipPlacement", "tooltipVariant", "tooltipPortal", "className", "variant", "disabled", "tabIndex"]);
1629
+ var internalRef = React.useRef();
1630
+ React.useImperativeHandle(ref, function () { return internalRef.current; });
1631
+ // Configure additional properties based on the type of the Component
1632
+ // for accessibility
1633
+ var accessibilityProps = {};
1634
+ if (Component === 'button') {
1635
+ accessibilityProps.type = 'button';
1636
+ }
1637
+ else {
1638
+ // We don't need to set an anchor's role, since it would be redundant
1639
+ if (Component !== 'a') {
1640
+ accessibilityProps.role = other.href || other.to ? 'link' : 'button';
1641
+ }
1642
+ if (disabled) {
1643
+ accessibilityProps['aria-disabled'] = disabled;
1644
+ }
1645
+ }
1624
1646
  return (React__default.createElement(React__default.Fragment, null,
1625
- React__default.createElement("button", tslib.__assign({ type: 'button', className: classNames(className, {
1647
+ React__default.createElement(Component, tslib.__assign({ className: classNames(className, {
1626
1648
  IconButton: true,
1627
1649
  'IconButton--primary': variant === 'primary',
1628
1650
  'IconButton--secondary': variant === 'secondary',
1629
1651
  'IconButton--error': variant === 'error'
1630
- }), ref: buttonRef, disabled: disabled }, other),
1652
+ }), ref: internalRef, disabled: disabled, tabIndex: disabled ? -1 : tabIndex }, accessibilityProps, other),
1631
1653
  React__default.createElement(Icon, { type: icon })),
1632
- !disabled && (React__default.createElement(Tooltip, { target: buttonRef, placement: tooltipPlacement, variant: tooltipVariant, portal: tooltipPortal, association: "aria-labelledby", hideElementOnHidden: true }, label))));
1654
+ !disabled && (React__default.createElement(Tooltip, { target: internalRef, placement: tooltipPlacement, variant: tooltipVariant, portal: tooltipPortal, association: "aria-labelledby", hideElementOnHidden: true }, label))));
1633
1655
  });
1634
1656
  IconButton.propTypes = {
1657
+ // @ts-expect-error
1658
+ as: PropTypes.elementType,
1635
1659
  // @ts-expect-error
1636
1660
  icon: PropTypes.string.isRequired,
1637
1661
  label: PropTypes.string.isRequired,
@@ -2249,7 +2273,7 @@ var Select = React__default.forwardRef(function (_a, ref) {
2249
2273
  })
2250
2274
  : children),
2251
2275
  React__default.createElement("div", { className: "arrow-down" })),
2252
- React__default.createElement("div", { className: "Error", id: errorId }, error)));
2276
+ error && (React__default.createElement("div", { id: errorId, className: "Error" }, error))));
2253
2277
  /* eslint-disable jsx-a11y/no-onchange */
2254
2278
  });
2255
2279
  Select.displayName = 'Select';
@@ -2296,13 +2320,13 @@ var RadioGroup = function (_a) {
2296
2320
  handleChange(radioValue);
2297
2321
  onChange(radio, (_a = inputs.current) === null || _a === void 0 ? void 0 : _a[index]);
2298
2322
  }, disabled: disabled, checked: isChecked }, other)),
2323
+ React__default.createElement("label", { htmlFor: id, className: classNames('Field__label', {
2324
+ 'Field__label--disabled': disabled
2325
+ }) }, label),
2299
2326
  React__default.createElement(Icon, { className: classNames('Radio__overlay', {
2300
2327
  'Radio__overlay--focused': isFocused,
2301
2328
  'Radio__overlay--disabled': disabled
2302
- }), type: isChecked ? 'radio-checked' : 'radio-unchecked', "aria-hidden": "true", onClick: function () { return onRadioClick(index); } }),
2303
- React__default.createElement("label", { htmlFor: id, className: classNames('Field__label', {
2304
- 'Field__label--disabled': disabled
2305
- }) }, label)));
2329
+ }), type: isChecked ? 'radio-checked' : 'radio-unchecked', "aria-hidden": "true", onClick: function () { return onRadioClick(index); } })));
2306
2330
  });
2307
2331
  // reset the input refs array
2308
2332
  // refs get clobbered every re-render anyway and this supports "dynamic" radios
@@ -2352,6 +2376,9 @@ var Checkbox = React.forwardRef(function (_a, ref) {
2352
2376
  onChange(e);
2353
2377
  }
2354
2378
  } }, other)),
2379
+ React__default.createElement("label", { className: classNames('Field__label', {
2380
+ 'Field__label--disabled': disabled
2381
+ }), htmlFor: id }, label),
2355
2382
  React__default.createElement(Icon, { className: classNames('Checkbox__overlay', {
2356
2383
  'Checkbox__overlay--disabled': disabled,
2357
2384
  'Checkbox__overlay--focused': focused,
@@ -2364,11 +2391,8 @@ var Checkbox = React.forwardRef(function (_a, ref) {
2364
2391
  else {
2365
2392
  (_b = checkRef.current) === null || _b === void 0 ? void 0 : _b.click();
2366
2393
  }
2367
- } }),
2368
- React__default.createElement("label", { className: classNames('Field__label', {
2369
- 'Field__label--disabled': disabled
2370
- }), htmlFor: id }, label)),
2371
- React__default.createElement("div", { id: errorId, className: "Error" }, error)));
2394
+ } })),
2395
+ error && (React__default.createElement("div", { id: errorId, className: "Error" }, error))));
2372
2396
  });
2373
2397
  Checkbox.displayName = 'Checkbox';
2374
2398
 
@@ -2475,7 +2499,7 @@ var TextField = /** @class */ (function (_super) {
2475
2499
  _this.input = input;
2476
2500
  setRef(fieldRef, input);
2477
2501
  } }, other, inputProps)),
2478
- React__default.createElement("div", { className: "Error", id: this.errorId }, error)));
2502
+ error && (React__default.createElement("div", { className: "Error", id: this.errorId }, error))));
2479
2503
  };
2480
2504
  TextField.prototype.onChange = function (e) {
2481
2505
  var _a, _b;
@@ -8162,7 +8186,7 @@ var Step = function (props) {
8162
8186
  // list items, therefore it is safe to clobber
8163
8187
  // it with the contents of the tooltip in the
8164
8188
  // tab stop's accessible name.
8165
- association: "aria-labelledby" },
8189
+ association: "aria-labelledby", "aria-label": isTooltip(props) ? props.tooltipText : undefined },
8166
8190
  React__default.createElement("div", { className: "Stepper__step-indicator" }))) : (React__default.createElement(React__default.Fragment, null,
8167
8191
  React__default.createElement("div", { className: "Stepper__step-indicator" }),
8168
8192
  'children' in props && (React__default.createElement("div", { className: "Stepper__step-label" }, props.children)))))));
@@ -8171,6 +8195,7 @@ Step.displayName = 'Step';
8171
8195
  Step.propTypes = {
8172
8196
  children: PropTypes.node,
8173
8197
  tooltip: PropTypes.node,
8198
+ tooltipText: PropTypes.string,
8174
8199
  className: PropTypes.string
8175
8200
  };
8176
8201
  var Stepper = function (_a) {
@@ -8205,6 +8230,38 @@ var ProgressBar = React.forwardRef(function (_a, ref) {
8205
8230
  });
8206
8231
  ProgressBar.displayName = 'ProgressBar';
8207
8232
 
8233
+ var Address = function (_a) {
8234
+ var children = _a.children, className = _a.className, other = tslib.__rest(_a, ["children", "className"]);
8235
+ return (React__default.createElement("address", tslib.__assign({ className: classNames('Address', className) }, other), children));
8236
+ };
8237
+ Address.displayName = 'Address';
8238
+ Address.propTypes = {
8239
+ children: PropTypes.node.isRequired,
8240
+ className: PropTypes.string
8241
+ };
8242
+ var AddressLine = function (_a) {
8243
+ var children = _a.children, className = _a.className, other = tslib.__rest(_a, ["children", "className"]);
8244
+ return children ? (React__default.createElement("div", tslib.__assign({ className: classNames('Address__line', className) }, other), children)) : null;
8245
+ };
8246
+ AddressLine.displayName = 'AddressLine';
8247
+ AddressLine.propTypes = {
8248
+ children: PropTypes.node,
8249
+ className: PropTypes.string
8250
+ };
8251
+ var AddressCityStateZip = function (_a) {
8252
+ var city = _a.city, state = _a.state, zip = _a.zip, className = _a.className, other = tslib.__rest(_a, ["city", "state", "zip", "className"]);
8253
+ return city || state || zip ? (React__default.createElement("div", tslib.__assign({ className: classNames('Address__city-state-zip', className) }, other), [[city, state].filter(Boolean).join(', '), zip]
8254
+ .filter(Boolean)
8255
+ .join(' '))) : null;
8256
+ };
8257
+ AddressCityStateZip.displayName = 'AddressCityStateZip';
8258
+ AddressCityStateZip.propTypes = {
8259
+ city: PropTypes.node,
8260
+ state: PropTypes.node,
8261
+ zip: PropTypes.node,
8262
+ className: PropTypes.string
8263
+ };
8264
+
8208
8265
  /**
8209
8266
  * Hook to be used similarly to the React.Component#componentDidMount.
8210
8267
  * Executes the provided `effect` when `dependencies` change but does not
@@ -8273,6 +8330,9 @@ ThemeProvider.propTypes = {
8273
8330
  initialTheme: PropTypes.string
8274
8331
  };
8275
8332
 
8333
+ exports.Address = Address;
8334
+ exports.AddressCityStateZip = AddressCityStateZip;
8335
+ exports.AddressLine = AddressLine;
8276
8336
  exports.Alert = Alert;
8277
8337
  exports.AlertActions = AlertActions;
8278
8338
  exports.AlertContent = AlertContent;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Based on @radix-ui/polymorphic:
3
+ * https://github.com/radix-ui/primitives/blob/main/packages/react/polymorphic/src/polymorphic.ts
4
+ */
5
+ import * as React from 'react';
6
+ declare type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
7
+ /**
8
+ * Infers the OwnProps if E is a ForwardRefExoticComponentWithAs
9
+ */
10
+ declare type OwnProps<E> = E extends ForwardRefComponent<any, infer P> ? P : {};
11
+ /**
12
+ * Infers the JSX.IntrinsicElement if E is a ForwardRefExoticComponentWithAs
13
+ */
14
+ declare type IntrinsicElement<E> = E extends ForwardRefComponent<infer I, any> ? I : never;
15
+ declare type ForwardRefExoticComponent<E, OwnProps> = React.ForwardRefExoticComponent<Merge<E extends React.ElementType ? React.ComponentPropsWithRef<E> : never, OwnProps & {
16
+ as?: E;
17
+ }>>;
18
+ interface ForwardRefComponent<IntrinsicElementString, OwnProps = {}
19
+ /**
20
+ * Extends original type to ensure built in React types play nice
21
+ * with polymorphic components still e.g. `React.ElementRef` etc.
22
+ */
23
+ > extends ForwardRefExoticComponent<IntrinsicElementString, OwnProps> {
24
+ /**
25
+ * When `as` prop is passed, use this overload.
26
+ * Merges original own props (without DOM props) and the inferred props
27
+ * from `as` element with the own props taking precendence.
28
+ *
29
+ * We explicitly avoid `React.ElementType` and manually narrow the prop types
30
+ * so that events are typed when using JSX.IntrinsicElements.
31
+ */
32
+ <As = IntrinsicElementString>(props: As extends '' ? {
33
+ as: keyof JSX.IntrinsicElements;
34
+ } : As extends React.ComponentType<infer P> ? Merge<P, OwnProps & {
35
+ as: As;
36
+ }> : As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], OwnProps & {
37
+ as: As;
38
+ }> : never): React.ReactElement | null;
39
+ }
40
+ export { ForwardRefComponent, OwnProps, IntrinsicElement, Merge };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "3.0.1-canary.03388cec",
3
+ "version": "3.0.1-canary.41ff0487",
4
4
  "description": "Fully accessible react components library for Deque Cauldron",
5
5
  "publishConfig": {
6
6
  "access": "public"