Skip to content

Commit 9c967a8

Browse files
committed
feat(ember-flight-icons): add types
1 parent dcd0000 commit 9c967a8

File tree

21 files changed

+71
-53
lines changed

21 files changed

+71
-53
lines changed

.changeset/long-rats-share.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hashicorp/ember-flight-icons": minor
3+
---
4+
5+
`FlightIcon` - converted component to TypeScript and published types

packages/components/src/components/hds/alert/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { HdsYieldSignature } from '../yield';
1818
import type { HdsAlertColors, HdsAlertTypes } from './types.ts';
1919
import type { HdsAlertTitleSignature } from './title.ts';
2020
import type { HdsAlertDescriptionSignature } from './description.ts';
21+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
2122

2223
export const TYPES: string[] = Object.values(HdsAlertTypeValues);
2324
export const DEFAULT_COLOR = HdsAlertColorValues.Neutral;
@@ -39,7 +40,7 @@ export interface HdsAlertSignature {
3940
Args: {
4041
type: HdsAlertTypes;
4142
color?: HdsAlertColors;
42-
icon?: string | false;
43+
icon?: FlightIconSignature['Args']['name'] | false;
4344
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4445
onDismiss?: (event: MouseEvent, ...args: any[]) => void;
4546
};
@@ -100,7 +101,7 @@ export default class HdsAlertComponent extends Component<HdsAlertSignature> {
100101
* @default null
101102
* @description The name of the icon to be used.
102103
*/
103-
get icon() {
104+
get icon(): FlightIconSignature['Args']['name'] | false {
104105
const { icon } = this.args;
105106

106107
// If `icon` isn't passed, use the pre-defined one from `color`

packages/components/src/components/hds/app-footer/link.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import Component from '@glimmer/component';
88
import type { HdsInteractiveSignature } from '../interactive/';
99
import type { HdsLinkColors, HdsLinkIconPositions } from '../link/types.ts';
1010
import type { HdsLinkInlineSignature } from '../link/inline.ts';
11+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
1112

1213
export interface HdsAppFooterLinkSignature {
1314
Args: HdsInteractiveSignature['Args'] & {
1415
color?: HdsLinkColors;
15-
icon?: string;
16+
icon?: FlightIconSignature['Args']['name'];
1617
iconPosition?: HdsLinkIconPositions;
1718
};
1819
Blocks: {

packages/components/src/components/hds/app-footer/status-link.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import type { HdsInteractiveSignature } from '../interactive/';
1212
import { HdsAppFooterStatusLinkStatusValues } from './types.ts';
1313
import type { HdsAppFooterStatusTypes } from './types.ts';
1414
import type { HdsAppFooterLinkSignature } from './link.ts';
15+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
1516

1617
export const STATUSES = HdsAppFooterStatusLinkStatusValues;
1718

1819
export interface HdsAppFooterStatusLinkSignature {
1920
Args: HdsInteractiveSignature['Args'] & {
2021
itemStyle?: SafeString;
2122
status?: HdsAppFooterStatusTypes;
22-
statusIcon?: string;
23+
statusIcon?: FlightIconSignature['Args']['name'];
2324
statusIconColor?: string;
2425
text?: string;
2526
};
@@ -64,7 +65,8 @@ export default class HdsAppFooterStatusLinkComponent extends Component<HdsAppFoo
6465
*/
6566
get statusIcon() {
6667
if (this.status && !this.args.statusIcon) {
67-
return STATUSES[this.status]?.iconName;
68+
return STATUSES[this.status]
69+
?.iconName as FlightIconSignature['Args']['name'];
6870
}
6971
return this.args.statusIcon;
7072
}

packages/components/src/components/hds/application-state/header.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
import TemplateOnlyComponent from '@ember/component/template-only';
77

8+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
9+
810
export interface HdsApplicationStateHeaderSignature {
911
Args: {
1012
title?: string;
1113
errorCode?: string;
12-
icon?: string;
14+
icon?: FlightIconSignature['Args']['name'];
1315
};
1416
Element: HTMLDivElement;
1517
}

packages/components/src/components/hds/badge/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from './types.ts';
1414

1515
import type { HdsBadgeColors, HdsBadgeSizes, HdsBadgeTypes } from './types.ts';
16+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
1617

1718
export const SIZES: string[] = Object.values(HdsBadgeSizeValues);
1819
export const TYPES: string[] = Object.values(HdsBadgeTypeValues);
@@ -27,7 +28,7 @@ export interface HdsBadgeSignature {
2728
type?: HdsBadgeTypes;
2829
color?: HdsBadgeColors;
2930
text: string;
30-
icon?: string | null;
31+
icon?: FlightIconSignature['Args']['name'];
3132
isIconOnly?: boolean;
3233
};
3334
Element: HTMLDivElement;

packages/components/src/components/hds/button/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Component from '@glimmer/component';
77
import { assert } from '@ember/debug';
88
import type { HdsInteractiveSignature } from '../interactive/';
9+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
910

1011
export const DEFAULT_SIZE = 'medium';
1112
export const DEFAULT_COLOR = 'primary';
@@ -23,7 +24,7 @@ export interface HdsButtonSignature {
2324
size?: HdsButtonSize;
2425
color?: HdsButtonColor;
2526
text: string;
26-
icon?: string;
27+
icon?: FlightIconSignature['Args']['name'];
2728
iconPosition?: HdsButtonIconPosition;
2829
isIconOnly?: boolean;
2930
isFullWidth?: boolean;

packages/components/src/components/hds/copy/button/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { HdsCopyButtonSizeValues } from './types.ts';
1111
import type { HdsCopyButtonSizes } from './types.ts';
1212
import type { HdsButtonSignature } from '../../button/';
1313
import type { HdsClipboardModifierSignature } from '../../../../modifiers/hds-clipboard.ts';
14+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
1415

1516
export const DEFAULT_SIZE = HdsCopyButtonSizeValues.Medium;
1617
export const SIZES: string[] = Object.values(HdsCopyButtonSizeValues);
@@ -40,7 +41,7 @@ export default class HdsCopyButtonComponent extends Component<HdsCopyButtonSigna
4041
* @description The icon to be displayed for each status; automatically calculated based on the tracked property `status`.
4142
*/
4243
get icon() {
43-
let icon = DEFAULT_ICON;
44+
let icon: FlightIconSignature['Args']['name'] = DEFAULT_ICON;
4445
if (this.status === 'success') {
4546
icon = SUCCESS_ICON;
4647
} else if (this.status === 'error') {

packages/components/src/components/hds/copy/snippet/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { action } from '@ember/object';
1010
import { HdsCopySnippetColorValues } from './types.ts';
1111
import type { HdsCopySnippetColors } from './types.ts';
1212
import type { HdsClipboardModifierSignature } from '../../../../modifiers/hds-clipboard.ts';
13+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
1314

1415
export const DEFAULT_COLOR = HdsCopySnippetColorValues.Primary;
1516
export const COLORS: string[] = Object.values(HdsCopySnippetColorValues);
@@ -56,7 +57,7 @@ export default class HdsCopySnippetComponent extends Component<HdsCopySnippetSig
5657
* @description Determines the icon to be used, based on the success state. Note that this is auto-tracked because it depends on a tracked property (status).
5758
*/
5859
get icon() {
59-
let icon = DEFAULT_ICON;
60+
let icon: FlightIconSignature['Args']['name'] = DEFAULT_ICON;
6061
if (this.status === 'success') {
6162
icon = SUCCESS_ICON;
6263
} else if (this.status === 'error') {

packages/components/src/components/hds/icon-tile/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import type {
1818
HdsIconTileSizes,
1919
} from './types.ts';
2020

21+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
22+
2123
export const DEFAULT_SIZE = 'medium';
2224
export const DEFAULT_COLOR = 'neutral';
2325
export const SIZES: string[] = Object.values(HdsIconTileSizeValues);
@@ -32,8 +34,8 @@ export interface HdsIconTileSignature {
3234
size?: HdsIconTileSizes;
3335
color?: HdsIconTileColors;
3436
logo?: HdsIconTileProducts;
35-
icon?: string | null;
36-
iconSecondary?: string;
37+
icon?: FlightIconSignature['Args']['name'];
38+
iconSecondary?: FlightIconSignature['Args']['name'];
3739
};
3840
Element: HTMLDivElement;
3941
}
@@ -94,7 +96,7 @@ export default class HdsIconTileComponent extends Component<HdsIconTileSignature
9496
* @type {string|null}
9597
* @default null
9698
*/
97-
get icon() {
99+
get icon(): FlightIconSignature['Args']['name'] | undefined {
98100
if (this.args.logo) {
99101
// for the logo version we use the colored versions directly
100102
return `${this.args.logo}-color`;

packages/components/src/components/hds/link/inline.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { HdsLinkColorValues, HdsLinkIconPositionValues } from './types.ts';
99

1010
import type { HdsInteractiveSignature } from '../interactive/';
1111
import type { HdsLinkColors, HdsLinkIconPositions } from './types.ts';
12+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
1213

1314
export const DEFAULT_ICONPOSITION = HdsLinkIconPositionValues.Trailing;
1415
export const DEFAULT_COLOR = HdsLinkColorValues.Primary;
@@ -18,7 +19,7 @@ export const COLORS: string[] = Object.values(HdsLinkColorValues);
1819
export interface HdsLinkInlineSignature {
1920
Args: HdsInteractiveSignature['Args'] & {
2021
color?: HdsLinkColors;
21-
icon?: string;
22+
icon?: FlightIconSignature['Args']['name'];
2223
iconPosition?: HdsLinkIconPositions;
2324
};
2425
Blocks: {

packages/components/src/components/hds/link/standalone.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import type {
1717
HdsLinkIconPositions,
1818
HdsLinkStandaloneSizes,
1919
} from './types.ts';
20+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
2021

2122
export interface HdsLinkStandaloneSignature {
2223
Args: HdsInteractiveSignature['Args'] & {
2324
size?: HdsLinkStandaloneSizes;
2425
color?: HdsLinkColors;
2526
text: string;
26-
icon: string;
27+
icon: FlightIconSignature['Args']['name'];
2728
iconPosition?: HdsLinkIconPositions;
2829
};
2930
Element: HdsInteractiveSignature['Element'];

packages/components/src/components/hds/side-nav/header/home-link.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import Component from '@glimmer/component';
77
import { assert } from '@ember/debug';
88

9+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
910
import type { HdsInteractiveSignature } from '../../interactive/';
1011

1112
interface HdsSideNavHeaderHomeLinkSignature {
1213
Args: HdsInteractiveSignature['Args'] & {
13-
icon: string;
14+
icon: FlightIconSignature['Args']['name'];
1415
color?: string;
1516
ariaLabel: string;
1617
};

packages/components/src/components/hds/side-nav/header/icon-button.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import Component from '@glimmer/component';
77
import { assert } from '@ember/debug';
88

9+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
910
import type { HdsInteractiveSignature } from '../../interactive/';
1011

1112
interface HdsSideNavHeaderIconButtonSignature {
1213
Args: HdsInteractiveSignature['Args'] & {
13-
icon: string;
14+
icon: FlightIconSignature['Args']['name'];
1415
ariaLabel: string;
1516
};
1617
Element: HdsInteractiveSignature['Element'];

packages/components/src/components/hds/side-nav/list/link.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import TemplateOnlyComponent from '@ember/component/template-only';
77

8+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
89
import type { HdsInteractiveSignature } from '../../interactive';
910

1011
export interface HdsSideNavListLinkSignature {
1112
Args: HdsInteractiveSignature['Args'] & {
12-
icon?: string;
13+
icon?: FlightIconSignature['Args']['name'];
1314
text?: string;
1415
badge?: string;
1516
count?: string;

packages/components/src/components/hds/side-nav/toggle-button.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
import TemplateOnlyComponent from '@ember/component/template-only';
77

8+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
9+
810
interface HdsSideNavToggleButtonSignature {
911
Args: {
10-
icon: string;
12+
icon: FlightIconSignature['Args']['name'];
1113
};
1214
Element: HTMLButtonElement;
1315
}

packages/components/src/components/hds/stepper/task/indicator.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
HdsStepperStatusToIconsValues,
1212
} from '../types.ts';
1313
import type { HdsStepperStatuses } from '../types.ts';
14+
import type { FlightIconSignature } from '@hashicorp/ember-flight-icons/components/flight-icon';
1415

1516
export const DEFAULT_STATUS = HdsStepperStatusesValues.Incomplete;
1617
export const STATUSES: string[] = Object.values(HdsStepperStatusesValues);
@@ -61,7 +62,9 @@ export default class HdsStepperTaskIndicatorComponent extends Component<HdsStepp
6162
*/
6263

6364
get iconName() {
64-
return MAPPING_STATUS_TO_ICONS[this.status];
65+
return MAPPING_STATUS_TO_ICONS[
66+
this.status
67+
] as FlightIconSignature['Args']['name'];
6568
}
6669

6770
/**

packages/components/unpublished-development-types/@hashicorp/ember-flight-icons/flight-icon.d.ts

-25
This file was deleted.

packages/ember-flight-icons/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@
8383
"main": "addon-main.cjs",
8484
"app-js": {
8585
"./components/flight-icon.js": "./dist/_app_/components/flight-icon.js",
86-
"./instance-initializers/load-sprite.js": "./dist/_app_/instance-initializers/load-sprite.js",
87-
"./template-registry.js": "./dist/_app_/template-registry.js"
86+
"./instance-initializers/load-sprite.js": "./dist/_app_/instance-initializers/load-sprite.js"
8887
}
8988
},
9089
"exports": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import FlightIcon from './components/flight-icon.ts';
2+
3+
export { FlightIcon };

packages/ember-flight-icons/src/components/flight-icon.js packages/ember-flight-icons/src/components/flight-icon.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,31 @@
66
import Component from '@glimmer/component';
77
import { guidFor } from '@ember/object/internals';
88
import { assert } from '@ember/debug';
9-
109
import { iconNames } from '@hashicorp/flight-icons/svg';
1110

12-
export default class FlightIconComponent extends Component {
13-
constructor() {
14-
super(...arguments);
11+
import type { IconName } from '@hashicorp/flight-icons/svg';
12+
13+
export interface FlightIconSignature {
14+
Args: {
15+
name?: IconName;
16+
color?: string;
17+
size?: '16' | '24';
18+
stretched?: boolean;
19+
isInlineBlock?: boolean;
20+
title?: string;
21+
};
22+
Element: SVGElement;
23+
}
24+
25+
export default class FlightIcon extends Component<FlightIconSignature> {
26+
constructor(owner: unknown, args: FlightIconSignature['Args']) {
27+
super(owner, args);
28+
1529
if (!this.args.name) {
1630
assert('Please provide to <FlightIcon> a value for @name');
1731
} else if (!iconNames.includes(this.args.name)) {
1832
assert(
19-
`The icon @name "${this.args.name}" provided to <FlightIcon> is not correct. Please verify it exists on https://helios.hashicorp.design/icons/library`,
33+
`The icon @name "${this.args.name}" provided to <FlightIcon> is not correct. Please verify it exists on https://helios.hashicorp.design/icons/library`
2034
);
2135
}
2236
}
@@ -125,7 +139,7 @@ export default class FlightIconComponent extends Component {
125139
* @return {string} The "class" attribute to apply to the component.
126140
*/
127141
get classNames() {
128-
let classes = ['flight-icon'];
142+
const classes = ['flight-icon'];
129143

130144
// add a class based on the @name argument
131145
classes.push(`flight-icon-${this.name}`);

0 commit comments

Comments
 (0)