Skip to content

Commit

Permalink
Add cssImports static property to UnlitElement
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih-erikli committed Sep 4, 2023
1 parent 02f8a77 commit f48ec63
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 72 deletions.
12 changes: 12 additions & 0 deletions src/fontra/client/core/unlit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export class SimpleElement extends HTMLElement {
for (const style of this._additionalStyles) {
this._appendStyle(style);
}
if (this.constructor.cssImports) {
for (const link of this.constructor.cssImports) {
this._appendLink(link);
}
}
}

_appendStyle(cssText) {
Expand All @@ -30,6 +35,13 @@ export class SimpleElement extends HTMLElement {
this.shadowRoot.appendChild(styleElement);
}

_appendLink(href) {
const linkElement = document.createElement("link");
linkElement.setAttribute("rel", "stylesheet");
linkElement.setAttribute("href", href);
this.shadowRoot.appendChild(linkElement);
}

appendStyle(cssText) {
this._additionalStyles.push(cssText);
}
Expand Down
71 changes: 71 additions & 0 deletions src/fontra/client/css/tooltip.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[data-title] {
position: relative;
cursor: default;
}

[data-title]:hover::before {
content: attr(data-title);
font-size: 10px;
text-align: center;
position: absolute;
display: block;
left: 200%;
bottom: calc(100% + 6px);
transform: translate(-50%);
background: #272727;
border-radius: 4px;
padding: 8px;
color: #ffffff;
z-index: 1;
opacity: 0;

/* disable when reduced-motion */
animation-name: disappear;
animation-delay: 1000ms;
animation-duration: 6s;
}

[data-title]:hover::after {
content: "";
position: absolute;
display: block;
left: 50%;
width: 0;
height: 0;
bottom: calc(100% + 1px);
margin-left: -4px;
border: 1px solid black;
border-color: #272727 transparent transparent transparent;
border-width: 5px 3px 0;
z-index: 1;
opacity: 0;

/* disable when reduced-motion */
animation-name: disappear;
animation-delay: 1000ms;
animation-duration: 6s;
}

/* disable when reduced-motion */
@keyframes disappear {
0% {
opacity: 1;
}
95% {
opacity: 1;
}
100% {
opacity: 0;
}
}

@media (prefers-reduced-motion) {
[data-title]:hover::before {
opacity: 1;
animation: none;
}
[data-title]:hover::after {
opacity: 1;
animation: none;
}
}
74 changes: 2 additions & 72 deletions src/fontra/client/web-components/icon-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,78 +27,6 @@ export class IconButton extends UnlitElement {
opacity: 35%;
transform: none;
}
[data-title] {
position: relative;
cursor: default;
}
[data-title]:hover::before {
content: attr(data-title);
font-size: 10px;
text-align: center;
position: absolute;
display: block;
left: 200%;
bottom: calc(100% + 6px);
transform: translate(-50%);
background: #272727;
border-radius: 4px;
padding: 8px;
color: #ffffff;
z-index: 1;
opacity: 0;
/* disable when reduced-motion */
animation-name: disappear;
animation-delay: 1000ms;
animation-duration: 6s;
}
[data-title]:hover::after {
content: "";
position: absolute;
display: block;
left: 50%;
width: 0;
height: 0;
bottom: calc(100% + 1px);
margin-left: -4px;
border: 1px solid black;
border-color: #272727 transparent transparent transparent;
border-width: 5px 3px 0;
z-index: 1;
opacity: 0;
/* disable when reduced-motion */
animation-name: disappear;
animation-delay: 1000ms;
animation-duration: 6s;
}
/* disable when reduced-motion */
@keyframes disappear {
0% {
opacity: 1;
}
95% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@media (prefers-reduced-motion) {
[data-title]:hover::before {
opacity: 1;
animation: none;
}
[data-title]:hover::after {
opacity: 1;
animation: none;
}
}
`;

constructor(src) {
Expand All @@ -108,6 +36,8 @@ export class IconButton extends UnlitElement {
}
}

static cssImports = ["/css/tooltip.css"];

static properties = {
src: { type: String },
title: { type: String },
Expand Down

0 comments on commit f48ec63

Please sign in to comment.