@audius/harmony 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_tslib.js +11 -1
- package/dist/_virtual/_tslib.js.map +1 -1
- package/dist/assets/icons/LogoPhantomPlain.svg.js +78 -0
- package/dist/assets/icons/LogoPhantomPlain.svg.js.map +1 -0
- package/dist/assets/icons/PaperAirplane.svg.js +76 -0
- package/dist/assets/icons/PaperAirplane.svg.js.map +1 -0
- package/dist/assets/icons/Pin.svg.js +76 -0
- package/dist/assets/icons/Pin.svg.js.map +1 -0
- package/dist/assets/icons/QrCode.svg.js +78 -0
- package/dist/assets/icons/QrCode.svg.js.map +1 -0
- package/dist/assets/icons/Send.svg.js +6 -3
- package/dist/assets/icons/Send.svg.js.map +1 -1
- package/dist/assets/icons/TowerBroadcast.svg.js +75 -0
- package/dist/assets/icons/TowerBroadcast.svg.js.map +1 -0
- package/dist/components/artwork/Artwork.d.ts.map +1 -1
- package/dist/components/artwork/Artwork.js +5 -4
- package/dist/components/artwork/Artwork.js.map +1 -1
- package/dist/components/avatar/Avatar.d.ts.map +1 -1
- package/dist/components/avatar/Avatar.js +1 -1
- package/dist/components/avatar/Avatar.js.map +1 -1
- package/dist/components/button/BaseButton/BaseButton.d.ts +1 -0
- package/dist/components/button/BaseButton/BaseButton.d.ts.map +1 -1
- package/dist/components/button/BaseButton/BaseButton.js +2 -2
- package/dist/components/button/BaseButton/BaseButton.js.map +1 -1
- package/dist/components/button/BaseButton/types.d.ts +1 -0
- package/dist/components/button/BaseButton/types.d.ts.map +1 -1
- package/dist/components/button/FilterButton/FilterButton.d.ts +1 -1
- package/dist/components/button/FilterButton/FilterButton.d.ts.map +1 -1
- package/dist/components/button/FilterButton/FilterButton.js +85 -61
- package/dist/components/button/FilterButton/FilterButton.js.map +1 -1
- package/dist/components/button/{OptionsFilterButton/OptionsFilterButton.stories.d.ts → FilterButton/FilterButton.stories.d.ts} +5 -4
- package/dist/components/button/FilterButton/FilterButton.stories.d.ts.map +1 -0
- package/dist/components/button/FilterButton/FilterButtonKeyHandler.d.ts +18 -0
- package/dist/components/button/FilterButton/FilterButtonKeyHandler.d.ts.map +1 -0
- package/dist/components/button/FilterButton/FilterButtonOption.d.ts +11 -0
- package/dist/components/button/FilterButton/FilterButtonOption.d.ts.map +1 -0
- package/dist/components/button/FilterButton/FilterButtonOption.js +57 -0
- package/dist/components/button/FilterButton/FilterButtonOption.js.map +1 -0
- package/dist/components/button/FilterButton/FilterButtonOptionsList.d.ts +21 -0
- package/dist/components/button/FilterButton/FilterButtonOptionsList.d.ts.map +1 -0
- package/dist/components/button/FilterButton/FilterButtonOptionsList.js +40 -0
- package/dist/components/button/FilterButton/FilterButtonOptionsList.js.map +1 -0
- package/dist/components/button/FilterButton/types.d.ts +51 -24
- package/dist/components/button/FilterButton/types.d.ts.map +1 -1
- package/dist/components/button/IconButton/IconButton.d.ts +19 -2
- package/dist/components/button/IconButton/IconButton.d.ts.map +1 -1
- package/dist/components/button/IconButton/IconButton.js +3 -2
- package/dist/components/button/IconButton/IconButton.js.map +1 -1
- package/dist/components/button/index.d.ts +3 -4
- package/dist/components/button/index.d.ts.map +1 -1
- package/dist/components/checkbox/Checkbox.d.ts +7 -0
- package/dist/components/checkbox/Checkbox.d.ts.map +1 -0
- package/dist/components/checkbox/Checkbox.js +64 -0
- package/dist/components/checkbox/Checkbox.js.map +1 -0
- package/dist/components/checkbox/Checkbox.stories.d.ts +9 -0
- package/dist/components/checkbox/Checkbox.stories.d.ts.map +1 -0
- package/dist/components/checkbox/Indeterminate.svg.js +114 -0
- package/dist/components/checkbox/Indeterminate.svg.js.map +1 -0
- package/dist/components/checkbox/Select.svg.js +118 -0
- package/dist/components/checkbox/Select.svg.js.map +1 -0
- package/dist/components/checkbox/index.d.ts +3 -0
- package/dist/components/checkbox/index.d.ts.map +1 -0
- package/dist/components/checkbox/types.d.ts +7 -0
- package/dist/components/checkbox/types.d.ts.map +1 -0
- package/dist/components/comments/ArtistPick/ArtistPick.d.ts +3 -0
- package/dist/components/comments/ArtistPick/ArtistPick.d.ts.map +1 -0
- package/dist/components/comments/ArtistPick/ArtistPick.js +20 -0
- package/dist/components/comments/ArtistPick/ArtistPick.js.map +1 -0
- package/dist/components/comments/ArtistPick/ArtistPick.stories.d.ts +7 -0
- package/dist/components/comments/ArtistPick/ArtistPick.stories.d.ts.map +1 -0
- package/dist/components/comments/ArtistPick/index.d.ts +3 -0
- package/dist/components/comments/ArtistPick/index.d.ts.map +1 -0
- package/dist/components/comments/ArtistPick/types.d.ts +5 -0
- package/dist/components/comments/ArtistPick/types.d.ts.map +1 -0
- package/dist/components/comments/CommentText/CommentText.d.ts +3 -0
- package/dist/components/comments/CommentText/CommentText.d.ts.map +1 -0
- package/dist/components/comments/CommentText/CommentText.js +36 -0
- package/dist/components/comments/CommentText/CommentText.js.map +1 -0
- package/dist/components/comments/CommentText/CommentText.stories.d.ts +10 -0
- package/dist/components/comments/CommentText/CommentText.stories.d.ts.map +1 -0
- package/dist/components/comments/CommentText/index.d.ts +3 -0
- package/dist/components/comments/CommentText/index.d.ts.map +1 -0
- package/dist/components/comments/CommentText/types.d.ts +5 -0
- package/dist/components/comments/CommentText/types.d.ts.map +1 -0
- package/dist/components/comments/IconText/IconText.d.ts +3 -0
- package/dist/components/comments/IconText/IconText.d.ts.map +1 -0
- package/dist/components/comments/IconText/IconText.js +19 -0
- package/dist/components/comments/IconText/IconText.js.map +1 -0
- package/dist/components/comments/IconText/IconText.stories.d.ts +7 -0
- package/dist/components/comments/IconText/IconText.stories.d.ts.map +1 -0
- package/dist/components/comments/IconText/index.d.ts +3 -0
- package/dist/components/comments/IconText/index.d.ts.map +1 -0
- package/dist/components/comments/IconText/types.d.ts +14 -0
- package/dist/components/comments/IconText/types.d.ts.map +1 -0
- package/dist/components/comments/Identifier/Identifier.d.ts +3 -0
- package/dist/components/comments/Identifier/Identifier.d.ts.map +1 -0
- package/dist/components/comments/Identifier/Identifier.js +30 -0
- package/dist/components/comments/Identifier/Identifier.js.map +1 -0
- package/dist/components/comments/Identifier/Identifier.stories.d.ts +7 -0
- package/dist/components/comments/Identifier/Identifier.stories.d.ts.map +1 -0
- package/dist/components/comments/Identifier/index.d.ts +3 -0
- package/dist/components/comments/Identifier/index.d.ts.map +1 -0
- package/dist/components/comments/Identifier/types.d.ts +5 -0
- package/dist/components/comments/Identifier/types.d.ts.map +1 -0
- package/dist/components/comments/SendIcon/SendIcon.d.ts +3 -0
- package/dist/components/comments/SendIcon/SendIcon.d.ts.map +1 -0
- package/dist/components/comments/SendIcon/SendIcon.js +36 -0
- package/dist/components/comments/SendIcon/SendIcon.js.map +1 -0
- package/dist/components/comments/SendIcon/SendIcon.stories.d.ts +7 -0
- package/dist/components/comments/SendIcon/SendIcon.stories.d.ts.map +1 -0
- package/dist/components/comments/SendIcon/index.d.ts +3 -0
- package/dist/components/comments/SendIcon/index.d.ts.map +1 -0
- package/dist/components/comments/SendIcon/types.d.ts +5 -0
- package/dist/components/comments/SendIcon/types.d.ts.map +1 -0
- package/dist/components/comments/Timestamp/Timestamp.d.ts +3 -0
- package/dist/components/comments/Timestamp/Timestamp.d.ts.map +1 -0
- package/dist/components/comments/Timestamp/Timestamp.js +13 -0
- package/dist/components/comments/Timestamp/Timestamp.js.map +1 -0
- package/dist/components/comments/Timestamp/Timestamp.stories.d.ts +7 -0
- package/dist/components/comments/Timestamp/Timestamp.stories.d.ts.map +1 -0
- package/dist/components/comments/Timestamp/index.d.ts +4 -0
- package/dist/components/comments/Timestamp/index.d.ts.map +1 -0
- package/dist/components/comments/Timestamp/types.d.ts +11 -0
- package/dist/components/comments/Timestamp/types.d.ts.map +1 -0
- package/dist/components/comments/Timestamp/types.js +10 -0
- package/dist/components/comments/Timestamp/types.js.map +1 -0
- package/dist/components/comments/Timestamp/util.d.ts +2 -0
- package/dist/components/comments/Timestamp/util.d.ts.map +1 -0
- package/dist/components/comments/Timestamp/util.js +26 -0
- package/dist/components/comments/Timestamp/util.js.map +1 -0
- package/dist/components/icon.d.ts +2 -1
- package/dist/components/icon.d.ts.map +1 -1
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/input/PasswordInput/PasswordInput.js +2 -2
- package/dist/components/input/SelectablePill/SelectablePill.d.ts.map +1 -1
- package/dist/components/input/SelectablePill/SelectablePill.js +1 -3
- package/dist/components/input/SelectablePill/SelectablePill.js.map +1 -1
- package/dist/components/input/TextInput/TextInput.d.ts +2 -0
- package/dist/components/input/TextInput/TextInput.d.ts.map +1 -1
- package/dist/components/input/TextInput/TextInput.js +10 -6
- package/dist/components/input/TextInput/TextInput.js.map +1 -1
- package/dist/components/input/TextInput/types.d.ts +8 -1
- package/dist/components/input/TextInput/types.d.ts.map +1 -1
- package/dist/components/input/TextInput/types.js.map +1 -1
- package/dist/components/internal/Menu.d.ts +22 -0
- package/dist/components/internal/Menu.d.ts.map +1 -0
- package/dist/components/internal/Menu.js +17 -0
- package/dist/components/internal/Menu.js.map +1 -0
- package/dist/components/internal/MenuItem.d.ts +19 -0
- package/dist/components/internal/MenuItem.d.ts.map +1 -0
- package/dist/components/internal/MenuItem.js +57 -0
- package/dist/components/internal/MenuItem.js.map +1 -0
- package/dist/components/internal/OptionKeyHandler.d.ts +30 -0
- package/dist/components/internal/OptionKeyHandler.d.ts.map +1 -0
- package/dist/components/{button/OptionsFilterButton/SelectPopupKeyHandler.js → internal/OptionKeyHandler.js} +6 -11
- package/dist/components/internal/OptionKeyHandler.js.map +1 -0
- package/dist/components/layout/Box/Box.js +4 -4
- package/dist/components/layout/Box/Box.js.map +1 -1
- package/dist/components/layout/Box/types.d.ts +6 -6
- package/dist/components/layout/Box/types.d.ts.map +1 -1
- package/dist/components/layout/Flex/Flex.d.ts.map +1 -1
- package/dist/components/layout/Flex/Flex.js +2 -2
- package/dist/components/layout/Flex/Flex.js.map +1 -1
- package/dist/components/layout/Flex/types.d.ts +2 -0
- package/dist/components/layout/Flex/types.d.ts.map +1 -1
- package/dist/components/modal/Modal.js +3 -3
- package/dist/components/modal/Modal.js.map +1 -1
- package/dist/components/modal/ModalContentPages.d.ts +10 -10
- package/dist/components/modal/ModalContentPages.d.ts.map +1 -1
- package/dist/components/modal/ModalContentPages.js +2 -2
- package/dist/components/modal/ModalContentPages.js.map +1 -1
- package/dist/components/modal/ModalHeader.js +2 -2
- package/dist/components/music-badge/MusicBadge.d.ts.map +1 -1
- package/dist/components/music-badge/MusicBadge.js +1 -1
- package/dist/components/music-badge/MusicBadge.js.map +1 -1
- package/dist/components/pill/Pill.d.ts +1 -0
- package/dist/components/pill/Pill.d.ts.map +1 -1
- package/dist/components/popup/Popup.d.ts +6 -1
- package/dist/components/popup/Popup.d.ts.map +1 -1
- package/dist/components/popup/Popup.js +47 -37
- package/dist/components/popup/Popup.js.map +1 -1
- package/dist/components/popup/types.d.ts +4 -0
- package/dist/components/popup/types.d.ts.map +1 -1
- package/dist/components/scrubber/Scrubber.d.ts.map +1 -1
- package/dist/components/scrubber/Scrubber.js +3 -13
- package/dist/components/scrubber/Scrubber.js.map +1 -1
- package/dist/components/scrubber/Slider.js +1 -1
- package/dist/components/scrubber/Slider.js.map +1 -1
- package/dist/components/segmented-control/SegmentedControl.js +1 -3
- package/dist/components/segmented-control/SegmentedControl.js.map +1 -1
- package/dist/components/select/Select/Select.d.ts +21 -0
- package/dist/components/select/Select/Select.d.ts.map +1 -0
- package/dist/components/select/Select/Select.js +115 -0
- package/dist/components/select/Select/Select.js.map +1 -0
- package/dist/components/select/Select/Select.stories.d.ts +8 -0
- package/dist/components/select/Select/Select.stories.d.ts.map +1 -0
- package/dist/components/select/Select/index.d.ts +3 -0
- package/dist/components/select/Select/index.d.ts.map +1 -0
- package/dist/components/select/Select/types.d.ts +46 -0
- package/dist/components/select/Select/types.d.ts.map +1 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.d.ts.map +1 -0
- package/dist/components/tag/Tag.d.ts.map +1 -1
- package/dist/components/tag/Tag.js +1 -1
- package/dist/components/tag/Tag.js.map +1 -1
- package/dist/components/text/Text.d.ts.map +1 -1
- package/dist/components/text/Text.js +15 -5
- package/dist/components/text/Text.js.map +1 -1
- package/dist/components/text/constants.d.ts +18 -0
- package/dist/components/text/constants.d.ts.map +1 -1
- package/dist/components/text/constants.js +7 -1
- package/dist/components/text/constants.js.map +1 -1
- package/dist/components/text/types.d.ts +2 -0
- package/dist/components/text/types.d.ts.map +1 -1
- package/dist/components/text-link/TextLink.d.ts.map +1 -1
- package/dist/components/text-link/TextLink.js +1 -1
- package/dist/components/text-link/TextLink.js.map +1 -1
- package/dist/foundations/color/color.d.ts +116 -0
- package/dist/foundations/color/color.d.ts.map +1 -1
- package/dist/foundations/color/color.js +2 -1
- package/dist/foundations/color/color.js.map +1 -1
- package/dist/foundations/color/primitive.d.ts +52 -0
- package/dist/foundations/color/primitive.d.ts.map +1 -1
- package/dist/foundations/color/primitive.js +52 -0
- package/dist/foundations/color/primitive.js.map +1 -1
- package/dist/foundations/color/semantic.d.ts +66 -0
- package/dist/foundations/color/semantic.d.ts.map +1 -1
- package/dist/foundations/color/semantic.js +8 -3
- package/dist/foundations/color/semantic.js.map +1 -1
- package/dist/foundations/theme/theme.d.ts +2 -0
- package/dist/foundations/theme/theme.d.ts.map +1 -1
- package/dist/foundations/theme/theme.js +4 -2
- package/dist/foundations/theme/theme.js.map +1 -1
- package/dist/foundations/theme/types.d.ts +6 -1
- package/dist/foundations/theme/types.d.ts.map +1 -1
- package/dist/foundations/typography/typography.d.ts +1 -0
- package/dist/foundations/typography/typography.d.ts.map +1 -1
- package/dist/foundations/typography/typography.js +2 -0
- package/dist/foundations/typography/typography.js.map +1 -1
- package/dist/harmony.css +1 -1
- package/dist/hooks/useClickOutside.d.ts +1 -1
- package/dist/hooks/useClickOutside.d.ts.map +1 -1
- package/dist/hooks/useClickOutside.js +11 -8
- package/dist/hooks/useClickOutside.js.map +1 -1
- package/dist/hooks/useControlled.d.ts +1 -1
- package/dist/hooks/useControlled.js.map +1 -1
- package/dist/hooks/useHotKeys.d.ts.map +1 -1
- package/dist/hooks/useHotKeys.js +2 -1
- package/dist/hooks/useHotKeys.js.map +1 -1
- package/dist/icons/logos.d.ts +1 -0
- package/dist/icons/logos.d.ts.map +1 -1
- package/dist/icons/logos.js +3 -1
- package/dist/icons/logos.js.map +1 -1
- package/dist/icons/utilityIcons.d.ts +4 -0
- package/dist/icons/utilityIcons.d.ts.map +1 -1
- package/dist/icons/utilityIcons.js +9 -1
- package/dist/icons/utilityIcons.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/utils/formatTrackTimestamp.d.ts +6 -0
- package/dist/utils/formatTrackTimestamp.d.ts.map +1 -0
- package/dist/utils/formatTrackTimestamp.js +18 -0
- package/dist/utils/formatTrackTimestamp.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +4 -2
- package/dist/components/button/OptionsFilterButton/OptionsFilterButton.d.ts +0 -18
- package/dist/components/button/OptionsFilterButton/OptionsFilterButton.d.ts.map +0 -1
- package/dist/components/button/OptionsFilterButton/OptionsFilterButton.js +0 -123
- package/dist/components/button/OptionsFilterButton/OptionsFilterButton.js.map +0 -1
- package/dist/components/button/OptionsFilterButton/OptionsFilterButton.stories.d.ts.map +0 -1
- package/dist/components/button/OptionsFilterButton/SelectPopupKeyHandler.d.ts +0 -18
- package/dist/components/button/OptionsFilterButton/SelectPopupKeyHandler.d.ts.map +0 -1
- package/dist/components/button/OptionsFilterButton/SelectPopupKeyHandler.js.map +0 -1
- package/dist/components/button/OptionsFilterButton/types.d.ts +0 -62
- package/dist/components/button/OptionsFilterButton/types.d.ts.map +0 -1
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { __assign } from '../../_virtual/_tslib.js';
|
|
2
2
|
import { jsx, Fragment, jsxs } from '@emotion/react/jsx-runtime';
|
|
3
|
-
import { forwardRef, useState, useCallback, useRef
|
|
3
|
+
import { forwardRef, useState, useEffect, useCallback, useRef } from 'react';
|
|
4
4
|
import { useTheme } from '@emotion/react';
|
|
5
5
|
import cn from 'classnames';
|
|
6
6
|
import ReactDOM from 'react-dom';
|
|
7
7
|
import { useTransition, animated } from 'react-spring';
|
|
8
|
+
import { usePrevious } from 'react-use';
|
|
8
9
|
import '../button/Button/Button.js';
|
|
9
10
|
import { PlainButton } from '../button/PlainButton/PlainButton.js';
|
|
10
11
|
import { IconClose } from '../../icons/utilityIcons.js';
|
|
11
12
|
import '@emotion/css';
|
|
12
13
|
import '../button/FollowButton/FollowButton.js';
|
|
13
|
-
import '../button/FilterButton/FilterButton.js';
|
|
14
|
-
import '../button/OptionsFilterButton/OptionsFilterButton.js';
|
|
15
14
|
import '../button/IconButton/IconButton.js';
|
|
16
15
|
import '../button/UnstyledButton.js';
|
|
16
|
+
import '../button/FilterButton/FilterButton.js';
|
|
17
|
+
import '../button/FilterButton/FilterButtonOption.js';
|
|
17
18
|
import { useClickOutside } from '../../hooks/useClickOutside.js';
|
|
18
19
|
import { getScrollParent } from '../../utils/getScrollParent.js';
|
|
19
20
|
import styles from './Popup.module.css.js';
|
|
@@ -40,18 +41,16 @@ var getComputedOrigins = function (anchorOrigin, transformOrigin, anchorRect, wr
|
|
|
40
41
|
return { anchorOrigin: anchorOrigin, transformOrigin: transformOrigin };
|
|
41
42
|
var containerWidth, containerHeight;
|
|
42
43
|
if (containerRef && containerRef.current) {
|
|
44
|
+
var containerRect = containerRef.current.getBoundingClientRect();
|
|
43
45
|
containerWidth =
|
|
44
|
-
|
|
45
|
-
CONTAINER_INSET_PADDING;
|
|
46
|
+
containerRect.width + containerRect.x - CONTAINER_INSET_PADDING;
|
|
46
47
|
containerHeight =
|
|
47
|
-
|
|
48
|
-
CONTAINER_INSET_PADDING;
|
|
48
|
+
containerRect.height + containerRect.y - CONTAINER_INSET_PADDING;
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
containerHeight =
|
|
54
|
-
portal.getBoundingClientRect().height - CONTAINER_INSET_PADDING;
|
|
51
|
+
var portalRect = portal.getBoundingClientRect();
|
|
52
|
+
containerWidth = portalRect.width + portalRect.x - CONTAINER_INSET_PADDING;
|
|
53
|
+
containerHeight = portalRect.height + portalRect.y - CONTAINER_INSET_PADDING;
|
|
55
54
|
}
|
|
56
55
|
// Get new wrapper position
|
|
57
56
|
var anchorTranslation = getOriginTranslation(anchorOrigin, anchorRect);
|
|
@@ -155,10 +154,25 @@ var closingAnimationDuration = 90;
|
|
|
155
154
|
* center-screened.
|
|
156
155
|
*/
|
|
157
156
|
var Popup = forwardRef(function Popup(props, ref) {
|
|
158
|
-
var
|
|
159
|
-
var
|
|
160
|
-
var
|
|
157
|
+
var isVisibleProp = props.isVisible;
|
|
158
|
+
var _a = useState('closed'), popupState = _a[0], setPopupState = _a[1];
|
|
159
|
+
var isVisible = popupState !== 'closed';
|
|
160
|
+
useEffect(function () {
|
|
161
|
+
if (popupState === 'closed' && isVisibleProp) {
|
|
162
|
+
setPopupState('opening');
|
|
163
|
+
}
|
|
164
|
+
else if (popupState === 'open' && !isVisibleProp) {
|
|
165
|
+
setPopupState('closing');
|
|
166
|
+
}
|
|
167
|
+
}, [isVisibleProp, popupState]);
|
|
168
|
+
return isVisible ? (jsx(PopupInternal, __assign({ ref: ref, popupState: popupState, setPopupState: setPopupState }, props))) : null;
|
|
169
|
+
});
|
|
170
|
+
var PopupInternal = forwardRef(function Popup(props, ref) {
|
|
171
|
+
var _a, _b, _c, _d, _e;
|
|
172
|
+
var popupState = props.popupState, setPopupState = props.setPopupState, anchorRef = props.anchorRef, checkIfClickInside = props.checkIfClickInside, children = props.children, className = props.className, isVisibleProp = props.isVisible, onAfterClose = props.onAfterClose, onClose = props.onClose, _f = props.anchorOrigin, anchorOriginProp = _f === void 0 ? defaultAnchorOrigin : _f, _g = props.transformOrigin, transformOriginProp = _g === void 0 ? defaultTransformOrigin : _g, dismissOnMouseLeave = props.dismissOnMouseLeave, _h = props.hideCloseButton, hideCloseButton = _h === void 0 ? false : _h, showHeader = props.showHeader, title = props.title, zIndex = props.zIndex, containerRef = props.containerRef, _j = props.portalLocation, portalLocation = _j === void 0 ? document.body : _j, _k = props.shadow, shadow = _k === void 0 ? 'mid' : _k, fixed = props.fixed, takeWidthOfAnchor = props.takeWidthOfAnchor;
|
|
173
|
+
var _l = useTheme(), spring = _l.spring, shadows = _l.shadows;
|
|
161
174
|
var isVisible = popupState !== 'closed';
|
|
175
|
+
var previousIsVisible = usePrevious(isVisible);
|
|
162
176
|
var handleClose = useCallback(function () {
|
|
163
177
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
164
178
|
setTimeout(function () {
|
|
@@ -167,17 +181,22 @@ var Popup = forwardRef(function Popup(props, ref) {
|
|
|
167
181
|
}
|
|
168
182
|
}, closingAnimationDuration);
|
|
169
183
|
}, [onClose, onAfterClose]);
|
|
170
|
-
var
|
|
184
|
+
var _m = [
|
|
171
185
|
anchorOriginProp,
|
|
172
186
|
transformOriginProp
|
|
173
|
-
], anchorOrigin =
|
|
174
|
-
var popupRef = useClickOutside(handleClose,
|
|
187
|
+
], anchorOrigin = _m[0], transformOrigin = _m[1];
|
|
188
|
+
var popupRef = useClickOutside(handleClose, isVisible, checkIfClickInside, typeof ref === 'function' ? undefined : ref);
|
|
175
189
|
var wrapperRef = useRef(null);
|
|
176
190
|
var originalTopPosition = useRef(0);
|
|
177
|
-
var
|
|
191
|
+
var _o = useState(anchorOrigin), computedTransformOrigin = _o[0], setComputedTransformOrigin = _o[1];
|
|
192
|
+
var wrapperHeight = (_b = (_a = wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : null;
|
|
193
|
+
var wrapperWidth = (_d = (_c = wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current) === null || _c === void 0 ? void 0 : _c.offsetWidth) !== null && _d !== void 0 ? _d : null;
|
|
194
|
+
var previousHeight = usePrevious(wrapperHeight);
|
|
195
|
+
var previousWidth = usePrevious(wrapperWidth);
|
|
196
|
+
var wrapperSizeChange = wrapperHeight !== previousHeight || wrapperWidth !== previousWidth;
|
|
178
197
|
// On visible, set the position
|
|
179
198
|
useEffect(function () {
|
|
180
|
-
if (isVisible) {
|
|
199
|
+
if ((isVisible && !previousIsVisible) || wrapperSizeChange) {
|
|
181
200
|
var _a = [anchorRef, wrapperRef].map(function (r) { var _a; return (_a = r === null || r === void 0 ? void 0 : r.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(); }), anchorRect = _a[0], wrapperRect = _a[1];
|
|
182
201
|
if (!anchorRect || !wrapperRect)
|
|
183
202
|
return;
|
|
@@ -194,17 +213,7 @@ var Popup = forwardRef(function Popup(props, ref) {
|
|
|
194
213
|
}
|
|
195
214
|
originalTopPosition.current = top_1;
|
|
196
215
|
}
|
|
197
|
-
}, [
|
|
198
|
-
isVisible,
|
|
199
|
-
wrapperRef,
|
|
200
|
-
anchorRef,
|
|
201
|
-
anchorOrigin,
|
|
202
|
-
transformOrigin,
|
|
203
|
-
setComputedTransformOrigin,
|
|
204
|
-
originalTopPosition,
|
|
205
|
-
portalLocation,
|
|
206
|
-
containerRef
|
|
207
|
-
]);
|
|
216
|
+
}, [isVisible, wrapperRef, anchorRef, anchorOrigin, transformOrigin, setComputedTransformOrigin, originalTopPosition, portalLocation, containerRef, previousIsVisible, previousHeight, wrapperSizeChange]);
|
|
208
217
|
// Callback invoked on each scroll. Uses original top position to scroll with content.
|
|
209
218
|
// Takes scrollParent to get the current scroll position as well as the intitial scroll position
|
|
210
219
|
// when the popup became visible.
|
|
@@ -244,14 +253,11 @@ var Popup = forwardRef(function Popup(props, ref) {
|
|
|
244
253
|
}, [isVisible, handleClose]);
|
|
245
254
|
useEffect(function () {
|
|
246
255
|
var _a;
|
|
247
|
-
if (popupState === 'closed' && isVisibleProp)
|
|
248
|
-
setPopupState('opening');
|
|
249
|
-
}
|
|
256
|
+
if (popupState === 'closed' && isVisibleProp) ;
|
|
250
257
|
else if (popupState === 'open' && !isVisibleProp) {
|
|
251
|
-
setPopupState('closing');
|
|
252
258
|
(_a = anchorRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
253
259
|
}
|
|
254
|
-
}, [isVisibleProp, popupState]);
|
|
260
|
+
}, [anchorRef, isVisibleProp, popupState]);
|
|
255
261
|
var transitions = useTransition(isVisibleProp, null, {
|
|
256
262
|
from: {
|
|
257
263
|
transform: "scale(0)",
|
|
@@ -271,7 +277,11 @@ var Popup = forwardRef(function Popup(props, ref) {
|
|
|
271
277
|
setPopupState(isDestroyed ? 'closed' : 'open');
|
|
272
278
|
}
|
|
273
279
|
});
|
|
274
|
-
var rootStyle = {
|
|
280
|
+
var rootStyle = {
|
|
281
|
+
zIndex: zIndex,
|
|
282
|
+
position: fixed ? 'fixed' : undefined,
|
|
283
|
+
width: takeWidthOfAnchor ? (_e = anchorRef.current) === null || _e === void 0 ? void 0 : _e.clientWidth : undefined
|
|
284
|
+
};
|
|
275
285
|
var handleMouseLeave = useCallback(function () {
|
|
276
286
|
if (dismissOnMouseLeave) {
|
|
277
287
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
@@ -288,5 +298,5 @@ var Popup = forwardRef(function Popup(props, ref) {
|
|
|
288
298
|
: null }));
|
|
289
299
|
});
|
|
290
300
|
|
|
291
|
-
export { Popup };
|
|
301
|
+
export { Popup, PopupInternal };
|
|
292
302
|
//# sourceMappingURL=Popup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popup.js","sources":["../../../src/components/popup/Popup.tsx"],"sourcesContent":["import {\n forwardRef,\n MutableRefObject,\n Ref,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react'\n\nimport { useTheme } from '@emotion/react'\nimport cn from 'classnames'\nimport ReactDOM from 'react-dom'\nimport { useTransition, animated } from 'react-spring'\n\nimport { PlainButton } from 'components/button'\nimport { IconClose } from 'icons'\nimport { ModalState } from 'utils/modalState'\n\nimport { useClickOutside } from '../../hooks/useClickOutside'\nimport { getScrollParent } from '../../utils/getScrollParent'\n\nimport styles from './Popup.module.css'\nimport type { PopupProps, Origin } from './types'\n\nconst messages = {\n close: 'close popup'\n}\n\n/**\n * Number of pixels between the edge of the container and the popup\n * before the popup needs to reposition itself to be in view.\n */\nconst CONTAINER_INSET_PADDING = 16\n\n/**\n * Figures out whether the specified position would overflow the window\n * and picks a better position accordingly\n * @param {Origin} anchorOrigin where the origin is on the trigger\n * @param {Origin} transformOrigin where the origin is on the popup\n * @param {DOMRect} anchorRect the position and size of the trigger\n * @param {DOMRect} wrapperRect the position and size of the popup\n * @return {{ anchorOrigin: Origin, transformOrigin: Origin }} the new origin after accounting for overflow\n */\nconst getComputedOrigins = (\n anchorOrigin: Origin,\n transformOrigin: Origin,\n anchorRect: DOMRect,\n wrapperRect: DOMRect,\n portal: HTMLElement,\n containerRef?: MutableRefObject<HTMLDivElement | undefined>\n) => {\n if (!anchorRect || !wrapperRect) return { anchorOrigin, transformOrigin }\n\n let containerWidth, containerHeight\n if (containerRef && containerRef.current) {\n containerWidth =\n containerRef.current.getBoundingClientRect().width -\n CONTAINER_INSET_PADDING\n containerHeight =\n containerRef.current.getBoundingClientRect().height -\n CONTAINER_INSET_PADDING\n } else {\n containerWidth =\n portal.getBoundingClientRect().width - CONTAINER_INSET_PADDING\n containerHeight =\n portal.getBoundingClientRect().height - CONTAINER_INSET_PADDING\n }\n\n // Get new wrapper position\n const anchorTranslation = getOriginTranslation(anchorOrigin, anchorRect)\n const wrapperTranslation = getOriginTranslation(transformOrigin, wrapperRect)\n const wrapperX = anchorRect.x + anchorTranslation.x - wrapperTranslation.x\n const wrapperY = anchorRect.y + anchorTranslation.y - wrapperTranslation.y\n\n // Check bounds of the wrapper in new position are inside container\n const overflowRight = wrapperX + wrapperRect.width > containerWidth\n const overflowLeft = wrapperX < 0\n const overflowBottom = wrapperY + wrapperRect.height > containerHeight\n const overflowTop = wrapperY < 0\n\n // For all overflows, flip the position\n if (overflowRight) {\n anchorOrigin.horizontal = 'left'\n transformOrigin.horizontal = 'right'\n }\n if (overflowLeft) {\n anchorOrigin.horizontal = 'right'\n transformOrigin.horizontal = 'left'\n }\n if (overflowTop) {\n anchorOrigin.vertical = 'bottom'\n transformOrigin.vertical = 'top'\n }\n if (overflowBottom) {\n anchorOrigin.vertical = 'top'\n transformOrigin.vertical = 'bottom'\n }\n return { anchorOrigin, transformOrigin }\n}\n\n/**\n * Figures out whether the specified position would still overflow the window\n * after being computed and adds extra offsets\n */\nconst getAdjustedPosition = (\n top: number,\n left: number,\n wrapperRect: DOMRect,\n portal: HTMLElement\n): { adjustedTop: number; adjustedLeft: number } => {\n if (!wrapperRect) return { adjustedTop: 0, adjustedLeft: 0 }\n\n const containerWidth =\n portal.getBoundingClientRect().width - CONTAINER_INSET_PADDING\n const containerHeight =\n portal.getBoundingClientRect().height - CONTAINER_INSET_PADDING\n // Account for the portal being a scrollable container.\n // This will happen if the document body itself is what scrolls.\n const containerTop = -1 * portal.getBoundingClientRect().top\n\n const overflowRight = left + wrapperRect.width > containerWidth\n const overflowLeft = left < 0\n const overflowBottom = top + wrapperRect.height > containerHeight\n const overflowTop = top < 0\n\n const adjusted = { adjustedTop: containerTop, adjustedLeft: 0 }\n if (overflowRight) {\n adjusted.adjustedLeft =\n adjusted.adjustedLeft - (left + wrapperRect.width - containerWidth)\n }\n if (overflowLeft) {\n adjusted.adjustedLeft = adjusted.adjustedLeft + wrapperRect.width\n }\n if (overflowTop) {\n adjusted.adjustedTop =\n adjusted.adjustedTop - (top + wrapperRect.height - containerHeight)\n }\n if (overflowBottom) {\n adjusted.adjustedTop = adjusted.adjustedTop + wrapperRect.height\n }\n return adjusted\n}\n\n/**\n * Gets the x, y offsets for the given origin using the dimensions\n * @param origin the relative origin\n * @param dimensions the dimensions to use with the relative origin\n * @returns the x and y coordinates of the new origin relative to the old one\n */\nconst getOriginTranslation = (\n origin: Origin,\n dimensions: { width: number; height: number }\n) => {\n let x = 0\n let y = 0\n const { width, height } = dimensions\n if (origin.horizontal === 'center') {\n x += width / 2\n } else if (origin.horizontal === 'right') {\n x += width\n }\n if (origin.vertical === 'center') {\n y += height / 2\n } else if (origin.vertical === 'bottom') {\n y += height\n }\n return { x, y }\n}\n\nconst defaultAnchorOrigin: Origin = {\n horizontal: 'center',\n vertical: 'bottom'\n}\n\nconst defaultTransformOrigin: Origin = {\n horizontal: 'center',\n vertical: 'top'\n}\n\nconst closingAnimationDuration = 90\n\n/**\n * A popup is an in-place container that shows on top of the UI. A popup does\n * not impact the rest of the UI (e.g. dimming background or shifting elements).\n * It differs from modals, which do take over the whole UI and are usually\n * center-screened.\n */\nexport const Popup = forwardRef<HTMLDivElement, PopupProps>(function Popup(\n props: PopupProps,\n ref: Ref<HTMLDivElement>\n) {\n const {\n anchorRef,\n checkIfClickInside,\n children,\n className,\n isVisible: isVisibleProp,\n onAfterClose,\n onClose,\n anchorOrigin: anchorOriginProp = defaultAnchorOrigin,\n transformOrigin: transformOriginProp = defaultTransformOrigin,\n dismissOnMouseLeave,\n hideCloseButton = false,\n showHeader,\n title,\n zIndex,\n containerRef,\n portalLocation = document.body,\n shadow = 'mid',\n fixed\n } = props\n const { spring, shadows } = useTheme()\n const [popupState, setPopupState] = useState<ModalState>('closed')\n\n const isVisible = popupState !== 'closed'\n\n const handleClose = useCallback(() => {\n onClose?.()\n setTimeout(() => {\n if (onAfterClose) {\n onAfterClose()\n }\n }, closingAnimationDuration)\n }, [onClose, onAfterClose])\n\n const [anchorOrigin, transformOrigin] = [\n anchorOriginProp,\n transformOriginProp\n ]\n\n const popupRef: React.MutableRefObject<HTMLDivElement> = useClickOutside(\n handleClose,\n checkIfClickInside,\n isVisible,\n typeof ref === 'function' ? undefined : ref\n )\n\n const wrapperRef = useRef<HTMLDivElement>(null)\n const originalTopPosition = useRef<number>(0)\n const [computedTransformOrigin, setComputedTransformOrigin] =\n useState(anchorOrigin)\n\n // On visible, set the position\n useEffect(() => {\n if (isVisible) {\n const [anchorRect, wrapperRect] = [anchorRef, wrapperRef].map((r) =>\n r?.current?.getBoundingClientRect()\n )\n if (!anchorRect || !wrapperRect) return\n\n const {\n anchorOrigin: anchorOriginComputed,\n transformOrigin: transformOriginComputed\n } = getComputedOrigins(\n anchorOrigin,\n transformOrigin,\n anchorRect,\n wrapperRect,\n portalLocation,\n containerRef\n )\n setComputedTransformOrigin(transformOriginComputed)\n\n const anchorTranslation = getOriginTranslation(\n anchorOriginComputed,\n anchorRect\n )\n const wrapperTranslation = getOriginTranslation(\n transformOriginComputed,\n wrapperRect\n )\n\n const top = anchorRect.y + anchorTranslation.y - wrapperTranslation.y\n const left = anchorRect.x + anchorTranslation.x - wrapperTranslation.x\n\n const { adjustedTop, adjustedLeft } = getAdjustedPosition(\n top,\n left,\n wrapperRect,\n portalLocation\n )\n\n if (wrapperRef.current) {\n wrapperRef.current.style.top = `${top + adjustedTop}px`\n wrapperRef.current.style.left = `${left + adjustedLeft}px`\n }\n\n originalTopPosition.current = top\n }\n }, [\n isVisible,\n wrapperRef,\n anchorRef,\n anchorOrigin,\n transformOrigin,\n setComputedTransformOrigin,\n originalTopPosition,\n portalLocation,\n containerRef\n ])\n\n // Callback invoked on each scroll. Uses original top position to scroll with content.\n // Takes scrollParent to get the current scroll position as well as the intitial scroll position\n // when the popup became visible.\n const watchScroll = useCallback(\n (scrollParent: Element, initialScrollPosition: number) => {\n const scrollTop = scrollParent.scrollTop\n if (wrapperRef.current) {\n wrapperRef.current.style.top = `${\n originalTopPosition.current - scrollTop + initialScrollPosition\n }px`\n }\n },\n [wrapperRef, originalTopPosition]\n )\n\n // Set up scroll listeners\n useEffect(() => {\n if (isVisible && anchorRef.current) {\n const scrollParent = getScrollParent(anchorRef.current)\n if (!scrollParent) return\n\n const initialScrollPosition = scrollParent.scrollTop\n const listener = () => watchScroll(scrollParent, initialScrollPosition)\n scrollParent.addEventListener('scroll', listener)\n return () => {\n scrollParent.removeEventListener('scroll', listener)\n }\n }\n\n return () => {}\n }, [isVisible, watchScroll, anchorRef])\n\n // Set up key listeners\n useEffect(() => {\n if (isVisible) {\n const escapeListener = (e: KeyboardEvent) => {\n if (e.code === 'Escape') {\n handleClose()\n }\n }\n\n window.addEventListener('keydown', escapeListener)\n\n return () => window.removeEventListener('keydown', escapeListener)\n }\n return () => {}\n }, [isVisible, handleClose])\n\n useEffect(() => {\n if (popupState === 'closed' && isVisibleProp) {\n setPopupState('opening')\n } else if (popupState === 'open' && !isVisibleProp) {\n setPopupState('closing')\n anchorRef.current?.focus()\n }\n }, [isVisibleProp, popupState])\n\n const transitions = useTransition(isVisibleProp, null, {\n from: {\n transform: `scale(0)`,\n opacity: 0\n },\n enter: {\n transform: `scale(1)`,\n opacity: 1\n },\n leave: {\n transform: `scale(0)`,\n opacity: 0\n },\n config: spring.standard,\n unique: true,\n onDestroyed: (isDestroyed) => {\n setPopupState(isDestroyed ? 'closed' : 'open')\n }\n })\n\n const rootStyle = { zIndex, position: fixed ? ('fixed' as const) : undefined }\n\n const handleMouseLeave = useCallback(() => {\n if (dismissOnMouseLeave) {\n onClose?.()\n }\n }, [dismissOnMouseLeave, onClose])\n\n return (\n <>\n {/* Portal the popup out of the dom structure so that it has a separate stacking context */}\n {popupState !== 'closed'\n ? ReactDOM.createPortal(\n <div\n ref={wrapperRef}\n className={styles.root}\n style={rootStyle}\n onMouseLeave={handleMouseLeave}\n >\n {transitions.map(({ item, key, props }) =>\n item ? (\n <animated.div\n className={cn(styles.popup, className)}\n css={{ boxShadow: shadows[shadow] }}\n ref={popupRef}\n key={key}\n style={{\n ...props,\n transformOrigin: `${computedTransformOrigin.horizontal} ${computedTransformOrigin.vertical}`\n }}\n >\n {showHeader && (\n <div\n className={cn(styles.header, {\n [styles.noAfter]: hideCloseButton\n })}\n >\n {hideCloseButton ? null : (\n <PlainButton\n variant='subdued'\n aria-label={messages.close}\n onClick={handleClose}\n iconLeft={IconClose}\n />\n )}\n <div className={styles.title}>{title}</div>\n </div>\n )}\n {children}\n </animated.div>\n ) : null\n )}\n </div>,\n portalLocation\n )\n : null}\n </>\n )\n})\n"],"names":["_jsx","_Fragment","_jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,IAAM,QAAQ,GAAG;AACf,IAAA,KAAK,EAAE,aAAa;CACrB,CAAA;AAED;;;AAGG;AACH,IAAM,uBAAuB,GAAG,EAAE,CAAA;AAElC;;;;;;;;AAQG;AACH,IAAM,kBAAkB,GAAG,UACzB,YAAoB,EACpB,eAAuB,EACvB,UAAmB,EACnB,WAAoB,EACpB,MAAmB,EACnB,YAA2D,EAAA;AAE3D,IAAA,IAAI,CAAC,UAAU,IAAI,CAAC,WAAW;AAAE,QAAA,OAAO,EAAE,YAAY,EAAA,YAAA,EAAE,eAAe,EAAA,eAAA,EAAE,CAAA;IAEzE,IAAI,cAAc,EAAE,eAAe,CAAA;AACnC,IAAA,IAAI,YAAY,IAAI,YAAY,CAAC,OAAO,EAAE;QACxC,cAAc;AACZ,YAAA,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,KAAK;AAClD,gBAAA,uBAAuB,CAAA;QACzB,eAAe;AACb,YAAA,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,MAAM;AACnD,gBAAA,uBAAuB,CAAA;AAC1B,KAAA;AAAM,SAAA;QACL,cAAc;AACZ,YAAA,MAAM,CAAC,qBAAqB,EAAE,CAAC,KAAK,GAAG,uBAAuB,CAAA;QAChE,eAAe;AACb,YAAA,MAAM,CAAC,qBAAqB,EAAE,CAAC,MAAM,GAAG,uBAAuB,CAAA;AAClE,KAAA;;IAGD,IAAM,iBAAiB,GAAG,oBAAoB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IACxE,IAAM,kBAAkB,GAAG,oBAAoB,CAAC,eAAe,EAAE,WAAW,CAAC,CAAA;AAC7E,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SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EACnC,GAAG,EAAE,QAAQ,EAEb,KAAK,EACA,QAAA,CAAA,QAAA,CAAA,EAAA,EAAA,KAAK,CACR,EAAA,EAAA,eAAe,EAAE,EAAA,CAAA,MAAA,CAAG,uBAAuB,CAAC,UAAU,EAAA,GAAA,CAAA,CAAA,MAAA,CAAI,uBAAuB,CAAC,QAAQ,CAAE,EAG7F,CAAA,EAAA,EAAA,EAAA,QAAA,EAAA,CAAA,UAAU,KACTA,IACE,CAAA,KAAA,EAAA,QAAA,CAAA,EAAA,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,GAAA,EAAA,GAAA,EAAA;AACzB,oCAAA,EAAA,CAAC,MAAM,CAAC,OAAO,CAAA,GAAG,eAAe;wCACjC,EAED,EAAA,EAAA,QAAA,EAAA,CAAA,eAAe,GAAG,IAAI,IACrBF,GAAC,CAAA,WAAW,IACV,OAAO,EAAC,SAAS,EAAA,YAAA,EACL,QAAQ,CAAC,KAAK,EAC1B,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,SAAS,EAAA,CACnB,CACH,EACDA,GAAA,CAAA,KAAA,EAAA,QAAA,CAAA,EAAK,SAAS,EAAE,MAAM,CAAC,KAAK,EAAG,EAAA,EAAA,QAAA,EAAA,KAAK,IAAO,CACvC,EAAA,CAAA,CAAA,CACP,EACA,QAAQ,CAvBJ,EAAA,CAAA,EAAA,GAAG,CAwBK,IACb,IAAI,CAAA;AA9BR,iBA8BQ,CACT,EAAA,CAAA,CACG,EACN,cAAc,CACf;AACH,cAAE,IAAI,EACP,CAAA,EACJ;AACH,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"Popup.js","sources":["../../../src/components/popup/Popup.tsx"],"sourcesContent":["import {\n forwardRef,\n MutableRefObject,\n Ref,\n SetStateAction,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react'\n\nimport { useTheme } from '@emotion/react'\nimport cn from 'classnames'\nimport ReactDOM from 'react-dom'\nimport { useTransition, animated } from 'react-spring'\nimport { usePrevious } from 'react-use'\n\nimport { PlainButton } from 'components/button'\nimport { IconClose } from 'icons'\nimport { ModalState } from 'utils/modalState'\n\nimport { useClickOutside } from '../../hooks/useClickOutside'\nimport { getScrollParent } from '../../utils/getScrollParent'\n\nimport styles from './Popup.module.css'\nimport type { PopupProps, Origin } from './types'\n\nconst messages = {\n close: 'close popup'\n}\n\n/**\n * Number of pixels between the edge of the container and the popup\n * before the popup needs to reposition itself to be in view.\n */\nconst CONTAINER_INSET_PADDING = 16\n\n/**\n * Figures out whether the specified position would overflow the window\n * and picks a better position accordingly\n * @param {Origin} anchorOrigin where the origin is on the trigger\n * @param {Origin} transformOrigin where the origin is on the popup\n * @param {DOMRect} anchorRect the position and size of the trigger\n * @param {DOMRect} wrapperRect the position and size of the popup\n * @return {{ anchorOrigin: Origin, transformOrigin: Origin }} the new origin after accounting for overflow\n */\nconst getComputedOrigins = (\n anchorOrigin: Origin,\n transformOrigin: Origin,\n anchorRect: DOMRect,\n wrapperRect: DOMRect,\n portal: HTMLElement,\n containerRef?: MutableRefObject<HTMLDivElement | undefined>\n) => {\n if (!anchorRect || !wrapperRect) return { anchorOrigin, transformOrigin }\n\n let containerWidth, containerHeight\n if (containerRef && containerRef.current) {\n const containerRect = containerRef.current.getBoundingClientRect()\n containerWidth =\n containerRect.width + containerRect.x - CONTAINER_INSET_PADDING\n containerHeight =\n containerRect.height + containerRect.y - CONTAINER_INSET_PADDING\n } else {\n const portalRect = portal.getBoundingClientRect()\n containerWidth = portalRect.width + portalRect.x - CONTAINER_INSET_PADDING\n containerHeight = portalRect.height + portalRect.y - CONTAINER_INSET_PADDING\n }\n\n // Get new wrapper position\n const anchorTranslation = getOriginTranslation(anchorOrigin, anchorRect)\n const wrapperTranslation = getOriginTranslation(transformOrigin, wrapperRect)\n const wrapperX = anchorRect.x + anchorTranslation.x - wrapperTranslation.x\n const wrapperY = anchorRect.y + anchorTranslation.y - wrapperTranslation.y\n\n // Check bounds of the wrapper in new position are inside container\n const overflowRight = wrapperX + wrapperRect.width > containerWidth\n const overflowLeft = wrapperX < 0\n const overflowBottom = wrapperY + wrapperRect.height > containerHeight\n const overflowTop = wrapperY < 0\n\n // For all overflows, flip the position\n if (overflowRight) {\n anchorOrigin.horizontal = 'left'\n transformOrigin.horizontal = 'right'\n }\n if (overflowLeft) {\n anchorOrigin.horizontal = 'right'\n transformOrigin.horizontal = 'left'\n }\n if (overflowTop) {\n anchorOrigin.vertical = 'bottom'\n transformOrigin.vertical = 'top'\n }\n if (overflowBottom) {\n anchorOrigin.vertical = 'top'\n transformOrigin.vertical = 'bottom'\n }\n return { anchorOrigin, transformOrigin }\n}\n\n/**\n * Figures out whether the specified position would still overflow the window\n * after being computed and adds extra offsets\n */\nconst getAdjustedPosition = (\n top: number,\n left: number,\n wrapperRect: DOMRect,\n portal: HTMLElement\n): { adjustedTop: number; adjustedLeft: number } => {\n if (!wrapperRect) return { adjustedTop: 0, adjustedLeft: 0 }\n\n const containerWidth =\n portal.getBoundingClientRect().width - CONTAINER_INSET_PADDING\n const containerHeight =\n portal.getBoundingClientRect().height - CONTAINER_INSET_PADDING\n // Account for the portal being a scrollable container.\n // This will happen if the document body itself is what scrolls.\n const containerTop = -1 * portal.getBoundingClientRect().top\n\n const overflowRight = left + wrapperRect.width > containerWidth\n const overflowLeft = left < 0\n const overflowBottom = top + wrapperRect.height > containerHeight\n const overflowTop = top < 0\n\n const adjusted = { adjustedTop: containerTop, adjustedLeft: 0 }\n if (overflowRight) {\n adjusted.adjustedLeft =\n adjusted.adjustedLeft - (left + wrapperRect.width - containerWidth)\n }\n if (overflowLeft) {\n adjusted.adjustedLeft = adjusted.adjustedLeft + wrapperRect.width\n }\n if (overflowTop) {\n adjusted.adjustedTop =\n adjusted.adjustedTop - (top + wrapperRect.height - containerHeight)\n }\n if (overflowBottom) {\n adjusted.adjustedTop = adjusted.adjustedTop + wrapperRect.height\n }\n return adjusted\n}\n\n/**\n * Gets the x, y offsets for the given origin using the dimensions\n * @param origin the relative origin\n * @param dimensions the dimensions to use with the relative origin\n * @returns the x and y coordinates of the new origin relative to the old one\n */\nconst getOriginTranslation = (\n origin: Origin,\n dimensions: { width: number; height: number }\n) => {\n let x = 0\n let y = 0\n const { width, height } = dimensions\n if (origin.horizontal === 'center') {\n x += width / 2\n } else if (origin.horizontal === 'right') {\n x += width\n }\n if (origin.vertical === 'center') {\n y += height / 2\n } else if (origin.vertical === 'bottom') {\n y += height\n }\n return { x, y }\n}\n\nconst defaultAnchorOrigin: Origin = {\n horizontal: 'center',\n vertical: 'bottom'\n}\n\nconst defaultTransformOrigin: Origin = {\n horizontal: 'center',\n vertical: 'top'\n}\n\nconst closingAnimationDuration = 90\n\n/**\n * A popup is an in-place container that shows on top of the UI. A popup does\n * not impact the rest of the UI (e.g. dimming background or shifting elements).\n * It differs from modals, which do take over the whole UI and are usually\n * center-screened.\n */\nexport const Popup = forwardRef<HTMLDivElement, PopupProps>(function Popup(\n props: PopupProps,\n ref: Ref<HTMLDivElement>\n) {\n const { isVisible: isVisibleProp } = props\n const [popupState, setPopupState] = useState<ModalState>('closed')\n\n const isVisible = popupState !== 'closed'\n useEffect(() => {\n if (popupState === 'closed' && isVisibleProp) {\n setPopupState('opening')\n } else if (popupState === 'open' && !isVisibleProp) {\n setPopupState('closing')\n }\n }, [isVisibleProp, popupState])\n\n return isVisible ? (\n <PopupInternal\n ref={ref}\n popupState={popupState}\n setPopupState={setPopupState}\n {...props}\n />\n ) : null\n})\n\nexport const PopupInternal = forwardRef<\n HTMLDivElement,\n PopupProps & {\n popupState: ModalState\n setPopupState: (value: SetStateAction<ModalState>) => void\n }\n>(function Popup(\n props: PopupProps & {\n popupState: ModalState\n setPopupState: (value: SetStateAction<ModalState>) => void\n },\n ref: Ref<HTMLDivElement>\n) {\n const {\n popupState,\n setPopupState,\n anchorRef,\n checkIfClickInside,\n children,\n className,\n isVisible: isVisibleProp,\n onAfterClose,\n onClose,\n anchorOrigin: anchorOriginProp = defaultAnchorOrigin,\n transformOrigin: transformOriginProp = defaultTransformOrigin,\n dismissOnMouseLeave,\n hideCloseButton = false,\n showHeader,\n title,\n zIndex,\n containerRef,\n portalLocation = document.body,\n shadow = 'mid',\n fixed,\n takeWidthOfAnchor\n } = props\n const { spring, shadows } = useTheme()\n\n const isVisible = popupState !== 'closed'\n const previousIsVisible = usePrevious(isVisible)\n\n const handleClose = useCallback(() => {\n onClose?.()\n setTimeout(() => {\n if (onAfterClose) {\n onAfterClose()\n }\n }, closingAnimationDuration)\n }, [onClose, onAfterClose])\n\n const [anchorOrigin, transformOrigin] = [\n anchorOriginProp,\n transformOriginProp\n ]\n\n const popupRef: React.MutableRefObject<HTMLDivElement> = useClickOutside(\n handleClose,\n isVisible,\n checkIfClickInside,\n typeof ref === 'function' ? undefined : ref\n )\n\n const wrapperRef = useRef<HTMLDivElement>(null)\n const originalTopPosition = useRef<number>(0)\n const [computedTransformOrigin, setComputedTransformOrigin] =\n useState(anchorOrigin)\n\n const wrapperHeight = wrapperRef?.current?.offsetHeight ?? null\n const wrapperWidth = wrapperRef?.current?.offsetWidth ?? null\n const previousHeight = usePrevious(wrapperHeight)\n const previousWidth = usePrevious(wrapperWidth)\n const wrapperSizeChange =\n wrapperHeight !== previousHeight || wrapperWidth !== previousWidth\n\n // On visible, set the position\n useEffect(() => {\n if ((isVisible && !previousIsVisible) || wrapperSizeChange) {\n const [anchorRect, wrapperRect] = [anchorRef, wrapperRef].map((r) =>\n r?.current?.getBoundingClientRect()\n )\n if (!anchorRect || !wrapperRect) return\n\n const {\n anchorOrigin: anchorOriginComputed,\n transformOrigin: transformOriginComputed\n } = getComputedOrigins(\n anchorOrigin,\n transformOrigin,\n anchorRect,\n wrapperRect,\n portalLocation,\n containerRef\n )\n setComputedTransformOrigin(transformOriginComputed)\n\n const anchorTranslation = getOriginTranslation(\n anchorOriginComputed,\n anchorRect\n )\n const wrapperTranslation = getOriginTranslation(\n transformOriginComputed,\n wrapperRect\n )\n\n const top = anchorRect.y + anchorTranslation.y - wrapperTranslation.y\n const left = anchorRect.x + anchorTranslation.x - wrapperTranslation.x\n\n const { adjustedTop, adjustedLeft } = getAdjustedPosition(\n top,\n left,\n wrapperRect,\n portalLocation\n )\n\n if (wrapperRef.current) {\n wrapperRef.current.style.top = `${top + adjustedTop}px`\n wrapperRef.current.style.left = `${left + adjustedLeft}px`\n }\n\n originalTopPosition.current = top\n }\n }, [isVisible, wrapperRef, anchorRef, anchorOrigin, transformOrigin, setComputedTransformOrigin, originalTopPosition, portalLocation, containerRef, previousIsVisible, previousHeight, wrapperSizeChange])\n\n // Callback invoked on each scroll. Uses original top position to scroll with content.\n // Takes scrollParent to get the current scroll position as well as the intitial scroll position\n // when the popup became visible.\n const watchScroll = useCallback(\n (scrollParent: Element, initialScrollPosition: number) => {\n const scrollTop = scrollParent.scrollTop\n if (wrapperRef.current) {\n wrapperRef.current.style.top = `${\n originalTopPosition.current - scrollTop + initialScrollPosition\n }px`\n }\n },\n [wrapperRef, originalTopPosition]\n )\n\n // Set up scroll listeners\n useEffect(() => {\n if (isVisible && anchorRef.current) {\n const scrollParent = getScrollParent(anchorRef.current)\n if (!scrollParent) return\n\n const initialScrollPosition = scrollParent.scrollTop\n const listener = () => watchScroll(scrollParent, initialScrollPosition)\n scrollParent.addEventListener('scroll', listener)\n return () => {\n scrollParent.removeEventListener('scroll', listener)\n }\n }\n\n return () => {}\n }, [isVisible, watchScroll, anchorRef])\n\n // Set up key listeners\n useEffect(() => {\n if (isVisible) {\n const escapeListener = (e: KeyboardEvent) => {\n if (e.code === 'Escape') {\n handleClose()\n }\n }\n\n window.addEventListener('keydown', escapeListener)\n\n return () => window.removeEventListener('keydown', escapeListener)\n }\n return () => {}\n }, [isVisible, handleClose])\n\n useEffect(() => {\n if (popupState === 'closed' && isVisibleProp) {\n } else if (popupState === 'open' && !isVisibleProp) {\n anchorRef.current?.focus()\n }\n }, [anchorRef, isVisibleProp, popupState])\n\n const transitions = useTransition(isVisibleProp, null, {\n from: {\n transform: `scale(0)`,\n opacity: 0\n },\n enter: {\n transform: `scale(1)`,\n opacity: 1\n },\n leave: {\n transform: `scale(0)`,\n opacity: 0\n },\n config: spring.standard,\n unique: true,\n onDestroyed: (isDestroyed) => {\n setPopupState(isDestroyed ? 'closed' : 'open')\n }\n })\n\n const rootStyle = {\n zIndex,\n position: fixed ? ('fixed' as const) : undefined,\n width: takeWidthOfAnchor ? anchorRef.current?.clientWidth : undefined\n }\n\n const handleMouseLeave = useCallback(() => {\n if (dismissOnMouseLeave) {\n onClose?.()\n }\n }, [dismissOnMouseLeave, onClose])\n\n return (\n <>\n {/* Portal the popup out of the dom structure so that it has a separate stacking context */}\n {popupState !== 'closed'\n ? ReactDOM.createPortal(\n <div\n ref={wrapperRef}\n className={styles.root}\n style={rootStyle}\n onMouseLeave={handleMouseLeave}\n >\n {transitions.map(({ item, key, props }) =>\n item ? (\n <animated.div\n className={cn(styles.popup, className)}\n css={{ boxShadow: shadows[shadow] }}\n ref={popupRef}\n key={key}\n style={{\n ...props,\n transformOrigin: `${computedTransformOrigin.horizontal} ${computedTransformOrigin.vertical}`\n }}\n >\n {showHeader && (\n <div\n className={cn(styles.header, {\n [styles.noAfter]: hideCloseButton\n })}\n >\n {hideCloseButton ? null : (\n <PlainButton\n variant='subdued'\n aria-label={messages.close}\n onClick={handleClose}\n iconLeft={IconClose}\n />\n )}\n <div className={styles.title}>{title}</div>\n </div>\n )}\n {children}\n </animated.div>\n ) : null\n )}\n </div>,\n portalLocation\n )\n : null}\n </>\n )\n})\n"],"names":["_jsx","_Fragment","_jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,IAAM,QAAQ,GAAG;AACf,IAAA,KAAK,EAAE,aAAa;CACrB,CAAA;AAED;;;AAGG;AACH,IAAM,uBAAuB,GAAG,EAAE,CAAA;AAElC;;;;;;;;AAQG;AACH,IAAM,kBAAkB,GAAG,UACzB,YAAoB,EACpB,eAAuB,EACvB,UAAmB,EAC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AAC,cAAc,GAAG,SAAS,CAAC,CAAA;IAE3D;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IAEpB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IAEzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAA;IAErD;;;OAGG;IACH,cAAc,CAAC,EAAE,WAAW,CAAA;IAC5B,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scrubber.d.ts","sourceRoot":"","sources":["../../../src/components/scrubber/Scrubber.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Scrubber.d.ts","sourceRoot":"","sources":["../../../src/components/scrubber/Scrubber.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAwB,MAAM,SAAS,CAAA;AAK7D;;;GAGG;AACH,eAAO,MAAM,QAAQ;sLAclB,aAAa;;;;;;;;;CA8Df,CAAA"}
|
|
@@ -2,24 +2,14 @@ import { __assign } from '../../_virtual/_tslib.js';
|
|
|
2
2
|
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
3
3
|
import { useState, useEffect } from 'react';
|
|
4
4
|
import cn from 'classnames';
|
|
5
|
-
import
|
|
5
|
+
import { formatTrackTimestamp } from '../../utils/formatTrackTimestamp.js';
|
|
6
|
+
import 'lodash';
|
|
6
7
|
import styles from './Scrubber.module.css.js';
|
|
7
8
|
import { Slider } from './Slider.js';
|
|
8
9
|
import { defaultScrubberProps } from './types.js';
|
|
9
10
|
|
|
10
|
-
var SECONDS_PER_MINUTE = 60;
|
|
11
|
-
var MINUTES_PER_HOUR = 60;
|
|
12
|
-
var SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR;
|
|
13
11
|
/** Timeout applied when releasing the drag-handle before timestamps reset. */
|
|
14
12
|
var SCRUB_RELEASE_TIMEOUT_MS = 200;
|
|
15
|
-
/** Pretty formats seconds into m:ss. */
|
|
16
|
-
var formatSeconds = function (seconds) {
|
|
17
|
-
var utc = moment.utc(moment.duration(seconds, 'seconds').asMilliseconds());
|
|
18
|
-
if (seconds > SECONDS_PER_HOUR) {
|
|
19
|
-
return utc.format('h:mm:ss');
|
|
20
|
-
}
|
|
21
|
-
return utc.format('m:ss');
|
|
22
|
-
};
|
|
23
13
|
/**
|
|
24
14
|
* @beta - This component was directly ported from stems and subject to change
|
|
25
15
|
* Wraps the `<Slider />` component and provides timestamp indicators.
|
|
@@ -53,7 +43,7 @@ var Scrubber = function (_a) {
|
|
|
53
43
|
_b[styles.isDisabled] = isDisabled,
|
|
54
44
|
_b[styles.isMobile] = isMobile,
|
|
55
45
|
_b.className = className,
|
|
56
|
-
_b)) }, { children: [includeTimestamps && (jsx("div", __assign({ className: styles.timestampStart }, { children:
|
|
46
|
+
_b)) }, { children: [includeTimestamps && (jsx("div", __assign({ className: styles.timestampStart }, { children: formatTrackTimestamp(timestampStart) }))), jsx(Slider, { mediaKey: mediaKey, isPlaying: isPlaying, isDisabled: isDisabled, isMobile: isMobile, elapsedSeconds: elapsedSeconds, totalSeconds: totalSeconds, playbackRate: playbackRate, onScrub: onHandleScrub, onScrubRelease: onHandleScrubRelease, includeExpandedTargets: includeExpandedTargets, style: style }), includeTimestamps && (jsx("div", __assign({ className: styles.timestampEnd }, { children: formatTrackTimestamp(totalSeconds) })))] })));
|
|
57
47
|
};
|
|
58
48
|
Scrubber.defaultProps = defaultScrubberProps;
|
|
59
49
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scrubber.js","sources":["../../../src/components/scrubber/Scrubber.tsx"],"sourcesContent":["import { useState, useEffect } from 'react'\n\nimport cn from 'classnames'\nimport
|
|
1
|
+
{"version":3,"file":"Scrubber.js","sources":["../../../src/components/scrubber/Scrubber.tsx"],"sourcesContent":["import { useState, useEffect } from 'react'\n\nimport cn from 'classnames'\n\nimport { formatTrackTimestamp } from 'utils'\n\nimport styles from './Scrubber.module.css'\nimport { Slider } from './Slider'\nimport { ScrubberProps, defaultScrubberProps } from './types'\n\n/** Timeout applied when releasing the drag-handle before timestamps reset. */\nconst SCRUB_RELEASE_TIMEOUT_MS = 200\n\n/**\n * @beta - This component was directly ported from stems and subject to change\n * Wraps the `<Slider />` component and provides timestamp indicators.\n */\nexport const Scrubber = ({\n mediaKey,\n isPlaying,\n isDisabled,\n isMobile,\n includeTimestamps,\n elapsedSeconds,\n totalSeconds,\n playbackRate,\n onScrub,\n onScrubRelease,\n includeExpandedTargets,\n style,\n className\n}: ScrubberProps) => {\n const [dragSeconds, setDragSeconds] = useState<number | null>(null)\n\n const resetDragSeconds = (isPlaying: boolean) => {\n if (isPlaying) {\n setTimeout(() => setDragSeconds(null), SCRUB_RELEASE_TIMEOUT_MS)\n }\n }\n\n const onHandleScrub = (seconds: number) => {\n setDragSeconds(seconds)\n if (onScrub) {\n onScrub(seconds)\n }\n }\n\n const onHandleScrubRelease = (seconds: number) => {\n if (onScrubRelease) {\n onScrubRelease(seconds)\n }\n resetDragSeconds(isPlaying)\n }\n\n useEffect(() => {\n resetDragSeconds(isPlaying)\n }, [isPlaying])\n\n const timestampStart = dragSeconds !== null ? dragSeconds : elapsedSeconds\n\n return (\n <div\n className={cn(styles.scrubber, {\n [styles.isDisabled]: isDisabled,\n [styles.isMobile]: isMobile,\n className\n })}\n >\n {includeTimestamps && (\n <div className={styles.timestampStart}>\n {formatTrackTimestamp(timestampStart)}\n </div>\n )}\n <Slider\n mediaKey={mediaKey}\n isPlaying={isPlaying}\n isDisabled={isDisabled}\n isMobile={isMobile}\n elapsedSeconds={elapsedSeconds}\n totalSeconds={totalSeconds}\n playbackRate={playbackRate}\n onScrub={onHandleScrub}\n onScrubRelease={onHandleScrubRelease}\n includeExpandedTargets={includeExpandedTargets}\n style={style}\n />\n {includeTimestamps && (\n <div className={styles.timestampEnd}>\n {formatTrackTimestamp(totalSeconds)}\n </div>\n )}\n </div>\n )\n}\n\nScrubber.defaultProps = defaultScrubberProps\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AAUA;AACA,IAAM,wBAAwB,GAAG,GAAG,CAAA;AAEpC;;;AAGG;AACI,IAAM,QAAQ,GAAG,UAAC,EAcT,EAAA;;AAbd,IAAA,IAAA,QAAQ,cAAA,EACR,SAAS,GAAA,EAAA,CAAA,SAAA,EACT,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,QAAQ,GAAA,EAAA,CAAA,QAAA,EACR,iBAAiB,GAAA,EAAA,CAAA,iBAAA,EACjB,cAAc,oBAAA,EACd,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,OAAO,GAAA,EAAA,CAAA,OAAA,EACP,cAAc,GAAA,EAAA,CAAA,cAAA,EACd,sBAAsB,4BAAA,EACtB,KAAK,GAAA,EAAA,CAAA,KAAA,EACL,SAAS,GAAA,EAAA,CAAA,SAAA,CAAA;IAEH,IAAA,EAAA,GAAgC,QAAQ,CAAgB,IAAI,CAAC,EAA5D,WAAW,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,cAAc,GAAA,EAAA,CAAA,CAAA,CAAiC,CAAA;IAEnE,IAAM,gBAAgB,GAAG,UAAC,SAAkB,EAAA;AAC1C,QAAA,IAAI,SAAS,EAAE;AACb,YAAA,UAAU,CAAC,YAAA,EAAM,OAAA,cAAc,CAAC,IAAI,CAAC,CAAA,EAAA,EAAE,wBAAwB,CAAC,CAAA;AACjE,SAAA;AACH,KAAC,CAAA;IAED,IAAM,aAAa,GAAG,UAAC,OAAe,EAAA;QACpC,cAAc,CAAC,OAAO,CAAC,CAAA;AACvB,QAAA,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,OAAO,CAAC,CAAA;AACjB,SAA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E,MAAM,CAAC,YAAY,EAChC,EAAA,EAAA,QAAA,EAAA,oBAAoB,CAAC,YAAY,CAAC,IAC/B,CACP,CAAA,EAAA,CAAA,CACG,EACP;AACH,EAAC;AAED,QAAQ,CAAC,YAAY,GAAG,oBAAoB;;;;"}
|
|
@@ -163,7 +163,7 @@ var Slider = function (_a) {
|
|
|
163
163
|
useEffect(function () {
|
|
164
164
|
setPercent(elapsedSeconds / totalSeconds);
|
|
165
165
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
166
|
-
}, [playbackRate]);
|
|
166
|
+
}, [playbackRate, elapsedSeconds, totalSeconds]);
|
|
167
167
|
// When the key changes, reset the animation
|
|
168
168
|
useEffect(function () {
|
|
169
169
|
if (mediaKey !== previousMediaKey) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.js","sources":["../../../src/components/scrubber/Slider.tsx"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, CSSProperties } from 'react'\nimport * as React from 'react'\n\nimport cn from 'classnames'\n\nimport styles from './Slider.module.css'\nimport { useAnimations } from './hooks'\nimport { ScrubberProps } from './types'\n\n/** Gets the X-position of a div. */\nconst getXPosition = (element: HTMLDivElement) => {\n const coords = element.getBoundingClientRect()\n return window.pageXOffset + coords.left\n}\n\n/**\n * A smooth scrubbable slider that relies on CSS animations rather\n * than progress ticks to achieve fluidity.\n */\nexport const Slider = ({\n mediaKey,\n isPlaying,\n isMobile,\n isDisabled,\n elapsedSeconds,\n totalSeconds,\n playbackRate,\n onScrub,\n onScrubRelease,\n includeExpandedTargets = true,\n style\n}: ScrubberProps) => {\n const [previousMediaKey, setPreviousMediaKey] = useState('')\n\n // Percentage of the complete scrubber being dragged to.\n // e.g. 0.25 means the user has dragged the scrubber 1/4th of the way.\n const dragPercent = useRef<number | null>(0)\n\n // Refs to handle event listeners\n const mouseMoveRef = useRef<((this: Document, ev: MouseEvent) => any) | null>(\n null\n )\n const mouseUpRef = useRef<((this: Document, ev: MouseEvent) => any) | null>(\n null\n )\n const touchMoveRef = useRef<((e: TouchEvent) => any) | null>(null)\n const touchEndRef = useRef<((e: TouchEvent) => any) | null>(null)\n\n // Div refs\n const railRef = useRef<HTMLDivElement>(null)\n const trackRef = useRef<HTMLDivElement>(null)\n const handleRef = useRef<HTMLDivElement>(null)\n\n const { play, pause, setPercent } = useAnimations(\n trackRef,\n handleRef,\n elapsedSeconds,\n totalSeconds,\n playbackRate\n )\n\n /**\n * Sets the percentage across the scrubber for a given pageX position.\n */\n const setDragPercent = useCallback(\n (pageX: number) => {\n if (railRef.current) {\n const clickPosition = pageX - getXPosition(railRef.current)\n const railWidth = railRef.current.offsetWidth\n const percent =\n Math.min(Math.max(0, clickPosition), railWidth) / railWidth\n dragPercent.current = percent\n }\n },\n [dragPercent]\n )\n\n /**\n * Sets the percentage across the scrubber for a given mouse event.\n */\n const setDragPercentMouse = useCallback(\n (e: React.MouseEvent | MouseEvent) => {\n setDragPercent(e.pageX)\n },\n [setDragPercent]\n )\n\n /**\n * Sets the percentage across the scurbber for a given touch event.\n */\n const setDragPercentTouch = useCallback(\n (e: React.TouchEvent | TouchEvent) => {\n setDragPercent(e.touches[0].pageX)\n },\n [setDragPercent]\n )\n\n /**\n * Watches user mouse movements while the scrubber handle is being dragged.\n */\n const onMouseMove = useCallback(\n (e: MouseEvent) => {\n e.stopPropagation()\n e.preventDefault()\n\n setDragPercentMouse(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n const seconds = dragPercent.current * totalSeconds\n if (onScrub) {\n onScrub(seconds)\n }\n }\n },\n [dragPercent, setDragPercentMouse, totalSeconds, setPercent, onScrub]\n )\n\n /**\n * Watches user touch movements while the scrubber handle is being dragged.\n */\n const onTouchMove = useCallback(\n (e: TouchEvent) => {\n e.stopPropagation()\n e.preventDefault()\n\n setDragPercentTouch(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n\n const seconds = dragPercent.current * totalSeconds\n if (onScrub) {\n onScrub(seconds)\n }\n }\n },\n [dragPercent, setDragPercentTouch, totalSeconds, setPercent, onScrub]\n )\n\n /**\n * Watches for a mouse-up action (which may not occur on the scrubber itself),\n * calls the release callback, and resets dragging state.\n */\n const onMouseUp = useCallback(() => {\n if (mouseMoveRef.current) {\n document.removeEventListener('mousemove', mouseMoveRef.current)\n }\n if (mouseUpRef.current) {\n document.removeEventListener('mouseup', mouseUpRef.current)\n }\n\n if (dragPercent.current !== null) {\n const seconds = dragPercent.current * totalSeconds\n if (onScrubRelease) {\n onScrubRelease(seconds)\n }\n\n dragPercent.current = null\n }\n }, [mouseMoveRef, mouseUpRef, dragPercent, totalSeconds, onScrubRelease])\n\n /**\n * Watches for a touch-end action (which may not occur on the scrubber itself),\n * calls the release callback, and resets dragging state.\n */\n const onTouchEnd = useCallback(() => {\n if (touchMoveRef.current) {\n document.removeEventListener('touchmove', touchMoveRef.current)\n }\n if (touchEndRef.current) {\n document.removeEventListener('touchend', touchEndRef.current)\n }\n\n if (dragPercent.current !== null) {\n const seconds = dragPercent.current * totalSeconds\n if (onScrubRelease) {\n onScrubRelease(seconds)\n }\n\n dragPercent.current = null\n }\n }, [touchMoveRef, touchEndRef, dragPercent, totalSeconds, onScrubRelease])\n\n /**\n * Attaches mouse-move and mouse-up event listeners and sets dragging state.\n */\n const onMouseDown = (e: React.MouseEvent) => {\n // Cancel mouse down if touch was fired.\n if (e.button !== 0 || touchMoveRef.current) return\n\n mouseMoveRef.current = onMouseMove\n mouseUpRef.current = onMouseUp\n document.addEventListener('mousemove', mouseMoveRef.current)\n document.addEventListener('mouseup', mouseUpRef.current)\n\n setDragPercentMouse(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n }\n }\n\n /**\n * Attaches touch-move and touch-end event listeners and sets dragging state.\n */\n const onTouchStart = (e: React.TouchEvent) => {\n touchMoveRef.current = onTouchMove\n touchEndRef.current = onTouchEnd\n document.addEventListener('touchmove', touchMoveRef.current)\n document.addEventListener('touchend', touchEndRef.current)\n\n setDragPercentTouch(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n }\n }\n\n // Watch interactions to the scrubber and call to animate\n useEffect(() => {\n if (!dragPercent.current) {\n if (isPlaying) play()\n else pause()\n }\n }, [isPlaying, dragPercent, play, pause])\n\n useEffect(() => {\n setPercent(elapsedSeconds / totalSeconds)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [playbackRate])\n\n // When the key changes, reset the animation\n useEffect(() => {\n if (mediaKey !== previousMediaKey) {\n if (!totalSeconds) {\n setPercent(0)\n } else {\n setPercent(elapsedSeconds / totalSeconds)\n }\n setPreviousMediaKey(mediaKey)\n }\n }, [\n mediaKey,\n previousMediaKey,\n setPreviousMediaKey,\n setPercent,\n elapsedSeconds,\n totalSeconds\n ])\n\n const getShowHandle = () =>\n !style || style.showHandle === undefined ? true : style.showHandle\n\n const getRailStyle = () => {\n const s: CSSProperties = {}\n if (style && style.railUnlistenedColor) {\n s.background = style.railUnlistenedColor\n }\n return s\n }\n\n const getTrackStyle = () => {\n const s: CSSProperties = {}\n if (style && style.railListenedColor) {\n s.background = style.railListenedColor\n }\n\n if (style && style.railListenedColor) {\n s.borderRadius = 'var(--unit-half)'\n }\n return s\n }\n\n const getSliderStyle = () => {\n if (style && style.sliderMargin) return { margin: style.sliderMargin }\n return {}\n }\n\n const getHandleStyle = () => {\n const s: CSSProperties = {}\n if (style) {\n if (style.handleColor) s.background = style.handleColor\n if (style.handleShadow) s.boxShadow = style.handleShadow\n }\n return s\n }\n\n return (\n <div\n className={cn(styles.slider, {\n [styles.isMobile]: isMobile,\n [styles.isDisabled]: isDisabled,\n [styles.showHandle]: getShowHandle(),\n [styles.expandedTargets]: includeExpandedTargets\n })}\n onMouseDown={isDisabled ? () => {} : onMouseDown}\n onTouchStart={isDisabled ? () => {} : onTouchStart}\n style={getSliderStyle()}\n >\n <div ref={railRef} className={styles.rail} style={getRailStyle()}>\n <div ref={trackRef} className={styles.trackWrapper}>\n <div\n ref={trackRef}\n className={styles.track}\n style={getTrackStyle()}\n />\n </div>\n </div>\n <div ref={handleRef} className={styles.handleWrapper}>\n <div\n ref={handleRef}\n className={styles.handle}\n style={getHandleStyle()}\n />\n </div>\n </div>\n )\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;AASA;AACA,IAAM,YAAY,GAAG,UAAC,OAAuB,EAAA;AAC3C,IAAA,IAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAA;AAC9C,IAAA,OAAO,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,CAAA;AACzC,CAAC,CAAA;AAED;;;AAGG;AACI,IAAM,MAAM,GAAG,UAAC,EAYP,EAAA;;AAXd,IAAA,IAAA,QAAQ,GAAA,EAAA,CAAA,QAAA,EACR,SAAS,GAAA,EAAA,CAAA,SAAA,EACT,QAAQ,GAAA,EAAA,CAAA,QAAA,EACR,UAAU,gBAAA,EACV,cAAc,GAAA,EAAA,CAAA,cAAA,EACd,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,OAAO,GAAA,EAAA,CAAA,OAAA,EACP,cAAc,GAAA,EAAA,CAAA,cAAA,EACd,EAA6B,GAAA,EAAA,CAAA,sBAAA,EAA7B,sBAAsB,GAAG,EAAA,KAAA,KAAA,CAAA,GAAA,IAAI,GAAA,EAAA,EAC7B,KAAK,GAAA,EAAA,CAAA,KAAA,CAAA;IAEC,IAAA,EAAA,GAA0C,QAAQ,CAAC,EAAE,CAAC,EAArD,gBAAgB,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,mBAAmB,GAAA,EAAA,CAAA,CAAA,CAAgB,CAAA;;;AAI5D,IAAA,IAAM,WAAW,GAAG,MAAM,CAAgB,CAAC,CAAC,CAAA;;AAG5C,IAAA,IAAM,YAAY,GAAG,MAAM,CACzB,IAAI,CACL,CAAA;AACD,IAAA,IAAM,UAAU,GAAG,MAAM,CACvB,IAAI,CACL,CAAA;AACD,IAAA,IAAM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D,KAAK,EAAE,cAAc,EAAE,EAEvB,EAAA,EAAA,QAAA,EAAA,CAAAC,GAAA,CAAA,KAAA,EAAA,QAAA,CAAA,EAAK,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,gBAC9DA,GAAK,CAAA,KAAA,EAAA,QAAA,CAAA,EAAA,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,YAAY,EAAA,EAAA,EAAA,QAAA,EAChDA,GACE,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,QAAQ,EACb,SAAS,EAAE,MAAM,CAAC,KAAK,EACvB,KAAK,EAAE,aAAa,EAAE,EAAA,CACtB,IACE,EACF,CAAA,CAAA,EACNA,GAAK,CAAA,KAAA,EAAA,QAAA,CAAA,EAAA,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,aAAa,EAAA,EAAA,EAAA,QAAA,EAClDA,aACE,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,CAAC,MAAM,EACxB,KAAK,EAAE,cAAc,EAAE,EACvB,CAAA,EAAA,CAAA,CACE,CACF,EAAA,CAAA,CAAA,EACP;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"Slider.js","sources":["../../../src/components/scrubber/Slider.tsx"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, CSSProperties } from 'react'\nimport * as React from 'react'\n\nimport cn from 'classnames'\n\nimport styles from './Slider.module.css'\nimport { useAnimations } from './hooks'\nimport { ScrubberProps } from './types'\n\n/** Gets the X-position of a div. */\nconst getXPosition = (element: HTMLDivElement) => {\n const coords = element.getBoundingClientRect()\n return window.pageXOffset + coords.left\n}\n\n/**\n * A smooth scrubbable slider that relies on CSS animations rather\n * than progress ticks to achieve fluidity.\n */\nexport const Slider = ({\n mediaKey,\n isPlaying,\n isMobile,\n isDisabled,\n elapsedSeconds,\n totalSeconds,\n playbackRate,\n onScrub,\n onScrubRelease,\n includeExpandedTargets = true,\n style\n}: ScrubberProps) => {\n const [previousMediaKey, setPreviousMediaKey] = useState('')\n\n // Percentage of the complete scrubber being dragged to.\n // e.g. 0.25 means the user has dragged the scrubber 1/4th of the way.\n const dragPercent = useRef<number | null>(0)\n\n // Refs to handle event listeners\n const mouseMoveRef = useRef<((this: Document, ev: MouseEvent) => any) | null>(\n null\n )\n const mouseUpRef = useRef<((this: Document, ev: MouseEvent) => any) | null>(\n null\n )\n const touchMoveRef = useRef<((e: TouchEvent) => any) | null>(null)\n const touchEndRef = useRef<((e: TouchEvent) => any) | null>(null)\n\n // Div refs\n const railRef = useRef<HTMLDivElement>(null)\n const trackRef = useRef<HTMLDivElement>(null)\n const handleRef = useRef<HTMLDivElement>(null)\n\n const { play, pause, setPercent } = useAnimations(\n trackRef,\n handleRef,\n elapsedSeconds,\n totalSeconds,\n playbackRate\n )\n\n /**\n * Sets the percentage across the scrubber for a given pageX position.\n */\n const setDragPercent = useCallback(\n (pageX: number) => {\n if (railRef.current) {\n const clickPosition = pageX - getXPosition(railRef.current)\n const railWidth = railRef.current.offsetWidth\n const percent =\n Math.min(Math.max(0, clickPosition), railWidth) / railWidth\n dragPercent.current = percent\n }\n },\n [dragPercent]\n )\n\n /**\n * Sets the percentage across the scrubber for a given mouse event.\n */\n const setDragPercentMouse = useCallback(\n (e: React.MouseEvent | MouseEvent) => {\n setDragPercent(e.pageX)\n },\n [setDragPercent]\n )\n\n /**\n * Sets the percentage across the scurbber for a given touch event.\n */\n const setDragPercentTouch = useCallback(\n (e: React.TouchEvent | TouchEvent) => {\n setDragPercent(e.touches[0].pageX)\n },\n [setDragPercent]\n )\n\n /**\n * Watches user mouse movements while the scrubber handle is being dragged.\n */\n const onMouseMove = useCallback(\n (e: MouseEvent) => {\n e.stopPropagation()\n e.preventDefault()\n\n setDragPercentMouse(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n const seconds = dragPercent.current * totalSeconds\n if (onScrub) {\n onScrub(seconds)\n }\n }\n },\n [dragPercent, setDragPercentMouse, totalSeconds, setPercent, onScrub]\n )\n\n /**\n * Watches user touch movements while the scrubber handle is being dragged.\n */\n const onTouchMove = useCallback(\n (e: TouchEvent) => {\n e.stopPropagation()\n e.preventDefault()\n\n setDragPercentTouch(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n\n const seconds = dragPercent.current * totalSeconds\n if (onScrub) {\n onScrub(seconds)\n }\n }\n },\n [dragPercent, setDragPercentTouch, totalSeconds, setPercent, onScrub]\n )\n\n /**\n * Watches for a mouse-up action (which may not occur on the scrubber itself),\n * calls the release callback, and resets dragging state.\n */\n const onMouseUp = useCallback(() => {\n if (mouseMoveRef.current) {\n document.removeEventListener('mousemove', mouseMoveRef.current)\n }\n if (mouseUpRef.current) {\n document.removeEventListener('mouseup', mouseUpRef.current)\n }\n\n if (dragPercent.current !== null) {\n const seconds = dragPercent.current * totalSeconds\n if (onScrubRelease) {\n onScrubRelease(seconds)\n }\n\n dragPercent.current = null\n }\n }, [mouseMoveRef, mouseUpRef, dragPercent, totalSeconds, onScrubRelease])\n\n /**\n * Watches for a touch-end action (which may not occur on the scrubber itself),\n * calls the release callback, and resets dragging state.\n */\n const onTouchEnd = useCallback(() => {\n if (touchMoveRef.current) {\n document.removeEventListener('touchmove', touchMoveRef.current)\n }\n if (touchEndRef.current) {\n document.removeEventListener('touchend', touchEndRef.current)\n }\n\n if (dragPercent.current !== null) {\n const seconds = dragPercent.current * totalSeconds\n if (onScrubRelease) {\n onScrubRelease(seconds)\n }\n\n dragPercent.current = null\n }\n }, [touchMoveRef, touchEndRef, dragPercent, totalSeconds, onScrubRelease])\n\n /**\n * Attaches mouse-move and mouse-up event listeners and sets dragging state.\n */\n const onMouseDown = (e: React.MouseEvent) => {\n // Cancel mouse down if touch was fired.\n if (e.button !== 0 || touchMoveRef.current) return\n\n mouseMoveRef.current = onMouseMove\n mouseUpRef.current = onMouseUp\n document.addEventListener('mousemove', mouseMoveRef.current)\n document.addEventListener('mouseup', mouseUpRef.current)\n\n setDragPercentMouse(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n }\n }\n\n /**\n * Attaches touch-move and touch-end event listeners and sets dragging state.\n */\n const onTouchStart = (e: React.TouchEvent) => {\n touchMoveRef.current = onTouchMove\n touchEndRef.current = onTouchEnd\n document.addEventListener('touchmove', touchMoveRef.current)\n document.addEventListener('touchend', touchEndRef.current)\n\n setDragPercentTouch(e)\n if (dragPercent.current !== null) {\n setPercent(dragPercent.current)\n }\n }\n\n // Watch interactions to the scrubber and call to animate\n useEffect(() => {\n if (!dragPercent.current) {\n if (isPlaying) play()\n else pause()\n }\n }, [isPlaying, dragPercent, play, pause])\n\n useEffect(() => {\n setPercent(elapsedSeconds / totalSeconds)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [playbackRate, elapsedSeconds, totalSeconds])\n\n // When the key changes, reset the animation\n useEffect(() => {\n if (mediaKey !== previousMediaKey) {\n if (!totalSeconds) {\n setPercent(0)\n } else {\n setPercent(elapsedSeconds / totalSeconds)\n }\n setPreviousMediaKey(mediaKey)\n }\n }, [\n mediaKey,\n previousMediaKey,\n setPreviousMediaKey,\n setPercent,\n elapsedSeconds,\n totalSeconds\n ])\n\n const getShowHandle = () =>\n !style || style.showHandle === undefined ? true : style.showHandle\n\n const getRailStyle = () => {\n const s: CSSProperties = {}\n if (style && style.railUnlistenedColor) {\n s.background = style.railUnlistenedColor\n }\n return s\n }\n\n const getTrackStyle = () => {\n const s: CSSProperties = {}\n if (style && style.railListenedColor) {\n s.background = style.railListenedColor\n }\n\n if (style && style.railListenedColor) {\n s.borderRadius = 'var(--unit-half)'\n }\n return s\n }\n\n const getSliderStyle = () => {\n if (style && style.sliderMargin) return { margin: style.sliderMargin }\n return {}\n }\n\n const getHandleStyle = () => {\n const s: CSSProperties = {}\n if (style) {\n if (style.handleColor) s.background = style.handleColor\n if (style.handleShadow) s.boxShadow = style.handleShadow\n }\n return s\n }\n\n return (\n <div\n className={cn(styles.slider, {\n [styles.isMobile]: isMobile,\n [styles.isDisabled]: isDisabled,\n [styles.showHandle]: getShowHandle(),\n [styles.expandedTargets]: includeExpandedTargets\n })}\n onMouseDown={isDisabled ? () => {} : onMouseDown}\n onTouchStart={isDisabled ? () => {} : onTouchStart}\n style={getSliderStyle()}\n >\n <div ref={railRef} className={styles.rail} style={getRailStyle()}>\n <div ref={trackRef} className={styles.trackWrapper}>\n <div\n ref={trackRef}\n className={styles.track}\n style={getTrackStyle()}\n />\n </div>\n </div>\n <div ref={handleRef} className={styles.handleWrapper}>\n <div\n ref={handleRef}\n className={styles.handle}\n style={getHandleStyle()}\n />\n </div>\n </div>\n )\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;AASA;AACA,IAAM,YAAY,GAAG,UAAC,OAAuB,EAAA;AAC3C,IAAA,IAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAA;AAC9C,IAAA,OAAO,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,CAAA;AACzC,CAAC,CAAA;AAED;;;AAGG;AACI,IAAM,MAAM,GAAG,UAAC,EAYP,EAAA;;AAXd,IAAA,IAAA,QAAQ,GAAA,EAAA,CAAA,QAAA,EACR,SAAS,GAAA,EAAA,CAAA,SAAA,EACT,QAAQ,GAAA,EAAA,CAAA,QAAA,EACR,UAAU,gBAAA,EACV,cAAc,GAAA,EAAA,CAAA,cAAA,EACd,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,OAAO,GAAA,EAAA,CAAA,OAAA,EACP,cAAc,GAAA,EAAA,CAAA,cAAA,EACd,EAA6B,GAAA,EAAA,CAAA,sBAAA,EAA7B,sBAAsB,GAAG,EAAA,KAAA,KAAA,CAAA,GAAA,IAAI,GAAA,EAAA,EAC7B,KAAK,GAAA,EAAA,CAAA,KAAA,CAAA;IAEC,IAAA,EAAA,GAA0C,QAAQ,CAAC,EAAE,CAAC,EAArD,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C3B,YAAA,EAAA,CAAC,MAAM,CAAC,UAAU,CAAA,GAAG,UAAU;AAC/B,YAAA,EAAA,CAAC,MAAM,CAAC,UAAU,CAAA,GAAG,aAAa,EAAE;AACpC,YAAA,EAAA,CAAC,MAAM,CAAC,eAAe,CAAA,GAAG,sBAAsB;gBAChD,EACF,WAAW,EAAE,UAAU,GAAG,YAAA,GAAQ,GAAG,WAAW,EAChD,YAAY,EAAE,UAAU,GAAG,YAAO,GAAC,GAAG,YAAY,EAClD,KAAK,EAAE,cAAc,EAAE,EAEvB,EAAA,EAAA,QAAA,EAAA,CAAAC,GAAA,CAAA,KAAA,EAAA,QAAA,CAAA,EAAK,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,gBAC9DA,GAAK,CAAA,KAAA,EAAA,QAAA,CAAA,EAAA,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,YAAY,EAAA,EAAA,EAAA,QAAA,EAChDA,GACE,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,QAAQ,EACb,SAAS,EAAE,MAAM,CAAC,KAAK,EACvB,KAAK,EAAE,aAAa,EAAE,EAAA,CACtB,IACE,EACF,CAAA,CAAA,EACNA,GAAK,CAAA,KAAA,EAAA,QAAA,CAAA,EAAA,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,aAAa,EAAA,EAAA,EAAA,QAAA,EAClDA,aACE,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,CAAC,MAAM,EACxB,KAAK,EAAE,cAAc,EAAE,EACvB,CAAA,EAAA,CAAA,CACE,CACF,EAAA,CAAA,CAAA,EACP;AACH;;;;"}
|
|
@@ -85,9 +85,7 @@ var SegmentedControl = function (props) {
|
|
|
85
85
|
? { width: "".concat(maxOptionWidth, "px") }
|
|
86
86
|
: undefined }, { children: [option.icon, jsx("input", { type: 'radio', checked: option.key === selectedOption, onChange: function () {
|
|
87
87
|
onSetSelected(option.key);
|
|
88
|
-
}, disabled: isOptionDisabled }), jsx(Text, __assign({ color: (_c = option.variant) !== null && _c !== void 0 ? _c : (isOptionDisabled ? 'subdued' : 'default'),
|
|
89
|
-
cursor: isOptionDisabled ? 'auto' : 'pointer'
|
|
90
|
-
} }, { children: option.text }))] })), idx !== props.options.length - 1 ? (jsx("div", { className: cn(styles.separator, (_b = {},
|
|
88
|
+
}, disabled: isOptionDisabled }), jsx(Text, __assign({ variant: 'body', strength: 'strong', css: function (theme) { return ({ lineHeight: theme.typography.lineHeight.s }); }, color: (_c = option.variant) !== null && _c !== void 0 ? _c : (isOptionDisabled ? 'subdued' : 'default') }, { children: option.text }))] })), idx !== props.options.length - 1 ? (jsx("div", { className: cn(styles.separator, (_b = {},
|
|
91
89
|
_b[styles.invisible] =
|
|
92
90
|
// Hide separator right of the selected option
|
|
93
91
|
selectedOption === option.key ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.js","sources":["../../../src/components/segmented-control/SegmentedControl.tsx"],"sourcesContent":["import { createRef, Fragment, useState, useRef, useEffect } from 'react'\n\nimport { ResizeObserver } from '@juggle/resize-observer'\nimport { useSpring, animated } from '@react-spring/web'\nimport cn from 'classnames'\nimport { mergeRefs } from 'react-merge-refs'\nimport useMeasure from 'react-use-measure'\n\nimport { Text } from 'components/text'\n\nimport styles from './SegmentedControl.module.css'\nimport { SegmentedControlProps } from './types'\n\n/**\n * A hybrid somewhere between a button group, radio buttons, and tabs;\n * segmented controls are used to switch between different options or views.\n */\nexport const SegmentedControl = <T extends string>(\n props: SegmentedControlProps<T>\n) => {\n const optionRefs = useRef(\n props.options.map((_) => createRef<HTMLLabelElement>())\n )\n const [selected, setSelected] = useState(props.options[0].key)\n const [maxOptionWidth, setMaxOptionWidth] = useState(0)\n\n const selectedOption = props.selected || selected\n\n const onSetSelected = (option: T) => {\n // Call props function if controlled\n if (props.onSelectOption) props.onSelectOption(option)\n setSelected(option)\n }\n\n const [tabProps, tabApi] = useSpring(() => ({\n to: { left: '0px', width: '0px' }\n }))\n\n useEffect(() => {\n setMaxOptionWidth(\n optionRefs.current.reduce((currentMax, ref) => {\n const rect = ref.current?.getBoundingClientRect()\n return Math.max(rect?.width ?? 0, currentMax)\n }, 0)\n )\n }, [])\n\n // Watch for resizes and repositions so that we move and resize the slider appropriately\n const [selectedRef, bounds] = useMeasure({\n offsetSize: true,\n polyfill: ResizeObserver\n })\n\n const [forceRefresh, setForceRefresh] = useState(false)\n useEffect(() => {\n setTimeout(() => {\n setForceRefresh(!forceRefresh)\n }, props.forceRefreshAfterMs)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n useEffect(() => {\n let selectedRefIdx = props.options.findIndex(\n (option) => option.key === selectedOption\n )\n if (selectedRefIdx === -1) selectedRefIdx = 0\n\n const { clientWidth: width, offsetLeft: left } = optionRefs.current[\n selectedRefIdx\n ]?.current ?? { clientWidth: 0, offsetLeft: 0 }\n\n tabApi.start({\n to: { left: `${left}px`, width: `${width}px` }\n })\n }, [\n props.options,\n props.equalWidth,\n selectedOption,\n props.selected,\n tabApi,\n selected,\n optionRefs,\n bounds,\n forceRefresh\n ])\n\n return (\n <div\n className={cn(styles.tabs, props.className, {\n [styles.containerFullWidth]: !!props.fullWidth,\n [styles.isMobile]: props.isMobile,\n [styles.disabled]: props.disabled\n })}\n role='radiogroup'\n aria-label={props.label}\n aria-labelledby={props['aria-labelledby']}\n >\n <animated.div className={styles.tabBackground} style={tabProps} />\n {props.options.map((option, idx) => {\n const isOptionDisabled = props.disabled || option.disabled\n return (\n <Fragment key={option.key}>\n <label\n ref={\n option.key === selectedOption\n ? mergeRefs([optionRefs.current[idx], selectedRef])\n : optionRefs.current[idx]\n }\n className={cn(styles.tab, {\n [styles.tabFullWidth]: !!props.fullWidth,\n [styles.disabled]: !props.disabled && option.disabled,\n [styles.isMobile]: props.isMobile\n })}\n style={\n props.equalWidth && maxOptionWidth\n ? { width: `${maxOptionWidth}px` }\n : undefined\n }\n >\n {option.icon}\n <input\n type='radio'\n checked={option.key === selectedOption}\n onChange={() => {\n onSetSelected(option.key)\n }}\n disabled={isOptionDisabled}\n />\n <Text\n color={\n option.variant ?? (isOptionDisabled ? 'subdued' : 'default')\n }\n css={{\n cursor: isOptionDisabled ? 'auto' : 'pointer'\n }}\n >\n {option.text}\n </Text>\n </label>\n {idx !== props.options.length - 1 ? (\n <div\n className={cn(styles.separator, {\n [styles.invisible]:\n // Hide separator right of the selected option\n selectedOption === option.key ||\n // Hide separator right of the last option\n idx === props.options.length - 1 ||\n // Hide separator right of an option if the next one is selected\n selectedOption === props.options[idx + 1].key\n })}\n />\n ) : null}\n </Fragment>\n )\n })}\n </div>\n )\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;AAaA;;;AAGG;AACI,IAAM,gBAAgB,GAAG,UAC9B,KAA+B,EAAA;;IAE/B,IAAM,UAAU,GAAG,MAAM,CACvB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,CAAC,EAAA,EAAK,OAAA,SAAS,EAAoB,GAAA,CAAC,CACxD,CAAA;AACK,IAAA,IAAA,KAA0B,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAvD,QAAQ,QAAA,EAAE,WAAW,QAAkC,CAAA;IACxD,IAAA,EAAA,GAAsC,QAAQ,CAAC,CAAC,CAAC,EAAhD,cAAc,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,iBAAiB,GAAA,EAAA,CAAA,CAAA,CAAe,CAAA;AAEvD,IAAA,IAAM,cAAc,GAAG,KAAK,CAAC,QAAQ,IAAI,QAAQ,CAAA;IAEjD,IAAM,aAAa,GAAG,UAAC,MAAS,EAAA;;QAE9B,IAAI,KAAK,CAAC,cAAc;AAAE,YAAA,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QACtD,WAAW,CAAC,MAAM,CAAC,CAAA;AACrB,KA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AC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG;oCAC/C,EACF,CAAA,IACA,IAAI,CAlDK,EAAA,EAAA,MAAM,CAAC,GAAG,CAmDd,EACZ;aACF,CAAC,CACE,EAAA,CAAA,CAAA,EACP;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"SegmentedControl.js","sources":["../../../src/components/segmented-control/SegmentedControl.tsx"],"sourcesContent":["import { createRef, Fragment, useState, useRef, useEffect } from 'react'\n\nimport { ResizeObserver } from '@juggle/resize-observer'\nimport { useSpring, animated } from '@react-spring/web'\nimport cn from 'classnames'\nimport { mergeRefs } from 'react-merge-refs'\nimport useMeasure from 'react-use-measure'\n\nimport { Text } from 'components/text'\n\nimport styles from './SegmentedControl.module.css'\nimport { SegmentedControlProps } from './types'\n\n/**\n * A hybrid somewhere between a button group, radio buttons, and tabs;\n * segmented controls are used to switch between different options or views.\n */\nexport const SegmentedControl = <T extends string>(\n props: SegmentedControlProps<T>\n) => {\n const optionRefs = useRef(\n props.options.map((_) => createRef<HTMLLabelElement>())\n )\n const [selected, setSelected] = useState(props.options[0].key)\n const [maxOptionWidth, setMaxOptionWidth] = useState(0)\n\n const selectedOption = props.selected || selected\n\n const onSetSelected = (option: T) => {\n // Call props function if controlled\n if (props.onSelectOption) props.onSelectOption(option)\n setSelected(option)\n }\n\n const [tabProps, tabApi] = useSpring(() => ({\n to: { left: '0px', width: '0px' }\n }))\n\n useEffect(() => {\n setMaxOptionWidth(\n optionRefs.current.reduce((currentMax, ref) => {\n const rect = ref.current?.getBoundingClientRect()\n return Math.max(rect?.width ?? 0, currentMax)\n }, 0)\n )\n }, [])\n\n // Watch for resizes and repositions so that we move and resize the slider appropriately\n const [selectedRef, bounds] = useMeasure({\n offsetSize: true,\n polyfill: ResizeObserver\n })\n\n const [forceRefresh, setForceRefresh] = useState(false)\n useEffect(() => {\n setTimeout(() => {\n setForceRefresh(!forceRefresh)\n }, props.forceRefreshAfterMs)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n useEffect(() => {\n let selectedRefIdx = props.options.findIndex(\n (option) => option.key === selectedOption\n )\n if (selectedRefIdx === -1) selectedRefIdx = 0\n\n const { clientWidth: width, offsetLeft: left } = optionRefs.current[\n selectedRefIdx\n ]?.current ?? { clientWidth: 0, offsetLeft: 0 }\n\n tabApi.start({\n to: { left: `${left}px`, width: `${width}px` }\n })\n }, [\n props.options,\n props.equalWidth,\n selectedOption,\n props.selected,\n tabApi,\n selected,\n optionRefs,\n bounds,\n forceRefresh\n ])\n\n return (\n <div\n className={cn(styles.tabs, props.className, {\n [styles.containerFullWidth]: !!props.fullWidth,\n [styles.isMobile]: props.isMobile,\n [styles.disabled]: props.disabled\n })}\n role='radiogroup'\n aria-label={props.label}\n aria-labelledby={props['aria-labelledby']}\n >\n <animated.div className={styles.tabBackground} style={tabProps} />\n {props.options.map((option, idx) => {\n const isOptionDisabled = props.disabled || option.disabled\n return (\n <Fragment key={option.key}>\n <label\n ref={\n option.key === selectedOption\n ? mergeRefs([optionRefs.current[idx], selectedRef])\n : optionRefs.current[idx]\n }\n className={cn(styles.tab, {\n [styles.tabFullWidth]: !!props.fullWidth,\n [styles.disabled]: !props.disabled && option.disabled,\n [styles.isMobile]: props.isMobile\n })}\n style={\n props.equalWidth && maxOptionWidth\n ? { width: `${maxOptionWidth}px` }\n : undefined\n }\n >\n {option.icon}\n <input\n type='radio'\n checked={option.key === selectedOption}\n onChange={() => {\n onSetSelected(option.key)\n }}\n disabled={isOptionDisabled}\n />\n <Text\n variant='body'\n strength='strong'\n css={(theme) => ({ lineHeight: theme.typography.lineHeight.s })}\n color={\n option.variant ?? (isOptionDisabled ? 'subdued' : 'default')\n }\n >\n {option.text}\n </Text>\n </label>\n {idx !== props.options.length - 1 ? (\n <div\n className={cn(styles.separator, {\n [styles.invisible]:\n // Hide separator right of the selected option\n selectedOption === option.key ||\n // Hide separator right of the last option\n idx === props.options.length - 1 ||\n // Hide separator right of an option if the next one is selected\n sel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,EACtC,QAAQ,EAAE,YAAA;AACR,wCAAA,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AAC3B,qCAAC,EACD,QAAQ,EAAE,gBAAgB,EAC1B,CAAA,EACFA,IAAC,IAAI,EAAA,QAAA,CAAA,EACH,OAAO,EAAC,MAAM,EACd,QAAQ,EAAC,QAAQ,EACjB,GAAG,EAAE,UAAC,KAAK,EAAA,EAAK,QAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,IAAC,EAC/D,KAAK,EACH,CAAA,EAAA,GAAA,MAAM,CAAC,OAAO,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,IAAC,gBAAgB,GAAG,SAAS,GAAG,SAAS,CAAC,EAAA,EAAA,EAAA,QAAA,EAG7D,MAAM,CAAC,IAAI,IACP,CACD,EAAA,CAAA,CAAA,EACP,GAAG,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAC/BA,aACE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,GAAA,EAAA,GAAA,EAAA;gCAC5B,EAAC,CAAA,MAAM,CAAC,SAAS,CAAA;;gCAEf,cAAc,KAAK,MAAM,CAAC,GAAG;;AAE7B,oCAAA,GAAG,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;;oCAEhC,cAAc,KAAK,KAAK,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG;oCAC/C,EACF,CAAA,IACA,IAAI,CAlDK,EAAA,EAAA,MAAM,CAAC,GAAG,CAmDd,EACZ;aACF,CAAC,CACE,EAAA,CAAA,CAAA,EACP;AACH;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MenuProps } from "../../internal/Menu";
|
|
3
|
+
/**
|
|
4
|
+
* A form input used for selecting a value: when collapsed it shows the
|
|
5
|
+
* currently selected option and when expanded, it shows a scrollable list
|
|
6
|
+
* of predefined options for the user to choose from.
|
|
7
|
+
*/
|
|
8
|
+
export declare const Select: <Value extends string>(props: {
|
|
9
|
+
value: Value;
|
|
10
|
+
onChange?: ((value: Value) => void) | undefined;
|
|
11
|
+
options: import("./types").SelectOption<Value>[];
|
|
12
|
+
children?: ((props: {
|
|
13
|
+
onChange: (value: Value) => void;
|
|
14
|
+
options: import("react").ReactNode;
|
|
15
|
+
}) => import("react").ReactNode) | undefined;
|
|
16
|
+
optionsLabel?: string | undefined;
|
|
17
|
+
InputProps?: Partial<import("../../input").TextInputProps> | undefined;
|
|
18
|
+
menuProps?: (Partial<MenuProps> & Partial<import("../../internal/Menu").MenuContentProps>) | undefined;
|
|
19
|
+
clearable?: boolean | undefined;
|
|
20
|
+
} & Omit<import("../../input").TextInputProps, "children" | "value" | "onChange"> & import("react").RefAttributes<HTMLInputElement>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
|
21
|
+
//# sourceMappingURL=Select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../../src/components/select/Select/Select.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAqB,SAAS,EAAE,4BAAgC;AAmBvE;;;;GAIG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;qOAkLjB,CAAA"}
|