@ringcentral/juno 2.5.0 → 2.8.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.
Files changed (44) hide show
  1. package/components/Buttons/IconButton/IconButton.d.ts +5 -1
  2. package/components/Buttons/IconButton/IconButton.js +2 -2
  3. package/components/Buttons/IconButton/styles/StyledIconButton.js +11 -14
  4. package/components/Dialer/DialPad/DialPad.d.ts +26 -8
  5. package/components/Dialer/DialPad/DialPad.js +3 -3
  6. package/components/Dialer/DialPad/styles/StyledDialPad.d.ts +3 -1
  7. package/components/Dialer/DialPad/styles/StyledDialPad.js +9 -2
  8. package/components/Dialer/DialPadButton/DialPadButton.d.ts +3 -3
  9. package/components/Dialer/DialPadButton/DialPadButton.js +4 -4
  10. package/components/Dialer/DialPadButton/styles/StyledDialPadButton.js +1 -2
  11. package/components/Downshift/styles/DownshiftStyle.d.ts +1 -1
  12. package/components/Forms/Picker/DatePicker/styles/StyledDatePickerHeader.d.ts +1 -1
  13. package/components/Forms/Picker/DatePicker/styles/StyledYear.d.ts +1 -1
  14. package/components/Forms/Picker/TimePicker/styles/StyledSelectionItem.d.ts +1 -1
  15. package/components/Forms/Picker/TimePicker/styles/StyledTimeIconButton.d.ts +1 -1
  16. package/components/Forms/Picker/styles/PickerBaseIconButton.d.ts +1 -1
  17. package/components/Forms/TextField/styles/ClearIconButton.d.ts +2 -2
  18. package/components/InlineEditable/InlineEditable.d.ts +1 -1
  19. package/es6/components/Buttons/IconButton/IconButton.js +2 -2
  20. package/es6/components/Buttons/IconButton/styles/StyledIconButton.js +11 -14
  21. package/es6/components/Dialer/DialPad/DialPad.js +5 -5
  22. package/es6/components/Dialer/DialPad/styles/StyledDialPad.js +9 -2
  23. package/es6/components/Dialer/DialPadButton/DialPadButton.js +4 -4
  24. package/es6/components/Dialer/DialPadButton/styles/StyledDialPadButton.js +1 -2
  25. package/es6/foundation/hooks/useEventListener/useEventListener.js +27 -8
  26. package/es6/foundation/hooks/useGlobalListener/createGlobalListener.js +81 -0
  27. package/es6/foundation/hooks/useGlobalListener/index.js +1 -0
  28. package/es6/foundation/hooks/useGlobalListener/useGlobalListener.js +67 -97
  29. package/es6/foundation/hooks/useLongPress/useLongPress.js +50 -31
  30. package/es6/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +27 -28
  31. package/foundation/hooks/useEventListener/useEventListener.d.ts +12 -16
  32. package/foundation/hooks/useEventListener/useEventListener.js +26 -7
  33. package/foundation/hooks/useGlobalListener/createGlobalListener.d.ts +55 -0
  34. package/foundation/hooks/useGlobalListener/createGlobalListener.js +83 -0
  35. package/foundation/hooks/useGlobalListener/index.d.ts +1 -0
  36. package/foundation/hooks/useGlobalListener/index.js +1 -0
  37. package/foundation/hooks/useGlobalListener/useGlobalListener.d.ts +11 -105
  38. package/foundation/hooks/useGlobalListener/useGlobalListener.js +67 -97
  39. package/foundation/hooks/useLongPress/useLongPress.d.ts +8 -8
  40. package/foundation/hooks/useLongPress/useLongPress.js +48 -29
  41. package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.d.ts +27 -14
  42. package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +27 -28
  43. package/foundation/typings/deepPartial.d.ts +1 -1
  44. package/package.json +1 -1
@@ -199,7 +199,7 @@ declare const RcInlineEditable: import("styled-components").StyledComponentClass
199
199
  * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
200
200
  */
201
201
  inputProps?: import("@material-ui/core").InputBaseComponentProps | undefined;
202
- } & Pick<React.DOMAttributes<HTMLDivElement>, "onFocus" | "onBlur" | "onKeyDown" | "onMouseDown"> & RcClassesProps<"label" | "placeholder" | "textField" | "saving"> & React.RefAttributes<any>, "ref" | "key" | "className" | "color" | "style" | "onFocus" | "onBlur" | "onChange" | "onKeyDown" | "onMouseDown" | "title" | "classes" | "placeholder" | "value" | "variant" | "disabled" | "fullWidth" | "TooltipProps" | "inputProps" | "multiline" | "maxLength" | "tooltipTitle" | "automationId" | "saving" | "shouldRemoveNode" | "onSave"> & {
202
+ } & Pick<React.DOMAttributes<HTMLDivElement>, "onFocus" | "onBlur" | "onKeyDown" | "onMouseDown"> & RcClassesProps<"label" | "placeholder" | "textField" | "saving"> & React.RefAttributes<any>, "ref" | "key" | "className" | "color" | "style" | "onFocus" | "onBlur" | "onChange" | "onKeyDown" | "onMouseDown" | "title" | "classes" | "placeholder" | "value" | "variant" | "disabled" | "fullWidth" | "TooltipProps" | "inputProps" | "tooltipTitle" | "multiline" | "maxLength" | "automationId" | "saving" | "shouldRemoveNode" | "onSave"> & {
203
203
  theme?: import("../../foundation").RcTheme | undefined;
204
204
  }>;
205
205
  export { RcInlineEditable };
