Skip to content

Commit 6498d0b

Browse files
authored
Flyout: Converted component to gts format (#3574)
1 parent 14d5d9e commit 6498d0b

File tree

4 files changed

+90
-68
lines changed

4 files changed

+90
-68
lines changed

.changeset/flat-ghosts-shop.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@hashicorp/design-system-components": patch
3+
---
4+
5+
<!-- START components/flyout -->
6+
`Flyout` - Converted component to gts format.
7+
<!-- END -->

packages/components/src/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export { default as HdsFilterBarTabsTab } from './components/hds/filter-bar/tabs
148148
export * from './components/hds/filter-bar/types.ts';
149149

150150
// Flyout
151-
export { default as HdsFlyout } from './components/hds/flyout/index.ts';
151+
export { default as HdsFlyout } from './components/hds/flyout/index.gts';
152152
export * from './components/hds/flyout/types.ts';
153153

154154
// Form > Layout

packages/components/src/components/hds/flyout/index.ts renamed to packages/components/src/components/hds/flyout/index.gts

Lines changed: 82 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@
55

66
import Component from '@glimmer/component';
77
import { tracked } from '@glimmer/tracking';
8-
import { action } from '@ember/object';
98
import { assert } from '@ember/debug';
10-
import { getElementId } from '../../../utils/hds-get-element-id.ts';
119
import { buildWaiter } from '@ember/test-waiters';
12-
import type { WithBoundArgs } from '@glint/template';
1310
import { modifier } from 'ember-modifier';
11+
import { hash } from '@ember/helper';
12+
// @ts-expect-error: missing types https://github.com/josemarluedke/ember-focus-trap/issues/86
13+
import focusTrap from 'ember-focus-trap/modifiers/focus-trap';
1414

15-
import type { HdsFlyoutSizes } from './types.ts';
15+
import type { WithBoundArgs } from '@glint/template';
1616

1717
import { HdsFlyoutSizesValues } from './types.ts';
18-
import HdsDialogPrimitiveBodyComponent from '../dialog-primitive/body.gts';
19-
import HdsDialogPrimitiveDescriptionComponent from '../dialog-primitive/description.gts';
20-
import HdsDialogPrimitiveFooterComponent from '../dialog-primitive/footer.gts';
21-
import HdsDialogPrimitiveHeaderComponent from '../dialog-primitive/header.gts';
18+
import HdsDialogPrimitiveBody from '../dialog-primitive/body.gts';
19+
import HdsDialogPrimitiveDescription from '../dialog-primitive/description.gts';
20+
import HdsDialogPrimitiveFooter from '../dialog-primitive/footer.gts';
21+
import HdsDialogPrimitiveHeader from '../dialog-primitive/header.gts';
22+
import HdsDialogPrimitiveOverlay from '../dialog-primitive/overlay.gts';
23+
import HdsDialogPrimitiveWrapper from '../dialog-primitive/wrapper.gts';
24+
import { getElementId } from '../../../utils/hds-get-element-id.ts';
25+
26+
import type { HdsFlyoutSizes } from './types.ts';
2227

2328
const waiter = buildWaiter('@hashicorp/design-system-components:flyout');
2429

@@ -37,19 +42,16 @@ export interface HdsFlyoutSignature {
3742
default: [
3843
{
3944
Header?: WithBoundArgs<
40-
typeof HdsDialogPrimitiveHeaderComponent,
45+
typeof HdsDialogPrimitiveHeader,
4146
'id' | 'onDismiss' | 'contextualClassPrefix'
4247
>;
4348
Description?: WithBoundArgs<
44-
typeof HdsDialogPrimitiveDescriptionComponent,
45-
'contextualClass'
46-
>;
47-
Body?: WithBoundArgs<
48-
typeof HdsDialogPrimitiveBodyComponent,
49+
typeof HdsDialogPrimitiveDescription,
4950
'contextualClass'
5051
>;
52+
Body?: WithBoundArgs<typeof HdsDialogPrimitiveBody, 'contextualClass'>;
5153
Footer?: WithBoundArgs<
52-
typeof HdsDialogPrimitiveFooterComponent,
54+
typeof HdsDialogPrimitiveFooter,
5355
'onDismiss' | 'contextualClass'
5456
>;
5557
},
@@ -131,7 +133,7 @@ export default class HdsFlyout extends Component<HdsFlyoutSignature> {
131133
}
132134

133135
// Register "onClose" callback function to be called when a native 'close' event is dispatched
134-
// eslint-disable-next-line @typescript-eslint/unbound-method
136+
135137
this._element.addEventListener('close', this.registerOnCloseCallback, true);
136138

137139
// If the flyout dialog is not already open
@@ -147,23 +149,22 @@ export default class HdsFlyout extends Component<HdsFlyoutSignature> {
147149

148150
this._element?.removeEventListener(
149151
'close',
150-
// eslint-disable-next-line @typescript-eslint/unbound-method
152+
151153
this.registerOnCloseCallback,
152154
true
153155
);
154156
};
155157
});
156158

157-
@action registerOnCloseCallback(event: Event) {
159+
registerOnCloseCallback = (event: Event) => {
158160
if (this.args.onClose && typeof this.args.onClose === 'function') {
159161
this.args.onClose(event);
160162
}
161163

162164
this._performCloseCleanup();
163-
}
165+
};
164166

165-
@action
166-
open(): void {
167+
open = (): void => {
167168
// Make flyout dialog visible using the native `showModal` method
168169
this._element.showModal();
169170
this._isOpen = true;
@@ -175,11 +176,9 @@ export default class HdsFlyout extends Component<HdsFlyoutSignature> {
175176
if (this.args.onOpen && typeof this.args.onOpen === 'function') {
176177
this.args.onOpen();
177178
}
178-
}
179+
};
179180

180-
@action
181-
// eslint-disable-next-line @typescript-eslint/require-await
182-
async onDismiss(): Promise<void> {
181+
onDismiss = (): void => {
183182
// allow ember test helpers to be aware of when the `close` event fires
184183
// when using `click` or other helpers from '@ember/test-helpers'
185184
if (this._element.open) {
@@ -193,5 +192,62 @@ export default class HdsFlyout extends Component<HdsFlyoutSignature> {
193192

194193
// Make flyout dialog invisible using the native `close` method
195194
this._element.close();
196-
}
195+
};
196+
197+
<template>
198+
<HdsDialogPrimitiveWrapper
199+
class={{this.classNames}}
200+
...attributes
201+
aria-labelledby={{this.id}}
202+
{{this._registerDialog}}
203+
{{focusTrap
204+
isActive=this._isOpen
205+
focusTrapOptions=(hash
206+
onDeactivate=this.onDismiss clickOutsideDeactivates=true
207+
)
208+
}}
209+
>
210+
<:header>
211+
{{yield
212+
(hash
213+
Header=(component
214+
HdsDialogPrimitiveHeader
215+
id=this.id
216+
onDismiss=this.onDismiss
217+
contextualClassPrefix="hds-flyout"
218+
titleTag="h1"
219+
)
220+
Description=(component
221+
HdsDialogPrimitiveDescription
222+
contextualClass="hds-flyout__description"
223+
)
224+
)
225+
}}
226+
</:header>
227+
<:body>
228+
{{yield
229+
(hash
230+
Body=(component
231+
HdsDialogPrimitiveBody contextualClass="hds-flyout__body"
232+
)
233+
)
234+
}}
235+
</:body>
236+
<:footer>
237+
{{yield
238+
(hash
239+
Footer=(component
240+
HdsDialogPrimitiveFooter
241+
onDismiss=this.onDismiss
242+
contextualClass="hds-flyout__footer"
243+
)
244+
)
245+
}}
246+
</:footer>
247+
</HdsDialogPrimitiveWrapper>
248+
249+
{{#if this._isOpen}}
250+
<HdsDialogPrimitiveOverlay @contextualClass="hds-flyout__overlay" />
251+
{{/if}}
252+
</template>
197253
}

packages/components/src/components/hds/flyout/index.hbs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)