Skip to content

Commit aac21ce

Browse files
committed
change to a single function call instead of static property
1 parent c09dd91 commit aac21ce

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

packages/components/src/components/hds/breadcrumb/item.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { assert } from '@ember/debug';
1010
import type { LinkTo } from '@ember/routing';
1111
import type { SafeString } from '@ember/template';
1212
import type { HdsIconSignature } from '../icon/index';
13+
import { getLinkToExternal } from '../../../utils/hds-link-to-external.ts';
1314

1415
export interface HdsBreadcrumbItemSignature {
1516
Args: {
@@ -29,22 +30,20 @@ export interface HdsBreadcrumbItemSignature {
2930
}
3031

3132
export default class HdsBreadcrumbItem extends Component<HdsBreadcrumbItemSignature> {
32-
static linkToExternal: LinkTo | null = null;
33-
3433
/**
3534
*
3635
* @param linkToExternal
3736
* @type LinkTo | null
3837
* @default null
3938
*/
4039
get linkToExternal(): LinkTo | null {
41-
const component = HdsBreadcrumbItem.linkToExternal;
40+
const component = getLinkToExternal();
4241
if (component === null) {
4342
assert(
4443
`HdsBreadcrumbItem: You attempted to use an external link without configuring HDS with an external component. Please add this in your app.js file:
4544
46-
import { HdsBreadcrumbItem } from @hashicorp/design-system-components/components;'
47-
HdsBreadcrumbItem.linkToExternal = LinkToExternalComponent;`
45+
import { setLinkToExternal } from '@hashicorp/design-system-components/utils/hds-link-to-external';
46+
setLinkToExternal(LinkToExternalComponent);`
4847
);
4948
}
5049
return component;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { action } from '@ember/object';
88
import { assert } from '@ember/debug';
99

1010
import type { LinkTo } from '@ember/routing';
11+
import { getLinkToExternal } from '../../../utils/hds-link-to-external.ts';
1112

1213
export interface HdsInteractiveSignature {
1314
Args: {
@@ -30,8 +31,6 @@ export interface HdsInteractiveSignature {
3031
}
3132

3233
export default class HdsInteractive extends Component<HdsInteractiveSignature> {
33-
static linkToExternal: LinkTo | null = null;
34-
3534
/**
3635
* Determines if a @href value is "external" (it adds target="_blank" rel="noopener noreferrer")
3736
*
@@ -40,13 +39,13 @@ export default class HdsInteractive extends Component<HdsInteractiveSignature> {
4039
* @default null
4140
*/
4241
get linkToExternal(): LinkTo | null {
43-
const component = HdsInteractive.linkToExternal;
42+
const component = getLinkToExternal();
4443
if (component === null) {
4544
assert(
4645
`HdsInteractive: You attempted to use an external link without configuring HDS with an external component. Please add this in your app.js file:
4746
48-
import { HdsInteractive } from '@hashicorp/design-system-components/components';
49-
HdsInteractive.linkToExternal = LinkToExternalComponent;`
47+
import { setLinkToExternal } from '@hashicorp/design-system-components/utils/hds-link-to-external';
48+
setLinkToExternal(LinkToExternalComponent);`
5049
);
5150
}
5251
return component;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { LinkTo } from '@ember/routing';
2+
3+
let LINK_TO_EXTERNAL_COMPONENT: LinkTo | null = null;
4+
5+
export function getLinkToExternal(): LinkTo | null {
6+
return LINK_TO_EXTERNAL_COMPONENT;
7+
}
8+
9+
export function setLinkToExternal(component: LinkTo | null): void {
10+
LINK_TO_EXTERNAL_COMPONENT = component;
11+
}

showcase/tests/integration/components/hds/breadcrumb/item-test.gts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { render, setupOnerror } from '@ember/test-helpers';
88

99
import { HdsBreadcrumbItem } from '@hashicorp/design-system-components/components';
1010
import { LinkTo } from '@ember/routing';
11+
import { setLinkToExternal } from '@hashicorp/design-system-components/utils/hds-link-to-external';
1112

1213
import { setupRenderingTest } from 'showcase/tests/helpers';
1314

@@ -97,8 +98,8 @@ module('Integration | Component | hds/breadcrumb/item', function (hooks) {
9798
test('it should error if @isRouteExternal is true and no component has been configured on the HdsBreadcrumbItem class', async function (assert) {
9899
const errorMessage = `HdsBreadcrumbItem: You attempted to use an external link without configuring HDS with an external component. Please add this in your app.js file:
99100
100-
import { HdsBreadcrumbItem } from @hashicorp/design-system-components/components;'
101-
HdsBreadcrumbItem.linkToExternal = LinkToExternalComponent;`;
101+
import { setLinkToExternal } from '@hashicorp/design-system-components/utils/hds-link-to-external';
102+
setLinkToExternal(LinkToExternalComponent);`;
102103

103104
assert.expect(1);
104105
setupOnerror(function (error) {
@@ -118,8 +119,7 @@ HdsBreadcrumbItem.linkToExternal = LinkToExternalComponent;`;
118119
});
119120

120121
test('it should render configured link component when @isRouteExternal is true', async function (assert) {
121-
HdsBreadcrumbItem.linkToExternal = LinkTo;
122-
122+
setLinkToExternal(LinkTo);
123123
assert.expect(1);
124124

125125
await render(
@@ -133,6 +133,6 @@ HdsBreadcrumbItem.linkToExternal = LinkToExternalComponent;`;
133133
</template>,
134134
);
135135
assert.dom('#test-breadcrumb-item > a').doesNotExist();
136-
HdsBreadcrumbItem.linkToExternal = null;
136+
setLinkToExternal(null);
137137
});
138138
});

showcase/tests/integration/components/hds/interactive/index-test.gts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { tracked } from 'tracked-built-ins';
1010

1111
import { HdsInteractive } from '@hashicorp/design-system-components/components';
1212
import { LinkTo } from '@ember/routing';
13+
import { setLinkToExternal } from '@hashicorp/design-system-components/utils/hds-link-to-external';
1314

1415
import { setupRenderingTest } from 'showcase/tests/helpers';
1516

@@ -160,8 +161,8 @@ module('Integration | Component | hds/interactive/index', function (hooks) {
160161
test('it should error if @isRouteExternal is true and no component has been configured on the HdsInteractive class', async function (assert) {
161162
const errorMessage = `HdsInteractive: You attempted to use an external link without configuring HDS with an external component. Please add this in your app.js file:
162163
163-
import { HdsInteractive } from '@hashicorp/design-system-components/components';
164-
HdsInteractive.linkToExternal = LinkToExternalComponent;`;
164+
import { setLinkToExternal } from '@hashicorp/design-system-components/utils/hds-link-to-external';
165+
setLinkToExternal(LinkToExternalComponent);`;
165166

166167
assert.expect(1);
167168
setupOnerror(function (error) {
@@ -180,8 +181,7 @@ HdsInteractive.linkToExternal = LinkToExternalComponent;`;
180181
});
181182

182183
test('it should render configured link component when @isRouteExternal is true', async function (assert) {
183-
HdsInteractive.linkToExternal = LinkTo;
184-
184+
setLinkToExternal(LinkTo);
185185
assert.expect(1);
186186

187187
await render(
@@ -194,6 +194,6 @@ HdsInteractive.linkToExternal = LinkToExternalComponent;`;
194194
</template>,
195195
);
196196
assert.dom('a#test-interactive').exists();
197-
HdsInteractive.linkToExternal = null;
197+
setLinkToExternal(null);
198198
});
199199
});

0 commit comments

Comments
 (0)