From 8c46fe1956841b1482a59a834b1c28898d3d41f2 Mon Sep 17 00:00:00 2001 From: Eugene Date: Wed, 29 May 2024 17:02:08 +0000 Subject: [PATCH 01/14] feat: Add emotionOptions --- README.md | 1 + .../component/src/ScrollToBottom/Composer.js | 26 ++++++++++--------- packages/component/src/useEmotion.js | 22 ++++++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 packages/component/src/useEmotion.js diff --git a/README.md b/README.md index 8d60e69..3a4e923 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ export default props => ( | `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 | +| `emotionOptions` | `object` | `undefined` | Additional options for the internal Emotion instance | | `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 | diff --git a/packages/component/src/ScrollToBottom/Composer.js b/packages/component/src/ScrollToBottom/Composer.js index 85adc3b..3939763 100644 --- a/packages/component/src/ScrollToBottom/Composer.js +++ b/packages/component/src/ScrollToBottom/Composer.js @@ -1,4 +1,3 @@ -import createEmotion from '@emotion/css/create-instance'; import PropTypes from 'prop-types'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; @@ -12,6 +11,7 @@ import State1Context from './State1Context'; import State2Context from './State2Context'; import StateContext from './StateContext'; import styleConsole from '../utils/styleConsole'; +import useEmotion from '../useEmotion'; import useStateRef from '../hooks/internal/useStateRef'; const DEFAULT_SCROLLER = () => Infinity; @@ -21,10 +21,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