@blueprintjs/icons 5.1.2 → 5.1.4

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,7 +1,7 @@
1
1
  export { IconSvgPaths16, IconSvgPaths20, getIconPaths } from "./allPaths";
2
2
  export { Icons, IconLoaderOptions, IconPathsLoader } from "./iconLoader";
3
- export { SVGIconAttributes, SVGIconProps } from "./svgIconProps";
4
- export { SVGIconContainer, SVGIconContainerProps } from "./svgIconContainer";
3
+ export { DefaultSVGIconAttributes, DefaultSVGIconProps, SVGIconAttributes, SVGIconProps } from "./svgIconProps";
4
+ export { SVGIconContainer, SVGIconContainerComponent, SVGIconContainerProps } from "./svgIconContainer";
5
5
  export { getIconContentString, IconCodepoints } from "./iconCodepoints";
6
6
  export { IconName, IconNames } from "./iconNames";
7
7
  export { IconSize, IconPaths } from "./iconTypes";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,2FAA2F;AAC3F,uCAA0E;AAAjE,0GAAA,cAAc,OAAA;AAAE,0GAAA,cAAc,OAAA;AAAE,wGAAA,YAAY,OAAA;AAErD,2CAAyE;AAAhE,mGAAA,KAAK,OAAA;AAEd,uDAA6E;AAApE,oHAAA,gBAAgB,OAAA;AACzB,mDAAwE;AAA/D,sHAAA,oBAAoB,OAAA;AAAE,gHAAA,cAAc,OAAA;AAC7C,yCAAkD;AAA/B,sGAAA,SAAS,OAAA;AAC5B,yCAAkD;AAAzC,qGAAA,QAAQ,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,2FAA2F;AAC3F,uCAA0E;AAAjE,0GAAA,cAAc,OAAA;AAAE,0GAAA,cAAc,OAAA;AAAE,wGAAA,YAAY,OAAA;AAErD,2CAAyE;AAAhE,mGAAA,KAAK,OAAA;AAEd,uDAAwG;AAA/F,oHAAA,gBAAgB,OAAA;AACzB,mDAAwE;AAA/D,sHAAA,oBAAoB,OAAA;AAAE,gHAAA,cAAc,OAAA;AAC7C,yCAAkD;AAA/B,sGAAA,SAAS,OAAA;AAC5B,yCAAkD;AAAzC,qGAAA,QAAQ,OAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import type { IconName } from "./iconNames";
3
3
  import type { SVGIconProps } from "./svgIconProps";
4
- export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
4
+ export type SVGIconContainerProps<T extends Element> = Omit<SVGIconProps<T>, "children"> & {
5
5
  /**
6
6
  * Icon name.
7
7
  */
@@ -10,5 +10,15 @@ export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
10
10
  * Icon contents, loaded via `IconLoader` and specified as `<path>` elements.
11
11
  */
12
12
  children: JSX.Element | JSX.Element[];
13
+ };
14
+ /**
15
+ * Generic icon container component type. This is essentially a type hack required to make forwardRef work with generic
16
+ * components. Note that this slows down TypeScript compilation, but it better than the alternative of globally
17
+ * augmenting "@types/react".
18
+ *
19
+ * @see https://stackoverflow.com/a/73795494/7406866
20
+ */
21
+ export interface SVGIconContainerComponent extends React.FC<SVGIconContainerProps<Element>> {
22
+ <T extends Element = Element>(props: SVGIconContainerProps<T>): React.ReactElement | null;
13
23
  }
14
- export declare const SVGIconContainer: React.FC<SVGIconContainerProps>;
24
+ export declare const SVGIconContainer: SVGIconContainerComponent;
@@ -21,6 +21,7 @@ var React = tslib_1.__importStar(require("react"));
21
21
  var Classes = tslib_1.__importStar(require("./classes"));
22
22
  var iconTypes_1 = require("./iconTypes");
23
23
  var jsUtils_1 = require("./jsUtils");
