55
66import Component from ' @glimmer/component' ;
77import { tracked } from ' @glimmer/tracking' ;
8- import { action } from '@ember/object' ;
98import { assert } from ' @ember/debug' ;
10- import { getElementId } from '../../../utils/hds-get-element-id.ts' ;
119import { buildWaiter } from ' @ember/test-waiters' ;
12- import type { WithBoundArgs } from '@glint/template' ;
1310import { 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
1717import { 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
2328const 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}
0 commit comments