Skip to content

Commit

Permalink
updated [popover][anchor] related code
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDoge committed Nov 20, 2024
1 parent f7be813 commit 8efa19a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
27 changes: 21 additions & 6 deletions project/app/src/app/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,35 @@ document.adoptedStyleSheets.push(
[popover] {
max-block-size: 100dvb;
max-inline-size: 100%;
inset: 0;
margin: auto;
}
[popover][anchor] {
margin: 0;
inset: 0;
inset: auto;
position-area: span-inline-start block-end;
position: absolute;
inset-inline-end: anchor(end);
inset-block-start: anchor(end);
position-try:
flip-inline,
flip-block,
flip-block flip-inline;
flip-inline,
flip-block flip-inline,
--final-block-start,
--final-block-end;
}
inline-size: max-content;
max-inline-size: 100dvi;
@position-try --final-block-start {
inset: auto;
inset-inline-end: 0;
inset-block-end: anchor(start);
}
@position-try --final-block-end {
inset: auto;
inset-inline-end: 0;
inset-block-start: anchor(end);
}
dialog::backdrop {
Expand Down
44 changes: 21 additions & 23 deletions project/app/src/features/feed/components/SelectSenderButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,29 @@ export function SelectSenderButton(params?: {
},
}).element;

return (
button()
.type("button")
.effect(useScope(SelectSenderButtonCss))
/* .effect((element) => { // Missing browser support
return button()
.type("button")
.effect(useScope(SelectSenderButtonCss))
.effect((element) => {
selectSenderPopover.anchorElement = element;
}) */
.ariaDescription("Currently selected sender contract, click to change.")
.popoverTargetElement(selectSenderPopover)
.effect((element) => {
element.after(selectSenderPopover);
return () => {
selectSenderPopover.remove();
};
})
.children(
selectedSender.derive((sender) => {
if (!sender) {
return "Select Sender";
}
})
.ariaDescription("Currently selected sender contract, click to change.")
.popoverTargetElement(selectSenderPopover)
.effect((element) => {
element.after(selectSenderPopover);
return () => {
selectSenderPopover.remove();
};
})
.children(
selectedSender.derive((sender) => {
if (!sender) {
return "Select Sender";
}

return fragment(img().src(sender.network.iconSrc), sender.key);
}),
)
);
return fragment(img().src(sender.network.iconSrc), sender.key);
}),
);
}

const SelectSenderButtonCss = css`
Expand Down
5 changes: 5 additions & 0 deletions project/app/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ declare global {
(value: bigint): `${bigint}`;
(value: boolean): `${boolean}`;
}

interface HTMLElement {
// If browser doesnt support it, popover just appears at the center, which is ok.
anchorElement?: HTMLElement;
}
}

0 comments on commit 8efa19a

Please sign in to comment.