Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: widen icon type to allow string #9915

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 120 additions & 120 deletions packages/calcite-components/src/components.d.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
setComponentLoaded,
setUpLoadableComponent,
} from "../../utils/loadable";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { SLOTS, CSS, IDS } from "./resources";
import { RequestedItem } from "./interfaces";

Expand Down Expand Up @@ -61,10 +61,10 @@ export class AccordionItem implements ConditionalSlotComponent, LoadableComponen
@Prop() description: string;

/** Specifies an icon to display at the start of the component. */
@Prop({ reflect: true }) iconStart: IconName;
@Prop({ reflect: true }) iconStart: IconNameOrString;

/** Specifies an icon to display at the end of the component. */
@Prop({ reflect: true }) iconEnd: IconName;
@Prop({ reflect: true }) iconEnd: IconNameOrString;

/** Displays the `iconStart` and/or `iconEnd` as flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl: FlipContext;
Expand Down
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/action/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
updateMessages,
} from "../../utils/t9n";
import { Alignment, Appearance, Scale } from "../interfaces";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { isBrowser } from "../../utils/browser";
import { ActionMessages } from "./assets/action/t9n";
import { CSS, SLOTS } from "./resources";
Expand Down Expand Up @@ -86,7 +86,7 @@ export class Action
@Prop({ reflect: true }) disabled = false;

/** Specifies an icon to display. */
@Prop() icon: IconName;
@Prop() icon: IconNameOrString;

/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;
Expand Down
6 changes: 3 additions & 3 deletions packages/calcite-components/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
} from "../../utils/t9n";
import { Kind, Scale } from "../interfaces";
import { KindIcons } from "../resources";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { AlertMessages } from "./assets/alert/t9n";
import { AlertDuration, Sync, Unregister } from "./interfaces";
import { CSS, DURATIONS, SLOTS } from "./resources";
Expand Down Expand Up @@ -111,7 +111,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
* When `true`, shows a default recommended icon. Alternatively,
* pass a Calcite UI Icon name to display a specific icon.
*/
@Prop({ reflect: true }) icon: IconName | boolean;
@Prop({ reflect: true }) icon: IconNameOrString | boolean;

/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;
Expand Down Expand Up @@ -309,7 +309,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
);
}

