-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor: refactor overlay styling to use css class #4861
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
// styles are inspired by `react-error-overlay` | ||
|
||
const msgStyles = { | ||
error: { | ||
backgroundColor: "rgba(206, 17, 38, 0.1)", | ||
color: "#fccfcf", | ||
}, | ||
warning: { | ||
backgroundColor: "rgba(251, 245, 180, 0.1)", | ||
color: "#fbf5b4", | ||
}, | ||
}; | ||
// The class names are quite generic, but it should be fine since they are | ||
// scoped to the iframe only. | ||
|
||
const iframeStyle = { | ||
position: "fixed", | ||
|
@@ -24,58 +16,131 @@ const iframeStyle = { | |
}; | ||
|
||
const containerStyle = { | ||
position: "fixed", | ||
boxSizing: "border-box", | ||
left: 0, | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
width: "100vw", | ||
height: "100vh", | ||
fontSize: "large", | ||
padding: "2rem 2rem 4rem 2rem", | ||
lineHeight: "1.2", | ||
whiteSpace: "pre-wrap", | ||
overflow: "auto", | ||
backgroundColor: "rgba(0, 0, 0, 0.9)", | ||
color: "white", | ||
className: "webpack-container", | ||
css: /* css */ `.webpack-container { | ||
position: fixed; | ||
box-sizing: border-box; | ||
left: 0; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
font-size: large; | ||
padding: 2rem 2rem 4rem 2rem; | ||
line-height: 1.2; | ||
white-space: pre-wrap; | ||
overflow: auto; | ||
background-color: rgba(0, 0, 0, 0.9); | ||
color: white; | ||
} | ||
`, | ||
}; | ||
|
||
const headerStyle = { | ||
color: "#e83b46", | ||
fontSize: "2em", | ||
whiteSpace: "pre-wrap", | ||
fontFamily: "sans-serif", | ||
margin: "0 2rem 2rem 0", | ||
flex: "0 0 auto", | ||
maxHeight: "50%", | ||
overflow: "auto", | ||
className: "webpack-header", | ||
css: /* css */ `.webpack-header { | ||
color: #e83b46; | ||
font-size: 2em; | ||
font-family: sans-serif; | ||
white-space: pre-wrap; | ||
margin: 0 2rem 2rem 0; | ||
flex: 0 0 auto; | ||
max-height: 50%; | ||
overflow: auto; | ||
} | ||
`, | ||
}; | ||
|
||
const dismissButtonStyle = { | ||
color: "#ffffff", | ||
lineHeight: "1rem", | ||
fontSize: "1.5rem", | ||
padding: "1rem", | ||
cursor: "pointer", | ||
position: "absolute", | ||
right: 0, | ||
top: 0, | ||
backgroundColor: "transparent", | ||
border: "none", | ||
className: "webpack-dismiss-btn", | ||
css: /* css */ `.webpack-dismiss-btn { | ||
color: #ffffff; | ||
line-height: 1rem; | ||
font-size: 1.5rem; | ||
padding: 1rem; | ||
cursor: pointer; | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
background-color: transparent; | ||
border: none; | ||
} | ||
|
||
.webpack-dismiss-btn:hover { | ||
color: #d1d5db; | ||
}`, | ||
}; | ||
|
||
const msgTypeStyle = { | ||
color: "#e83b46", | ||
fontSize: "1.2em", | ||
marginBottom: "1rem", | ||
fontFamily: "sans-serif", | ||
className: "webpack-msg-type", | ||
css: /* css */ `.webpack-msg-type { | ||
margin-bottom: 1rem; | ||
color: #e83b46; | ||
font-size: 1.2em; | ||
font-family: sans-serif; | ||
} | ||
|
||
.webpack-msg-type[data-can-open] { | ||
cursor: pointer; | ||
} | ||
`, | ||
}; | ||
|
||
const msgTextStyle = { | ||
lineHeight: "1.5", | ||
fontSize: "1rem", | ||
fontFamily: "Menlo, Consolas, monospace", | ||
className: "webpack-msg-text", | ||
css: /* css */ `.webpack-msg-text { | ||
line-height: 1.5; | ||
font-size: 1rem; | ||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lovingly copied from TailwindCSS |
||
} | ||
`, | ||
}; | ||
|
||
const msgStyles = { | ||
error: { | ||
className: "webpack-error-msg", | ||
css: /* css */ `.webpack-error-msg { | ||
background-color: rgba(206, 17, 38, 0.1); | ||
color: #fccfcf; | ||
padding: 1rem 1rem 1.5rem 1rem; | ||
}`, | ||
}, | ||
warning: { | ||
className: "webpack-warning-msg", | ||
css: /* css */ `.webpack-warning-msg { | ||
background-color: rgba(251, 245, 180, 0.1); | ||
color: #fbf5b4; | ||
padding: 1rem 1rem 1.5rem 1rem; | ||
}`, | ||
}, | ||
}; | ||
|
||
/** | ||
* @typedef {Object} CssLoader | ||
* @property {(css: string) => void} load | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {Document} doc | ||
* @return {CssLoader} | ||
*/ | ||
const createCssLoader = (doc) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. css loader could be confusing? Any suggestion is welcome. |
||
/** @type {string[]} */ | ||
const loadedCss = []; | ||
|
||
return { | ||
load: (css) => { | ||
// ignore CSS rule that has loaded before | ||
if (!loadedCss.includes(css)) { | ||
const style = doc.createElement("style"); | ||
style.innerHTML = css; | ||
doc.head.appendChild(style); | ||
loadedCss.push(css); | ||
} | ||
}, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can create a lot of problems. Shorty - we already tried this solution and we had a lot of issues about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Any issues that was raised before on this? Maybe worth include them in the comments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They were, but they are difficult to find because they are scattered and many headings do not match the original problem, I tried to search for them, but unfortunately I can not find but I remember very well that we had problems with this 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, tag me when you stumble them then. |
||
}; | ||
|
||
export { | ||
|
@@ -86,4 +151,5 @@ export { | |
dismissButtonStyle, | ||
msgTypeStyle, | ||
msgTextStyle, | ||
createCssLoader, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentionally keep iframe styling to use inline style because we can't scope CSS for it.