@@ -15,7 +15,7 @@ var _RcIconButton = memo(forwardRef(function (inProps, ref) {
15
15
  // eslint-disable-next-line react-hooks/rules-of-hooks
16
16
  useDeprecatedCheck(RcIconButton, props, rcIconButtonWarning);
17
17
  }
18
- var _b = props.buttonRef, buttonRef = _b === void 0 ? ref : _b, className = props.className, classesProp = props.classes, children = props.children, title = props.title, disabledFakeBorder = props.disabledFakeBorder, symbol = props.symbol, disabled = props.disabled, invisible = props.invisible, type = props.type, loading = props.loading, TouchRippleProps = props.TouchRippleProps, variant = props.variant, CircularProgressProps = props.CircularProgressProps, color = props.color, shouldPersistBg = props.shouldPersistBg, stretchIcon = props.stretchIcon, iconColor = props.iconColor, iconSize = props.iconSize, disableTouchRipple = props.disableTouchRipple, useColorWhenDisabled = props.useColorWhenDisabled, size = props.size, radius = props.radius, elevation = props.elevation, activeElevation = props.activeElevation, aRef = props.aRef, tooltipTitle = props.tooltipTitle, tooltipForceHide = props.tooltipForceHide, disableToolTip = props.disableToolTip, alwaysEnableTooltip = props.alwaysEnableTooltip, tooltipPlacement = props.tooltipPlacement, ariaLabel = props.ariaLabel, popperProps = props.popperProps, externalLink = props.externalLink, download = props.download, autoFocus = props.autoFocus, href = props.href, rest = __rest(props, ["buttonRef", "className", "classes", "children", "title", "disabledFakeBorder", "symbol", "disabled", "invisible", "type", "loading", "TouchRippleProps", "variant", "CircularProgressProps", "color", "shouldPersistBg", "stretchIcon", "iconColor", "iconSize", "disableTouchRipple", "useColorWhenDisabled", "size", "radius", "elevation", "activeElevation", "aRef", "tooltipTitle", "tooltipForceHide", "disableToolTip", "alwaysEnableTooltip", "tooltipPlacement", "ariaLabel", "popperProps", "externalLink", "download", "autoFocus", "href"]);
18
+ var _b = props.buttonRef, buttonRef = _b === void 0 ? ref : _b, IconProps = props.IconProps, className = props.className, classesProp = props.classes, children = props.children, title = props.title, disabledFakeBorder = props.disabledFakeBorder, symbol = props.symbol, disabled = props.disabled, invisible = props.invisible, type = props.type, loading = props.loading, TouchRippleProps = props.TouchRippleProps, variant = props.variant, CircularProgressProps = props.CircularProgressProps, color = props.color, shouldPersistBg = props.shouldPersistBg, stretchIcon = props.stretchIcon, iconColor = props.iconColor, iconSize = props.iconSize, disableTouchRipple = props.disableTouchRipple, useColorWhenDisabled = props.useColorWhenDisabled, size = props.size, radius = props.radius, elevation = props.elevation, activeElevation = props.activeElevation, aRef = props.aRef, tooltipTitle = props.tooltipTitle, tooltipForceHide = props.tooltipForceHide, disableToolTip = props.disableToolTip, alwaysEnableTooltip = props.alwaysEnableTooltip, tooltipPlacement = props.tooltipPlacement, ariaLabel = props.ariaLabel, popperProps = props.popperProps, externalLink = props.externalLink, download = props.download, autoFocus = props.autoFocus, href = props.href, rest = __rest(props, ["buttonRef", "IconProps", "className", "classes", "children", "title", "disabledFakeBorder", "symbol", "disabled", "invisible", "type", "loading", "TouchRippleProps", "variant", "CircularProgressProps", "color", "shouldPersistBg", "stretchIcon", "iconColor", "iconSize", "disableTouchRipple", "useColorWhenDisabled", "size", "radius", "elevation", "activeElevation", "aRef", "tooltipTitle", "tooltipForceHide", "disableToolTip", "alwaysEnableTooltip", "tooltipPlacement", "ariaLabel", "popperProps", "externalLink", "download", "autoFocus", "href"]);
19
19
  var theme = useTheme();
20
20
  var isOutline = variant === 'outline';
21
21
  var isContained = variant === 'contained';
@@ -31,7 +31,7 @@ var _RcIconButton = memo(forwardRef(function (inProps, ref) {
31
31
  _a));
32
32
  var iconButton = (function () {
33
33
  var _a, _b;
34
- var icon = React.isValidElement(children) || children === '' ? children : (React.createElement(RcIcon, { symbol: symbol, className: classes.icon, loading: loading, CircularProgressProps: CircularProgressProps }, children));
34
+ var icon = React.isValidElement(children) || children === '' ? children : (React.createElement(RcIcon, __assign({ symbol: symbol, className: classes.icon, loading: loading, CircularProgressProps: CircularProgressProps }, IconProps), children));
35
35
  var iconButton = (React.createElement(RcButtonBase, __assign({ ref: buttonRef, disableRipple: ((_b = (_a = theme.props) === null || _a === void 0 ? void 0 : _a.MuiButtonBase) === null || _b === void 0 ? void 0 : _b.disableRipple) || isPlain, type: type, disabled: disabled, "aria-label": ariaLabel || tooltipTitle || title, title: title, "aria-disabled": disabled, className: IconClassName, TouchRippleProps: combineProps({
36
36
  classes: RcIconButtonTouchRippleClasses,
37
37
  }, TouchRippleProps) }, rest), icon));
@@ -1,14 +1,11 @@
1
1
  import { __makeTemplateObject } from "tslib";
2
2
  import { backgroundTransition, css, focusVisible, focusVisibleColor, getParsePaletteColor, nonTouchHoverMedia, palette2, paletteContrastText, px, radius, setOpacity, shadows, fakeBorder, } from '../../../../foundation';
3
- import { RcIcon } from '../../../Icon';
4
3
  import { RcIconButtonClasses, RcIconButtonFocusVisibleInsetSize, RcIconButtonSizes, RcIconButtonTouchRippleClasses, } from '../utils';
5
4
  export var getFocusVisibleInsetSize = function (_a) {
6
5
  var size = _a.size;
7
6
  var inset = RcIconButtonFocusVisibleInsetSize[size];
8
7
  return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n top: -", "px;\n right: -", "px;\n bottom: -", "px;\n left: -", "px;\n "], ["\n top: -", "px;\n right: -", "px;\n bottom: -", "px;\n left: -", "px;\n "])), inset, inset, inset, inset);
9
8
  };
10
- // * text inside button should also set style
11
- var childrenClass = "&," + RcIcon;
12
9
  var containedVariantTransitions = function (_a) {
13
10
  var theme = _a.theme;
14
11
  return theme.transitions.create(['background-color', 'box-shadow', 'border'], {
@@ -41,13 +38,13 @@ export var iconButtonStyle = function (_a) {
41
38
  radius: currRadius,
42
39
  pseudo: true,
43
40
  });
44
- return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n\n width: ", ";\n height: ", ";\n color: ", ";\n border-radius: ", ";\n transition: ", ";\n cursor: ", ";\n background-color: ", ";\n box-shadow: ", ";\n\n ", ";\n\n ", " {\n font-size: ", ";\n }\n\n ", " {\n &:hover {\n background-color: ", ";\n\n ", " {\n color: ", ";\n }\n }\n }\n\n &:active {\n ", " {\n color: ", ";\n }\n }\n\n ", " {\n background-color: ", ";\n\n &:active {\n ", " {\n color: ", ";\n }\n }\n\n ", ";\n }\n\n &.", " {\n background-color: ", ";\n }\n\n &.", " {\n ", " {\n color: ", ";\n }\n\n background-color: ", ";\n }\n\n &.", " {\n opacity: 0;\n visibility: hidden;\n width: 0;\n height: 0;\n }\n\n &.", " {\n border: 1px solid ", ";\n }\n\n &.", " {\n color: ", ";\n background-color: ", ";\n\n &:before {\n content: '';\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n width: 100%;\n height: 100%;\n border-radius: ", ";\n position: absolute;\n }\n\n ", ";\n\n ", " {\n &:hover {\n &:before {\n background-color: ", ";\n }\n\n ", " {\n color: ", ";\n }\n }\n }\n\n ", " {\n &:before {\n background-color: ", ";\n }\n\n ", " {\n color: ", ";\n }\n }\n\n &:active {\n ", "\n\n ", " {\n color: ", ";\n }\n }\n }\n\n &.", " {\n ", ";\n }\n\n .", " {\n border-radius: 0;\n animation-name: none;\n opacity: 0;\n }\n\n ", "\n "], ["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n\n width: ", ";\n height: ", ";\n color: ", ";\n border-radius: ", ";\n transition: ", ";\n cursor: ", ";\n background-color: ", ";\n box-shadow: ", ";\n\n ",
45
- ";\n\n ", " {\n font-size: ",
46
- ";\n }\n\n ", " {\n &:hover {\n background-color: ",
47
- ";\n\n ", " {\n color: ", ";\n }\n }\n }\n\n &:active {\n ", " {\n color: ", ";\n }\n }\n\n ", " {\n background-color: ",
48
- ";\n\n &:active {\n ", " {\n color: ", ";\n }\n }\n\n ", ";\n }\n\n &.", " {\n background-color: ", ";\n }\n\n &.", " {\n ", " {\n color: ",
49
- ";\n }\n\n background-color: ", ";\n }\n\n &.", " {\n opacity: 0;\n visibility: hidden;\n width: 0;\n height: 0;\n }\n\n &.", " {\n border: 1px solid ", ";\n }\n\n &.", " {\n color: ", ";\n background-color: ", ";\n\n &:before {\n content: '';\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n width: 100%;\n height: 100%;\n border-radius: ", ";\n position: absolute;\n }\n\n ", ";\n\n ", " {\n &:hover {\n &:before {\n background-color: ", ";\n }\n\n ", " {\n color: ", ";\n }\n }\n }\n\n ", " {\n &:before {\n background-color: ", ";\n }\n\n ", " {\n color: ", ";\n }\n }\n\n &:active {\n ",
50
- "\n\n ", " {\n color: ", ";\n }\n }\n }\n\n &.", " {\n ", ";\n }\n\n .", " {\n border-radius: 0;\n animation-name: none;\n opacity: 0;\n }\n\n "
41
+ return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n\n width: ", ";\n height: ", ";\n color: ", ";\n border-radius: ", ";\n transition: ", ";\n cursor: ", ";\n background-color: ", ";\n box-shadow: ", ";\n\n ", ";\n\n font-size: ", ";\n\n ", " {\n &:hover {\n background-color: ", ";\n\n color: ", ";\n }\n }\n\n &:active {\n color: ", ";\n }\n\n ", " {\n background-color: ", ";\n\n &:active {\n color: ", ";\n }\n\n ", ";\n }\n\n &.", " {\n background-color: ", ";\n }\n\n &.", " {\n color: ", ";\n\n background-color: ", ";\n }\n\n &.", " {\n opacity: 0;\n visibility: hidden;\n width: 0;\n height: 0;\n }\n\n &.", " {\n border: 1px solid ", ";\n }\n\n &.", " {\n color: ", ";\n background-color: ", ";\n\n &:before {\n content: '';\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n width: 100%;\n height: 100%;\n border-radius: ", ";\n position: absolute;\n }\n\n ", ";\n\n ", " {\n &:hover {\n &:before {\n background-color: ", ";\n }\n\n color: ", ";\n }\n }\n\n ", " {\n &:before {\n background-color: ", ";\n }\n\n color: ", ";\n }\n\n &:active {\n ", "\n\n color: ", ";\n }\n }\n\n &.", " {\n ", ";\n }\n\n .", " {\n border-radius: 0;\n animation-name: none;\n opacity: 0;\n }\n\n ", "\n "], ["\n display: inline-flex;\n justify-content: center;\n align-items: center;\n\n width: ", ";\n height: ", ";\n color: ", ";\n border-radius: ", ";\n transition: ", ";\n cursor: ", ";\n background-color: ", ";\n box-shadow: ", ";\n\n ",
42
+ ";\n\n font-size: ",
43
+ ";\n\n ", " {\n &:hover {\n background-color: ",
44
+ ";\n\n color: ", ";\n }\n }\n\n &:active {\n color: ", ";\n }\n\n ", " {\n background-color: ",
45
+ ";\n\n &:active {\n color: ", ";\n }\n\n ", ";\n }\n\n &.", " {\n background-color: ", ";\n }\n\n &.", " {\n color: ",
46
+ ";\n\n background-color: ", ";\n }\n\n &.", " {\n opacity: 0;\n visibility: hidden;\n width: 0;\n height: 0;\n }\n\n &.", " {\n border: 1px solid ", ";\n }\n\n &.", " {\n color: ", ";\n background-color: ", ";\n\n &:before {\n content: '';\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n width: 100%;\n height: 100%;\n border-radius: ", ";\n position: absolute;\n }\n\n ", ";\n\n ", " {\n &:hover {\n &:before {\n background-color: ", ";\n }\n\n color: ", ";\n }\n }\n\n ", " {\n &:before {\n background-color: ", ";\n }\n\n color: ", ";\n }\n\n &:active {\n ",
47
+ "\n\n color: ", ";\n }\n }\n\n &.", " {\n ", ";\n }\n\n .", " {\n border-radius: 0;\n animation-name: none;\n opacity: 0;\n }\n\n "
51
48
  /**
52
49
  * that is equilateral triangle, the third Side length is
53
50
  * Math.sqrt(2) = 1.414213562373095, so we scale that
@@ -55,17 +52,17 @@ export var iconButtonStyle = function (_a) {
55
52
  */
56
53
  ,
57
54
  "\n "])), containerSize, containerSize, mainColor, radiusValue, backgroundTransition, disabled ? 'default' : 'pointer', (shouldPersistBg || isInverse) && persistBgColor, nowShadow, nowShadow && css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n transition: ", ";\n\n &:active {\n box-shadow: ", ";\n }\n "], ["\n transition: ", ";\n\n &:active {\n box-shadow: ",
58
- ";\n }\n "])), containedVariantTransitions, shadows(activeElevation !== null && activeElevation !== void 0 ? activeElevation : (elevation ? Math.min(+elevation + 11, 24) : '12'))), childrenClass, stretchIcon
55
+ ";\n }\n "])), containedVariantTransitions, shadows(activeElevation !== null && activeElevation !== void 0 ? activeElevation : (elevation ? Math.min(+elevation + 11, 24) : '12'))), stretchIcon
59
56
  ? containerSize