private renderIcon(icon: IconName): VNode {
private renderIcon(icon: IconNameOrString): VNode {
return (
<div class={CSS.icon}>
<calcite-icon flipRtl={this.iconFlipRtl} icon={icon} scale={getIconScale(this.scale)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
setComponentLoaded,
setUpLoadableComponent,
} from "../../utils/loadable";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { BlockSectionMessages } from "./assets/block-section/t9n";
import { BlockSectionToggleDisplay } from "./interfaces";
import { CSS, ICONS, IDS } from "./resources";
Expand All @@ -50,13 +50,13 @@ export class BlockSection implements LocalizedComponent, T9nComponent, LoadableC
// --------------------------------------------------------------------------

/** Specifies an icon to display at the end of the component. */
@Prop({ reflect: true }) iconEnd: IconName;
@Prop({ reflect: true }) iconEnd: IconNameOrString;

/** Displays the `iconStart` and/or `iconEnd` as flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl: FlipContext;

/** Specifies an icon to display at the start of the component. */
@Prop({ reflect: true }) iconStart: IconName;
@Prop({ reflect: true }) iconStart: IconNameOrString;

/**
* When `true`, expands the component and its contents.
Expand Down
6 changes: 3 additions & 3 deletions packages/calcite-components/src/components/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../../utils/openCloseComponent";
import { OverlayPositioning } from "../../utils/floating-ui";
import { FlipContext } from "../interfaces";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { CSS, ICONS, IDS, SLOTS } from "./resources";
import { BlockMessages } from "./assets/block/t9n";

Expand Down Expand Up @@ -107,13 +107,13 @@ export class Block
@Prop({ reflect: true }) headingLevel: HeadingLevel;

/** Specifies an icon to display at the end of the component. */
@Prop({ reflect: true }) iconEnd: IconName;
@Prop({ reflect: true }) iconEnd: IconNameOrString;

/** Displays the `iconStart` and/or `iconEnd` as flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl: FlipContext;

/** Specifies an icon to display at the start of the component. */
@Prop({ reflect: true }) iconStart: IconName;
@Prop({ reflect: true }) iconStart: IconNameOrString;

/**
* When `true`, a busy indicator is displayed.
Expand Down
6 changes: 3 additions & 3 deletions packages/calcite-components/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from "../../utils/t9n";
import { Appearance, FlipContext, Kind, Scale, Width } from "../interfaces";
import { toAriaBoolean } from "../../utils/dom";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { isBrowser } from "../../utils/browser";
import { ButtonMessages } from "./assets/button/t9n";
import { ButtonAlignment } from "./interfaces";
Expand Down Expand Up @@ -118,13 +118,13 @@ export class Button
@Prop({ reflect: true }) href: string;

/** Specifies an icon to display at the end of the component. */
@Prop({ reflect: true }) iconEnd: IconName;
@Prop({ reflect: true }) iconEnd: IconNameOrString;

/** Displays the `iconStart` and/or `iconEnd` as flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl: FlipContext;

/** Specifies an icon to display at the start of the component. */
@Prop({ reflect: true }) iconStart: IconName;
@Prop({ reflect: true }) iconStart: IconNameOrString;

/**
* When `true`, a busy indicator is displayed and interaction is disabled.
Expand Down
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
updateHostInteraction,
} from "../../utils/interactive";
import { isActivationKey } from "../../utils/key";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { CSS, ICONS, SLOTS } from "./resources";
import { CardMessages } from "./assets/card/t9n";

Expand Down Expand Up @@ -277,7 +277,7 @@ export class Card
}

private renderSelectionIcon(): VNode {
const icon: IconName =
const icon: IconNameOrString =
this.selectionMode === "multiple" && this.selected
? ICONS.selected
: this.selectionMode === "multiple"
Expand Down
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/chip/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import { isActivationKey } from "../../utils/key";
import { getIconScale } from "../../utils/component";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { isBrowser } from "../../utils/browser";
import { ChipMessages } from "./assets/chip/t9n";
import { CSS, SLOTS, ICONS } from "./resources";
Expand Down Expand Up @@ -74,7 +74,7 @@ export class Chip
@Prop({ reflect: true }) closable = false;

/** Specifies an icon to display. */
@Prop({ reflect: true }) icon: IconName;
@Prop({ reflect: true }) icon: IconNameOrString;

/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ComboboxChildElement } from "../combobox/interfaces";
import { getAncestors, getDepth, isSingleLike } from "../combobox/utils";
import { Scale, SelectionMode } from "../interfaces";
import { getIconScale } from "../../utils/component";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { CSS, SLOTS } from "./resources";

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
@Prop({ reflect: true }) guid = guid();

/** Specifies an icon to display. */
@Prop({ reflect: true }) icon: IconName;
@Prop({ reflect: true }) icon: IconNameOrString;

/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;
Expand Down Expand Up @@ -203,7 +203,7 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
//
// --------------------------------------------------------------------------

renderIcon(iconPath: IconName): VNode {
renderIcon(iconPath: IconNameOrString): VNode {
return this.icon ? (
<calcite-icon
class={{
Expand All @@ -219,8 +219,8 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
}

renderSelectIndicator(showDot: boolean): VNode;
renderSelectIndicator(showDot: boolean, iconPath: IconName): VNode;
renderSelectIndicator(showDot: boolean, iconPath?: IconName): VNode {
renderSelectIndicator(showDot: boolean, iconPath: IconNameOrString): VNode;
renderSelectIndicator(showDot: boolean, iconPath?: IconNameOrString): VNode {
return showDot ? (
<span
class={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import { Scale, SelectionMode, Status } from "../interfaces";
import { CSS as XButtonCSS, XButton } from "../functional/XButton";
import { componentOnReady, getIconScale } from "../../utils/component";
import { Validation } from "../functional/Validation";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { ComboboxMessages } from "./assets/combobox/t9n";
import { ComboboxChildElement, SelectionDisplay } from "./interfaces";
import { ComboboxChildSelector, ComboboxItem, ComboboxItemGroup, CSS } from "./resources";
Expand Down Expand Up @@ -188,7 +188,7 @@ export class Combobox
@Prop() placeholder: string;

/** Specifies the placeholder icon for the input. */
@Prop({ reflect: true }) placeholderIcon: IconName;
@Prop({ reflect: true }) placeholderIcon: IconNameOrString;

/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) placeholderIconFlipRtl = false;
Expand All @@ -205,7 +205,7 @@ export class Combobox
@Prop() validationMessage: string;

/** Specifies the validation icon to display under the component. */
@Prop({ reflect: true }) validationIcon: IconName | boolean;
@Prop({ reflect: true }) validationIcon: IconNameOrString | boolean;

/**
* The current validation state of the component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
InteractiveContainer,
updateHostInteraction,
} from "../../utils/interactive";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { CSS } from "./resources";

/**
Expand Down Expand Up @@ -60,10 +60,10 @@ export class DropdownItem implements InteractiveComponent, LoadableComponent {
@Prop({ reflect: true }) iconFlipRtl: FlipContext;

/** Specifies an icon to display at the start of the component. */
@Prop({ reflect: true }) iconStart: IconName;
@Prop({ reflect: true }) iconStart: IconNameOrString;

/** Specifies an icon to display at the end of the component. */
@Prop({ reflect: true }) iconEnd: IconName;
@Prop({ reflect: true }) iconEnd: IconNameOrString;

/** Accessible name for the component. */
@Prop() label: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/fab/fab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
setUpLoadableComponent,
} from "../../utils/loadable";
import { Appearance, Kind, Scale } from "../interfaces";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { CSS, ICONS } from "./resources";

@Component({
Expand Down Expand Up @@ -50,7 +50,7 @@ export class Fab implements InteractiveComponent, LoadableComponent {
*
* @default "plus"
*/
@Prop({ reflect: true }) icon: IconName = ICONS.plus;
@Prop({ reflect: true }) icon: IconNameOrString = ICONS.plus;

/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FunctionalComponent, h } from "@stencil/core";
import { JSXBase } from "@stencil/core/internal";
import { Scale, Status } from "../interfaces";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";

interface ValidationProps extends JSXBase.HTMLAttributes {
scale: Scale;
status: Status;
icon?: IconName | boolean;
icon?: IconNameOrString | boolean;
message: string;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Scale } from "../interfaces";
import { isBrowser } from "../../utils/browser";
import { CSS } from "./resources";
import { fetchIcon, getCachedIconData, scaleToPx } from "./utils";
import { IconName } from "./interfaces";
import { IconNameOrString } from "./interfaces";

@Component({
tag: "calcite-icon",
Expand All @@ -29,7 +29,7 @@ export class Icon {
@Prop({
reflect: true,
})
icon: IconName = null;
icon: IconNameOrString = null;

/**
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ type CamelCaseIcons = ExtractBaseIcon<keyof typeof icons>;
type KebabCaseIcons = KebabCase<CamelCaseIcons>;

export type IconName = KebabCaseIcons | CamelCaseIcons;
export type IconNameOrString = IconName | string;
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/icon/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CalciteIconPath } from "@esri/calcite-ui-icons";
import { getAssetPath } from "@stencil/core";
import { Scale } from "../interfaces";
import { IconName } from "./interfaces";
import { IconNameOrString } from "./interfaces";

export interface FetchIconProps {
icon: IconName;
icon: IconNameOrString;
scale: Scale;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import { guid } from "../../utils/guid";
import { getIconScale } from "../../utils/component";
import { Status } from "../interfaces";
import { Validation } from "../functional/Validation";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { syncHiddenFormInput } from "../input/common/input";
import { isBrowser } from "../../utils/browser";
import { normalizeToCurrentCentury, isTwoDigitYear } from "./utils";
Expand Down Expand Up @@ -279,7 +279,7 @@ export class InputDatePicker
@Prop() validationMessage: string;

/** Specifies the validation icon to display under the component. */
@Prop({ reflect: true }) validationIcon: IconName | boolean;
@Prop({ reflect: true }) validationIcon: IconNameOrString | boolean;

/**
* The current validation state of the component.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Element, h, Host, Prop, VNode, Watch } from "@stencil/core";
import { setRequestedIcon } from "../../utils/dom";
import { Scale, Status } from "../interfaces";
import { IconName } from "../icon/interfaces";
import { IconNameOrString } from "../icon/interfaces";
import { StatusIconDefaults } from "./interfaces";

/**
Expand All @@ -20,7 +20,7 @@ export class InputMessage {
//--------------------------------------------------------------------------

/** Specifies an icon to display. */
@Prop({ reflect: true }) icon: IconName | boolean;
@Prop({ reflect: true }) icon: IconNameOrString | boolean;

/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;
Expand Down Expand Up @@ -66,15 +66,15 @@ export class InputMessage {
@Element() el: HTMLCalciteInputMessageElement;

/** the computed icon to render */
private requestedIcon?: IconName;
private requestedIcon?: IconNameOrString;

//--------------------------------------------------------------------------
//
// Private Methods
//
//--------------------------------------------------------------------------

private renderIcon(iconName: IconName): VNode {
private renderIcon(iconName: IconNameOrString): VNode {
if (iconName) {
return (
<calcite-icon
Expand Down
Loading
Loading