Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/little-games-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@hashicorp/design-system-components": minor
---

<!-- START components/icon -->
`Icon` - Converted component to `.gts` format
<!-- END -->
2 changes: 1 addition & 1 deletion packages/components/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export { default as HdsFormToggleField } from './components/hds/form/toggle/fiel
export { default as HdsFormToggleGroup } from './components/hds/form/toggle/group.ts';

// Icon
export { default as HdsIcon } from './components/hds/icon/index.ts';
export { default as HdsIcon } from './components/hds/icon/index.gts';
export * from './components/hds/icon/types.ts';

// IconTile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*/

import Component from '@glimmer/component';
import { guidFor } from '@ember/object/internals';
import { assert } from '@ember/debug';
import { guidFor } from '@ember/object/internals';
import { iconNames } from '@hashicorp/flight-icons/svg';
import { HdsIconSizeValues, HdsIconColorValues } from './types.ts';
import type { HdsIconSizes, HdsIconColors } from './types';
import type { IconName } from '@hashicorp/flight-icons/svg';
import type Owner from '@ember/owner';

import { HdsIconSizeValues, HdsIconColorValues } from './types.ts';
import type { HdsIconSizes, HdsIconColors } from './types';

export const COLORS: HdsIconColors[] = Object.values(HdsIconColorValues);
export const NAMES = iconNames;

Expand Down Expand Up @@ -44,11 +45,11 @@ export default class HdsIcon extends Component<HdsIconSignature> {
}
}

get isInline(): boolean {
get isInline() {
return this.args.isInline ?? false;
}

get predefinedColor(): HdsIconColors | undefined {
get predefinedColor() {
const { color } = this.args;

if (color && COLORS.includes(color as HdsIconColors)) {
Expand All @@ -58,15 +59,15 @@ export default class HdsIcon extends Component<HdsIconSignature> {
}
}

get fillColor(): string {
get fillColor() {
if (this.predefinedColor !== undefined) {
return 'currentColor';
} else {
return this.args.color ?? 'currentColor';
}
}

get size(): string {
get size() {
return this.args.size ?? HdsIconSizeValues.Sixteen;
}

Expand All @@ -77,15 +78,15 @@ export default class HdsIcon extends Component<HdsIconSignature> {
};
}

get title(): string | null {
get title() {
return this.args.title ?? null;
}

get role(): string | null {
get role() {
return this.args.title ? 'img' : null;
}

get ariaLabelledby(): string | null {
get ariaLabelledby() {
return this.args.title ? this._titleId : null;
}

Expand All @@ -112,4 +113,30 @@ export default class HdsIcon extends Component<HdsIconSignature> {

return classes.join(' ');
}

<template>
<svg
class={{this.classNames}}
...attributes
aria-hidden={{if @title "false" "true"}}
aria-labelledby={{this.ariaLabelledby}}
data-test-icon={{@name}}
fill={{this.fillColor}}
id={{this._iconId}}
role={{this.role}}
width={{this.svgSize.width}}
height={{this.svgSize.height}}
viewBox="0 0 {{this.size}} {{this.size}}"
xmlns="http://www.w3.org/2000/svg"
>
{{#if @title}}
<title id={{this._titleId}}>{{@title}}</title>
<g role="presentation">
<use href="#flight-{{@name}}-{{this.size}}" />
</g>
{{else}}
<use href="#flight-{{@name}}-{{this.size}}" />
{{/if}}
</svg>
</template>
}
28 changes: 0 additions & 28 deletions packages/components/src/components/hds/icon/index.hbs

This file was deleted.