60
57
  : px(isOutline
61
58
  ? iconSize * 1.2 // keep size same as before
62
59
  : iconSize), nonTouchHoverMedia, isPlain
63
60
  ? 'transparent'
64
- : setOpacity(mainColor, isInverse ? '24' : '08'), childrenClass, setOpacity(mainColor, '88'), childrenClass, mainColor, focusVisible, isPlain
61
+ : setOpacity(mainColor, isInverse ? '24' : '08'), setOpacity(mainColor, '88'), mainColor, focusVisible, isPlain
65
62
  ? 'transparent'
66
- : setOpacity(mainColor, isInverse ? '32' : '16'), childrenClass, setOpacity(mainColor, '88'), isPlain && plainIconButtonFocusStyle({ radius: currRadius }), RcIconButtonClasses.persistBg, persistBgColor, RcIconButtonClasses.disabled, childrenClass, useColorWhenDisabled
63
+ : setOpacity(mainColor, isInverse ? '32' : '16'), setOpacity(mainColor, '88'), isPlain && plainIconButtonFocusStyle({ radius: currRadius }), RcIconButtonClasses.persistBg, persistBgColor, RcIconButtonClasses.disabled, useColorWhenDisabled
67
64
  ? setOpacity(mainColor, '32')
68
- : palette2('disabled', 'f02'), isInverse && setOpacity(mainColor, '12'), RcIconButtonClasses.invisible, RcIconButtonClasses.outline, palette2('neutral', 'l03'), RcIconButtonClasses.contained, mainColorContrast, mainColor, radiusValue, contrastColorBorder, nonTouchHoverMedia, setOpacity(mainColorContrast, '08'), childrenClass, mainColorContrast, focusVisible, setOpacity(mainColorContrast, '16'), childrenClass, mainColorContrast, disableRipple && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n &:before {\n background-color: ", ";\n }\n "], ["\n &:before {\n background-color: ", ";\n }\n "])), setOpacity(mainColorContrast, '24')), childrenClass, mainColorContrast, RcIconButtonClasses.inverse, contrastColorBorder, RcIconButtonTouchRippleClasses.ripplePulsate,
65
+ : palette2('disabled', 'f02'), isInverse && setOpacity(mainColor, '12'), RcIconButtonClasses.invisible, RcIconButtonClasses.outline, palette2('neutral', 'l03'), RcIconButtonClasses.contained, mainColorContrast, mainColor, radiusValue, contrastColorBorder, nonTouchHoverMedia, setOpacity(mainColorContrast, '08'), mainColorContrast, focusVisible, setOpacity(mainColorContrast, '16'), mainColorContrast, disableRipple && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n &:before {\n background-color: ", ";\n }\n "], ["\n &:before {\n background-color: ", ";\n }\n "])), setOpacity(mainColorContrast, '24')), mainColorContrast, RcIconButtonClasses.inverse, contrastColorBorder, RcIconButtonTouchRippleClasses.ripplePulsate,
69
66
  /**
70
67
  * that is equilateral triangle, the third Side length is
71
68
  * Math.sqrt(2) = 1.414213562373095, so we scale that
@@ -3,14 +3,14 @@ import React, { forwardRef, useEffect, useImperativeHandle, useRef, } from 'reac
3
3
  import { styled, useDebounce, useEventCallback, useForkRef, useKeyboardMoveFocus, useOnlyOneFocusable, useThemeProps, } from '../../../foundation';
4
4
  import { RcIconButtonClasses } from '../../Buttons/IconButton/utils';
5
5
  import { RcVisuallyHidden } from '../../VisuallyHidden';
6
- import { DialPadButton } from '../DialPadButton';
6
+ import { RcDialPadButton } from '../DialPadButton';
7
7
  import { useRcDialerContext } from '../utils';
8
- import { keypadContainerStyle } from './styles';
8
+ import { DialPadStyle } from './styles';
9
9
  import { ACCEPTABLE_KEYS, DIALER_PAD_ICONS, DIALER_PAD_PLUS, useKeyAudio, } from './utils';
10
10
  var DEBOUNCE_TIME = 30;
11
11
  var _RcDialPad = forwardRef(function (inProps, ref) {
12
12
  var props = useThemeProps({ props: inProps, name: 'RcDialPad' });
13
- var sounds = props.sounds, volume = props.volume, muted = props.muted, classes = props.classes, onChangeProp = props.onChange, longPressDelay = props.longPressDelay, action = props.action, persistBgTime = props.persistBgTime, control = props.control, getDialPadButtonProps = props.getDialPadButtonProps, _a = props.externalWindow, externalWindow = _a === void 0 ? window : _a, divProps = __rest(props, ["sounds", "volume", "muted", "classes", "onChange", "longPressDelay", "action", "persistBgTime", "control", "getDialPadButtonProps", "externalWindow"]);
13
+ var sounds = props.sounds, volume = props.volume, autoSize = props.autoSize, muted = props.muted, classes = props.classes, onChangeProp = props.onChange, longPressDelay = props.longPressDelay, action = props.action, persistBgTime = props.persistBgTime, control = props.control, getDialPadButtonProps = props.getDialPadButtonProps, _a = props.externalWindow, externalWindow = _a === void 0 ? window : _a, divProps = __rest(props, ["sounds", "volume", "autoSize", "muted", "classes", "onChange", "longPressDelay", "action", "persistBgTime", "control", "getDialPadButtonProps", "externalWindow"]);
14
14
  var containerRef = useRef(null);
15
15
  var hiddenRef = useRef(null);
16
16
  var keyTimerMapRef = useRef({});
@@ -106,7 +106,7 @@ var _RcDialPad = forwardRef(function (inProps, ref) {
106
106
  var ariaLabelArr = additionLabel
107
107
  ? [key, additionLabel]
108
108
  : [key];
109
- return (React.createElement(DialPadButton, __assign({ classes: classes, symbol: symbol, key: key, value: key, onKeyEffect: handleKeyEffect }, getItemProps(index), { "aria-label": ariaLabelArr.join(','), onKeyDown: onKeyFocusedIndexHandle }, (_b = {}, _b[dialButtonKey] = key, _b), getDialPadButtonProps === null || getDialPadButtonProps === void 0 ? void 0 : getDialPadButtonProps(key), (key === '0'
109
+ return (React.createElement(RcDialPadButton, __assign({ classes: classes, symbol: symbol, key: key, value: key, onKeyEffect: handleKeyEffect }, getItemProps(index), { "aria-label": ariaLabelArr.join(','), onKeyDown: onKeyFocusedIndexHandle }, (_b = {}, _b[dialButtonKey] = key, _b), getDialPadButtonProps === null || getDialPadButtonProps === void 0 ? void 0 : getDialPadButtonProps(key), (key === '0'
110
110
  ? {
111
111
  longPressValue: DIALER_PAD_PLUS,
112
112
  longPressDelay: longPressDelay,
@@ -115,7 +115,7 @@ var _RcDialPad = forwardRef(function (inProps, ref) {
115
115
  })));
116
116
  });
117
117
  /** @release */
