Skip to content

Commit 3e52116

Browse files
committed
Modify AuIcon to take an inline component for the icon
1 parent 654711a commit 3e52116

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

addon/components/au-icon.gts

+26-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { getOwner } from '@ember/owner';
22
import Component from '@glimmer/component';
3+
import { type ComponentLike } from '@glint/template';
34

45
export interface AuIconSignature {
56
Args: {
67
alignment?: 'left' | 'right';
78
// TODO: We should deprecate the non-boolean versions since there is no reason to support them
89
ariaHidden?: boolean | 'true' | 'false';
9-
icon: string;
10+
icon: string | ComponentLike<Record<string, never>>;
1011
size?: 'large';
1112
};
1213
Element: SVGSVGElement;
@@ -39,16 +40,30 @@ export default class AuIcon extends Component<AuIconSignature> {
3940
}
4041
}
4142

43+
get iconComponent() {
44+
return typeof this.args.icon !== 'string' && this.args.icon;
45+
}
46+
4247
<template>
43-
<svg
44-
role="img"
45-
class="au-c-icon au-c-icon--{{@icon}} {{this.alignment}} {{this.size}}"
46-
aria-hidden={{this.ariaHidden}}
47-
...attributes
48-
>
49-
<use
50-
xlink:href="{{this.iconPrefix}}@appuniversum/ember-appuniversum/appuniversum-symbolset.svg#{{@icon}}"
51-
></use>
52-
</svg>
48+
{{#if this.iconComponent}}
49+
{{#let this.iconComponent as |Icon|}}
50+
{{! @glint-expect-error: glint doesn't like us setting attributes on the passed component }}
51+
<Icon
52+
class="au-c-icon {{this.alignment}} {{this.size}}"
53+
aria-hidden={{this.ariaHidden}}
54+
/>
55+
{{/let}}
56+
{{else}}
57+
<svg
58+
role="img"
59+
class="au-c-icon au-c-icon--{{@icon}} {{this.alignment}} {{this.size}}"
60+
aria-hidden={{this.ariaHidden}}
61+
...attributes
62+
>
63+
<use
64+
xlink:href="{{this.iconPrefix}}@appuniversum/ember-appuniversum/appuniversum-symbolset.svg#{{@icon}}"
65+
></use>
66+
</svg>
67+
{{/if}}
5368
</template>
5469
}

0 commit comments

Comments
 (0)