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(components): popover #2109

Merged
merged 50 commits into from
Dec 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
93d48b4
feat: added post-popover and post-popup components
gfellerph Oct 18, 2023
d0170f0
fix: popoverRef should be set
gfellerph Oct 18, 2023
c96d199
fix: refactor unnecessary no pointer events
gfellerph Oct 18, 2023
75d968e
feat: improve popover base component
gfellerph Oct 20, 2023
bea295d
fix: improve event handling
gfellerph Oct 20, 2023
c9d2131
refactor: add elevation mixin for usage in components
gfellerph Oct 20, 2023
7c9747b
fix: close button should have pointer cursor
gfellerph Oct 20, 2023
d04145b
docs: add popup story
gfellerph Oct 20, 2023
12235eb
chore: add component types to cypress tests
gfellerph Oct 20, 2023
3eb06f5
test: add tests for popup
gfellerph Oct 20, 2023
d70f248
fix: remove fallbackAxisSideDirection
gfellerph Oct 20, 2023
d70cec8
refactor: rename post-popover to post-popovercontainer
gfellerph Oct 26, 2023
90eca1a
chore: fix types
gfellerph Oct 26, 2023
772f06c
refactor: rename post-popup to post-popover
gfellerph Oct 26, 2023
4d116de
test: fix specs
gfellerph Oct 26, 2023
a6d0b99
chore(header): fix linting issues
gfellerph Oct 26, 2023
2f9e621
chore: fix code smell
gfellerph Oct 26, 2023
f8eb981
chore: add changeset
gfellerph Oct 26, 2023
3e3fe64
chore: fix linting
gfellerph Oct 26, 2023
245fcb6
Merge branch 'main' into popup-component
gfellerph Oct 26, 2023
464ae8b
Merge branch 'main' into popup-component
gfellerph Oct 30, 2023
b93bb4a
fix(e2e): Revert vite 4.11 upgrade
imagoiq Oct 30, 2023
2729a93
chore: update generated files
gfellerph Oct 31, 2023
a77a84d
test: add tests for post-popovercontainer
gfellerph Oct 31, 2023
71493ae
Merge branch 'main' into popup-component
gfellerph Oct 31, 2023
5e673d1
Update packages/components/cypress/e2e/popover.cy.ts
gfellerph Nov 2, 2023
13fd523
Update packages/components/src/components/post-popovercontainer/post-…
gfellerph Nov 2, 2023
5c21efa
Update packages/components/src/components/post-popovercontainer/post-…
gfellerph Nov 2, 2023
342544d
Update packages/components/src/components/post-popovercontainer/post-…
gfellerph Nov 9, 2023
6f4f2a2
Merge branch 'main' into popup-component
gfellerph Nov 24, 2023
27436b1
update popover styles and set required props
gfellerph Nov 24, 2023
15645f7
fix firefox popovers
gfellerph Nov 24, 2023
295cf7b
Merge branch 'main' into popup-component
imagoiq Nov 30, 2023
244e2f5
Merge branch 'main' into popup-component
imagoiq Nov 30, 2023
d914021
Merge branch 'main' into popup-component
imagoiq Nov 30, 2023
e6610de
fix: stop pointerup/down propagation for firefox
gfellerph Dec 1, 2023
81e669c
Merge branch 'main' into popup-component
gfellerph Dec 4, 2023
f314814
Merge branch 'main' into popup-component
gfellerph Dec 4, 2023
778c5af
fix: keep font-size and padding flexible and context aware
gfellerph Dec 4, 2023
aacdcc0
fix: set aria-expanded when toggling
gfellerph Dec 4, 2023
aa988cb
feat: return new state when toggling popovercontainer
gfellerph Dec 4, 2023
3571b42
feat: add title option to story, wrap content
gfellerph Dec 4, 2023
ea51ecf
chore: add start:clean command to root package.json
gfellerph Dec 4, 2023
f784fef
chore: does not belong here
gfellerph Dec 5, 2023
99aa577
tests: use fixture for popover tests
gfellerph Dec 6, 2023
01d5270
tests: fix popover tests
gfellerph Dec 6, 2023
08c38c6
chore: clean up index.html
gfellerph Dec 6, 2023
5d7fb97
fix: revert popover-polyfill to 0.2.3
gfellerph Dec 6, 2023
272babc
fix: show close button in high contrast mode
gfellerph Dec 6, 2023
4b97847
Merge branch 'main' into popup-component
gfellerph Dec 6, 2023
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
Next Next commit
feat: added post-popover and post-popup components
Also refactored post-tooltip to use post-popover as a base
gfellerph committed Oct 18, 2023
commit 93d48b425f6089fff5eb1e6190b6b9da666cddb3
95 changes: 85 additions & 10 deletions packages/components/src/components.d.ts
Original file line number Diff line number Diff line change
@@ -6,10 +6,8 @@
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { AlertType } from "./components/post-alert/alert-types";
import { BackgroundColor } from "./components/post-tooltip/types";
import { Placement } from "@floating-ui/dom";
export { AlertType } from "./components/post-alert/alert-types";
export { BackgroundColor } from "./components/post-tooltip/types";
export { Placement } from "@floating-ui/dom";
export namespace Components {
interface PostAlert {
@@ -85,6 +83,52 @@ export namespace Components {
*/
"scale"?: number | null;
}
interface PostPopover {
/**
* Wheter or not to display a little pointer arrow
*/
"arrow"?: boolean;
/**
* Programmatically hide this tooltip
*/
"hide": () => Promise<void>;
/**
* Defines the placement of the tooltip according to the floating-ui options available at https://floating-ui.com/docs/computePosition#placement. Tooltips are automatically flipped to the opposite side if there is not enough available space and are shifted towards the viewport if they would overlap edge boundaries.
*/
"placement"?: Placement;
/**
* Programmatically display the tooltip
* @param target An element with [data-tooltip-target="id"] where the tooltip should be shown
*/
"show": (target: HTMLElement) => Promise<void>;
/**
* Toggle tooltip display
* @param target An element with [data-tooltip-target="id"] where the tooltip should be shown
* @param force Pass true to always show or false to always hide
*/
"toggle": (target: HTMLElement, force?: boolean) => Promise<void>;
}
interface PostPopup {
/**
* Programmatically hide this popup
*/
"hide": () => Promise<void>;
/**
* Defines the placement of the popup according to the floating-ui options available at https://floating-ui.com/docs/computePosition#placement. Popups are automatically flipped to the opposite side if there is not enough available space and are shifted towards the viewport if they would overlap edge boundaries.
*/
"placement"?: Placement;
/**
* Programmatically display the popup
* @param target An element with [data-popup-target="id"] where the popup should be shown
*/
"show": (target: HTMLElement) => Promise<void>;
/**
* Toggle popup display
* @param target An element with [data-popup-target="id"] where the popup should be anchored to
* @param force Pass true to always show or false to always hide
*/
"toggle": (target: HTMLElement, force?: boolean) => Promise<void>;
}
interface PostTabHeader {
/**
* The name of the panel controlled by the tab header.
@@ -108,10 +152,6 @@ export namespace Components {
"show": (panelName: string) => Promise<void>;
}
interface PostTooltip {
/**
* Defines the background color of the tooltip. Choose the one that provides the best contrast in your scenario.
*/
"backgroundColor"?: BackgroundColor;
/**
* Programmatically hide this tooltip
*/
@@ -137,6 +177,10 @@ export interface PostAlertCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLPostAlertElement;
}
export interface PostPopoverCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLPostPopoverElement;
}
export interface PostTabsCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLPostTabsElement;
@@ -163,6 +207,18 @@ declare global {
prototype: HTMLPostIconElement;
new (): HTMLPostIconElement;
};
interface HTMLPostPopoverElement extends Components.PostPopover, HTMLStencilElement {
}
var HTMLPostPopoverElement: {
prototype: HTMLPostPopoverElement;
new (): HTMLPostPopoverElement;
};
interface HTMLPostPopupElement extends Components.PostPopup, HTMLStencilElement {
}
var HTMLPostPopupElement: {
prototype: HTMLPostPopupElement;
new (): HTMLPostPopupElement;
};
interface HTMLPostTabHeaderElement extends Components.PostTabHeader, HTMLStencilElement {
}
var HTMLPostTabHeaderElement: {
@@ -191,6 +247,8 @@ declare global {
"post-alert": HTMLPostAlertElement;
"post-collapsible": HTMLPostCollapsibleElement;
"post-icon": HTMLPostIconElement;
"post-popover": HTMLPostPopoverElement;
"post-popup": HTMLPostPopupElement;
"post-tab-header": HTMLPostTabHeaderElement;
"post-tab-panel": HTMLPostTabPanelElement;
"post-tabs": HTMLPostTabsElement;
@@ -267,6 +325,23 @@ declare namespace LocalJSX {
*/
"scale"?: number | null;
}
interface PostPopover {
/**
* Wheter or not to display a little pointer arrow
*/
"arrow"?: boolean;
"onPostPopoverToggled"?: (event: PostPopoverCustomEvent<boolean>) => void;
/**
* Defines the placement of the tooltip according to the floating-ui options available at https://floating-ui.com/docs/computePosition#placement. Tooltips are automatically flipped to the opposite side if there is not enough available space and are shifted towards the viewport if they would overlap edge boundaries.
*/
"placement"?: Placement;
}
interface PostPopup {
/**
* Defines the placement of the popup according to the floating-ui options available at https://floating-ui.com/docs/computePosition#placement. Popups are automatically flipped to the opposite side if there is not enough available space and are shifted towards the viewport if they would overlap edge boundaries.
*/
"placement"?: Placement;
}
interface PostTabHeader {
/**
* The name of the panel controlled by the tab header.
@@ -290,10 +365,6 @@ declare namespace LocalJSX {
"onTabChange"?: (event: PostTabsCustomEvent<HTMLPostTabPanelElement['name']>) => void;
}
interface PostTooltip {
/**
* Defines the background color of the tooltip. Choose the one that provides the best contrast in your scenario.
*/
"backgroundColor"?: BackgroundColor;
/**
* Defines the placement of the tooltip according to the floating-ui options available at https://floating-ui.com/docs/computePosition#placement. Tooltips are automatically flipped to the opposite side if there is not enough available space and are shifted towards the viewport if they would overlap edge boundaries.
*/
@@ -303,6 +374,8 @@ declare namespace LocalJSX {
"post-alert": PostAlert;
"post-collapsible": PostCollapsible;
"post-icon": PostIcon;
"post-popover": PostPopover;
"post-popup": PostPopup;
"post-tab-header": PostTabHeader;
"post-tab-panel": PostTabPanel;
"post-tabs": PostTabs;
@@ -319,6 +392,8 @@ declare module "@stencil/core" {
* @class PostIcon - representing a stencil component
*/
"post-icon": LocalJSX.PostIcon & JSXBase.HTMLAttributes<HTMLPostIconElement>;
"post-popover": LocalJSX.PostPopover & JSXBase.HTMLAttributes<HTMLPostPopoverElement>;
"post-popup": LocalJSX.PostPopup & JSXBase.HTMLAttributes<HTMLPostPopupElement>;
"post-tab-header": LocalJSX.PostTabHeader & JSXBase.HTMLAttributes<HTMLPostTabHeaderElement>;
"post-tab-panel": LocalJSX.PostTabPanel & JSXBase.HTMLAttributes<HTMLPostTabPanelElement>;
"post-tabs": LocalJSX.PostTabs & JSXBase.HTMLAttributes<HTMLPostTabsElement>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@use 'sass:meta';
@use 'sass:math';
@use '@swisspost/design-system-styles/variables/color';
@use '@swisspost/design-system-styles/variables/commons';
@use '@swisspost/design-system-styles/variables/spacing';
@use '@swisspost/design-system-styles/mixins/color' as color-mx;
@use '@swisspost/design-system-styles/functions/color' as color-fn;

// Puts polyfilled styles in a separate layer so they are easy to override
// Can be removed as soon as popover is supported by all major browsers
// https://caniuse.com/?search=popover
@layer polyfill {
@include meta.load-css('@oddbird/popover-polyfill/dist/popover.css');
}

div {
position: absolute;
z-index: commons.$zindex-popover;

width: max-content;
max-width: 30ch;
margin: 0;
padding: 0;

color: var(--post-contrast-color);
background-color: rgb(var(--post-bg-rgb));
border-color: transparent; // Keeping the default border for HCM
border-radius: commons.$border-radius;

// Keeps the little arrow visible
overflow: visible;
}

.arrow {
position: absolute;
// Diagonale of 16px -> 1rem -> 1/1.41 = ~0.7
// https://www.omnicalculator.com/math/square-diagonal?c=CHF&v=hide:0,diagonal:16!cm
width: math.div(spacing.$spacer, math.sqrt(2));
aspect-ratio: 1/1;
background-color: inherit;
rotate: 45deg;
pointer-events: none;
z-index: -1;

// High contrast mode borders
border-right: 2px solid transparent;
border-bottom: 2px solid transparent;
}
Loading