118
- var RcDialPad = styled(_RcDialPad)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), keypadContainerStyle);
118
+ var RcDialPad = styled(_RcDialPad)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), DialPadStyle);
119
119
  RcDialPad.defaultProps = {
120
120
  persistBgTime: 200,
121
121
  volume: 1,
@@ -1,4 +1,11 @@
1
1
  import { __makeTemplateObject } from "tslib";
2
2
  import { css } from '../../../../foundation';
3
- export var keypadContainerStyle = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-wrap: wrap;\n justify-content: space-between;\n"], ["\n display: flex;\n flex-wrap: wrap;\n justify-content: space-between;\n"])));
4
- var templateObject_1;
3
+ import { RcIcon } from '../../../Icon';
4
+ import { RcDialPadButton } from '../../DialPadButton';
5
+ var itemScale = "27.59%";
6
+ export var DialPadStyle = function (_a) {
7
+ var _b = _a.autoSize, autoSize = _b === void 0 ? true : _b;
8
+ return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n flex-wrap: wrap;\n\n ", "\n "], ["\n display: flex;\n flex-wrap: wrap;\n\n ",
9
+ "\n "])), autoSize && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n justify-content: space-between;\n\n ", " {\n width: ", ";\n height: 0;\n padding-top: ", ";\n\n ", " {\n position: absolute;\n top: 0;\n left: 0;\n svg {\n height: 100%;\n width: 100%;\n }\n }\n }\n "], ["\n justify-content: space-between;\n\n ", " {\n width: ", ";\n height: 0;\n padding-top: ", ";\n\n ", " {\n position: absolute;\n top: 0;\n left: 0;\n svg {\n height: 100%;\n width: 100%;\n }\n }\n }\n "])), RcDialPadButton, itemScale, itemScale, RcIcon));
10
+ };
11
+ var templateObject_1, templateObject_2;
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { styled, useLongPress } from '../../../foundation';
4
4
  import { RcIconButton } from '../../Buttons';
