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

feat: popover plugin support #475

Merged
merged 8 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@spectrum-web-components/menu": "0.43.0",
"@spectrum-web-components/overlay": "0.43.0",
"@spectrum-web-components/picker": "0.43.0",
"@spectrum-web-components/popover": "0.43.0",
Copy link
Member Author

@dylandepass dylandepass Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already a transient dependancy, added to make eslint happy.

"@spectrum-web-components/progress-circle": "0.43.0",
"@spectrum-web-components/search": "0.43.0",
"@spectrum-web-components/status-light": "0.43.0",
Expand Down
12 changes: 12 additions & 0 deletions src/extension/app/components/plugin/plugin-action-bar.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ export const style = css`
opacity: 0.5;
}

action-bar overlay-trigger sp-popover .content {
padding: 10px;
height: 100%;
}

action-bar overlay-trigger sp-popover .content iframe {
width: 100%;
height: 100%;
border: 0;
color-scheme: auto;
}

#plugin-menu sp-menu-group [slot="header"] {
text-transform: uppercase;
font-size: var(--spectrum-global-dimension-font-size-75);
Expand Down
27 changes: 26 additions & 1 deletion src/extension/app/components/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/* eslint-disable max-len */

import { html } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';
import { EXTERNAL_EVENTS } from '../../constants.js';

/**
Expand Down Expand Up @@ -150,6 +151,14 @@
return this.config.isBadge;
}

/**
* Is this plugin a popover?
* @returns {boolean} True if the plugin is a popover
*/
isPopover() {
return this.config.isPopover;
}

/**
* Adds a plugin to this plugin's children.
* @param {Plugin} plugin The plugin to add
Expand Down Expand Up @@ -257,13 +266,29 @@
`;
}

if (this.isPopover() && this.config.url) {
const src = new URL(this.config.url);
src.searchParams.set('theme', this.appStore.theme);
return html`

Check warning on line 272 in src/extension/app/components/plugin/plugin.js

View check run for this annotation

Codecov / codecov/patch

src/extension/app/components/plugin/plugin.js#L270-L272

Added lines #L270 - L272 were not covered by tests
<overlay-trigger receivesFocus="true" offset="-3">
<sk-action-button quiet slot="trigger">${this.getButtonText()}</sk-action-button>
<sp-popover slot="click-content" placement="top" tip style=${ifDefined(this.config.popoverRect)}>
<div class="content">
<iframe title="Popover content" src=${src}></iframe>
</div>
</sp-popover>
</overlay-trigger>`;
}

return html`
<sk-action-button
class=${this.getId()}
.disabled=${!this.isEnabled()}
quiet
@click=${(evt) => this.onButtonClick(evt)}
>${this.getButtonText()}</sk-action-button>
>
${this.getButtonText()}
</sk-action-button>
`;
}

Expand Down
5 changes: 5 additions & 0 deletions src/extension/app/store/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ export class AppStore {
passConfig,
passReferrer,
isPalette,
isPopover,
popoverRect,
event: eventName,
environments,
excludePaths,
Expand Down Expand Up @@ -417,7 +419,10 @@ export class AppStore {
pinned,
confirm,
container: containerId,
url,
isBadge,
isPopover,
popoverRect,
badgeVariant,
};

Expand Down
2 changes: 2 additions & 0 deletions src/extension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import '@spectrum-web-components/divider/sp-divider.js';
import '@spectrum-web-components/dialog/sp-dialog-base.js';
import '@spectrum-web-components/menu/sp-menu-divider.js';
import '@spectrum-web-components/overlay/sp-overlay.js';
import '@spectrum-web-components/overlay/overlay-trigger.js';
import '@spectrum-web-components/popover/sp-popover.js';
import '@spectrum-web-components/picker/sp-picker.js';
import '@spectrum-web-components/status-light/sp-status-light.js';
import '@spectrum-web-components/switch/sp-switch.js';
Expand Down
2 changes: 2 additions & 0 deletions src/extension/types/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
* @prop {boolean} [isContainer] Determines whether to turn this plugin into a dropdown
* @prop {boolean} [isPalette] Determines whether a URL is opened in a palette instead of a new tab
* @prop {string} [paletteRect] The dimensions and position of a palette (optional)
* @prop {boolean} [isPopover] Determines whether a URL is opened in a popover instead of a new tab
* @prop {string} [popoverRect] The dimensions and position of a popover (optional)
* @prop {boolean} [isBadge] Determines whether the plugin is a badge (optional)
* @prop {string} [badgeVariant] The color variant of the badge (optional)
* @prop {string[]} [environments] Specifies when to show this plugin (admin, edit, dev, preview, live, prod)
Expand Down