-
-
Notifications
You must be signed in to change notification settings - Fork 510
feat(wxt-demo): add rem-to-px postcss example for Shadow Root UI #2333
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
Closed
Aniket-lodh
wants to merge
5
commits into
wxt-dev:main
from
Aniket-lodh:feat/wxt-demo-rem-fix-example
+75
−0
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f16991
feat(wxt-demo): add rem-to-px postcss example for Shadow Root UI
Aniket-lodh 3f2ac99
chore: add postcss to devDependencies in wxt-demo package
Aniket-lodh 69b2b69
Update packages/wxt-demo/src/entrypoints/rem-fix.content/style.css
Aniket-lodh be26122
Update packages/wxt-demo/src/entrypoints/rem-fix.content/index.ts
Aniket-lodh 3468f50
Update packages/wxt-demo/src/entrypoints/rem-fix.content/index.ts
Aniket-lodh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import postcssRemToResponsivePx from 'postcss-rem-to-responsive-pixel'; | ||
|
|
||
| export default { | ||
| plugins: [ | ||
| postcssRemToResponsivePx({ | ||
| rootValue: 16, | ||
| propList: ['*'], | ||
| transformUnit: 'px', | ||
| }), | ||
| ], | ||
| }; |
31 changes: 31 additions & 0 deletions
31
packages/wxt-demo/src/entrypoints/rem-fix.content/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import './style.css'; | ||
|
|
||
| export default defineContentScript({ | ||
| matches: ['<all_urls>'], | ||
| cssInjectionMode: 'ui', | ||
|
|
||
| async main(ctx) { | ||
| const ui = await createShadowRootUi(ctx, { | ||
| name: 'rem-fix-demo', | ||
| position: 'inline', | ||
| anchor: 'body', | ||
| append: 'first', | ||
| onMount(container) { | ||
| const card = document.createElement('div'); | ||
| card.classList.add('rem-fix-card'); | ||
|
|
||
| const title = document.createElement('h3'); | ||
| title.textContent = 'rem → px Demo'; | ||
|
|
||
| const desc = document.createElement('p'); | ||
| desc.textContent = `This UI uses 'rem' units in CSS, converted to 'px' at build time by 'postcss-rem-to-responsive-pixel'. | ||
| It will render at the same size regardless of the host pages root 'font-size'.`; | ||
|
|
||
| card.append(title, desc); | ||
| container.append(card); | ||
| }, | ||
| }); | ||
|
|
||
| ui.mount(); | ||
| }, | ||
| }); | ||
30 changes: 30 additions & 0 deletions
30
packages/wxt-demo/src/entrypoints/rem-fix.content/style.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * These rem values will be converted to px at build time | ||
| * by postcss-rem-to-responsive-pixel, making this UI immune | ||
| * to host page font-size overrides. | ||
| */ | ||
| .rem-fix-card { | ||
| padding: 1rem; | ||
| border-radius: 0.5rem; | ||
| background-color: #1e1e2e; | ||
| color: #cdd6f4; | ||
| font-family: system-ui, -apple-system, sans-serif; | ||
| font-size: 0.875rem; | ||
| line-height: 1.5; | ||
| border: 1px solid #45475a; | ||
| max-width: 20rem; | ||
| box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.3); | ||
|
|
||
| h3 { | ||
| margin-right:0.5rem; | ||
| font-size: 1rem; | ||
| font-weight: 600; | ||
| color: #a6e3a1; | ||
| } | ||
|
|
||
| p { | ||
| font-size: 0.75rem; | ||
| color: #a6adc8; | ||
| } | ||
| } | ||
|
Aniket-lodh marked this conversation as resolved.
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Run prettier, because that line isn't formatted properly.