5
5
  import { buttonWrapperStyle } from './styles';
6
- var _DialPadButton = function (props) {
6
+ var _RcDialPadButton = function (props) {
7
7
  var value = props.value, longPressValue = props.longPressValue, longPressDelay = props.longPressDelay, onKeyEffect = props.onKeyEffect, rest = __rest(props, ["value", "longPressValue", "longPressDelay", "onKeyEffect"]);
8
8
  var isPressEvent = typeof longPressDelay === 'number' && typeof longPressValue === 'string';
9
9
  var _a = useLongPress({
@@ -18,7 +18,7 @@ var _DialPadButton = function (props) {
18
18
  }, rest, { delay: longPressDelay }), ref = _a.ref, events = __rest(_a, ["ref"]);
19
19
  return (React.createElement(RcIconButton, __assign({ ref: ref, variant: "round", stretchIcon: true }, rest, events)));
20
20
  };
21
- var DialPadButton = styled(_DialPadButton)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), buttonWrapperStyle);
22
- DialPadButton.displayName = 'DialPadButton';
23
- export { DialPadButton };
21
+ var RcDialPadButton = styled(_RcDialPadButton)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), buttonWrapperStyle);
22
+ RcDialPadButton.displayName = 'RcDialPadButton';
23
+ export { RcDialPadButton };
24
24
  var templateObject_1;
