-
Notifications
You must be signed in to change notification settings - Fork 38
feat: add styleOptions.stylesRoot prop #137
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8c46fe1
feat: Add emotionOptions
OEvgeny bea612e
Add tests and pass through emotionOptions
OEvgeny 51d47f3
Add back cache for default emotion objects
OEvgeny efc9eb3
Changelog
OEvgeny a69b5b0
Wording
OEvgeny d750fb3
Cleanup
OEvgeny 48aedd9
Rename to styleOptions
OEvgeny 37f8cde
Add more tests
OEvgeny f9340b6
Fix tests
OEvgeny c8a8d54
Apply suggestions from code review
OEvgeny 2d0ae79
Address suggestions
OEvgeny da4516e
Fix test
OEvgeny 7b831d0
Fix docs
OEvgeny e762b5b
Fix table markup
OEvgeny 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ parserOptions: | |
ecmaVersion: 12 | ||
sourceType: module | ||
|
||
env: | ||
es6: true | ||
|
||
plugins: | ||
- prettier | ||
|
||
|
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
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,52 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title></title> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | ||
<script src="/react-scroll-to-bottom.development.js"></script> | ||
<script src="/test-harness.js"></script> | ||
<script src="/assets/page-object-model.js"></script> | ||
</head> | ||
<body> | ||
<div id="styles"></div> | ||
<div id="app"></div> | ||
</body> | ||
<script type="text/babel" data-presets="react"> | ||
'use strict'; | ||
|
||
const additionalOptions = { | ||
container: document.getElementById('styles') | ||
}; | ||
|
||
run(async function () { | ||
await new Promise(resolve => | ||
ReactDOM.render( | ||
<ReactScrollToBottom.default | ||
className="react-scroll-to-bottom" | ||
followButtonClassName="follow" | ||
scrollViewClassName="scrollable" | ||
emotionOptions={additionalOptions} | ||
> | ||
{pageObjects.paragraphs.map(paragraph => ( | ||
<p key={paragraph}>{paragraph}</p> | ||
))} | ||
</ReactScrollToBottom.default>, | ||
document.getElementById('app'), | ||
resolve | ||
) | ||
); | ||
|
||
await pageObjects.scrollStabilizedAtBottom(); | ||
|
||
expect(document.getElementsByClassName('follow')[0]).toBeFalsy(); | ||
|
||
await pageObjects.mouseWheel(-100); | ||
|
||
await pageObjects.scrollStabilized(); | ||
|
||
expect(document.getElementsByClassName('follow')[0]).toBeTruthy(); | ||
expect(document.getElementById('styles').childElementCount).toBeGreaterThan(0); | ||
}); | ||
</script> | ||
</html> |
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,3 @@ | ||
/** @jest-environment ./packages/test-harness/JestEnvironment */ | ||
|
||
test('should-respect-options.html', () => runHTML('should-respect-options.html')); |
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
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,58 @@ | ||
import createEmotion from '@emotion/css/create-instance'; | ||
import { useEffect, useMemo, useRef } from 'react'; | ||
|
||
import createCSSKey from '../../createCSSKey'; | ||
|
||
const sharedEmotionByNonce = new Map(); | ||
const sharedEmotionUsedTimes = new WeakMap(); | ||
|
||
export default function useEmotion(nonce, emotionOptions) { | ||
const emotion = useMemo(() => { | ||
const defaultOptions = { | ||
key: 'react-scroll-to-bottom--css-' + createCSSKey(), | ||
nonce | ||
}; | ||
if (emotionOptions) { | ||
return createEmotion({ | ||
...defaultOptions, | ||
...emotionOptions | ||
}); | ||
} | ||
const emotion = sharedEmotionByNonce.get(nonce) ?? createEmotion(defaultOptions); | ||
sharedEmotionByNonce.set(nonce, emotion); | ||
sharedEmotionUsedTimes.set(emotion, sharedEmotionUsedTimes.get(emotion) ?? 0 + 1); | ||
return emotion; | ||
}, [nonce, emotionOptions]); | ||
|
||
const nonceRef = useRef(); | ||
nonceRef.current = nonce; | ||
|
||
useEffect( | ||
() => | ||
emotion && | ||
(() => { | ||
if (sharedEmotionUsedTimes.has(emotion)) { | ||
sharedEmotionUsedTimes.set(emotion, sharedEmotionUsedTimes.get(emotion) ?? 0 - 1); | ||
if (sharedEmotionUsedTimes.get(emotion) > 0) { | ||
return; | ||
} | ||
} | ||
|
||
sharedEmotionUsedTimes.delete(emotion); | ||
|
||
if (sharedEmotionByNonce.get(nonceRef.current) === emotion) { | ||
sharedEmotionByNonce.delete(nonceRef.current); | ||
} | ||
|
||
const { | ||
sheet: { container, tags } | ||
} = emotion; | ||
for (const child of tags) { | ||
container.removeChild(child); | ||
} | ||
}), | ||
[emotion] | ||
); | ||
|
||
return emotion; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.