24
+ // eslint-disable-next-line prefer-arrow-callback
24
25
  exports.SVGIconContainer = React.forwardRef(function (props, ref) {
25
26
  var children = props.children, className = props.className, color = props.color, htmlTitle = props.htmlTitle, iconName = props.iconName, _a = props.size, size = _a === void 0 ? iconTypes_1.IconSize.STANDARD : _a, svgProps = props.svgProps, _b = props.tagName, tagName = _b === void 0 ? "span" : _b, title = props.title, htmlProps = tslib_1.__rest(props, ["children", "className", "color", "htmlTitle", "iconName", "size", "svgProps", "tagName", "title"]);
26
27
  var isLarge = size >= iconTypes_1.IconSize.LARGE;
@@ -1 +1 @@
1
- {"version":3,"file":"svgIconContainer.js","sourceRoot":"","sources":["../../src/svgIconContainer.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;AAEH,kEAAoC;AACpC,mDAA+B;AAE/B,yDAAqC;AAErC,yCAAuC;AACvC,qCAAqC;AAexB,QAAA,gBAAgB,GAAoC,KAAK,CAAC,UAAU,CAC7E,UAAC,KAAK,EAAE,GAAG;IAEH,IAAA,QAAQ,GAUR,KAAK,SAVG,EACR,SAAS,GAST,KAAK,UATI,EACT,KAAK,GAQL,KAAK,MARA,EACL,SAAS,GAOT,KAAK,UAPI,EACT,QAAQ,GAMR,KAAK,SANG,EACR,KAKA,KAAK,KALmB,EAAxB,IAAI,mBAAG,oBAAQ,CAAC,QAAQ,KAAA,EACxB,QAAQ,GAIR,KAAK,SAJG,EACR,KAGA,KAAK,QAHW,EAAhB,OAAO,mBAAG,MAAM,KAAA,EAChB,KAAK,GAEL,KAAK,MAFA,EACF,SAAS,kBACZ,KAAK,EAXH,mGAWL,CADe,CACN;IAEV,IAAM,OAAO,GAAG,IAAI,IAAI,oBAAQ,CAAC,KAAK,CAAC;IACvC,IAAM,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,oBAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAQ,CAAC,QAAQ,CAAC;IACnE,IAAM,OAAO,GAAG,cAAO,aAAa,cAAI,aAAa,CAAE,CAAC;IACxD,IAAM,OAAO,GAAG,IAAA,kBAAQ,EAAC,WAAW,CAAC,CAAC;IACtC,IAAM,cAAc,sBAChB,WAAW,EAAE,QAAQ,EACrB,IAAI,EAAE,KAAK,EACX,MAAM,EAAE,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CAAC,EAC7E,GAAG,KAAA,EACH,KAAK,EAAE,SAAS,KAEpB,gDAAS,cAAc;YAClB,KAAK,IAAI,mCAAQ,KAAK,CAAS;YAC/B,QAAQ,CACP,CACT,CAAC;KACL;AACL,CAAC,CAAC,CAAC;AACH,wBAAgB,CAAC,WAAW,GAAG,6BAA6B,CAAC"}
@@ -1,17 +1,34 @@
1
1
  import * as React from "react";
2
+ type OmittedDOMAttributes = "children" | "dangerouslySetInnerHTML";
2
3
  /**
3
- * DOM attributes assignable as props to the root element rendered by an SVG icon component
4
- * (which may be a `<span>`, `<svg>` or some custom HTML element).
4
+ * Default set of DOM attributes which are assignable as props to the root element rendered by an
5
+ * SVG icon component. This limited set of attributes is assignable to any `<Icon>` component regardless
6
+ * of its `tagName` prop (it works for both HTML and SVG elements).
5
7
  */
6
- export type SVGIconAttributes = React.AriaAttributes & Omit<React.DOMAttributes<Element>, "children" | "dangerouslySetInnerHTML"> & Pick<React.HTMLAttributes<Element>, "id" | "style" | "tabIndex" | "role">;
8
+ export type DefaultSVGIconAttributes = React.AriaAttributes & Omit<React.DOMAttributes<Element>, OmittedDOMAttributes> & Pick<React.HTMLAttributes<Element>, "id" | "style" | "tabIndex" | "role">;
7
9
  /**
8
- * Interface used for generated icon components which already have their name and path defined
9
- * (through the rendered Handlebars template).
10
+ * DOM attributes which are assignable as props to the root element rendered by an SVG icon component.
11
+ * Specify a type parameter to narrow this type and allow more attributes to be passed to the root element.
12
+ *
13
+ * @see https://blueprintjs.com/docs/#core/components/icon.dom-attributes
14
+ *
15
+ * When `tagName` is specified, either:
16
+ * - as a custom HTML element tag name,
17
+ * - as `null` to signfiy that there should be no wrapper around the `<svg>` element,
18
+ * - or its default value of "span" is used,
19
+ * then it may be useful to narrow this type to pass along additional attributes which not supported by
20
+ * the more general `DefaultSVGIconAttributes` interface. You can do this by specifying a generic type param
21
+ * on `<Icon>` components, for example:
22
+ *
23
+ * ```
24
+ * <Icon<HTMLSpanElement> icon="drag-handle-horizontal" draggable="false" />
25
+ * ```
10
26
  */
11
- export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttributes {
27
+ export type SVGIconAttributes<T extends Element = Element> = T extends SVGElement ? Omit<React.SVGAttributes<T>, OmittedDOMAttributes> : T extends HTMLElement ? Omit<React.HTMLAttributes<T>, OmittedDOMAttributes> : DefaultSVGIconAttributes;
28
+ export interface SVGIconOwnProps {
12
29
  /** A space-delimited list of class names to pass along to the SVG element. */
13
30
  className?: string;
14
- /** This component does not support custom children. */
31
+ /** This component does not support child nodes. */
15
32
  children?: never;
16
33
  /**
17
34
  * Color of icon. This is used as the `fill` attribute on the `<svg>` image
@@ -56,3 +73,17 @@ export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttribute
56
73
  /** Props to apply to the `SVG` element */
57
74
  svgProps?: React.HTMLAttributes<SVGElement>;
58
75
  }
76
+ /**
77
+ * Interface for generated icon components which have their name and icon paths statically defined
78
+ * inside their JS implementation.
79
+ *
80
+ * @see https://blueprintjs.com/docs/#core/components/icon.static-components
81
+ */
82
+ export type SVGIconProps<T extends Element = Element> = React.RefAttributes<T> & SVGIconAttributes<T> & SVGIconOwnProps;
83
+ /**
84
+ * The default SVG icon props interface, equivalent to `SVGIconProps` with its default type parameter.
85
+ * This is primarly exported for documentation purposes; users should reference `SVGIconProps<T>` instead.
86
+ */
87
+ export interface DefaultSVGIconProps extends React.RefAttributes<Element>, SVGIconAttributes<Element>, SVGIconOwnProps {
88
+ }
89
+ export {};
@@ -1,7 +1,7 @@
1
1
  export { IconSvgPaths16, IconSvgPaths20, getIconPaths } from "./allPaths";
2
2
  export { Icons, IconLoaderOptions, IconPathsLoader } from "./iconLoader";
3
- export { SVGIconAttributes, SVGIconProps } from "./svgIconProps";
4
- export { SVGIconContainer, SVGIconContainerProps } from "./svgIconContainer";
3
+ export { DefaultSVGIconAttributes, DefaultSVGIconProps, SVGIconAttributes, SVGIconProps } from "./svgIconProps";
4
+ export { SVGIconContainer, SVGIconContainerComponent, SVGIconContainerProps } from "./svgIconContainer";
5
5
  export { getIconContentString, IconCodepoints } from "./iconCodepoints";
6
6
  export { IconName, IconNames } from "./iconNames";
7
7
  export { IconSize, IconPaths } from "./iconTypes";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2FAA2F;AAC3F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAsC,MAAM,cAAc,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAyB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2FAA2F;AAC3F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAsC,MAAM,cAAc,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAoD,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import type { IconName } from "./iconNames";
3
3
  import type { SVGIconProps } from "./svgIconProps";
4
- export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
4
+ export type SVGIconContainerProps<T extends Element> = Omit<SVGIconProps<T>, "children"> & {
5
5
  /**
6
6
  * Icon name.
7
7
  */
@@ -10,5 +10,15 @@ export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
10
10
  * Icon contents, loaded via `IconLoader` and specified as `<path>` elements.
11
11
  */
12
12
  children: JSX.Element | JSX.Element[];
13
+ };
14
+ /**
15
+ * Generic icon container component type. This is essentially a type hack required to make forwardRef work with generic
16
+ * components. Note that this slows down TypeScript compilation, but it better than the alternative of globally
17
+ * augmenting "@types/react".
18
+ *
19
+ * @see https://stackoverflow.com/a/73795494/7406866
20
+ */
21
+ export interface SVGIconContainerComponent extends React.FC<SVGIconContainerProps<Element>> {
22
+ <T extends Element = Element>(props: SVGIconContainerProps<T>): React.ReactElement | null;
13
23
  }
14
- export declare const SVGIconContainer: React.FC<SVGIconContainerProps>;
24
+ export declare const SVGIconContainer: SVGIconContainerComponent;
@@ -18,6 +18,7 @@ import * as React from "react";
18
18
  import * as Classes from "./classes";
19
19
  import { IconSize } from "./iconTypes";
20
20
  import { uniqueId } from "./jsUtils";
21
+ // eslint-disable-next-line prefer-arrow-callback
21
22
  export var SVGIconContainer = React.forwardRef(function (props, ref) {
22
23
  var children = props.children, className = props.className, color = props.color, htmlTitle = props.htmlTitle, iconName = props.iconName, _a = props.size, size = _a === void 0 ? IconSize.STANDARD : _a, svgProps = props.svgProps, _b = props.tagName, tagName = _b === void 0 ? "span" : _b, title = props.title, htmlProps = __rest(props, ["children", "className", "color", "htmlTitle", "iconName", "size", "svgProps", "tagName", "title"]);
23
24
  var isLarge = size >= IconSize.LARGE;
@@ -1 +1 @@
1
- {"version":3,"file":"svgIconContainer.js","sourceRoot":"","sources":["../../src/svgIconContainer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,MAAM,a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6B,CAAC"}
@@ -1,17 +1,34 @@
1
1
  import * as React from "react";
2
+ type OmittedDOMAttributes = "children" | "dangerouslySetInnerHTML";
2
3
  /**
3
- * DOM attributes assignable as props to the root element rendered by an SVG icon component
4
- * (which may be a `<span>`, `<svg>` or some custom HTML element).
4
+ * Default set of DOM attributes which are assignable as props to the root element rendered by an
5
+ * SVG icon component. This limited set of attributes is assignable to any `<Icon>` component regardless
6
+ * of its `tagName` prop (it works for both HTML and SVG elements).
5
7
  */
6
- export type SVGIconAttributes = React.AriaAttributes & Omit<React.DOMAttributes<Element>, "children" | "dangerouslySetInnerHTML"> & Pick<React.HTMLAttributes<Element>, "id" | "style" | "tabIndex" | "role">;
8
+ export type DefaultSVGIconAttributes = React.AriaAttributes & Omit<React.DOMAttributes<Element>, OmittedDOMAttributes> & Pick<React.HTMLAttributes<Element>, "id" | "style" | "tabIndex" | "role">;
7
9
  /**
8
- * Interface used for generated icon components which already have their name and path defined
9
- * (through the rendered Handlebars template).
10
+ * DOM attributes which are assignable as props to the root element rendered by an SVG icon component.
11
+ * Specify a type parameter to narrow this type and allow more attributes to be passed to the root element.
12
+ *
13
+ * @see https://blueprintjs.com/docs/#core/components/icon.dom-attributes
14
+ *
15
+ * When `tagName` is specified, either:
16
+ * - as a custom HTML element tag name,
17
+ * - as `null` to signfiy that there should be no wrapper around the `<svg>` element,
18
+ * - or its default value of "span" is used,
19
+ * then it may be useful to narrow this type to pass along additional attributes which not supported by
20
+ * the more general `DefaultSVGIconAttributes` interface. You can do this by specifying a generic type param
21
+ * on `<Icon>` components, for example:
22
+ *
23
+ * ```
24
+ * <Icon<HTMLSpanElement> icon="drag-handle-horizontal" draggable="false" />
25
+ * ```
10
26
  */
11
- export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttributes {
27
+ export type SVGIconAttributes<T extends Element = Element> = T extends SVGElement ? Omit<React.SVGAttributes<T>, OmittedDOMAttributes> : T extends HTMLElement ? Omit<React.HTMLAttributes<T>, OmittedDOMAttributes> : DefaultSVGIconAttributes;
28
+ export interface SVGIconOwnProps {
12
29
  /** A space-delimited list of class names to pass along to the SVG element. */
13
30
  className?: string;
14
- /** This component does not support custom children. */
31
+ /** This component does not support child nodes. */
15
32
  children?: never;
16
33
  /**
17
34
  * Color of icon. This is used as the `fill` attribute on the `<svg>` image
@@ -56,3 +73,17 @@ export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttribute
56
73
  /** Props to apply to the `SVG` element */
57
74
  svgProps?: React.HTMLAttributes<SVGElement>;
58
75
  }
76
+ /**
77
+ * Interface for generated icon components which have their name and icon paths statically defined
78
+ * inside their JS implementation.
79
+ *
80
+ * @see https://blueprintjs.com/docs/#core/components/icon.static-components
81
+ */
82
+ export type SVGIconProps<T extends Element = Element> = React.RefAttributes<T> & SVGIconAttributes<T> & SVGIconOwnProps;
83
+ /**
84
+ * The default SVG icon props interface, equivalent to `SVGIconProps` with its default type parameter.
85
+ * This is primarly exported for documentation purposes; users should reference `SVGIconProps<T>` instead.
86
+ */
87
+ export interface DefaultSVGIconProps extends React.RefAttributes<Element>, SVGIconAttributes<Element>, SVGIconOwnProps {
88
+ }
89
+ export {};
@@ -1,7 +1,7 @@
1
1
  export { IconSvgPaths16, IconSvgPaths20, getIconPaths } from "./allPaths";
2
2
  export { Icons, IconLoaderOptions, IconPathsLoader } from "./iconLoader";
3
- export { SVGIconAttributes, SVGIconProps } from "./svgIconProps";
4
- export { SVGIconContainer, SVGIconContainerProps } from "./svgIconContainer";
3
+ export { DefaultSVGIconAttributes, DefaultSVGIconProps, SVGIconAttributes, SVGIconProps } from "./svgIconProps";
4
+ export { SVGIconContainer, SVGIconContainerComponent, SVGIconContainerProps } from "./svgIconContainer";
5
5
  export { getIconContentString, IconCodepoints } from "./iconCodepoints";
6
6
  export { IconName, IconNames } from "./iconNames";
7
7
  export { IconSize, IconPaths } from "./iconTypes";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2FAA2F;AAC3F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAsC,MAAM,cAAc,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAyB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2FAA2F;AAC3F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAsC,MAAM,cAAc,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAoD,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import type { IconName } from "./iconNames";
3
3
  import type { SVGIconProps } from "./svgIconProps";
4
- export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
4
+ export type SVGIconContainerProps<T extends Element> = Omit<SVGIconProps<T>, "children"> & {
5
5
  /**
6
6
  * Icon name.
7
7
  */
@@ -10,5 +10,15 @@ export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
10
10
  * Icon contents, loaded via `IconLoader` and specified as `<path>` elements.
11
11
  */
12
12
  children: JSX.Element | JSX.Element[];
13
+ };
14
+ /**
15
+ * Generic icon container component type. This is essentially a type hack required to make forwardRef work with generic
16
+ * components. Note that this slows down TypeScript compilation, but it better than the alternative of globally
17
+ * augmenting "@types/react".
18
+ *
19
+ * @see https://stackoverflow.com/a/73795494/7406866
20
+ */
21
+ export interface SVGIconContainerComponent extends React.FC<SVGIconContainerProps<Element>> {
22
+ <T extends Element = Element>(props: SVGIconContainerProps<T>): React.ReactElement | null;
13
23
  }
14
- export declare const SVGIconContainer: React.FC<SVGIconContainerProps>;
24
+ export declare const SVGIconContainer: SVGIconContainerComponent;
@@ -17,7 +17,8 @@ import * as React from "react";
17
17
  import * as Classes from "./classes";
18
18
  import { IconSize } from "./iconTypes";
19
19
  import { uniqueId } from "./jsUtils";
20
- export const SVGIconContainer = React.forwardRef((props, ref) => {
20
+ // eslint-disable-next-line prefer-arrow-callback
21
+ export const SVGIconContainer = React.forwardRef(function (props, ref) {
21
22
  const { children, className, color, htmlTitle, iconName, size = IconSize.STANDARD, svgProps, tagName = "span", title, ...htmlProps } = props;
22
23
  const isLarge = size >= IconSize.LARGE;
23
24
  const pixelGridSize = isLarge ? IconSize.LARGE : IconSize.STANDARD;
@@ -1 +1 @@
1
- {"version":3,"file":"svgIconContainer.js","sourceRoot":"","sources":["../../src/svgIconContainer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAerC,MAAM,CAAC,MAAM,gBAAgB,GAAoC,KAAK,CAAC,UAAU,CAC7E,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACX,MAAM,EACF,QAAQ,EACR,SAAS,EACT,KAAK,EACL,SAAS,EACT,QAAQ,EACR,IAAI,GAAG,QAAQ,CAAC,QAA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AC,OAAO,CAAC,CAAC,CAAC,SAAS,EAC5C,GAAG,EAAE,GAA+B,KAChC,cAAc,KACd,SAAS;YAEZ,KAAK,IAAI,+BAAO,EAAE,EAAE,OAAO,IAAG,KAAK,CAAS;YAC5C,QAAQ,CACP,CACT,CAAC;KACL;SAAM;QACH,OAAO,KAAK,CAAC,aAAa,CACtB,OAAO,EACP;YACI,GAAG,SAAS;YACZ,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;YACvC,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,IAAI,QAAQ,EAAE,EAAE,SAAS,CAAC;YAC7E,GAAG;YACH,KAAK,EAAE,SAAS;SACnB,EACD,gCAAS,cAAc;YAClB,KAAK,IAAI,mCAAQ,KAAK,CAAS;YAC/B,QAAQ,CACP,CACT,CAAC;KACL;AACL,CAAC,CAAC,CAAC;AACH,gBAAgB,CAAC,WAAW,GAAG,6BAA6B,CAAC"}
@@ -1,17 +1,34 @@
1
1
  import * as React from "react";
2
+ type OmittedDOMAttributes = "children" | "dangerouslySetInnerHTML";
2
3
  /**
3
- * DOM attributes assignable as props to the root element rendered by an SVG icon component
4
- * (which may be a `<span>`, `<svg>` or some custom HTML element).
4
+ * Default set of DOM attributes which are assignable as props to the root element rendered by an
5
+ * SVG icon component. This limited set of attributes is assignable to any `<Icon>` component regardless
6
+ * of its `tagName` prop (it works for both HTML and SVG elements).
5
7
  */
6
- export type SVGIconAttributes = React.AriaAttributes & Omit<React.DOMAttributes<Element>, "children" | "dangerouslySetInnerHTML"> & Pick<React.HTMLAttributes<Element>, "id" | "style" | "tabIndex" | "role">;
8
+ export type DefaultSVGIconAttributes = React.AriaAttributes & Omit<React.DOMAttributes<Element>, OmittedDOMAttributes> & Pick<React.HTMLAttributes<Element>, "id" | "style" | "tabIndex" | "role">;
7
9
  /**
8
- * Interface used for generated icon components which already have their name and path defined
9
- * (through the rendered Handlebars template).
10
+ * DOM attributes which are assignable as props to the root element rendered by an SVG icon component.
11
+ * Specify a type parameter to narrow this type and allow more attributes to be passed to the root element.
12
+ *
13
+ * @see https://blueprintjs.com/docs/#core/components/icon.dom-attributes
14
+ *
15
+ * When `tagName` is specified, either:
16
+ * - as a custom HTML element tag name,
17
+ * - as `null` to signfiy that there should be no wrapper around the `<svg>` element,
18
+ * - or its default value of "span" is used,
19
+ * then it may be useful to narrow this type to pass along additional attributes which not supported by
20
+ * the more general `DefaultSVGIconAttributes` interface. You can do this by specifying a generic type param
21
+ * on `<Icon>` components, for example:
22
+ *
23
+ * ```
24
+ * <Icon<HTMLSpanElement> icon="drag-handle-horizontal" draggable="false" />
25
+ * ```
10
26
  */
11
- export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttributes {
27
+ export type SVGIconAttributes<T extends Element = Element> = T extends SVGElement ? Omit<React.SVGAttributes<T>, OmittedDOMAttributes> : T extends HTMLElement ? Omit<React.HTMLAttributes<T>, OmittedDOMAttributes> : DefaultSVGIconAttributes;
28
+ export interface SVGIconOwnProps {
12
29
  /** A space-delimited list of class names to pass along to the SVG element. */
13
30
  className?: string;
14
- /** This component does not support custom children. */
31
+ /** This component does not support child nodes. */
15
32
  children?: never;
16
33
  /**
17
34
  * Color of icon. This is used as the `fill` attribute on the `<svg>` image
@@ -56,3 +73,17 @@ export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttribute
56
73
  /** Props to apply to the `SVG` element */
57
74
  svgProps?: React.HTMLAttributes<SVGElement>;
58
75
  }
76
+ /**
77
+ * Interface for generated icon components which have their name and icon paths statically defined
78
+ * inside their JS implementation.
79
+ *
80
+ * @see https://blueprintjs.com/docs/#core/components/icon.static-components
81
+ */
82
+ export type SVGIconProps<T extends Element = Element> = React.RefAttributes<T> & SVGIconAttributes<T> & SVGIconOwnProps;
83
+ /**
84
+ * The default SVG icon props interface, equivalent to `SVGIconProps` with its default type parameter.
85
+ * This is primarly exported for documentation purposes; users should reference `SVGIconProps<T>` instead.
86
+ */
87
+ export interface DefaultSVGIconProps extends React.RefAttributes<Element>, SVGIconAttributes<Element>, SVGIconOwnProps {
88
+ }
89
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueprintjs/icons",
3
- "version": "5.1.2",
3
+ "version": "5.1.4",
4
4
  "description": "Components, fonts, icons, and css files for creating and displaying icons.",
5
5
  "main": "lib/cjs/generated/index.js",
6
6
  "module": "lib/esm/generated/index.js",
package/src/icons-list.md CHANGED
@@ -7,6 +7,7 @@ Be sure to check out the docs on [loading icons](#icons/loading-icons) and how t
7
7
  <div class="@ns-callout @ns-intent-primary @ns-icon-info-sign">
8
8
 
9
9
  See the [**`Icon` component documentation**](#core/components/icon) (in the `@blueprintjs/core` package) for React API details.
10
+
10
11
  </div>
11
12
 
12
13
  @reactDocs Icons
package/src/index.md CHANGED
@@ -10,6 +10,7 @@ provides provides over 500 vector UI icons in two sizes (16px and 20px) and two
10
10
  <div class="@ns-callout @ns-intent-primary @ns-icon-info-sign">
11
11
 
12
12
  See the [**`Icon` component documentation**](#core/components/icon) (in the `@blueprintjs/core` package) for React API details.
13
+
13
14
  </div>
14
15
 
15
16
  ```sh
package/src/index.ts CHANGED
@@ -18,8 +18,8 @@
18
18
  export { IconSvgPaths16, IconSvgPaths20, getIconPaths } from "./allPaths";
19
19
 
20
20
  export { Icons, IconLoaderOptions, IconPathsLoader } from "./iconLoader";
21
- export { SVGIconAttributes, SVGIconProps } from "./svgIconProps";
22
- export { SVGIconContainer, SVGIconContainerProps } from "./svgIconContainer";
21
+ export { DefaultSVGIconAttributes, DefaultSVGIconProps, SVGIconAttributes, SVGIconProps } from "./svgIconProps";
22
+ export { SVGIconContainer, SVGIconContainerComponent, SVGIconContainerProps } from "./svgIconContainer";
23
23
  export { getIconContentString, IconCodepoints } from "./iconCodepoints";
24
24
  export { IconName, IconNames } from "./iconNames";
25
25
  export { IconSize, IconPaths } from "./iconTypes";
@@ -11,6 +11,7 @@ approaches.
11
11
  <div class="@ns-callout @ns-intent-primary @ns-icon-info-sign">
12
12
 
13
13
  See the [**`Icon` component documentation**](#core/components/icon) (in the `@blueprintjs/core` package) for React API details.
14
+
14
15
  </div>
15
16
 
16
17
  @## Using static imports
@@ -22,7 +22,7 @@ import { IconSize } from "./iconTypes";
22
22
  import { uniqueId } from "./jsUtils";
23
23
  import type { SVGIconProps } from "./svgIconProps";
24
24
 
25
- export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
25
+ export type SVGIconContainerProps<T extends Element> = Omit<SVGIconProps<T>, "children"> & {
26
26
  /**
27
27
  * Icon name.
28
28
  */
@@ -32,60 +32,78 @@ export interface SVGIconContainerProps extends Omit<SVGIconProps, "children"> {
32
32
  * Icon contents, loaded via `IconLoader` and specified as `<path>` elements.
33
33
  */
34
34
  children: JSX.Element | JSX.Element[];
35
+ };
36
+
37
+ /**
38
+ * Generic icon container component type. This is essentially a type hack required to make forwardRef work with generic
39
+ * components. Note that this slows down TypeScript compilation, but it better than the alternative of globally
40
+ * augmenting "@types/react".
41
+ *
42
+ * @see https://stackoverflow.com/a/73795494/7406866
43
+ */
44
+ export interface SVGIconContainerComponent extends React.FC<SVGIconContainerProps<Element>> {
45
+ <T extends Element = Element>(props: SVGIconContainerProps<T>): React.ReactElement | null;
35
46
  }
36
47
 
37
- export const SVGIconContainer: React.FC<SVGIconContainerProps> = React.forwardRef<any, SVGIconContainerProps>(
38
- (props, ref) => {
39
- const {
40
- children,
41
- className,
42
- color,
43
- htmlTitle,
44
- iconName,
45
- size = IconSize.STANDARD,
46
- svgProps,
47
- tagName = "span",
48
- title,
49
- ...htmlProps
50
- } = props;
48
+ // eslint-disable-next-line prefer-arrow-callback
49
+ export const SVGIconContainer: SVGIconContainerComponent = React.forwardRef(function <T extends Element>(
50
+ props: SVGIconContainerProps<T>,
51
+ ref: React.Ref<T>,
52
+ ) {
53
+ const {
54
+ children,
55
+ className,
56
+ color,
57
+ htmlTitle,
58
+ iconName,
59
+ size = IconSize.STANDARD,
60
+ svgProps,
61
+ tagName = "span",
62
+ title,
63
+ ...htmlProps
64
+ } = props;
51
65
 
52
- const isLarge = size >= IconSize.LARGE;
53
- const pixelGridSize = isLarge ? IconSize.LARGE : IconSize.STANDARD;
54
- const viewBox = `0 0 ${pixelGridSize} ${pixelGridSize}`;
55
- const titleId = uniqueId("iconTitle");
56
- const sharedSvgProps = {
57
- "data-icon": iconName,
58
- fill: color,
59
- height: size,
60
- role: "img",
61
- viewBox,
62
- width: size,
63
- ...svgProps,
64
- };
66
+ const isLarge = size >= IconSize.LARGE;
67
+ const pixelGridSize = isLarge ? IconSize.LARGE : IconSize.STANDARD;
68
+ const viewBox = `0 0 ${pixelGridSize} ${pixelGridSize}`;
69
+ const titleId = uniqueId("iconTitle");
70
+ const sharedSvgProps = {
71
+ "data-icon": iconName,
72
+ fill: color,
73
+ height: size,
74
+ role: "img",
75
+ viewBox,
76
+ width: size,
77
+ ...svgProps,
78
+ };
65
79
 
66
- if (tagName === null) {
67
- return (
68
- <svg aria-labelledby={title ? titleId : undefined} ref={ref} {...sharedSvgProps} {...htmlProps}>
69
- {title && <title id={titleId}>{title}</title>}
70
- {children}
71
- </svg>
72
- );
73
- } else {
74
- return React.createElement(
75
- tagName,
76
- {
77
- ...htmlProps,
78
- "aria-hidden": title ? undefined : true,
79
- className: classNames(Classes.ICON, `${Classes.ICON}-${iconName}`, className),
80
- ref,
81
- title: htmlTitle,
82
- },
83
- <svg {...sharedSvgProps}>
84
- {title && <title>{title}</title>}
85
- {children}
86
- </svg>,
87
- );
88
- }
89
- },
90
- );
80
+ if (tagName === null) {
81
+ return (
82
+ <svg
83
+ aria-labelledby={title ? titleId : undefined}
84
+ ref={ref as React.Ref<SVGSVGElement>}
85
+ {...sharedSvgProps}
86
+ {...htmlProps}
87
+ >
88
+ {title && <title id={titleId}>{title}</title>}
89
+ {children}
90
+ </svg>
91
+ );
92
+ } else {
93
+ return React.createElement(
94
+ tagName,
95
+ {
96
+ ...htmlProps,
97
+ "aria-hidden": title ? undefined : true,
98
+ className: classNames(Classes.ICON, `${Classes.ICON}-${iconName}`, className),
99
+ ref,
100
+ title: htmlTitle,
101
+ },
102
+ <svg {...sharedSvgProps}>
103
+ {title && <title>{title}</title>}
104
+ {children}
105
+ </svg>,
106
+ );
107
+ }
108
+ });
91
109
  SVGIconContainer.displayName = "Blueprint5.SVGIconContainer";
@@ -15,23 +15,46 @@
15
15
 
16
16
  import * as React from "react";
17
17
 
18
+ type OmittedDOMAttributes = "children" | "dangerouslySetInnerHTML";
19
+
18
20
  /**
19
- * DOM attributes assignable as props to the root element rendered by an SVG icon component
20
- * (which may be a `<span>`, `<svg>` or some custom HTML element).
21
+ * Default set of DOM attributes which are assignable as props to the root element rendered by an
22
+ * SVG icon component. This limited set of attributes is assignable to any `<Icon>` component regardless
23
+ * of its `tagName` prop (it works for both HTML and SVG elements).
21
24
  */
22
- export type SVGIconAttributes = React.AriaAttributes &
23
- Omit<React.DOMAttributes<Element>, "children" | "dangerouslySetInnerHTML"> &
25
+ export type DefaultSVGIconAttributes = React.AriaAttributes &
26
+ Omit<React.DOMAttributes<Element>, OmittedDOMAttributes> &
24
27
  Pick<React.HTMLAttributes<Element>, "id" | "style" | "tabIndex" | "role">;
25
28
 
26
29
  /**
27
- * Interface used for generated icon components which already have their name and path defined
28
- * (through the rendered Handlebars template).
30
+ * DOM attributes which are assignable as props to the root element rendered by an SVG icon component.
31
+ * Specify a type parameter to narrow this type and allow more attributes to be passed to the root element.
32
+ *
33
+ * @see https://blueprintjs.com/docs/#core/components/icon.dom-attributes
34
+ *
35
+ * When `tagName` is specified, either:
36
+ * - as a custom HTML element tag name,
37
+ * - as `null` to signfiy that there should be no wrapper around the `<svg>` element,
38
+ * - or its default value of "span" is used,
39
+ * then it may be useful to narrow this type to pass along additional attributes which not supported by
40
+ * the more general `DefaultSVGIconAttributes` interface. You can do this by specifying a generic type param
41
+ * on `<Icon>` components, for example:
42
+ *
43
+ * ```
44
+ * <Icon<HTMLSpanElement> icon="drag-handle-horizontal" draggable="false" />
45
+ * ```
29
46
  */
30
- export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttributes {
47
+ export type SVGIconAttributes<T extends Element = Element> = T extends SVGElement
48
+ ? Omit<React.SVGAttributes<T>, OmittedDOMAttributes>
49
+ : T extends HTMLElement
50
+ ? Omit<React.HTMLAttributes<T>, OmittedDOMAttributes>
51
+ : DefaultSVGIconAttributes;
52
+
53
+ export interface SVGIconOwnProps {
31
54
  /** A space-delimited list of class names to pass along to the SVG element. */
32
55
  className?: string;
33
56
 
34
- /** This component does not support custom children. */
57
+ /** This component does not support child nodes. */
35
58
  children?: never;
36
59
 
37
60
  /**
@@ -83,3 +106,21 @@ export interface SVGIconProps extends React.RefAttributes<any>, SVGIconAttribute
83
106
  /** Props to apply to the `SVG` element */
84
107
  svgProps?: React.HTMLAttributes<SVGElement>;
85
108
  }
109
+
110
+ // N.B. the following inteface is defined as a type alias instead of an interface due to a TypeScript limitation
111
+ // where interfaces cannot extend conditionally-defined union types.
112
+ /**
113
+ * Interface for generated icon components which have their name and icon paths statically defined
114
+ * inside their JS implementation.
115
+ *
116
+ * @see https://blueprintjs.com/docs/#core/components/icon.static-components
117
+ */
118
+ export type SVGIconProps<T extends Element = Element> = React.RefAttributes<T> & SVGIconAttributes<T> & SVGIconOwnProps;
119
+
120
+ /**
121
+ * The default SVG icon props interface, equivalent to `SVGIconProps` with its default type parameter.
122
+ * This is primarly exported for documentation purposes; users should reference `SVGIconProps<T>` instead.
123
+ */
124
+ export interface DefaultSVGIconProps extends React.RefAttributes<Element>, SVGIconAttributes<Element>, SVGIconOwnProps {
125
+ // empty interface for documentation purposes (documentalist handles this better than the SVGIconProps<T> type alias)
126
+ }