@@ -1,6 +1,5 @@
1
1
  import { __makeTemplateObject } from "tslib";
2
2
  import { css, palette2 } from '../../../../foundation';
3
3
  import { RcIcon } from '../../../Icon';
4
- var itemScale = "27.59%";
5
- export var buttonWrapperStyle = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n && {\n width: ", ";\n height: 0;\n }\n\n padding-top: ", ";\n\n ", " {\n position: absolute;\n top: 0;\n left: 0;\n svg {\n height: 100%;\n width: 100%;\n path:first-child {\n fill: ", ";\n }\n path:nth-child(2) {\n fill: ", ";\n }\n }\n }\n"], ["\n && {\n width: ", ";\n height: 0;\n }\n\n padding-top: ", ";\n\n ", " {\n position: absolute;\n top: 0;\n left: 0;\n svg {\n height: 100%;\n width: 100%;\n path:first-child {\n fill: ", ";\n }\n path:nth-child(2) {\n fill: ", ";\n }\n }\n }\n"])), itemScale, itemScale, RcIcon, palette2('neutral', 'f06'), palette2('neutral', 'f04'));
4
+ export var buttonWrapperStyle = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", " {\n svg {\n path:first-child {\n fill: ", ";\n }\n path:nth-child(2) {\n fill: ", ";\n }\n }\n }\n"], ["\n ", " {\n svg {\n path:first-child {\n fill: ", ";\n }\n path:nth-child(2) {\n fill: ", ";\n }\n }\n }\n"])), RcIcon, palette2('neutral', 'f06'), palette2('neutral', 'f04'));
6
5
  var templateObject_1;
@@ -1,4 +1,4 @@
1
- import { __read } from "tslib";
1
+ import { __assign, __rest } from "tslib";
2
2
  import { useEffect, useRef } from 'react';
3
3
  import { getRefElement } from '../../utils';
4
4
  import { useEventCallback } from '../useEventCallback';
@@ -17,13 +17,14 @@ import { useEventCallback } from '../useEventCallback';
17
17
  * useEventListener(window, 'keyup', () => console.log('window key up'))
