diff --git a/.eslintrc.yml b/.eslintrc.yml index 7a04aec..d80c8c8 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -5,6 +5,9 @@ parserOptions: ecmaVersion: 12 sourceType: module +env: + es6: true + plugins: - prettier diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dbd656..b53a041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- Added `styleOptions.stylesRoot` property which allows to specify a container node component styles will be placed into, by [@OEvgeny](https://github.com/OEvgeny) in PR [#137](https://github.com/compulim/react-scroll-to-bottom/pull/137) + ## [4.2.0] - 2021-10-14 ### Changed diff --git a/README.md b/README.md index 8d60e69..80220cf 100644 --- a/README.md +++ b/README.md @@ -62,18 +62,19 @@ export default props => ( ## Props -| Name | Type | Default | Description | -| ----------------------- | ---------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -| `checkInterval` | `number` | 150 | Recurring interval of stickiness check, in milliseconds (minimum is 17 ms) | -| `className` | `string` | | Set the class name for the root element | -| `debounce` | `number` | `17` | Set the debounce for tracking the `onScroll` event | -| `debug` | `bool` | `NODE_ENV === 'development'` | Show debug information in console | -| `followButtonClassName` | `string` | | Set the class name for the follow button | -| `initialScrollBehavior` | `string` | `smooth` | Set the initial scroll behavior, either `"auto"` (discrete scrolling) or `"smooth"` | -| `mode` | `string` | `"bottom"` | Set it to `"bottom"` for scroll-to-bottom, `"top"` for scroll-to-top | -| `nonce` | `string` | | Set the nonce for [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) | -| `scroller` | `function` | `() => Infinity` | A function to determine how far should scroll when scroll is needed | -| `scrollViewClassName` | `string` | | Set the class name for the container element that house all `props.children` | +| Name | Type | Default | Description | +| ------------------------- | ---------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `checkInterval` | `number` | 150 | Recurring interval of stickiness check, in milliseconds (minimum is 17 ms) | +| `className` | `string` | | Set the class name for the root element | +| `debounce` | `number` | `17` | Set the debounce for tracking the `onScroll` event | +| `debug` | `bool` | `NODE_ENV === 'development'` | Show debug information in console | +| `followButtonClassName` | `string` | | Set the class name for the follow button | +| `initialScrollBehavior` | `string` | `smooth` | Set the initial scroll behavior, either `"auto"` (discrete scrolling) or `"smooth"` | +| `mode` | `string` | `"bottom"` | Set it to `"bottom"` for scroll-to-bottom, `"top"` for scroll-to-top | +| `nonce` | `string` | | Set the nonce for [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) | +| `scroller` | `function` | `() => Infinity` | A function to determine how far should scroll when scroll is needed | +| `scrollViewClassName` | `string` | | Set the class name for the container element that house all `props.children` | +| `styleOptions.stylesRoot` | `Node` | `undefined` | Set the container node for component styles to be placed into. When set to `undefined`, will use `document.head` | ## Hooks diff --git a/__tests__/should-respect-container-change.html b/__tests__/should-respect-container-change.html new file mode 100644 index 0000000..4133053 --- /dev/null +++ b/__tests__/should-respect-container-change.html @@ -0,0 +1,72 @@ + + + + + + + + + + + +
+
+
+ + + diff --git a/__tests__/should-respect-container-change.js b/__tests__/should-respect-container-change.js new file mode 100644 index 0000000..18c8092 --- /dev/null +++ b/__tests__/should-respect-container-change.js @@ -0,0 +1,3 @@ +/** @jest-environment ./packages/test-harness/JestEnvironment */ + +test('should-respect-container-change.html', () => runHTML('should-respect-container-change.html')); diff --git a/__tests__/should-respect-nonce-change.html b/__tests__/should-respect-nonce-change.html new file mode 100644 index 0000000..a912d84 --- /dev/null +++ b/__tests__/should-respect-nonce-change.html @@ -0,0 +1,75 @@ + + + + + + + + + + + +
+
+
+ + + diff --git a/__tests__/should-respect-nonce-change.js b/__tests__/should-respect-nonce-change.js new file mode 100644 index 0000000..3968d44 --- /dev/null +++ b/__tests__/should-respect-nonce-change.js @@ -0,0 +1,3 @@ +/** @jest-environment ./packages/test-harness/JestEnvironment */ + +test('should-respect-nonce-change.html', () => runHTML('should-respect-nonce-change.html')); diff --git a/__tests__/should-respect-options.html b/__tests__/should-respect-options.html new file mode 100644 index 0000000..00f4f30 --- /dev/null +++ b/__tests__/should-respect-options.html @@ -0,0 +1,52 @@ + + + + + + + + + + + +
+
+ + + diff --git a/__tests__/should-respect-options.js b/__tests__/should-respect-options.js new file mode 100644 index 0000000..4daaad4 --- /dev/null +++ b/__tests__/should-respect-options.js @@ -0,0 +1,3 @@ +/** @jest-environment ./packages/test-harness/JestEnvironment */ + +test('should-respect-options.html', () => runHTML('should-respect-options.html')); diff --git a/packages/component/src/BasicScrollToBottom.js b/packages/component/src/BasicScrollToBottom.js index 0db0547..ac0e29b 100644 --- a/packages/component/src/BasicScrollToBottom.js +++ b/packages/component/src/BasicScrollToBottom.js @@ -47,7 +47,8 @@ const BasicScrollToBottom = ({ mode, nonce, scroller, - scrollViewClassName + scrollViewClassName, + styleOptions }) => ( Infinity; @@ -21,10 +20,6 @@ const MODE_TOP = 'top'; const NEAR_END_THRESHOLD = 1; const SCROLL_DECISION_DURATION = 34; // 2 frames -// We pool the emotion object by nonce. -// This is to make sure we don't generate too many unneeded