Skip to content

Commit c60e976

Browse files
authored
Merge pull request #481 from piemonkey/feature/pass-icon-component
[Experimental feature] Add support for using components as icons
2 parents b5b8f45 + 5780b3d commit c60e976

10 files changed

+47
-32
lines changed

addon/components/au-accordion.gts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { tracked } from '@glimmer/tracking';
55
import { modifier } from 'ember-modifier';
66
import AuButton from './au-button';
77
import AuContent from './au-content';
8-
import AuIcon from './au-icon';
8+
import AuIcon, { type AuIconSignature } from './au-icon';
99
import AuLoader from './au-loader';
1010
import AuToolbar from './au-toolbar';
1111

@@ -16,8 +16,8 @@ const autofocus = modifier(function autofocus(element: HTMLElement) {
1616
export interface AuAccordionSignature {
1717
Args: {
1818
buttonLabel?: string;
19-
iconClosed?: string;
20-
iconOpen?: string;
19+
iconClosed?: AuIconSignature['Args']['icon'];
20+
iconOpen?: AuIconSignature['Args']['icon'];
2121
isOpenInitially?: boolean;
2222
loading?: boolean;
2323
reverse?: boolean;

addon/components/au-alert.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { on } from '@ember/modifier';
22
import { action } from '@ember/object';
33
import Component from '@glimmer/component';
44
import { tracked } from '@glimmer/tracking';
5-
import AuIcon from './au-icon';
5+
import AuIcon, { type AuIconSignature } from './au-icon';
66

77
export interface AuAlertSignature {
88
Args: {
99
closable?: boolean;
10-
icon?: string;
10+
icon?: AuIconSignature['Args']['icon'];
1111
iconVisible?: boolean;
1212
onClose?: () => void;
1313
size?: 'tiny' | 'small';

addon/components/au-badge.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Component from '@glimmer/component';
2-
import AuIcon from './au-icon';
2+
import AuIcon, { type AuIconSignature } from './au-icon';
33

44
export interface AuBadgeSignature {
55
Args: {
6-
icon?: string;
6+
icon?: AuIconSignature['Args']['icon'];
77
iconVisible?: boolean;
88
number?: number;
99
size?: 'small';

addon/components/au-button.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Component from '@glimmer/component';
2-
import AuIcon from './au-icon';
2+
import AuIcon, { type AuIconSignature } from './au-icon';
33
import { LoadingAnimation } from '../private/components/loading-animation';
44

55
const SKINS = [
@@ -15,7 +15,7 @@ export interface AuButtonSignature {
1515
alert?: boolean;
1616
disabled?: boolean;
1717
hideText?: boolean;
18-
icon?: string;
18+
icon?: AuIconSignature['Args']['icon'];
1919
iconAlignment?: 'left' | 'right';
2020
loading?: boolean;
2121
loadingMessage?: string;

addon/components/au-card.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { tracked } from '@glimmer/tracking';
66
import AuBadge from './au-badge';
77
import AuButton from './au-button';
88
import AuContent, { type AuContentSignature } from './au-content';
9-
import AuIcon from './au-icon';
9+
import AuIcon, { type AuIconSignature } from './au-icon';
1010

1111
export interface AuCardSignature {
1212
Args: {
@@ -188,7 +188,7 @@ export default class AuCard extends Component<AuCardSignature> {
188188

189189
interface HeaderSignature {
190190
Args: {
191-
badgeIcon?: string;
191+
badgeIcon?: AuIconSignature['Args']['icon'];
192192
badgeNumber?: number;
193193
badgeSize?: 'small';
194194
badgeSkin?: 'border' | 'action' | 'brand' | 'success' | 'warning' | 'error';

addon/components/au-icon.gts

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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<{ Element: Element }>;
1011
size?: 'large';
1112
};
12-
Element: SVGSVGElement;
13+
Element: Element;
1314
}
1415

1516
export default class AuIcon extends Component<AuIconSignature> {
@@ -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+
<Icon
51+
class="au-c-icon {{this.alignment}} {{this.size}}"
52+
aria-hidden={{this.ariaHidden}}
53+
...attributes
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
}

addon/components/au-input.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Component from '@glimmer/component';
2-
import AuIcon from './au-icon';
2+
import AuIcon, { type AuIconSignature } from './au-icon';
33

44
export interface AuInputSignature {
55
Args: {
66
disabled?: boolean;
77
error?: boolean;
8-
icon?: string;
8+
icon?: AuIconSignature['Args']['icon'];
99
iconAlignment?: 'left' | 'right';
1010
warning?: boolean;
1111
width?: 'block';

addon/components/au-link-external.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Component from '@glimmer/component';
2-
import AuIcon from './au-icon';
2+
import AuIcon, { type AuIconSignature } from './au-icon';
33

44
const SKIN_CLASSES = {
55
primary: 'au-c-link',
@@ -12,7 +12,7 @@ const SKIN_CLASSES = {
1212
export interface AuLinkExternalSignature {
1313
Args: {
1414
hideText?: boolean;
15-
icon?: string;
15+
icon?: AuIconSignature['Args']['icon'];
1616
iconAlignment?: 'left' | 'right';
1717
skin?:
1818
| 'primary'

addon/components/au-link.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LinkTo } from '@ember/routing';
22
import Component from '@glimmer/component';
3-
import AuIcon from './au-icon';
3+
import AuIcon, { type AuIconSignature } from './au-icon';
44
import linkToModels from '../private/helpers/link-to-models';
55

66
const SKIN_CLASSES = {
@@ -22,7 +22,7 @@ export interface AuLinkSignature {
2222
| 'button-naked';
2323
width?: 'block';
2424
query?: Record<string, unknown>;
25-
icon?: string;
25+
icon?: AuIconSignature['Args']['icon'];
2626
route: string;
2727
hideText?: boolean;
2828
model?: unknown;

addon/components/au-pill.gts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { on } from '@ember/modifier';
22
import { LinkTo } from '@ember/routing';
33
import Component from '@glimmer/component';
4-
import AuIcon from './au-icon';
4+
import AuIcon, { type AuIconSignature } from './au-icon';
55
import linkToModels from '../private/helpers/link-to-models';
66

77
const PILL_SIZES = ['small'];
88

99
export interface AuPillSignature {
1010
Args: {
11-
actionIcon?: string;
11+
actionIcon?: AuIconSignature['Args']['icon'];
1212
actionText?: string;
1313
draft?: boolean;
1414
href?: string;
@@ -144,7 +144,7 @@ export default class AuPill extends Component<AuPillSignature> {
144144

145145
interface InnerSignature {
146146
Args: {
147-
icon?: string;
147+
icon?: AuIconSignature['Args']['icon'];
148148
iconAlignment?: 'left' | 'right';
149149
hideText?: boolean;
150150
};

0 commit comments

Comments
 (0)