Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popover improvements #730

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/swirl-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,7 @@ export namespace Components {
"parentScrollContainer"?: HTMLElement;
"setAriaAttributes"?: boolean;
"swirlPopover": string | HTMLSwirlPopoverElement;
"triggerOnClick"?: boolean;
"triggerOnHover"?: boolean;
}
interface SwirlProgressIndicator {
Expand Down Expand Up @@ -5925,6 +5926,7 @@ declare namespace LocalJSX {
"parentScrollContainer"?: HTMLElement;
"setAriaAttributes"?: boolean;
"swirlPopover": string | HTMLSwirlPopoverElement;
"triggerOnClick"?: boolean;
"triggerOnHover"?: boolean;
}
interface SwirlProgressIndicator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class SwirlPopoverTrigger {
@Prop() parentScrollContainer?: HTMLElement;
@Prop() setAriaAttributes?: boolean = true;
@Prop() swirlPopover!: string | HTMLSwirlPopoverElement;
@Prop() triggerOnClick?: boolean = true;
@Prop() triggerOnHover?: boolean = false;
@Prop() hoverLingerDuration?: number;
@Prop() hoverDelay?: number;
Expand Down Expand Up @@ -59,6 +60,12 @@ export class SwirlPopoverTrigger {
this.updateTriggerElAriaAttributes();
}

@Watch("triggerOnHover")
watchHover() {
clearTimeout(this.hoverDelayReference);
clearTimeout(this.hoverLingerReference);
}

private getPopoverEl() {
return typeof this.swirlPopover === "string"
? document.querySelector<HTMLSwirlPopoverElement>(`#${this.swirlPopover}`)
Expand Down Expand Up @@ -110,7 +117,9 @@ export class SwirlPopoverTrigger {

this.hoverDelayReference = setTimeout(() => {
this.hoverDelayReference = undefined;
this.mouseenterHandler();
if (this.triggerOnHover) {
this.mouseenterHandler();
}
}, this.hoverDelay);
};

Expand Down Expand Up @@ -139,9 +148,7 @@ export class SwirlPopoverTrigger {

private onMouseleave = () => {
clearTimeout(this.hoverDelayReference);
if (!Boolean(this.hoverDelayReference)) {
this.mouseleaveHandler();
}
this.mouseleaveHandler();
};

private mouseleaveHandler = () => {
Expand All @@ -152,7 +159,9 @@ export class SwirlPopoverTrigger {
private startHoverLingerTimer() {
clearTimeout(this.hoverLingerReference);
this.hoverLingerReference = setTimeout(() => {
this.getPopoverEl().close(true);
if (this.triggerIsActive && this.isPopoverOpen()) {
this.getPopoverEl().close(true);
}
this.triggerIsActive = false;
}, this.hoverLingerDuration);
}
Expand All @@ -162,6 +171,8 @@ export class SwirlPopoverTrigger {
}

private onClick = () => {
if (!this.triggerOnClick) return;

const popoverEl = this.getPopoverEl();
const triggerEl = this.getTriggerEl();

Expand Down
4 changes: 4 additions & 0 deletions packages/swirl-components/vscode-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -12831,6 +12831,10 @@
"name": "swirl-popover",
"description": ""
},
{
"name": "trigger-on-click",
"description": ""
},
{
"name": "trigger-on-hover",
"description": ""
Expand Down
Binary file modified packages/swirl-icons/dart/lib/fonts/flip-legacy-icons.ttf
Binary file not shown.
Binary file modified packages/swirl-icons/dart/lib/fonts/swirl-icons.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/swirl-tokens/dart/lib/styles.dark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

// Do not edit directly
// Generated on Wed, 05 Jun 2024 10:14:18 GMT
// Generated on Fri, 07 Jun 2024 14:29:24 GMT



Expand Down
2 changes: 1 addition & 1 deletion packages/swirl-tokens/dart/lib/styles.light.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

// Do not edit directly
// Generated on Wed, 05 Jun 2024 10:14:18 GMT
// Generated on Fri, 07 Jun 2024 14:29:24 GMT



Expand Down
Loading