18
18
  * ```
19
19
  */
20
- export function useEventListener(target) {
21
- var o = [];
22
- for (var _i = 1; _i < arguments.length; _i++) {
23
- o[_i - 1] = arguments[_i];
20
+ export function useEventListener(target, key, callback) {
21
+ var args = [];
22
+ for (var _i = 3; _i < arguments.length; _i++) {
23
+ args[_i - 3] = arguments[_i];
24
24
  }
25
- var _a = __read(o, 3), key = _a[0], cb = _a[1], options = _a[2];
26
- var listener = useEventCallback(cb);
25
+ var _a = getListenerOverloadOption(args), options = _a.options, config = _a.config;
26
+ var _b = (config || {}).startImmediately, startImmediately = _b === void 0 ? true : _b;
27
+ var listener = useEventCallback(callback);
27
28
  var cancelRef = useRef(function () { });
28
29
  var bindRef = useRef(function () { });
29
30
  var currentRefElm = getRefElement(target);
@@ -38,7 +39,9 @@ export function useEventListener(target) {
38
39
  cancelRef.current = function () {
39
40
  return currentElm.removeEventListener(key, listener, options);
40
41
  };
41
- bindRef.current();
42
+ if (startImmediately) {
43
+ bindRef.current();
44
+ }
42
45
  return cancelRef.current;
43
46
  // eslint-disable-next-line react-hooks/exhaustive-deps
44
47
  }, [target, currentRefElm]);
@@ -47,3 +50,19 @@ export function useEventListener(target) {
47
50
  remove: function () { return cancelRef.current(); },
48
51
  };
49
52
  }
53
+ function getListenerOverloadOption(args) {
54
+ var options;
55
+ var config;
56
+ if (typeof args[0] === 'boolean') {
57
+ options = args[0];
58
+ config = args[1];
59
+ }
60
+ else {
61
+ var _a = __assign(__assign({}, (args[0] || {})), (args[1] || {})), startImmediately = _a.startImmediately, restOptions = __rest(_a, ["startImmediately"]);
62
+ options = restOptions;
63
+ config = {
64
+ startImmediately: startImmediately,
65
+ };
66
+ }
67
+ return { options: options, config: config };
68
+ }
@@ -0,0 +1,81 @@
1
+ import { getRefElement } from '../../utils';
2
+ export var globalListenerEventMap = new Map();
3
+ /**
4
+ * create globalListener handler for share one listener event
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const globalListener = createGlobalListener('focus', () => { console.log('focus') });
9
+ * const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
10
+ * globalListener.listen();
11
+ * globalListener2.listen();
12
+ *
13
+ * => // that will only create an event listener on window, but every callback will get emit value when event triggered
14
+ * ```
15
+ */
16
+ export var createGlobalListener = function (key, listener, options, _a) {
17
+ var _b = _a === void 0 ? {} : _a, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d;
18
+ var listening = false;
19
+ var getMapValue = function () { return globalListenerEventMap.get(customKey); };
20
+ var addListener = function () {
21
+ if (listening)
22
+ return;
23
+ var savedEvent = getMapValue();
24
+ if (!(savedEvent === null || savedEvent === void 0 ? void 0 : savedEvent.exec)) {
25
+ var exec = function (e) {
26
+ var event = getMapValue();
27
+ event === null || event === void 0 ? void 0 : event.listeners.forEach(function (c) { return c(e); });
28
+ };
29
+ globalListenerEventMap.set(customKey, {
30
+ exec: exec,
31
+ listeners: new Set([listener]),
32
+ });
33
+ var target = getRefElement(targetProp);
34
+ target === null || target === void 0 ? void 0 : target.addEventListener(key, exec, options);
35
+ }
36
+ else {
37
+ savedEvent.listeners.add(listener);
38
+ }
39
+ listening = true;
40
+ };
41
+ var removeListener = function () {
42
+ if (!listening)
43
+ return;
44
+ listening = false;
45
+ var _savedEvent = getMapValue();
46
+ if (!_savedEvent)
47
+ return;
48
+ var listeners = _savedEvent.listeners;
49
+ listeners.delete(listener);
50
+ if (listeners.size === 0) {
51
+ var target = getRefElement(targetProp);
52
+ target === null || target === void 0 ? void 0 : target.removeEventListener(key, _savedEvent.exec, options);
53
+ globalListenerEventMap.delete(customKey);
54
+ }
55
+ };
56
+ return {
57
+ listen: function () { return addListener(); },
58
+ /**
59
+ * remove listener
60
+ */
61
+ remove: function () { return removeListener(); },
62
+ /**
63
+ * current listener state
64
+ */
65
+ get state() {
66
+ return {
67
+ /**
68
+ * current listener state count
69
+ */
70
+ get count() {
71
+ var _a;
72
+ return ((_a = getMapValue()) === null || _a === void 0 ? void 0 : _a.listeners.size) || 0;
73
+ },
74
+ /**
75
+ * is that be listening
76
+ */
77
+ listening: listening,
78
+ };
79
+ },
80
+ };
81
+ };
@@ -1 +1,2 @@
1
+ export * from './createGlobalListener';
1
2
  export * from './useGlobalListener';
@@ -1,89 +1,8 @@
1
+ import { __assign, __rest } from "tslib";
1
2
  import { useEffect, useRef } from 'react';
2
3
  import { getRefElement, logInDev } from '../../utils';
3
4
  import { useEventCallback } from '../useEventCallback';
