Skip to content

Commit

Permalink
Use anchor positioning for copyable source
Browse files Browse the repository at this point in the history
To prevent overflow issue with tooltips and the source copy button
caused by `position: relative`, use anchors instead (and add a polyfill).
  • Loading branch information
hojberg committed Jan 7, 2025
1 parent adafca5 commit d4510ca
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 4 deletions.
152 changes: 152 additions & 0 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 @@ -30,6 +30,7 @@
"prettier": "^2.8.4"
},
"dependencies": {
"@oddbird/css-anchor-positioning": "^0.4.0",
"date-fns": "^2.29.3",
"katex": "^0.16.4",
"mermaid": "^10.6.1"
Expand Down
5 changes: 5 additions & 0 deletions src/UI/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import polyfill from '@oddbird/css-anchor-positioning/fn';

if (!("anchorName" in document.documentElement.style)) {
polyfill();
}
9 changes: 5 additions & 4 deletions src/css/code/definition-doc.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,17 @@
}

.definition-doc .copyable-source {
position: relative;
anchor-name: --copyable-source;
}

.definition-doc .copyable-source .copy-on-click {
position-anchor: --copyable-source;
position: absolute;
top: 0;
right: 0;
display: none;
top: anchor(0%);
right: anchor(100%);
background: var(--u-color_action);
border-radius: var(--border-radius-base);
display: none;
}

.definition-doc .copyable-source:hover .copy-on-click {
Expand Down

0 comments on commit d4510ca

Please sign in to comment.