@deque/cauldron-react 6.3.0 → 6.3.1-canary.131d0134

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.
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- interface BreadcrumbLinkProps extends Omit<React.LinkHTMLAttributes<HTMLLinkElement>, 'as'> {
3
- as?: React.ElementType;
4
- }
5
- declare const BreadcrumbLink: React.ForwardRefExoticComponent<BreadcrumbLinkProps & React.RefAttributes<HTMLElement>>;
2
+ import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
3
+ type BreadcrumbLinkProps = PolymorphicProps<React.LinkHTMLAttributes<HTMLLinkElement>>;
4
+ declare const BreadcrumbLink: PolymorphicComponent<BreadcrumbLinkProps>;
6
5
  export default BreadcrumbLink;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- interface Props extends React.HTMLAttributes<HTMLElement> {
2
+ import type { PolymorphicComponent, PolymorphicProps } from '../../utils/polymorphicComponent';
3
+ interface FieldWrapProps extends PolymorphicProps<React.HTMLAttributes<HTMLElement>> {
3
4
  children: React.ReactNode;
4
- as?: React.ElementType | string;
5
5
  }
6
- declare const FieldWrap: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLElement>>;
6
+ declare const FieldWrap: PolymorphicComponent<FieldWrapProps>;
7
7
  export default FieldWrap;
@@ -1,14 +1,8 @@
1
- /**
2
- * Unfortunately, eslint does not recognize the Polymorphic component has propTypes set
3
- *
4
- * We might be able to remove this if we upgrade eslint and associated plugins
5
- * See: https://github.com/dequelabs/cauldron/issues/451
6
- */
7
1
  import React from 'react';
8
- import * as Polymorphic from '../../utils/polymorphic-type';
9
2
  import { IconType } from '../Icon';
10
3
  import { TooltipProps } from '../Tooltip';
11
- export interface IconButtonOwnProps {
4
+ import { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
5
+ export interface IconButtonProps extends PolymorphicProps<React.HTMLAttributes<HTMLButtonElement>, 'button'> {
12
6
  icon: IconType;
13
7
  label: React.ReactNode;
14
8
  tooltipPlacement?: TooltipProps['placement'];
@@ -17,12 +11,5 @@ export interface IconButtonOwnProps {
17
11
  variant?: 'primary' | 'secondary' | 'error';
18
12
  large?: boolean;
19
13
  }
20
- type PolymorphicIconButton = Polymorphic.ForwardRefComponent<'button', IconButtonOwnProps>;
21
- /**
22
- * Unfortunately, eslint does not recognize that this Polymorphic component has a displayName set
23
- *
24
- * We might be able to remove this if we upgrade eslint and associated plugins
25
- * See: https://github.com/dequelabs/cauldron/issues/451
26
- */
27
- declare const IconButton: PolymorphicIconButton;
14
+ declare const IconButton: PolymorphicComponent<IconButtonProps, "button">;
28
15
  export default IconButton;
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
2
  import type { ListboxOption } from './ListboxContext';
3
3
  import type { ListboxValue } from './ListboxOption';
4
- interface ListboxProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'> {
5
- as?: React.ElementType | string;
4
+ import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
5
+ interface ListboxProps extends PolymorphicProps<Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'>> {
6
6
  value?: ListboxValue;
7
7
  navigation?: 'cycle' | 'bound';
8
8
  onSelectionChange?: <T extends HTMLElement = HTMLElement>({ value }: {
@@ -12,5 +12,5 @@ interface ListboxProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect
12
12
  }) => void;
13
13
  onActiveChange?: (option: ListboxOption) => void;
14
14
  }
15
- declare const Listbox: React.ForwardRefExoticComponent<ListboxProps & React.RefAttributes<HTMLElement>>;
15
+ declare const Listbox: PolymorphicComponent<ListboxProps>;
16
16
  export default Listbox;
@@ -1,9 +1,9 @@
1
1
  import { ContentNode } from '../../types';
2
2
  import React from 'react';
3
- interface ListboxGroupProps extends React.HTMLAttributes<HTMLElement> {
4
- as?: React.ElementType | string;
3
+ import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
4
+ interface ListboxGroupProps extends PolymorphicProps<React.HTMLAttributes<HTMLElement>> {
5
5
  groupLabelProps?: React.HTMLAttributes<HTMLLIElement>;
6
6
  label: ContentNode;
7
7
  }
8
- declare const ListboxGroup: React.ForwardRefExoticComponent<ListboxGroupProps & React.RefAttributes<HTMLElement>>;
8
+ declare const ListboxGroup: PolymorphicComponent<ListboxGroupProps>;
9
9
  export default ListboxGroup;
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
+ import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
2
3
  export type ListboxValue = Readonly<string | number | undefined>;
3
- interface ListboxOptionsProps extends React.HTMLAttributes<HTMLElement> {
4
- as?: React.ElementType | string;
4
+ interface ListboxOptionProps extends PolymorphicProps<React.HTMLAttributes<HTMLElement>> {
5
5
  value?: ListboxValue;
6
6
  disabled?: boolean;
7
7
  activeClass?: string;
8
8
  }
9
- declare const ListboxOption: React.ForwardRefExoticComponent<ListboxOptionsProps & React.RefAttributes<HTMLElement>>;
9
+ declare const ListboxOption: PolymorphicComponent<ListboxOptionProps>;
10
10
  export default ListboxOption;
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import { type TooltipProps } from '../Tooltip';
3
- interface TextEllipsisProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
4
+ interface TextEllipsisProps extends PolymorphicProps<React.HTMLAttributes<HTMLElement>> {
4
5
  children: string;
5
6
  maxLines?: number;
6
- as?: React.ElementType;
7
7
  refProp?: string;
8
8
  tooltipProps?: Omit<TooltipProps, 'target' | 'association'>;
9
9
  }
10
- declare const TextEllipsis: React.ForwardRefExoticComponent<TextEllipsisProps & React.RefAttributes<HTMLElement>>;
10
+ declare const TextEllipsis: PolymorphicComponent<TextEllipsisProps>;
11
11
  export default TextEllipsis;
package/lib/index.js CHANGED
@@ -1797,13 +1797,6 @@ var TooltipContent = function (_a) {
1797
1797
  return (React__default["default"].createElement("div", tslib.__assign({ className: classNames__default["default"]('TooltipContent', className) }, other)));
1798
1798
  };
1799
1799
 
1800
- /**
1801
- * Unfortunately, eslint does not recognize that this Polymorphic component has a displayName set
1802
- *
1803
- * We might be able to remove this if we upgrade eslint and associated plugins
1804
- * See: https://github.com/dequelabs/cauldron/issues/451
1805
- */
1806
- // eslint-disable-next-line react/display-name
1807
1800
  var IconButton = React.forwardRef(function (_a, ref) {
1808
1801
  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, large = _a.large, other = tslib.__rest(_a, ["as", "icon", "label", "tooltipPlacement", "tooltipVariant", "tooltipPortal", "className", "variant", "disabled", "tabIndex", "large"]);
1809
1802
  var internalRef = React.useRef();
@@ -2436,7 +2429,7 @@ var TextFieldWrapper = React.forwardRef(function (_a, ref) {
2436
2429
  TextFieldWrapper.displayName = 'TextFieldWrapper';
2437
2430
 
2438
2431
  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"]);
2432
+ var className = _a.className, 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, inputProps = tslib.__rest(_a, ["className", "label", "defaultValue", "onChange", "hideLabel", "placeholder", "isForm", "id", "value", "trailingChildren"]);
2440
2433
  var isControlled = typeof propValue !== 'undefined';
2441
2434
  var _f = tslib.__read(React.useState(isControlled ? propValue : defaultValue), 2), value = _f[0], setValue = _f[1];
2442
2435
  var _g = tslib.__read(propId ? [propId] : nextId.useId(1, 'search-field'), 1), id = _g[0];
@@ -2458,11 +2451,11 @@ var SearchField = React.forwardRef(function (_a, ref) {
2458
2451
  return (React__default["default"].createElement(Field, { role: isForm ? 'search' : undefined, className: "SearchField", "aria-labelledby": isForm ? "".concat(inputId, "-label") : undefined },
2459
2452
  hideLabel ? (React__default["default"].createElement(Offscreen, null,
2460
2453
  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
2454
+ React__default["default"].createElement(TextFieldWrapper, { className: classNames__default["default"](className, {
2455
+ 'TextFieldWrapper--disabled': inputProps.disabled
2463
2456
  }) },
2464
2457
  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" })),
2458
+ React__default["default"].createElement("input", tslib.__assign({ id: inputId, value: value, onChange: handleChange, placeholder: placeholder, ref: ref }, inputProps, { type: "search" })),
2466
2459
  trailingChildren)));
2467
2460
  });
2468
2461
  SearchField.displayName = 'SearchField';
@@ -3560,7 +3553,9 @@ var ComboboxOption = React.forwardRef(function (_a, ref) {
3560
3553
  }
3561
3554
  return (React__default["default"].createElement(ListboxOption, tslib.__assign({ as: "li", className: classNames__default["default"]('ComboboxOption', className, {
3562
3555
  'ComboboxOption--disabled': disabled
3563
- }), activeClass: "ComboboxOption--active", ref: comboboxOptionRef, disabled: disabled, id: id, value: propValue }, props),
3556
+ }), activeClass: "ComboboxOption--active",
3557
+ // @ts-expect-error use HTMLElement even though the underlying element is an li element
3558
+ ref: comboboxOptionRef, disabled: disabled, id: id, value: propValue }, props),
3564
3559
  React__default["default"].createElement("span", null,
3565
3560
  React__default["default"].createElement(ComboboxMatch, null, children),
3566
3561
  description && (React__default["default"].createElement("div", { className: "ComboboxOption__description" }, description))),
@@ -0,0 +1,10 @@
1
+ import type * as React from 'react';
2
+ type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
3
+ export type PolymorphicProps<Props = {}, ElementType extends React.ElementType = React.ElementType> = Props & {
4
+ as?: ElementType;
5
+ };
6
+ export type PolymorphicComponentProps<Props = {}, ElementType extends React.ElementType = React.ElementType> = Merge<ElementType extends keyof JSX.IntrinsicElements ? React.PropsWithRef<JSX.IntrinsicElements[ElementType]> : ElementType extends React.ElementType ? React.ComponentPropsWithRef<ElementType> : never, PolymorphicProps<Props, ElementType>>;
7
+ export type PolymorphicComponent<Props = {}, ElementType extends React.ElementType = React.ElementType> = Merge<React.ForwardRefExoticComponent<Props>, {
8
+ <T extends React.ElementType = ElementType>(props: PolymorphicComponentProps<Props, T>): React.ReactElement | null;
9
+ }>;
10
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "6.3.0",
3
+ "version": "6.3.1-canary.131d0134",
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,40 +0,0 @@
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
- type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
7
- /**
8
- * Infers the OwnProps if E is a ForwardRefExoticComponentWithAs
9
- */
10
- type OwnProps<E> = E extends ForwardRefComponent<any, infer P> ? P : {};
11
- /**
12
- * Infers the JSX.IntrinsicElement if E is a ForwardRefExoticComponentWithAs
13
- */
14
- type IntrinsicElement<E> = E extends ForwardRefComponent<infer I, any> ? I : never;
15
- 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 };