4
- export var globalListenerEventMap = new Map();
5
- /**
6
- * create globalListener handler for share one listener event
7
- *
8
- * @example
9
- * ```ts
10
- * const globalListener = createGlobalListener('focus', () => { console.log('focus') });
11
- * const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
12
- * globalListener.listen();
13
- * globalListener2.listen();
14
- *
15
- * => // that will only create an event listener on window, but every callback will get emit value when event triggered
16
- * ```
17
- */
18
- export var createGlobalListener = function (key, listener, _a) {
19
- var _b = _a === void 0 ? {} : _a, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d;
20
- var listening = false;
21
- var getMapValue = function () { return globalListenerEventMap.get(customKey); };
22
- var addListener = function () {
23
- if (listening)
24
- return;
25
- var savedEvent = getMapValue();
26
- if (!(savedEvent === null || savedEvent === void 0 ? void 0 : savedEvent.exec)) {
27
- var exec = function (e) {
28
- var event = getMapValue();
29
- event === null || event === void 0 ? void 0 : event.listeners.forEach(function (c) { return c(e); });
30
- };
31
- globalListenerEventMap.set(customKey, {
32
- exec: exec,
33
- listeners: new Set([listener]),
34
- });
35
- var target = getRefElement(targetProp);
36
- target === null || target === void 0 ? void 0 : target.addEventListener(key, exec);
37
- }
38
- else {
39
- savedEvent.listeners.add(listener);
40
- }
41
- listening = true;
42
- };
43
- var removeListener = function () {
44
- if (!listening)
45
- return;
46
- listening = false;
47
- var _savedEvent = getMapValue();
48
- if (!_savedEvent)
49
- return;
50
- var listeners = _savedEvent.listeners;
51
- listeners.delete(listener);
52
- if (listeners.size === 0) {
53
- var target = getRefElement(targetProp);
54
- target === null || target === void 0 ? void 0 : target.removeEventListener(key, _savedEvent.exec);
55
- globalListenerEventMap.delete(customKey);
56
- }
57
- };
58
- return {
59
- /**
60
- * bind listener again
61
- */
62
- listen: function () { return addListener(); },
63
- /**
64
- * remove listener
65
- */
66
- remove: function () { return removeListener(); },
67
- /**
68
- * current listener state
69
- */
70
- get state() {
71
- return {
72
- /**
73
- * current listener state count
74
- */
75
- get count() {
76
- var _a;
77
- return ((_a = getMapValue()) === null || _a === void 0 ? void 0 : _a.listeners.size) || 0;
78
- },
79
- /**
80
- * is that be listening
81
- */
82
- listening: listening,
83
- };
84
- },
85
- };
86
- };
5
+ import { createGlobalListener, } from './createGlobalListener';
87
6
  /**
88
7
  * bind global event, when you bind same key event,
89
8
  * that will reuse one event listener and trigger both callback once that listener be triggered.
@@ -91,40 +10,91 @@ export var createGlobalListener = function (key, listener, _a) {
91
10
  * also you can control listener with method `listen` and `remove`
92
11
  * and get listener `state` for check listener count number and current listing state.
93
12
  *
94
- * - `key` `options` only work when set first time, never change after first render
13
+ * config:
14
+ * - `target`: custom binding event target, default is `window`
15
+ * - `customKey`: custom key for determining different event group, default is same as `key`
16
+ * - `startImmediately`: start listener immediately, default is `true`
17
+ *
18
+ * * `key`, `options` only work when set first time, never change after first render
95
19
  *
96
20
  * @example
97
21
  * ```ts
98
22
  * useGlobalListener('keyup', () => console.log('window key up1'))
23
+ *
99
24
  * useGlobalListener('keyup', () => console.log('window key up2'))
100
- * useGlobalListener('keyup', () => console.log('window key up3'))
25
+ *
26
+ * useGlobalListener('touchend', () => console.log('window key up3'), {
27
+ * target: someWantHostElement,
28
+ * customKey: 'hostTouchend',
29
+ * })
30
+ *
31
+ * useGlobalListener('touchend', () => console.log('window key up3'), { passive: false }, {
32
+ * target: someWantHostElement,
33
+ * customKey: 'hostTouchend',
34
+ * })
101
35
  *
102
36
  * => // that will only create an event listener on `window`, but every callback will get emit value when event triggered
103
37
  * ```
104
38
  */
105
- export function useGlobalListener(key, listener, options) {
106
- if (options === void 0) { options = {}; }
39
+ export function useGlobalListener(key, listener) {
40
+ var args = [];
41
+ for (var _i = 2; _i < arguments.length; _i++) {
42
+ args[_i - 2] = arguments[_i];
43
+ }
44
+ var _a = getListenerOverloadOption(args), options = _a.options, config = _a.config;
45
+ var _b = config || {}, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d, _e = _b.startImmediately, startImmediately = _e === void 0 ? true : _e;
107
46
  var _listener = useEventCallback(listener);
108
- var globalListener = useRef(createGlobalListener(key, _listener, options)).current;
47
+ var globalListener = useRef(createGlobalListener(key, _listener, options, {
48
+ customKey: customKey,
49
+ target: targetProp,
50
+ })).current;
109
51
  if (process.env.NODE_ENV !== 'production') {
110
- var _a = options.customKey, customKey_1 = _a === void 0 ? key : _a, _b = options.target, targetProp_1 = _b === void 0 ? window : _b;
111
52
  // eslint-disable-next-line react-hooks/rules-of-hooks
112
53
  useEffect(function () {
113
- var target = getRefElement(targetProp_1);
114
- if (target !== window && customKey_1 === key) {
115
- logInDev({
116
- component: 'useGlobalListener',
117
- message: 'When you custom binding event target, you must custom key for determining different event group',
118
- level: 'error',
119
- });
54
+ if (customKey === key) {
55
+ if (Object.keys(options).length > 0) {
56
+ logInDev({
57
+ component: 'useGlobalListener',
58
+ message: 'when have set options, suggest you also bind customKey, otherwise, it may use previous listener without same options',
59
+ level: 'warn',
60
+ });
61
+ }
62
+ var target = getRefElement(targetProp);
63
+ if (target !== window) {
64
+ logInDev({
65
+ component: 'useGlobalListener',
66
+ message: 'When you custom binding event target, you must custom key for determining different event group',
67
+ level: 'error',
68
+ });
69
+ }
120
70
  }
121
71
  // eslint-disable-next-line react-hooks/exhaustive-deps
122
72
  }, []);
123
73
  }
124
74
  useEffect(function () {
125
- globalListener.listen();
75
+ if (startImmediately) {
76
+ globalListener.listen();
77
+ }
126
78
  return globalListener.remove;
127
79
  // eslint-disable-next-line react-hooks/exhaustive-deps
128
80
  }, []);
129
81
  return globalListener;
130
82
  }
83
+ function getListenerOverloadOption(args) {
84
+ var options;
85
+ var config;
86
+ if (typeof args[0] === 'boolean') {
87
+ options = args[0];
88
+ config = args[1];
89
+ }
90
+ else {
91
+ var _a = __assign(__assign({}, (args[0] || {})), (args[1] || {})), startImmediately = _a.startImmediately, customKey = _a.customKey, target = _a.target, restOptions = __rest(_a, ["startImmediately", "customKey", "target"]);
92
+ options = restOptions;
93
+ config = {
94
+ startImmediately: startImmediately,
95
+ customKey: customKey,
96
+ target: target,
97
+ };
98
+ }
99
+ return { options: options, config: config };
100
+ }