Skip to content

Commit d035d4e

Browse files
committed
refactor(tile): Dragging from head bound to title part
1 parent ec380c9 commit d035d4e

File tree

1 file changed

+58
-51
lines changed

1 file changed

+58
-51
lines changed

src/components/tile-manager/tile.ts

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LitElement, html, nothing } from 'lit';
22
import { property, query, state } from 'lit/decorators.js';
3+
import { createRef, ref } from 'lit/directives/ref.js';
34
import { styleMap } from 'lit/directives/style-map.js';
45
import { startViewTransition } from '../../animations/player.js';
56
import { themes } from '../../theming/theming-decorator.js';
@@ -127,7 +128,8 @@ export default class IgcTileComponent extends EventEmitterMixin<
127128
}: TileManagerContext) => {
128129
this._dragController.setConfig({
129130
enabled: !this.disableDrag && dragMode !== 'none',
130-
trigger: dragMode === 'tile-header' ? () => this._header : undefined,
131+
trigger:
132+
dragMode === 'tile-header' ? () => this._headerRef.value! : undefined,
131133
});
132134
};
133135

@@ -159,8 +161,7 @@ export default class IgcTileComponent extends EventEmitterMixin<
159161
: true;
160162
}
161163

162-
@query('[part="header"]')
163-
protected _header!: HTMLDivElement;
164+
protected _headerRef = createRef<HTMLSlotElement>();
164165

165166
@query(IgcResizeContainerComponent.tagName)
166167
protected _resizeContainer?: IgcResizeContainerComponent;
@@ -494,34 +495,53 @@ export default class IgcTileComponent extends EventEmitterMixin<
494495
});
495496
}
496497

497-
protected _renderAction({
498-
icon,
499-
handler,
500-
}: {
501-
icon: string;
502-
handler: () => unknown;
503-
}) {
498+
protected _renderDefaultAction(type: 'maximize' | 'fullscreen') {
499+
const [icon, listener] =
500+
type === 'fullscreen'
501+
? [
502+
this.fullscreen ? 'fullscreen_exit' : 'fullscreen',
503+
this._handleFullscreen,
504+
]
505+
: [
506+
this._maximized ? 'collapse_content' : 'expand_content',
507+
this._handleMaximize,
508+
];
509+
504510
return html`
505511
<igc-icon-button
506512
variant="flat"
507513
collection="default"
508514
exportparts="icon"
509515
name=${icon}
510516
aria-label=${icon}
511-
@click=${handler}
517+
@click=${listener}
512518
></igc-icon-button>
513519
`;
514520
}
515521

522+
protected _renderHeader() {
523+
return html`
524+
<div part="header">
525+
<slot ${ref(this._headerRef)} part="title" name="title"></slot>
526+
<section part="actions">
527+
<slot name="default-actions">
528+
<slot name="maximize-action">
529+
${this.fullscreen
530+
? nothing
531+
: this._renderDefaultAction('maximize')}
532+
</slot>
533+
<slot name="fullscreen-action">
534+
${this._renderDefaultAction('fullscreen')}
535+
</slot>
536+
</slot>
537+
<slot name="actions"></slot>
538+
</section>
539+
</div>
540+
<igc-divider></igc-divider>
541+
`;
542+
}
543+
516544
protected _renderContent() {
517-
const maximize = {
518-
icon: this.maximized ? 'collapse_content' : 'expand_content',
519-
handler: this._handleMaximize,
520-
};
521-
const fullscreen = {
522-
icon: this.fullscreen ? 'fullscreen_exit' : 'fullscreen',
523-
handler: this._handleFullscreen,
524-
};
525545
const parts = partNameMap({
526546
base: true,
527547
'drag-over': this._hasDragOver && !this._isSlideMode,
@@ -542,48 +562,35 @@ export default class IgcTileComponent extends EventEmitterMixin<
542562

543563
return html`
544564
<div part=${parts} .inert=${this._hasDragOver} style=${styleMap(styles)}>
545-
<div part="header">
546-
<slot part="title" name="title"></slot>
547-
<section part="actions">
548-
<slot name="default-actions">
549-
<slot name="maximize-action">
550-
${!this.fullscreen ? this._renderAction(maximize) : nothing}
551-
</slot>
552-
<slot name="fullscreen-action">
553-
${this._renderAction(fullscreen)}
554-
</slot>
555-
</slot>
556-
<slot name="actions"></slot>
557-
</section>
558-
</div>
559-
<igc-divider></igc-divider>
560-
565+
${this._renderHeader()}
561566
<div part="content-container">
562567
<slot></slot>
563568
</div>
564569
</div>
565570
`;
566571
}
567572

568-
protected override render() {
569-
const active = this._resizeMode === 'always';
573+
protected _renderResizeContainer() {
574+
return html`
575+
<igc-resize
576+
part="resize"
577+
mode="deferred"
578+
?active=${this._resizeMode === 'always'}
579+
.ghostFactory=${createTileGhost}
580+
@igcResizeStart=${this._handleResizeStart}
581+
@igcResize=${this._handleResize}
582+
@igcResizeEnd=${this._handleResizeEnd}
583+
@igcResizeCancel=${this._handleResizeCancel}
584+
>
585+
${this._renderContent()}
586+
</igc-resize>
587+
`;
588+
}
570589

590+
protected override render() {
571591
return this._resizeDisabled
572592
? this._renderContent()
573-
: html`
574-
<igc-resize
575-
part="resize"
576-
mode="deferred"
577-
?active=${active}
578-
.ghostFactory=${createTileGhost}
579-
@igcResizeStart=${this._handleResizeStart}
580-
@igcResize=${this._handleResize}
581-
@igcResizeEnd=${this._handleResizeEnd}
582-
@igcResizeCancel=${this._handleResizeCancel}
583-
>
584-
${this._renderContent()}
585-
</igc-resize>
586-
`;
593+
: this._renderResizeContainer();
587594
}
588595
}
589596

0 commit comments

Comments
 (0)