@@ -7,14 +7,14 @@ import Component from '@glimmer/component';
7
7
import { htmlSafe } from ' @ember/template' ;
8
8
import { assert } from ' @ember/debug' ;
9
9
import { LinkTo } from ' @ember/routing' ;
10
- // @ts-expect-error: no types
11
- import LinkToExternal from ' ember-engines/components/link-to-external-component.js' ;
10
+ import { dependencySatisfies , importSync } from ' @embroider/macros' ;
12
11
import HdsIcon from ' ../icon/index.gts' ;
13
12
import hdsLinkToModels from ' ../../../helpers/hds-link-to-models.ts' ;
14
13
import hdsLinkToQuery from ' ../../../helpers/hds-link-to-query.ts' ;
15
14
16
15
import type { SafeString } from ' @ember/template' ;
17
16
import type { HdsIconSignature } from ' ../icon' ;
17
+ import type Owner from ' @ember/owner' ;
18
18
19
19
export interface HdsBreadcrumbItemSignature {
20
20
Args: {
@@ -34,6 +34,26 @@ export interface HdsBreadcrumbItemSignature {
34
34
}
35
35
36
36
export default class HdsBreadcrumbItem extends Component <HdsBreadcrumbItemSignature > {
37
+ linkToComponent = LinkTo ;
38
+
39
+ constructor (owner : Owner , args : HdsBreadcrumbItemSignature [' Args' ]) {
40
+ super (owner , args );
41
+
42
+ if (this .args .isRouteExternal ) {
43
+ if (dependencySatisfies (' ember-engines' , ' *' )) {
44
+ // @ts-expect-error: shape is unknown
45
+ this .linkToComponent = importSync (
46
+ ' ember-engines/components/link-to-external-component.js'
47
+ ).default as LinkTo ;
48
+ } else {
49
+ assert (
50
+ ` @isRouteExternal is only available when using the "ember-engines" addon. Please install it to use this feature. ` ,
51
+ false
52
+ );
53
+ }
54
+ }
55
+ }
56
+
37
57
/**
38
58
* @param maxWidth
39
59
* @type {string}
@@ -79,6 +99,16 @@ export default class HdsBreadcrumbItem extends Component<HdsBreadcrumbItemSignat
79
99
return classes .join (' ' );
80
100
}
81
101
102
+ get isRouteExternal(): boolean {
103
+ const { isRouteExternal } = this .args ;
104
+
105
+ if (isRouteExternal && dependencySatisfies (' ember-engines' , ' *' )) {
106
+ return isRouteExternal ;
107
+ } else {
108
+ return false ;
109
+ }
110
+ }
111
+
82
112
<template >
83
113
<li class =" hds-breadcrumb__item" style ={{this .itemStyle }} ...attributes >
84
114
{{#if @ current }}
@@ -91,39 +121,21 @@ export default class HdsBreadcrumbItem extends Component<HdsBreadcrumbItemSignat
91
121
<span class =" hds-breadcrumb__text" >{{@ text }} </span >
92
122
</div >
93
123
{{else }}
94
- {{#if @ isRouteExternal }}
95
- <LinkToExternal
96
- class =" hds-breadcrumb__link"
97
- @ current-when ={{@ current-when }}
98
- @ models ={{hdsLinkToModels @ model @ models}}
99
- @ query ={{hdsLinkToQuery @ query}}
100
- @ replace ={{@ replace }}
101
- @ route ={{@ route }}
102
- >
103
- {{#if @ icon }}
104
- <div class =" hds-breadcrumb__icon" >
105
- <HdsIcon @ name ={{@ icon }} @ size =" 16" @ stretched ={{ true }} />
106
- </div >
107
- {{/if }}
108
- <span class =" hds-breadcrumb__text" >{{@ text }} </span >
109
- </LinkToExternal >
110
- {{else }}
111
- <LinkTo
112
- class =" hds-breadcrumb__link"
113
- @ current-when ={{@ current-when }}
114
- @ models ={{hdsLinkToModels @ model @ models}}
115
- @ query ={{hdsLinkToQuery @ query}}
116
- @ replace ={{@ replace }}
117
- @ route ={{@ route }}
118
- >
119
- {{#if @ icon }}
120
- <div class =" hds-breadcrumb__icon" >
121
- <HdsIcon @ name ={{@ icon }} @ size =" 16" @ stretched ={{ true }} />
122
- </div >
123
- {{/if }}
124
- <span class =" hds-breadcrumb__text" >{{@ text }} </span >
125
- </LinkTo >
126
- {{/if }}
124
+ <this .linkToComponent
125
+ class =" hds-breadcrumb__link"
126
+ @ current-when ={{@ current-when }}
127
+ @ models ={{hdsLinkToModels @ model @ models}}
128
+ @ query ={{hdsLinkToQuery @ query}}
129
+ @ replace ={{@ replace }}
130
+ @ route ={{@ route }}
131
+ >
132
+ {{#if @ icon }}
133
+ <div class =" hds-breadcrumb__icon" >
134
+ <HdsIcon @ name ={{@ icon }} @ size =" 16" @ stretched ={{ true }} />
135
+ </div >
136
+ {{/if }}
137
+ <span class =" hds-breadcrumb__text" >{{@ text }} </span >
138
+ </this .linkToComponent >
127
139
{{/if }}
128
140
</li >
129
141
</template >
0 commit comments