-
Notifications
You must be signed in to change notification settings - Fork 65
Added message stream to popover #1978
Changes from all commits
59826a6
cc62130
62d03a0
ccc374d
425f3dd
6ded148
e6554f6
c62aae7
ff05837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -391,3 +391,28 @@ <h3> | |
<sky-popover #asyncPopover> | ||
My asynchronous popover. | ||
</sky-popover> | ||
|
||
<h3> | ||
Popovers may be interacted with programatically | ||
</h3> | ||
|
||
<p> | ||
<button | ||
type="button" | ||
class="sky-btn sky-btn-default" | ||
[skyPopover]="programaticPopover" | ||
Blackbaud-TrevorBurch marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "programmatic" |
||
[skyPopoverMessageStream]="popoverController"> | ||
Open popover via click | ||
</button> | ||
|
||
|
||
<button | ||
type="button" | ||
class="sky-btn sky-btn-default" | ||
(click)="openPopover()"> | ||
Open popover programatically | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "programmatically" |
||
</button> | ||
</p> | ||
<sky-popover #programaticPopover> | ||
This popover has a programatic trigger on the second button. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "programmatic" |
||
</sky-popover> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ import { | |
import { | ||
SkyPopoverComponent | ||
} from '../../core'; | ||
import { SkyPopoverMessageType } from '../../modules/popover/types/popover-message-type'; | ||
import { SkyPopoverMessage } from '../../modules/popover/types/popover-message'; | ||
import { Subject } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'sky-popover-demo', | ||
|
@@ -22,6 +25,8 @@ export class SkyPopoverDemoComponent { | |
@ViewChild('asyncPopover') | ||
public asyncPopover: SkyPopoverComponent; | ||
|
||
public popoverController = new Subject<SkyPopoverMessage>(); | ||
|
||
constructor() { | ||
setTimeout(() => { | ||
this.asyncPopoverRef = this.asyncPopover; | ||
|
@@ -35,4 +40,16 @@ export class SkyPopoverDemoComponent { | |
public onPopoverClosed(popoverComponent: any) { | ||
alert('The popover was closed: ' + popoverComponent.popoverTitle); | ||
} | ||
|
||
public openPopover() { | ||
this.sendMessage(SkyPopoverMessageType.Open); | ||
setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is causing some strange behavior in the demo. I would isolate this to two separate buttons, "Open" and "Close". |
||
this.sendMessage(SkyPopoverMessageType.Close); | ||
}, 5000); | ||
} | ||
|
||
private sendMessage(type: SkyPopoverMessageType) { | ||
const message: SkyPopoverMessage = { type }; | ||
this.popoverController.next(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -23,6 +23,8 @@ import { | |||
} from './types'; | ||||
|
||||
import { SkyPopoverComponent } from './popover.component'; | ||||
import { SkyPopoverMessage } from './types/popover-message'; | ||||
import { SkyPopoverMessageType } from './types/popover-message-type'; | ||||
|
||||
@Directive({ | ||||
selector: '[skyPopover]' | ||||
|
@@ -40,6 +42,9 @@ export class SkyPopoverDirective implements OnChanges, OnDestroy { | |||
@Input() | ||||
public skyPopoverTrigger: SkyPopoverTrigger = 'click'; | ||||
|
||||
@Input() | ||||
public skyPopoverMessageStream = new Subject<SkyPopoverMessage>(); | ||||
|
||||
private idled = new Subject<boolean>(); | ||||
|
||||
constructor( | ||||
|
@@ -59,6 +64,7 @@ export class SkyPopoverDirective implements OnChanges, OnDestroy { | |||
|
||||
public ngOnDestroy(): void { | ||||
this.removeEventListeners(); | ||||
this.idled.complete(); | ||||
} | ||||
|
||||
public togglePopover() { | ||||
|
@@ -97,6 +103,12 @@ export class SkyPopoverDirective implements OnChanges, OnDestroy { | |||
private addEventListeners() { | ||||
const element = this.elementRef.nativeElement; | ||||
|
||||
this.skyPopoverMessageStream | ||||
.takeUntil(this.idled) | ||||
.subscribe(message => { | ||||
this.handleIncomingMessages(message); | ||||
}); | ||||
|
||||
Observable | ||||
.fromEvent(element, 'keyup') | ||||
.takeUntil(this.idled) | ||||
|
@@ -159,4 +171,24 @@ export class SkyPopoverDirective implements OnChanges, OnDestroy { | |||
this.idled.unsubscribe(); | ||||
this.idled = new Subject<boolean>(); | ||||
} | ||||
|
||||
private handleIncomingMessages(message: SkyPopoverMessage) { | ||||
/* tslint:disable-next-line:switch-default */ | ||||
switch (message.type) { | ||||
case SkyPopoverMessageType.Open: | ||||
this.positionPopover(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to make sure that the popover itself uses the message stream to open/close/position so that consumers can interrupt the message stream as they see fit. For example, you would replace
...with this.sendMessage(SkyPopoverMessageType.Open) ;
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dropdown does it this way too: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue created: #1994 |
||||
break; | ||||
|
||||
case SkyPopoverMessageType.Close: | ||||
this.closePopover(); | ||||
break; | ||||
|
||||
case SkyPopoverMessageType.Reposition: | ||||
// Only reposition the popover if it is already open. | ||||
if (this.isPopoverOpen()) { | ||||
this.positionPopover(); | ||||
} | ||||
break; | ||||
} | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum SkyPopoverMessageType { | ||
Open = 0, | ||
Close = 1, | ||
Reposition = 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { SkyPopoverMessageType } from './popover-message-type'; | ||
|
||
export interface SkyPopoverMessage { | ||
type?: SkyPopoverMessageType; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"programmatically"