@skbkontur/react-ui 3.10.0 → 3.11.0-csi.1
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/CHANGELOG.md +19 -0
- package/LICENSE +21 -21
- package/cjs/components/Button/Button.d.ts +1 -1
- package/cjs/components/Button/Button.js +4 -3
- package/cjs/components/Button/Button.js.map +1 -1
- package/cjs/components/Button/Button.styles.d.ts +1 -0
- package/cjs/components/Button/Button.styles.js +38 -28
- package/cjs/components/Button/Button.styles.js.map +1 -1
- package/cjs/components/CurrencyLabel/CurrencyLabel.md +23 -23
- package/cjs/components/DropdownMenu/DropdownMenu.d.ts +2 -2
- package/cjs/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/cjs/components/Gapped/Gapped.md +43 -43
- package/cjs/components/Hint/Hint.d.ts +2 -1
- package/cjs/components/Hint/Hint.js +0 -16
- package/cjs/components/Hint/Hint.js.map +1 -1
- package/cjs/components/Input/Input.md +13 -13
- package/cjs/components/Kebab/Kebab.d.ts +2 -2
- package/cjs/components/Kebab/Kebab.js.map +1 -1
- package/cjs/components/MenuItem/MenuItem.d.ts +1 -1
- package/cjs/components/MenuItem/MenuItem.js +1 -4
- package/cjs/components/MenuItem/MenuItem.js.map +1 -1
- package/cjs/components/Modal/Modal.d.ts +8 -0
- package/cjs/components/Modal/Modal.js +19 -2
- package/cjs/components/Modal/Modal.js.map +1 -1
- package/cjs/components/PasswordInput/PasswordInput.md +9 -9
- package/cjs/components/RadioGroup/RadioGroup.md +43 -43
- package/cjs/components/ScrollContainer/ScrollBar.js +4 -2
- package/cjs/components/ScrollContainer/ScrollBar.js.map +1 -1
- package/cjs/components/ScrollContainer/ScrollContainer.js +2 -1
- package/cjs/components/ScrollContainer/ScrollContainer.js.map +1 -1
- package/cjs/components/ScrollContainer/ScrollContainer.styles.d.ts +1 -0
- package/cjs/components/ScrollContainer/ScrollContainer.styles.js +12 -8
- package/cjs/components/ScrollContainer/ScrollContainer.styles.js.map +1 -1
- package/cjs/components/Select/Select.js +4 -1
- package/cjs/components/Select/Select.js.map +1 -1
- package/cjs/components/SidePage/SidePage.d.ts +9 -0
- package/cjs/components/SidePage/SidePage.js +33 -3
- package/cjs/components/SidePage/SidePage.js.map +1 -1
- package/cjs/components/Spinner/Spinner.d.ts +8 -0
- package/cjs/components/Spinner/Spinner.js +21 -3
- package/cjs/components/Spinner/Spinner.js.map +1 -1
- package/cjs/components/Spinner/Spinner.md +1 -0
- package/cjs/components/Spinner/Spinner.styles.d.ts +2 -1
- package/cjs/components/Spinner/Spinner.styles.js +13 -10
- package/cjs/components/Spinner/Spinner.styles.js.map +1 -1
- package/cjs/components/Switcher/Switcher.styles.js +4 -2
- package/cjs/components/Switcher/Switcher.styles.js.map +1 -1
- package/cjs/components/Token/Token.md +112 -112
- package/cjs/components/Tooltip/Tooltip.d.ts +8 -21
- package/cjs/components/Tooltip/Tooltip.js +14 -27
- package/cjs/components/Tooltip/Tooltip.js.map +1 -1
- package/cjs/components/TooltipMenu/TooltipMenu.d.ts +2 -2
- package/cjs/components/TooltipMenu/TooltipMenu.js.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +2 -1
- package/cjs/index.js.map +1 -1
- package/cjs/internal/DropdownContainer/DropdownContainer.d.ts +1 -0
- package/cjs/internal/DropdownContainer/DropdownContainer.js +15 -2
- package/cjs/internal/DropdownContainer/DropdownContainer.js.map +1 -1
- package/cjs/internal/DropdownContainer/DropdownContainer.styles.d.ts +3 -0
- package/cjs/internal/DropdownContainer/DropdownContainer.styles.js +9 -0
- package/cjs/internal/DropdownContainer/DropdownContainer.styles.js.map +1 -0
- package/cjs/internal/Menu/Menu.d.ts +2 -0
- package/cjs/internal/Menu/Menu.js +33 -3
- package/cjs/internal/Menu/Menu.js.map +1 -1
- package/cjs/internal/Menu/Menu.styles.d.ts +3 -0
- package/cjs/internal/Menu/Menu.styles.js +23 -3
- package/cjs/internal/Menu/Menu.styles.js.map +1 -1
- package/cjs/internal/Popup/Popup.d.ts +5 -4
- package/cjs/internal/Popup/Popup.js +13 -24
- package/cjs/internal/Popup/Popup.js.map +1 -1
- package/cjs/internal/Popup/PopupHelper.d.ts +2 -2
- package/cjs/internal/Popup/PopupHelper.js.map +1 -1
- package/cjs/internal/Popup/types.d.ts +1 -0
- package/cjs/internal/Popup/types.js +1 -0
- package/cjs/internal/Popup/types.js.map +1 -0
- package/cjs/internal/PopupMenu/PopupMenu.d.ts +3 -3
- package/cjs/internal/PopupMenu/PopupMenu.js +17 -3
- package/cjs/internal/PopupMenu/PopupMenu.js.map +1 -1
- package/cjs/internal/PopupMenu/validatePositions.d.ts +2 -2
- package/cjs/internal/PopupMenu/validatePositions.js +2 -4
- package/cjs/internal/PopupMenu/validatePositions.js.map +1 -1
- package/cjs/internal/ThemeShowcase/ThemeShowcase.md +13 -13
- package/cjs/internal/icons/SpinnerIcon.d.ts +4 -1
- package/cjs/internal/icons/SpinnerIcon.js +5 -2
- package/cjs/internal/icons/SpinnerIcon.js.map +1 -1
- package/cjs/lib/ModalStack.js +16 -17
- package/cjs/lib/ModalStack.js.map +1 -1
- package/cjs/lib/theming/AnimationKeyframes.js +1 -1
- package/cjs/lib/theming/AnimationKeyframes.js.map +1 -1
- package/cjs/lib/theming/useTheme.d.ts +1 -0
- package/cjs/lib/theming/useTheme.js +7 -0
- package/cjs/lib/theming/useTheme.js.map +1 -0
- package/cjs/lib/utils.d.ts +32 -0
- package/cjs/lib/utils.js +62 -2
- package/cjs/lib/utils.js.map +1 -1
- package/cjs/typings/html-props.d.ts +123 -0
- package/components/Button/Button/Button.js +3 -7
- package/components/Button/Button/Button.js.map +1 -1
- package/components/Button/Button.d.ts +1 -1
- package/components/Button/Button.styles/Button.styles.js +31 -28
- package/components/Button/Button.styles/Button.styles.js.map +1 -1
- package/components/Button/Button.styles.d.ts +1 -0
- package/components/CurrencyLabel/CurrencyLabel.md +23 -23
- package/components/DropdownMenu/DropdownMenu/DropdownMenu.js.map +1 -1
- package/components/DropdownMenu/DropdownMenu.d.ts +2 -2
- package/components/Gapped/Gapped.md +43 -43
- package/components/Hint/Hint/Hint.js.map +1 -1
- package/components/Hint/Hint.d.ts +2 -1
- package/components/Input/Input.md +13 -13
- package/components/Kebab/Kebab/Kebab.js.map +1 -1
- package/components/Kebab/Kebab.d.ts +2 -2
- package/components/MenuItem/MenuItem/MenuItem.js +2 -7
- package/components/MenuItem/MenuItem/MenuItem.js.map +1 -1
- package/components/MenuItem/MenuItem.d.ts +1 -1
- package/components/Modal/Modal/Modal.js +19 -2
- package/components/Modal/Modal/Modal.js.map +1 -1
- package/components/Modal/Modal.d.ts +8 -0
- package/components/PasswordInput/PasswordInput.md +9 -9
- package/components/RadioGroup/RadioGroup.md +43 -43
- package/components/ScrollContainer/ScrollBar/ScrollBar.js +6 -2
- package/components/ScrollContainer/ScrollBar/ScrollBar.js.map +1 -1
- package/components/ScrollContainer/ScrollContainer/ScrollContainer.js +2 -1
- package/components/ScrollContainer/ScrollContainer/ScrollContainer.js.map +1 -1
- package/components/ScrollContainer/ScrollContainer.styles/ScrollContainer.styles.js +11 -8
- package/components/ScrollContainer/ScrollContainer.styles/ScrollContainer.styles.js.map +1 -1
- package/components/ScrollContainer/ScrollContainer.styles.d.ts +1 -0
- package/components/Select/Select/Select.js +5 -2
- package/components/Select/Select/Select.js.map +1 -1
- package/components/SidePage/SidePage/SidePage.js +37 -2
- package/components/SidePage/SidePage/SidePage.js.map +1 -1
- package/components/SidePage/SidePage.d.ts +9 -0
- package/components/Spinner/Spinner/Spinner.js +6 -3
- package/components/Spinner/Spinner/Spinner.js.map +1 -1
- package/components/Spinner/Spinner.d.ts +8 -0
- package/components/Spinner/Spinner.md +1 -0
- package/components/Spinner/Spinner.styles/Spinner.styles.js +12 -9
- package/components/Spinner/Spinner.styles/Spinner.styles.js.map +1 -1
- package/components/Spinner/Spinner.styles.d.ts +2 -1
- package/components/Switcher/Switcher.styles/Switcher.styles.js +3 -1
- package/components/Switcher/Switcher.styles/Switcher.styles.js.map +1 -1
- package/components/Token/Token.md +112 -112
- package/components/Tooltip/Tooltip/Tooltip.js +2 -2
- package/components/Tooltip/Tooltip/Tooltip.js.map +1 -1
- package/components/Tooltip/Tooltip.d.ts +8 -21
- package/components/TooltipMenu/TooltipMenu/TooltipMenu.js.map +1 -1
- package/components/TooltipMenu/TooltipMenu.d.ts +2 -2
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/internal/DropdownContainer/DropdownContainer/DropdownContainer.js +9 -2
- package/internal/DropdownContainer/DropdownContainer/DropdownContainer.js.map +1 -1
- package/internal/DropdownContainer/DropdownContainer.d.ts +1 -0
- package/internal/DropdownContainer/DropdownContainer.styles/DropdownContainer.styles.js +10 -0
- package/internal/DropdownContainer/DropdownContainer.styles/DropdownContainer.styles.js.map +1 -0
- package/internal/DropdownContainer/DropdownContainer.styles/package.json +6 -0
- package/internal/DropdownContainer/DropdownContainer.styles.d.ts +3 -0
- package/internal/Menu/Menu/Menu.js +30 -6
- package/internal/Menu/Menu/Menu.js.map +1 -1
- package/internal/Menu/Menu.d.ts +2 -0
- package/internal/Menu/Menu.styles/Menu.styles.js +12 -3
- package/internal/Menu/Menu.styles/Menu.styles.js.map +1 -1
- package/internal/Menu/Menu.styles.d.ts +3 -0
- package/internal/Popup/Popup/Popup.js +3 -2
- package/internal/Popup/Popup/Popup.js.map +1 -1
- package/internal/Popup/Popup.d.ts +5 -4
- package/internal/Popup/PopupHelper/PopupHelper.js.map +1 -1
- package/internal/Popup/PopupHelper.d.ts +2 -2
- package/internal/Popup/types/package.json +6 -0
- package/internal/Popup/types/types.js +0 -0
- package/internal/Popup/types/types.js.map +1 -0
- package/internal/Popup/types.d.ts +1 -0
- package/internal/PopupMenu/PopupMenu/PopupMenu.js +3 -3
- package/internal/PopupMenu/PopupMenu/PopupMenu.js.map +1 -1
- package/internal/PopupMenu/PopupMenu.d.ts +3 -3
- package/internal/PopupMenu/validatePositions/validatePositions.js +2 -2
- package/internal/PopupMenu/validatePositions/validatePositions.js.map +1 -1
- package/internal/PopupMenu/validatePositions.d.ts +2 -2
- package/internal/ThemeShowcase/ThemeShowcase.md +13 -13
- package/internal/icons/SpinnerIcon/SpinnerIcon.js +5 -2
- package/internal/icons/SpinnerIcon/SpinnerIcon.js.map +1 -1
- package/internal/icons/SpinnerIcon.d.ts +4 -1
- package/lib/ModalStack/ModalStack.js +9 -13
- package/lib/ModalStack/ModalStack.js.map +1 -1
- package/lib/theming/AnimationKeyframes/AnimationKeyframes.js +1 -1
- package/lib/theming/AnimationKeyframes/AnimationKeyframes.js.map +1 -1
- package/lib/theming/useTheme/package.json +6 -0
- package/lib/theming/useTheme/useTheme.js +5 -0
- package/lib/theming/useTheme/useTheme.js.map +1 -0
- package/lib/theming/useTheme.d.ts +1 -0
- package/lib/utils/utils.js +66 -0
- package/lib/utils/utils.js.map +1 -1
- package/lib/utils.d.ts +32 -0
- package/package.json +7 -5
- package/typings/html-props.d.ts +123 -0
- package/cjs/internal/PopupMenu/PopupMenuPositions.d.ts +0 -2
- package/cjs/internal/PopupMenu/PopupMenuPositions.js +0 -15
- package/cjs/internal/PopupMenu/PopupMenuPositions.js.map +0 -1
- package/internal/PopupMenu/PopupMenuPositions/PopupMenuPositions.js +0 -1
- package/internal/PopupMenu/PopupMenuPositions/PopupMenuPositions.js.map +0 -1
- package/internal/PopupMenu/PopupMenuPositions/package.json +0 -6
- package/internal/PopupMenu/PopupMenuPositions.d.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["MenuItem.tsx"],"names":["MenuItem","rootNode","theme","mouseEntered","setRootNode","renderMain","props","link","comment","icon","loose","state","_enableIconPadding","component","onMouseEnter","onMouseLeave","rest","hover","disabled","iconElement","styles","className","root","selected","withIcon","Boolean","children","content","Component","getComponent","handleMouseEnterFix","handleMouseLeave","commentHover","e","href","render","React","__KONTUR_REACT_UI__","__MENU_ITEM__","propTypes","PropTypes","node","bool","string","oneOfType","target","onClick","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AAUE,IATO,EAWxB/B,KAAK,EAAE6B,mBAAUG,MAXO,EAaxBE,MAAM,EAAEL,mBAAUG,MAbM,EAexBG,OAAO,EAAEN,mBAAUO,IAfK,E;;;AAgIrB,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,KAAD,EAAwE;AAChG;AACA,SAAO,CAAAA,KAAK,QAAL,2BAAAA,KAAK,CAAEC,IAAP,iCAAab,mBAAb,MAAqC,UAA5C;AACD,CAHM,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport { isFunction } from '../../lib/utils';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode/rootNodeDecorator';\n\nimport { styles } from './MenuItem.styles';\n\nexport type MenuItemState = null | 'hover' | 'selected' | void;\n\nexport interface MenuItemProps extends CommonProps {\n /**\n * @ignore\n */\n _enableIconPadding?: boolean;\n /**\n * Добавляет описание для элемента меню.\n */\n comment?: React.ReactNode;\n /**\n * Отключенное состояние.\n */\n disabled?: boolean;\n /**\n * Добавляет элементу меню иконку.\n */\n icon?: React.ReactElement<any>;\n /**\n * Меняет цвет текста на синий.\n */\n link?: boolean;\n /**\n * @ignore\n */\n loose?: boolean;\n /**\n * @ignore\n */\n state?: MenuItemState;\n /**\n * HTML-событие `onclick`.\n */\n onClick?: (event: React.SyntheticEvent<HTMLElement>) => void;\n /**\n * HTML-событие `mouseenter`.\n */\n onMouseEnter?: React.MouseEventHandler;\n /**\n * HTML-событие `mouseleave`.\n */\n onMouseLeave?: React.MouseEventHandler;\n children?: React.ReactNode | ((state: MenuItemState) => React.ReactNode);\n /**\n * HTML-атрибут `target`.\n */\n target?: React.AnchorHTMLAttributes<HTMLAnchorElement>['target'];\n /**\n * HTML-атрибут `title`.\n */\n title?: React.AnchorHTMLAttributes<HTMLAnchorElement>['title'];\n /**\n * HTML-атрибут `href`.\n */\n href?: React.AnchorHTMLAttributes<HTMLAnchorElement>['href'];\n /**\n * Заменяет корневой элемент, на компонент переданный в проп.\n *\n * По умолчанию корневой элемент рендерится как `button`. <br />Если передан `href`, то вместо `button` рендерится `a`.\n */\n component?: React.ComponentType<any>;\n}\n\n/**\n *\n * `MenuItem` - это вложенный компонент, задающий базовые стили для элемента меню и позволяющий навигироваться по элементам меню с помощью клавиатуры.\n *\n * Сущности в которых может быть использован `MenuItem`: [`DropdownMenu`](#/Components/DropdownMenu), [`Kebab`](#/Components/Kebab), [`TooltipMenu`](#/Components/TooltipMenu) и [`Select`](#/Components/Select).\n */\n@rootNode\nexport class MenuItem extends React.Component<MenuItemProps> {\n public static __KONTUR_REACT_UI__ = 'MenuItem';\n public static __MENU_ITEM__ = true;\n\n public static propTypes = {\n comment: PropTypes.node,\n\n disabled: PropTypes.bool,\n\n href: PropTypes.string,\n\n icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),\n\n loose: PropTypes.bool,\n\n state: PropTypes.string,\n\n target: PropTypes.string,\n\n onClick: PropTypes.func,\n };\n\n private theme!: Theme;\n private mouseEntered = false;\n private setRootNode!: TSetRootNode;\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n {this.renderMain}\n </CommonWrapper>\n );\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain = (props: CommonWrapperRestProps<MenuItemProps>) => {\n const { link, comment, icon, loose, state, _enableIconPadding, component, onMouseEnter, onMouseLeave, ...rest } =\n props;\n\n const hover = state === 'hover' && !this.props.disabled;\n\n let iconElement = null;\n if (icon) {\n iconElement = <div className={styles.icon(this.theme)}>{icon}</div>;\n }\n\n const className = cx({\n [styles.root(this.theme)]: true,\n [styles.loose()]: !!loose,\n [styles.hover(this.theme)]: hover,\n [styles.selected(this.theme)]: state === 'selected',\n [styles.link(this.theme)]: !!link,\n [styles.withIcon(this.theme)]: Boolean(iconElement) || !!_enableIconPadding,\n [styles.disabled(this.theme)]: !!this.props.disabled,\n });\n\n const { children } = this.props;\n\n let content = children;\n if (isFunction(children)) {\n content = children(this.props.state);\n }\n\n const Component = this.getComponent();\n\n return (\n <Component\n {...rest}\n state={state}\n onMouseOver={this.handleMouseEnterFix}\n onMouseLeave={this.handleMouseLeave}\n className={className}\n tabIndex={-1}\n >\n {iconElement}\n {content}\n {this.props.comment && (\n <div\n data-tid=\"MenuItem__comment\"\n className={cx({\n [styles.comment(this.theme)]: true,\n [styles.commentHover(this.theme)]: hover,\n })}\n >\n {comment}\n </div>\n )}\n </Component>\n );\n };\n\n // https://github.com/facebook/react/issues/10109\n // Mouseenter event not triggered when cursor moves from disabled button\n private handleMouseEnterFix = (e: React.MouseEvent<HTMLElement>) => {\n if (!this.mouseEntered && this.props.onMouseEnter) {\n this.mouseEntered = true;\n this.props.onMouseEnter(e);\n }\n };\n\n private handleMouseLeave = (e: React.MouseEvent<HTMLElement>) => {\n this.mouseEntered = false;\n if (this.props.onMouseLeave) {\n this.props.onMouseLeave(e);\n }\n };\n\n private getComponent = () => {\n const { disabled, component, href } = this.props;\n\n if (disabled) {\n return 'button';\n }\n\n if (component) {\n return component;\n }\n\n if (href) {\n return 'a';\n }\n\n return 'button';\n };\n}\n\nexport const isMenuItem = (child: React.ReactNode): child is React.ReactElement<MenuItemProps> => {\n // @ts-ignore\n return child?.type?.__KONTUR_REACT_UI__ === 'MenuItem';\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["MenuItem.tsx"],"names":["MenuItem","rootNode","theme","mouseEntered","setRootNode","renderMain","props","link","comment","icon","loose","state","_enableIconPadding","component","onMouseEnter","onMouseLeave","rest","hover","disabled","iconElement","styles","className","root","selected","withIcon","Boolean","children","content","Component","getComponent","handleMouseEnterFix","handleMouseLeave","commentHover","e","href","render","React","__KONTUR_REACT_UI__","__MENU_ITEM__","propTypes","PropTypes","node","bool","string","oneOfType","target","onClick","func","isMenuItem"],"mappings":"udAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA,6C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA;AACA;AACA;AACA;AACA;AACA,G;;AAEaA,Q,OADZC,2B;;;;;;;;;;;;;;;;;;;;;;AAuBSC,IAAAA,K;AACAC,IAAAA,Y,GAAe,K;AACfC,IAAAA,W;;;;;;;;;;;;;;;;;AAiBAC,IAAAA,U,GAAa,UAACC,KAAD,EAAkD;AAC7DC,MAAAA,IAD6D;AAEnED,MAAAA,KAFmE,CAC7DC,IAD6D,CACvDC,OADuD,GAEnEF,KAFmE,CACvDE,OADuD,CAC9CC,IAD8C,GAEnEH,KAFmE,CAC9CG,IAD8C,CACxCC,KADwC,GAEnEJ,KAFmE,CACxCI,KADwC,CACjCC,KADiC,GAEnEL,KAFmE,CACjCK,KADiC,CAC1BC,kBAD0B,GAEnEN,KAFmE,CAC1BM,kBAD0B,CACNC,SADM,GAEnEP,KAFmE,CACNO,SADM,CACKC,YADL,GAEnER,KAFmE,CACKQ,YADL,CACmBC,YADnB,GAEnET,KAFmE,CACmBS,YADnB,CACoCC,IADpC,+CAEnEV,KAFmE;;AAIrE,UAAMW,KAAK,GAAGN,KAAK,KAAK,OAAV,IAAqB,CAAC,MAAKL,KAAL,CAAWY,QAA/C;;AAEA,UAAIC,WAAW,GAAG,IAAlB;AACA,UAAIV,IAAJ,EAAU;AACRU,QAAAA,WAAW,gBAAG,sCAAK,SAAS,EAAEC,iBAAOX,IAAP,CAAY,MAAKP,KAAjB,CAAhB,IAA0CO,IAA1C,CAAd;AACD;;AAED,UAAMY,SAAS,GAAG;AACfD,uBAAOE,IAAP,CAAY,MAAKpB,KAAjB,CADe,IACW,IADX;AAEfkB,uBAAOV,KAAP,EAFe,IAEE,CAAC,CAACA,KAFJ;AAGfU,uBAAOH,KAAP,C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,EASxB/B,KAAK,EAAE8B,mBAAUE,IATO,EAWxB/B,KAAK,EAAE6B,mBAAUG,MAXO,EAaxBE,MAAM,EAAEL,mBAAUG,MAbM,EAexBG,OAAO,EAAEN,mBAAUO,IAfK,E;;;AAgIrB,IAAMC,UAAU,GAAG,+BAAmB,UAAnB,CAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport { isFunction, isReactUIComponent } from '../../lib/utils';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode/rootNodeDecorator';\n\nimport { styles } from './MenuItem.styles';\n\nexport type MenuItemState = null | 'hover' | 'selected' | void;\n\nexport interface MenuItemProps extends CommonProps {\n /**\n * @ignore\n */\n _enableIconPadding?: boolean;\n /**\n * Добавляет описание для элемента меню.\n */\n comment?: React.ReactNode;\n /**\n * Отключенное состояние.\n */\n disabled?: boolean;\n /**\n * Добавляет элементу меню иконку.\n */\n icon?: React.ReactElement<any>;\n /**\n * Меняет цвет текста на синий.\n */\n link?: boolean;\n /**\n * @ignore\n */\n loose?: boolean;\n /**\n * @ignore\n */\n state?: MenuItemState;\n /**\n * HTML-событие `onclick`.\n */\n onClick?: (event: React.SyntheticEvent<HTMLElement>) => void;\n /**\n * HTML-событие `mouseenter`.\n */\n onMouseEnter?: React.MouseEventHandler;\n /**\n * HTML-событие `mouseleave`.\n */\n onMouseLeave?: React.MouseEventHandler;\n children?: React.ReactNode | ((state: MenuItemState) => React.ReactNode);\n /**\n * HTML-атрибут `target`.\n */\n target?: React.AnchorHTMLAttributes<HTMLAnchorElement>['target'];\n /**\n * HTML-атрибут `title`.\n */\n title?: React.AnchorHTMLAttributes<HTMLAnchorElement>['title'];\n /**\n * HTML-атрибут `href`.\n */\n href?: React.AnchorHTMLAttributes<HTMLAnchorElement>['href'];\n /**\n * Заменяет корневой элемент, на компонент переданный в проп.\n *\n * По умолчанию корневой элемент рендерится как `button`. <br />Если передан `href`, то вместо `button` рендерится `a`.\n */\n component?: React.ComponentType<any>;\n}\n\n/**\n *\n * `MenuItem` - это вложенный компонент, задающий базовые стили для элемента меню и позволяющий навигироваться по элементам меню с помощью клавиатуры.\n *\n * Сущности в которых может быть использован `MenuItem`: [`DropdownMenu`](#/Components/DropdownMenu), [`Kebab`](#/Components/Kebab), [`TooltipMenu`](#/Components/TooltipMenu) и [`Select`](#/Components/Select).\n */\n@rootNode\nexport class MenuItem extends React.Component<MenuItemProps> {\n public static __KONTUR_REACT_UI__ = 'MenuItem';\n public static __MENU_ITEM__ = true;\n\n public static propTypes = {\n comment: PropTypes.node,\n\n disabled: PropTypes.bool,\n\n href: PropTypes.string,\n\n icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),\n\n loose: PropTypes.bool,\n\n state: PropTypes.string,\n\n target: PropTypes.string,\n\n onClick: PropTypes.func,\n };\n\n private theme!: Theme;\n private mouseEntered = false;\n private setRootNode!: TSetRootNode;\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n {this.renderMain}\n </CommonWrapper>\n );\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain = (props: CommonWrapperRestProps<MenuItemProps>) => {\n const { link, comment, icon, loose, state, _enableIconPadding, component, onMouseEnter, onMouseLeave, ...rest } =\n props;\n\n const hover = state === 'hover' && !this.props.disabled;\n\n let iconElement = null;\n if (icon) {\n iconElement = <div className={styles.icon(this.theme)}>{icon}</div>;\n }\n\n const className = cx({\n [styles.root(this.theme)]: true,\n [styles.loose()]: !!loose,\n [styles.hover(this.theme)]: hover,\n [styles.selected(this.theme)]: state === 'selected',\n [styles.link(this.theme)]: !!link,\n [styles.withIcon(this.theme)]: Boolean(iconElement) || !!_enableIconPadding,\n [styles.disabled(this.theme)]: !!this.props.disabled,\n });\n\n const { children } = this.props;\n\n let content = children;\n if (isFunction(children)) {\n content = children(this.props.state);\n }\n\n const Component = this.getComponent();\n\n return (\n <Component\n {...rest}\n state={state}\n onMouseOver={this.handleMouseEnterFix}\n onMouseLeave={this.handleMouseLeave}\n className={className}\n tabIndex={-1}\n >\n {iconElement}\n {content}\n {this.props.comment && (\n <div\n data-tid=\"MenuItem__comment\"\n className={cx({\n [styles.comment(this.theme)]: true,\n [styles.commentHover(this.theme)]: hover,\n })}\n >\n {comment}\n </div>\n )}\n </Component>\n );\n };\n\n // https://github.com/facebook/react/issues/10109\n // Mouseenter event not triggered when cursor moves from disabled button\n private handleMouseEnterFix = (e: React.MouseEvent<HTMLElement>) => {\n if (!this.mouseEntered && this.props.onMouseEnter) {\n this.mouseEntered = true;\n this.props.onMouseEnter(e);\n }\n };\n\n private handleMouseLeave = (e: React.MouseEvent<HTMLElement>) => {\n this.mouseEntered = false;\n if (this.props.onMouseLeave) {\n this.props.onMouseLeave(e);\n }\n };\n\n private getComponent = () => {\n const { disabled, component, href } = this.props;\n\n if (disabled) {\n return 'button';\n }\n\n if (component) {\n return component;\n }\n\n if (href) {\n return 'a';\n }\n\n return 'button';\n };\n}\n\nexport const isMenuItem = isReactUIComponent('MenuItem');\n"]}
|
|
@@ -39,6 +39,7 @@ export interface ModalState {
|
|
|
39
39
|
hasHeader: boolean;
|
|
40
40
|
hasFooter: boolean;
|
|
41
41
|
hasPanel: boolean;
|
|
42
|
+
shards: Array<React.RefObject<any> | HTMLElement>;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* Модальное окно
|
|
@@ -68,10 +69,17 @@ export declare class Modal extends React.Component<ModalProps, ModalState> {
|
|
|
68
69
|
private containerNode;
|
|
69
70
|
private mouseDownTarget;
|
|
70
71
|
private mouseUpTarget;
|
|
72
|
+
private shards;
|
|
71
73
|
componentDidMount(): void;
|
|
72
74
|
componentWillUnmount(): void;
|
|
73
75
|
render(): JSX.Element;
|
|
74
76
|
private renderMain;
|
|
77
|
+
/**
|
|
78
|
+
* Добавить элемент, который будет учитывать FocusLock
|
|
79
|
+
*
|
|
80
|
+
* @param shard
|
|
81
|
+
*/
|
|
82
|
+
addShard: (shard: React.RefObject<any> | HTMLElement) => void;
|
|
75
83
|
private requestClose;
|
|
76
84
|
private refContainer;
|
|
77
85
|
private handleStackChange;
|
|
@@ -66,6 +66,7 @@ var mountedModalsCount = 0;
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
|
|
69
|
+
|
|
69
70
|
|
|
70
71
|
|
|
71
72
|
/**
|
|
@@ -100,7 +101,8 @@ Modal = /*#__PURE__*/function (_React$Component) {(0, _inheritsLoose2.default)(M
|
|
|
100
101
|
horizontalScroll: false,
|
|
101
102
|
hasHeader: false,
|
|
102
103
|
hasFooter: false,
|
|
103
|
-
hasPanel: false
|
|
104
|
+
hasPanel: false,
|
|
105
|
+
shards: [] };_this.
|
|
104
106
|
|
|
105
107
|
|
|
106
108
|
theme = void 0;_this.
|
|
@@ -108,6 +110,10 @@ Modal = /*#__PURE__*/function (_React$Component) {(0, _inheritsLoose2.default)(M
|
|
|
108
110
|
containerNode = null;_this.
|
|
109
111
|
mouseDownTarget = null;_this.
|
|
110
112
|
mouseUpTarget = null;_this.
|
|
113
|
+
shards = new Set();_this.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
111
117
|
|
|
112
118
|
|
|
113
119
|
|
|
@@ -226,6 +232,13 @@ Modal = /*#__PURE__*/function (_React$Component) {(0, _inheritsLoose2.default)(M
|
|
|
226
232
|
|
|
227
233
|
|
|
228
234
|
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
addShard = function (shard) {
|
|
239
|
+
_this.shards.add(shard);
|
|
240
|
+
_this.setState({ shards: [].concat(Array.from(_this.shards.values())) });
|
|
241
|
+
};_this.
|
|
229
242
|
|
|
230
243
|
requestClose = function () {
|
|
231
244
|
if (_this.props.disableClose) {
|
|
@@ -300,5 +313,9 @@ Modal = /*#__PURE__*/function (_React$Component) {(0, _inheritsLoose2.default)(M
|
|
|
300
313
|
|
|
301
314
|
setHasPanel = function (hasPanel) {if (hasPanel === void 0) {hasPanel = false;}
|
|
302
315
|
_this.state.hasPanel !== hasPanel && _this.setState({ hasPanel: hasPanel });
|
|
303
|
-
};return _this;}var _proto = Modal.prototype;_proto.componentDidMount = function componentDidMount() {this.stackSubscription = _ModalStack.ModalStack.add(this, this.handleStackChange);if (mountedModalsCount === 0) {window.addEventListener('resize', this.checkHorizontalScrollAppearance);}mountedModalsCount++;window.addEventListener('keydown', this.handleKeyDown);this.checkHorizontalScrollAppearance();if (this.containerNode) {this.containerNode.addEventListener('scroll', LayoutEvents.emit);}};_proto.componentWillUnmount = function componentWillUnmount() {if (--mountedModalsCount === 0) {window.removeEventListener('resize', this.checkHorizontalScrollAppearance);LayoutEvents.emit();}window.removeEventListener('keydown', this.handleKeyDown);if (this.stackSubscription != null) {this.stackSubscription.remove();}_ModalStack.ModalStack.remove(this);if (this.containerNode) {this.containerNode.removeEventListener('scroll', LayoutEvents.emit);}};_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return _this2.renderMain();});};_proto.renderMain = function renderMain() {var _cx;var _this$state = this.state,hasHeader = _this$state.hasHeader,hasFooter = _this$state.hasFooter,hasPanel = _this$state.hasPanel;var modalContextProps = { hasHeader: hasHeader, horizontalScroll: this.state.horizontalScroll, setHasHeader: this.setHasHeader, setHasFooter: this.setHasFooter, setHasPanel: this.setHasPanel };if (hasHeader && !this.props.noClose) {modalContextProps.close = { disableClose: this.props.disableClose, requestClose: this.requestClose };}if (!hasFooter) {modalContextProps.additionalPadding = true;}if (hasFooter && hasPanel) {modalContextProps.additionalPadding = true;}var style = {};var containerStyle = {};if (this.props.width) {style.width = this.props.width;} else {containerStyle.width = 'auto';}return /*#__PURE__*/_react.default.createElement(_RenderContainer.RenderContainer, null, /*#__PURE__*/_react.default.createElement(_CommonWrapper.CommonWrapper, this.props, /*#__PURE__*/_react.default.createElement(_ZIndex.ZIndex, { priority: 'Modal', className: _Modal.styles.root() }, /*#__PURE__*/_react.default.createElement(_HideBodyVerticalScroll.HideBodyVerticalScroll, null), this.state.hasBackground && /*#__PURE__*/_react.default.createElement("div", { className: _Modal.styles.bg(this.theme) }), /*#__PURE__*/_react.default.createElement("div", { ref: this.refContainer, className: _Modal.styles.container(), onMouseDown: this.handleContainerMouseDown, onMouseUp: this.handleContainerMouseUp, onClick: this.handleContainerClick, "data-tid": "modal-container" }, /*#__PURE__*/_react.default.createElement("div", { className: (0, _Emotion.cx)((_cx = {}, _cx[_Modal.styles.centerContainer(this.theme)] = true, _cx[_Modal.styles.alignTop()] = Boolean(this.props.alignTop), _cx)), style: containerStyle, "data-tid": "modal-content" }, /*#__PURE__*/_react.default.createElement("div", { className: _Modal.styles.window(this.theme), style: style }, /*#__PURE__*/_react.default.createElement(_ResizeDetector.ResizeDetector, { onResize: this.handleResize }, /*#__PURE__*/_react.default.createElement(_reactFocusLock.default, { disabled: this.props.disableFocusLock, autoFocus: false }, !hasHeader && !this.props.noClose ? /*#__PURE__*/_react.default.createElement(_ZIndex.ZIndex, { priority: 'ModalCross', className: _Modal.styles.closeWrapper(this.theme) }, /*#__PURE__*/_react.default.createElement(_ModalClose.ModalClose, { requestClose: this.requestClose, disableClose: this.props.disableClose })) : null, /*#__PURE__*/_react.default.createElement(_ModalContext.ModalContext.Provider, { value: modalContextProps }, this.props.children)))))))));}
|
|
316
|
+
};return _this;}var _proto = Modal.prototype;_proto.componentDidMount = function componentDidMount() {this.stackSubscription = _ModalStack.ModalStack.add(this, this.handleStackChange);if (mountedModalsCount === 0) {window.addEventListener('resize', this.checkHorizontalScrollAppearance);}mountedModalsCount++;window.addEventListener('keydown', this.handleKeyDown);this.checkHorizontalScrollAppearance();if (this.containerNode) {this.containerNode.addEventListener('scroll', LayoutEvents.emit);}};_proto.componentWillUnmount = function componentWillUnmount() {if (--mountedModalsCount === 0) {window.removeEventListener('resize', this.checkHorizontalScrollAppearance);LayoutEvents.emit();}window.removeEventListener('keydown', this.handleKeyDown);if (this.stackSubscription != null) {this.stackSubscription.remove();}_ModalStack.ModalStack.remove(this);if (this.containerNode) {this.containerNode.removeEventListener('scroll', LayoutEvents.emit);}};_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return _this2.renderMain();});};_proto.renderMain = function renderMain() {var _cx;var _this$state = this.state,hasHeader = _this$state.hasHeader,hasFooter = _this$state.hasFooter,hasPanel = _this$state.hasPanel;var modalContextProps = { hasHeader: hasHeader, horizontalScroll: this.state.horizontalScroll, setHasHeader: this.setHasHeader, setHasFooter: this.setHasFooter, setHasPanel: this.setHasPanel };if (hasHeader && !this.props.noClose) {modalContextProps.close = { disableClose: this.props.disableClose, requestClose: this.requestClose };}if (!hasFooter) {modalContextProps.additionalPadding = true;}if (hasFooter && hasPanel) {modalContextProps.additionalPadding = true;}var style = {};var containerStyle = {};if (this.props.width) {style.width = this.props.width;} else {containerStyle.width = 'auto';}return /*#__PURE__*/_react.default.createElement(_RenderContainer.RenderContainer, null, /*#__PURE__*/_react.default.createElement(_CommonWrapper.CommonWrapper, this.props, /*#__PURE__*/_react.default.createElement(_ZIndex.ZIndex, { priority: 'Modal', className: _Modal.styles.root() }, /*#__PURE__*/_react.default.createElement(_HideBodyVerticalScroll.HideBodyVerticalScroll, null), this.state.hasBackground && /*#__PURE__*/_react.default.createElement("div", { className: _Modal.styles.bg(this.theme) }), /*#__PURE__*/_react.default.createElement("div", { ref: this.refContainer, className: _Modal.styles.container(), onMouseDown: this.handleContainerMouseDown, onMouseUp: this.handleContainerMouseUp, onClick: this.handleContainerClick, "data-tid": "modal-container" }, /*#__PURE__*/_react.default.createElement("div", { className: (0, _Emotion.cx)((_cx = {}, _cx[_Modal.styles.centerContainer(this.theme)] = true, _cx[_Modal.styles.alignTop()] = Boolean(this.props.alignTop), _cx)), style: containerStyle, "data-tid": "modal-content" }, /*#__PURE__*/_react.default.createElement("div", { className: _Modal.styles.window(this.theme), style: style }, /*#__PURE__*/_react.default.createElement(_ResizeDetector.ResizeDetector, { onResize: this.handleResize }, /*#__PURE__*/_react.default.createElement(_reactFocusLock.default, { shards: this.state.shards, disabled: this.props.disableFocusLock, autoFocus: false }, !hasHeader && !this.props.noClose ? /*#__PURE__*/_react.default.createElement(_ZIndex.ZIndex, { priority: 'ModalCross', className: _Modal.styles.closeWrapper(this.theme) }, /*#__PURE__*/_react.default.createElement(_ModalClose.ModalClose, { requestClose: this.requestClose, disableClose: this.props.disableClose })) : null, /*#__PURE__*/_react.default.createElement(_ModalContext.ModalContext.Provider, { value: modalContextProps }, this.props.children)))))))));} /**
|
|
317
|
+
* Добавить элемент, который будет учитывать FocusLock
|
|
318
|
+
*
|
|
319
|
+
* @param shard
|
|
320
|
+
*/;return Modal;}(_react.default.Component);exports.Modal = Modal;Modal.__KONTUR_REACT_UI__ = 'Modal';Modal.Header = _ModalHeader.ModalHeader;Modal.Body = _ModalBody.ModalBody;Modal.Footer = _ModalFooter.ModalFooter;Modal.defaultProps = { // NOTE: в ie нормально не работает
|
|
304
321
|
disableFocusLock: _client.isIE11 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Modal.tsx"],"names":["mountedModalsCount","Modal","state","stackPosition","hasBackground","horizontalScroll","hasHeader","hasFooter","hasPanel","theme","stackSubscription","containerNode","mouseDownTarget","mouseUpTarget","requestClose","props","disableClose","onClose","refContainer","center","handleStackChange","stack","setState","indexOf","ModalStack","isBlocking","handleContainerMouseDown","event","target","handleContainerMouseUp","handleContainerClick","ignoreBackgroundClick","currentTarget","handleKeyDown","e","checkHorizontalScrollAppearance","hasScroll","containerClientWidth","clientWidth","containerScrollWidth","scrollWidth","handleResize","LayoutEvents","emit","setHasHeader","setHasFooter","setHasPanel","componentDidMount","add","window","addEventListener","componentWillUnmount","removeEventListener","remove","render","renderMain","modalContextProps","noClose","close","additionalPadding","style","containerStyle","width","styles","root","bg","container","centerContainer","alignTop","Boolean","disableFocusLock","closeWrapper","children","React","Component","__KONTUR_REACT_UI__","Header","ModalHeader","Body","ModalBody","Footer","ModalFooter","defaultProps","isIE11"],"mappings":"sbAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,kBAAkB,GAAG,CAAzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,G;AACaC,K;;;;;;;;;;;;AAYJC,IAAAA,K,GAAoB;AACzBC,MAAAA,aAAa,EAAE,CADU;AAEzBC,MAAAA,aAAa,EAAE,IAFU;AAGzBC,MAAAA,gBAAgB,EAAE,KAHO;AAIzBC,MAAAA,SAAS,EAAE,KAJc;AAKzBC,MAAAA,SAAS,EAAE,KALc;AAMzBC,MAAAA,QAAQ,EAAE,KANe,E;;;AASnBC,IAAAA,K;AACAC,IAAAA,iB,GAAmD,I;AACnDC,IAAAA,a,GAAuC,I;AACvCC,IAAAA,e,GAAsC,I;AACtCC,IAAAA,a,GAAoC,I;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHpCC,IAAAA,Y,GAAe,YAAM;AAC3B,UAAI,MAAKC,KAAL,CAAWC,YAAf,EAA6B;AAC3B;AACD;AACD,UAAI,MAAKD,KAAL,CAAWE,OAAf,EAAwB;AACtB,cAAKF,KAAL,CAAWE,OAAX;AACD;AACF,K;;AAEOC,IAAAA,Y,GAAe,UAACC,MAAD,EAA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AAC,KAAKtD,KAAL,CAAWqD,QAAZ,CAFnB,OADb,EAKE,KAAK,EAAEP,cALT,EAME,YAAS,eANX,iBAQE,sCAAK,SAAS,EAAEE,cAAOd,MAAP,CAAc,KAAKxC,KAAnB,CAAhB,EAA2C,KAAK,EAAEmD,KAAlD,iBACE,6BAAC,8BAAD,IAAgB,QAAQ,EAAE,KAAKnB,YAA/B,iBACE,6BAAC,uBAAD,IAAW,QAAQ,EAAE,KAAK1B,KAAL,CAAWuD,gBAAhC,EAAkD,SAAS,EAAE,KAA7D,IACG,CAAChE,SAAD,IAAc,CAAC,KAAKS,KAAL,CAAW0C,OAA1B,gBACC,6BAAC,cAAD,IAAQ,QAAQ,EAAE,YAAlB,EAAgC,SAAS,EAAEM,cAAOQ,YAAP,CAAoB,KAAK9D,KAAzB,CAA3C,iBACE,6BAAC,sBAAD,IAAY,YAAY,EAAE,KAAKK,YAA/B,EAA6C,YAAY,EAAE,KAAKC,KAAL,CAAWC,YAAtE,GADF,CADD,GAIG,IALN,eAME,6BAAC,0BAAD,CAAc,QAAd,IAAuB,KAAK,EAAEwC,iBAA9B,IAAkD,KAAKzC,KAAL,CAAWyD,QAA7D,CANF,CADF,CADF,CARF,CARF,CAHF,CADF,CADF,CADF,CAwCD,C,gBA/IwBC,eAAMC,S,wBAApBzE,K,CACG0E,mB,GAAsB,O,CADzB1E,K,CAGG2E,M,GAASC,wB,CAHZ5E,K,CAIG6E,I,GAAOC,oB,CAJV9E,K,CAKG+E,M,GAASC,wB,CALZhF,K,CAOGiF,Y,GAAe,EAC3B;AACAZ,EAAAA,gBAAgB,EAAEa,cAFS,E","sourcesContent":["import React from 'react';\nimport FocusLock from 'react-focus-lock';\n\nimport { isKeyEscape } from '../../lib/events/keyboard/identifiers';\nimport * as LayoutEvents from '../../lib/LayoutEvents';\nimport { RenderContainer } from '../../internal/RenderContainer';\nimport { ZIndex } from '../../internal/ZIndex';\nimport { stopPropagation } from '../../lib/events/stopPropagation';\nimport { HideBodyVerticalScroll } from '../../internal/HideBodyVerticalScroll';\nimport { ModalStack, ModalStackSubscription } from '../../lib/ModalStack';\nimport { ResizeDetector } from '../../internal/ResizeDetector';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { isIE11 } from '../../lib/client';\nimport { CommonWrapper, CommonProps } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\n\nimport { ModalContext, ModalContextProps } from './ModalContext';\nimport { ModalFooter } from './ModalFooter';\nimport { ModalHeader } from './ModalHeader';\nimport { ModalBody } from './ModalBody';\nimport { ModalClose } from './ModalClose';\nimport { styles } from './Modal.styles';\n\nlet mountedModalsCount = 0;\n\nexport interface ModalProps extends CommonProps {\n /**\n * Отключает событие onClose, также дизейблит кнопку закрытия модалки\n */\n disableClose?: boolean;\n\n /**\n * Выравнивание окна по верху страницы.\n */\n alignTop?: boolean;\n\n /**\n * Не закрывать окно при клике на фон.\n */\n ignoreBackgroundClick?: boolean;\n\n /**\n * Не показывать крестик для закрытия окна.\n */\n noClose?: boolean;\n width?: number | string;\n\n /**\n * Вызывается, когда пользователь запросил закрытие окна (нажал на фон, на\n * Escape или на крестик).\n */\n onClose?: () => void;\n\n /**\n * Не использовать фокус-лок внутри модалки.\n * По умолчанию true для IE11.\n */\n disableFocusLock?: boolean;\n}\n\nexport interface ModalState {\n stackPosition: number;\n hasBackground: boolean;\n horizontalScroll: boolean;\n hasHeader: boolean;\n hasFooter: boolean;\n hasPanel: boolean;\n}\n\n/**\n * Модальное окно\n *\n * Содержит в себе три компоненты: **Modal.Header**,\n * **Modal.Body** и **Modal.Footer**\n *\n * Для отображения серой плашки в футере в компонент\n * **Footer** необходимо передать пропс **panel**\n *\n * Для отключения прилипания шапки и футера\n * в соответствующий компонет нужно передать\n * проп **sticky** со значением **false**\n * (по-умолчанию прилипание включено)\n */\nexport class Modal extends React.Component<ModalProps, ModalState> {\n public static __KONTUR_REACT_UI__ = 'Modal';\n\n public static Header = ModalHeader;\n public static Body = ModalBody;\n public static Footer = ModalFooter;\n\n public static defaultProps = {\n // NOTE: в ie нормально не работает\n disableFocusLock: isIE11,\n };\n\n public state: ModalState = {\n stackPosition: 0,\n hasBackground: true,\n horizontalScroll: false,\n hasHeader: false,\n hasFooter: false,\n hasPanel: false,\n };\n\n private theme!: Theme;\n private stackSubscription: ModalStackSubscription | null = null;\n private containerNode: HTMLDivElement | null = null;\n private mouseDownTarget: EventTarget | null = null;\n private mouseUpTarget: EventTarget | null = null;\n\n public componentDidMount() {\n this.stackSubscription = ModalStack.add(this, this.handleStackChange);\n\n if (mountedModalsCount === 0) {\n window.addEventListener('resize', this.checkHorizontalScrollAppearance);\n }\n\n mountedModalsCount++;\n window.addEventListener('keydown', this.handleKeyDown);\n this.checkHorizontalScrollAppearance();\n\n if (this.containerNode) {\n this.containerNode.addEventListener('scroll', LayoutEvents.emit);\n }\n }\n\n public componentWillUnmount() {\n if (--mountedModalsCount === 0) {\n window.removeEventListener('resize', this.checkHorizontalScrollAppearance);\n LayoutEvents.emit();\n }\n\n window.removeEventListener('keydown', this.handleKeyDown);\n if (this.stackSubscription != null) {\n this.stackSubscription.remove();\n }\n ModalStack.remove(this);\n\n if (this.containerNode) {\n this.containerNode.removeEventListener('scroll', LayoutEvents.emit);\n }\n }\n\n public render(): JSX.Element {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const { hasHeader, hasFooter, hasPanel } = this.state;\n\n const modalContextProps: ModalContextProps = {\n hasHeader,\n horizontalScroll: this.state.horizontalScroll,\n setHasHeader: this.setHasHeader,\n setHasFooter: this.setHasFooter,\n setHasPanel: this.setHasPanel,\n };\n if (hasHeader && !this.props.noClose) {\n modalContextProps.close = {\n disableClose: this.props.disableClose,\n requestClose: this.requestClose,\n };\n }\n if (!hasFooter) {\n modalContextProps.additionalPadding = true;\n }\n if (hasFooter && hasPanel) {\n modalContextProps.additionalPadding = true;\n }\n\n const style: { width?: number | string } = {};\n const containerStyle: { width?: number | string } = {};\n\n if (this.props.width) {\n style.width = this.props.width;\n } else {\n containerStyle.width = 'auto';\n }\n\n return (\n <RenderContainer>\n <CommonWrapper {...this.props}>\n <ZIndex priority={'Modal'} className={styles.root()}>\n <HideBodyVerticalScroll />\n {this.state.hasBackground && <div className={styles.bg(this.theme)} />}\n <div\n ref={this.refContainer}\n className={styles.container()}\n onMouseDown={this.handleContainerMouseDown}\n onMouseUp={this.handleContainerMouseUp}\n onClick={this.handleContainerClick}\n data-tid=\"modal-container\"\n >\n <div\n className={cx({\n [styles.centerContainer(this.theme)]: true,\n [styles.alignTop()]: Boolean(this.props.alignTop),\n })}\n style={containerStyle}\n data-tid=\"modal-content\"\n >\n <div className={styles.window(this.theme)} style={style}>\n <ResizeDetector onResize={this.handleResize}>\n <FocusLock disabled={this.props.disableFocusLock} autoFocus={false}>\n {!hasHeader && !this.props.noClose ? (\n <ZIndex priority={'ModalCross'} className={styles.closeWrapper(this.theme)}>\n <ModalClose requestClose={this.requestClose} disableClose={this.props.disableClose} />\n </ZIndex>\n ) : null}\n <ModalContext.Provider value={modalContextProps}>{this.props.children}</ModalContext.Provider>\n </FocusLock>\n </ResizeDetector>\n </div>\n </div>\n </div>\n </ZIndex>\n </CommonWrapper>\n </RenderContainer>\n );\n }\n\n private requestClose = () => {\n if (this.props.disableClose) {\n return;\n }\n if (this.props.onClose) {\n this.props.onClose();\n }\n };\n\n private refContainer = (center: HTMLDivElement | null) => {\n this.containerNode = center;\n };\n\n private handleStackChange = (stack: ReadonlyArray<React.Component>) => {\n this.setState({ stackPosition: stack.indexOf(this), hasBackground: ModalStack.isBlocking(this) });\n };\n\n private handleContainerMouseDown = (event: React.MouseEvent) => {\n this.mouseDownTarget = event.target;\n };\n\n private handleContainerMouseUp = (event: React.MouseEvent) => {\n this.mouseUpTarget = event.target;\n };\n\n private handleContainerClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!this.props.ignoreBackgroundClick) {\n const { target, currentTarget } = event;\n if (target === currentTarget && this.mouseDownTarget === currentTarget && this.mouseUpTarget === currentTarget) {\n this.requestClose();\n }\n }\n };\n\n private handleKeyDown = (e: KeyboardEvent) => {\n if (this.state.stackPosition !== 0) {\n return;\n }\n if (isKeyEscape(e)) {\n stopPropagation(e);\n this.requestClose();\n }\n };\n\n private checkHorizontalScrollAppearance = () => {\n let hasScroll = false;\n\n if (this.containerNode) {\n const containerClientWidth = this.containerNode.clientWidth;\n const containerScrollWidth = this.containerNode.scrollWidth;\n hasScroll = containerClientWidth < containerScrollWidth;\n }\n if (hasScroll && !this.state.horizontalScroll) {\n this.setState({ horizontalScroll: true });\n } else if (this.state.horizontalScroll) {\n this.setState({ horizontalScroll: false });\n }\n };\n\n private handleResize = (event: UIEvent) => {\n LayoutEvents.emit();\n };\n\n private setHasHeader = (hasHeader = true) => {\n this.state.hasHeader !== hasHeader && this.setState({ hasHeader });\n };\n\n private setHasFooter = (hasFooter = true) => {\n this.state.hasFooter !== hasFooter && this.setState({ hasFooter });\n };\n\n private setHasPanel = (hasPanel = false) => {\n this.state.hasPanel !== hasPanel && this.setState({ hasPanel });\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["Modal.tsx"],"names":["mountedModalsCount","Modal","state","stackPosition","hasBackground","horizontalScroll","hasHeader","hasFooter","hasPanel","shards","theme","stackSubscription","containerNode","mouseDownTarget","mouseUpTarget","Set","addShard","shard","add","setState","Array","from","values","requestClose","props","disableClose","onClose","refContainer","center","handleStackChange","stack","indexOf","ModalStack","isBlocking","handleContainerMouseDown","event","target","handleContainerMouseUp","handleContainerClick","ignoreBackgroundClick","currentTarget","handleKeyDown","e","checkHorizontalScrollAppearance","hasScroll","containerClientWidth","clientWidth","containerScrollWidth","scrollWidth","handleResize","LayoutEvents","emit","setHasHeader","setHasFooter","setHasPanel","componentDidMount","window","addEventListener","componentWillUnmount","removeEventListener","remove","render","renderMain","modalContextProps","noClose","close","additionalPadding","style","containerStyle","width","styles","root","bg","container","centerContainer","alignTop","Boolean","disableFocusLock","closeWrapper","children","React","Component","__KONTUR_REACT_UI__","Header","ModalHeader","Body","ModalBody","Footer","ModalFooter","defaultProps","isIE11"],"mappings":"sbAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,kBAAkB,GAAG,CAAzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,G;AACaC,K;;;;;;;;;;;;AAYJC,IAAAA,K,GAAoB;AACzBC,MAAAA,aAAa,EAAE,CADU;AAEzBC,MAAAA,aAAa,EAAE,IAFU;AAGzBC,MAAAA,gBAAgB,EAAE,KAHO;AAIzBC,MAAAA,SAAS,EAAE,KAJc;AAKzBC,MAAAA,SAAS,EAAE,KALc;AAMzBC,MAAAA,QAAQ,EAAE,KANe;AAOzBC,MAAAA,MAAM,EAAE,EAPiB,E;;;AAUnBC,IAAAA,K;AACAC,IAAAA,iB,GAAmD,I;AACnDC,IAAAA,a,GAAuC,I;AACvCC,IAAAA,e,GAAsC,I;AACtCC,IAAAA,a,GAAoC,I;AACpCL,IAAAA,M,GAAS,IAAIM,GAAJ,E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HVC,IAAAA,Q,GAAW,UAACC,KAAD,EAA+C;AAC/D,YAAKR,MAAL,CAAYS,GAAZ,CAAgBD,KAAhB;AACA,YAAKE,QAAL,CAAc,EAACV,MAAM,YAAMW,KAAK,CAACC,IAAN,CAAW,MAAKZ,MAAL,CAAYa,MAAZ,EAAX,CAAN,CAAP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GAASC,wB,CALZvF,K,CAOGwF,Y,GAAe,EAC3B;AACAZ,EAAAA,gBAAgB,EAAEa,cAFS,E","sourcesContent":["import React from 'react';\nimport FocusLock from 'react-focus-lock';\n\nimport { isKeyEscape } from '../../lib/events/keyboard/identifiers';\nimport * as LayoutEvents from '../../lib/LayoutEvents';\nimport { RenderContainer } from '../../internal/RenderContainer';\nimport { ZIndex } from '../../internal/ZIndex';\nimport { stopPropagation } from '../../lib/events/stopPropagation';\nimport { HideBodyVerticalScroll } from '../../internal/HideBodyVerticalScroll';\nimport { ModalStack, ModalStackSubscription } from '../../lib/ModalStack';\nimport { ResizeDetector } from '../../internal/ResizeDetector';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { isIE11 } from '../../lib/client';\nimport { CommonWrapper, CommonProps } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\n\nimport { ModalContext, ModalContextProps } from './ModalContext';\nimport { ModalFooter } from './ModalFooter';\nimport { ModalHeader } from './ModalHeader';\nimport { ModalBody } from './ModalBody';\nimport { ModalClose } from './ModalClose';\nimport { styles } from './Modal.styles';\n\nlet mountedModalsCount = 0;\n\nexport interface ModalProps extends CommonProps {\n /**\n * Отключает событие onClose, также дизейблит кнопку закрытия модалки\n */\n disableClose?: boolean;\n\n /**\n * Выравнивание окна по верху страницы.\n */\n alignTop?: boolean;\n\n /**\n * Не закрывать окно при клике на фон.\n */\n ignoreBackgroundClick?: boolean;\n\n /**\n * Не показывать крестик для закрытия окна.\n */\n noClose?: boolean;\n width?: number | string;\n\n /**\n * Вызывается, когда пользователь запросил закрытие окна (нажал на фон, на\n * Escape или на крестик).\n */\n onClose?: () => void;\n\n /**\n * Не использовать фокус-лок внутри модалки.\n * По умолчанию true для IE11.\n */\n disableFocusLock?: boolean;\n}\n\nexport interface ModalState {\n stackPosition: number;\n hasBackground: boolean;\n horizontalScroll: boolean;\n hasHeader: boolean;\n hasFooter: boolean;\n hasPanel: boolean;\n shards: Array<React.RefObject<any> | HTMLElement>;\n}\n\n/**\n * Модальное окно\n *\n * Содержит в себе три компоненты: **Modal.Header**,\n * **Modal.Body** и **Modal.Footer**\n *\n * Для отображения серой плашки в футере в компонент\n * **Footer** необходимо передать пропс **panel**\n *\n * Для отключения прилипания шапки и футера\n * в соответствующий компонет нужно передать\n * проп **sticky** со значением **false**\n * (по-умолчанию прилипание включено)\n */\nexport class Modal extends React.Component<ModalProps, ModalState> {\n public static __KONTUR_REACT_UI__ = 'Modal';\n\n public static Header = ModalHeader;\n public static Body = ModalBody;\n public static Footer = ModalFooter;\n\n public static defaultProps = {\n // NOTE: в ie нормально не работает\n disableFocusLock: isIE11,\n };\n\n public state: ModalState = {\n stackPosition: 0,\n hasBackground: true,\n horizontalScroll: false,\n hasHeader: false,\n hasFooter: false,\n hasPanel: false,\n shards: [],\n };\n\n private theme!: Theme;\n private stackSubscription: ModalStackSubscription | null = null;\n private containerNode: HTMLDivElement | null = null;\n private mouseDownTarget: EventTarget | null = null;\n private mouseUpTarget: EventTarget | null = null;\n private shards = new Set<React.RefObject<any> | HTMLElement>();\n\n public componentDidMount() {\n this.stackSubscription = ModalStack.add(this, this.handleStackChange);\n\n if (mountedModalsCount === 0) {\n window.addEventListener('resize', this.checkHorizontalScrollAppearance);\n }\n\n mountedModalsCount++;\n window.addEventListener('keydown', this.handleKeyDown);\n this.checkHorizontalScrollAppearance();\n\n if (this.containerNode) {\n this.containerNode.addEventListener('scroll', LayoutEvents.emit);\n }\n }\n\n public componentWillUnmount() {\n if (--mountedModalsCount === 0) {\n window.removeEventListener('resize', this.checkHorizontalScrollAppearance);\n LayoutEvents.emit();\n }\n\n window.removeEventListener('keydown', this.handleKeyDown);\n if (this.stackSubscription != null) {\n this.stackSubscription.remove();\n }\n ModalStack.remove(this);\n\n if (this.containerNode) {\n this.containerNode.removeEventListener('scroll', LayoutEvents.emit);\n }\n }\n\n public render(): JSX.Element {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const { hasHeader, hasFooter, hasPanel } = this.state;\n\n const modalContextProps: ModalContextProps = {\n hasHeader,\n horizontalScroll: this.state.horizontalScroll,\n setHasHeader: this.setHasHeader,\n setHasFooter: this.setHasFooter,\n setHasPanel: this.setHasPanel,\n };\n if (hasHeader && !this.props.noClose) {\n modalContextProps.close = {\n disableClose: this.props.disableClose,\n requestClose: this.requestClose,\n };\n }\n if (!hasFooter) {\n modalContextProps.additionalPadding = true;\n }\n if (hasFooter && hasPanel) {\n modalContextProps.additionalPadding = true;\n }\n\n const style: { width?: number | string } = {};\n const containerStyle: { width?: number | string } = {};\n\n if (this.props.width) {\n style.width = this.props.width;\n } else {\n containerStyle.width = 'auto';\n }\n\n return (\n <RenderContainer>\n <CommonWrapper {...this.props}>\n <ZIndex priority={'Modal'} className={styles.root()}>\n <HideBodyVerticalScroll />\n {this.state.hasBackground && <div className={styles.bg(this.theme)} />}\n <div\n ref={this.refContainer}\n className={styles.container()}\n onMouseDown={this.handleContainerMouseDown}\n onMouseUp={this.handleContainerMouseUp}\n onClick={this.handleContainerClick}\n data-tid=\"modal-container\"\n >\n <div\n className={cx({\n [styles.centerContainer(this.theme)]: true,\n [styles.alignTop()]: Boolean(this.props.alignTop),\n })}\n style={containerStyle}\n data-tid=\"modal-content\"\n >\n <div className={styles.window(this.theme)} style={style}>\n <ResizeDetector onResize={this.handleResize}>\n <FocusLock shards={this.state.shards} disabled={this.props.disableFocusLock} autoFocus={false}>\n {!hasHeader && !this.props.noClose ? (\n <ZIndex priority={'ModalCross'} className={styles.closeWrapper(this.theme)}>\n <ModalClose requestClose={this.requestClose} disableClose={this.props.disableClose} />\n </ZIndex>\n ) : null}\n <ModalContext.Provider value={modalContextProps}>{this.props.children}</ModalContext.Provider>\n </FocusLock>\n </ResizeDetector>\n </div>\n </div>\n </div>\n </ZIndex>\n </CommonWrapper>\n </RenderContainer>\n );\n }\n\n /**\n * Добавить элемент, который будет учитывать FocusLock\n *\n * @param shard\n */\n public addShard = (shard: React.RefObject<any> | HTMLElement) => {\n this.shards.add(shard);\n this.setState({shards: [...Array.from(this.shards.values())]});\n };\n\n private requestClose = () => {\n if (this.props.disableClose) {\n return;\n }\n if (this.props.onClose) {\n this.props.onClose();\n }\n };\n\n private refContainer = (center: HTMLDivElement | null) => {\n this.containerNode = center;\n };\n\n private handleStackChange = (stack: ReadonlyArray<React.Component>) => {\n this.setState({ stackPosition: stack.indexOf(this), hasBackground: ModalStack.isBlocking(this) });\n };\n\n private handleContainerMouseDown = (event: React.MouseEvent) => {\n this.mouseDownTarget = event.target;\n };\n\n private handleContainerMouseUp = (event: React.MouseEvent) => {\n this.mouseUpTarget = event.target;\n };\n\n private handleContainerClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!this.props.ignoreBackgroundClick) {\n const { target, currentTarget } = event;\n if (target === currentTarget && this.mouseDownTarget === currentTarget && this.mouseUpTarget === currentTarget) {\n this.requestClose();\n }\n }\n };\n\n private handleKeyDown = (e: KeyboardEvent) => {\n if (this.state.stackPosition !== 0) {\n return;\n }\n if (isKeyEscape(e)) {\n stopPropagation(e);\n this.requestClose();\n }\n };\n\n private checkHorizontalScrollAppearance = () => {\n let hasScroll = false;\n\n if (this.containerNode) {\n const containerClientWidth = this.containerNode.clientWidth;\n const containerScrollWidth = this.containerNode.scrollWidth;\n hasScroll = containerClientWidth < containerScrollWidth;\n }\n if (hasScroll && !this.state.horizontalScroll) {\n this.setState({ horizontalScroll: true });\n } else if (this.state.horizontalScroll) {\n this.setState({ horizontalScroll: false });\n }\n };\n\n private handleResize = (event: UIEvent) => {\n LayoutEvents.emit();\n };\n\n private setHasHeader = (hasHeader = true) => {\n this.state.hasHeader !== hasHeader && this.setState({ hasHeader });\n };\n\n private setHasFooter = (hasFooter = true) => {\n this.state.hasFooter !== hasFooter && this.setState({ hasFooter });\n };\n\n private setHasPanel = (hasPanel = false) => {\n this.state.hasPanel !== hasPanel && this.setState({ hasPanel });\n };\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
```jsx harmony
|
|
2
|
-
<PasswordInput />
|
|
3
|
-
```
|
|
4
|
-
|
|
5
|
-
Пример с отслеживанием нажатия CapsLock:
|
|
6
|
-
|
|
7
|
-
```jsx harmony
|
|
8
|
-
<PasswordInput detectCapsLock />
|
|
9
|
-
```
|
|
1
|
+
```jsx harmony
|
|
2
|
+
<PasswordInput />
|
|
3
|
+
```
|
|
4
|
+
|
|
5
|
+
Пример с отслеживанием нажатия CapsLock:
|
|
6
|
+
|
|
7
|
+
```jsx harmony
|
|
8
|
+
<PasswordInput detectCapsLock />
|
|
9
|
+
```
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
```jsx harmony
|
|
2
|
-
import { Gapped, Radio } from '@skbkontur/react-ui';
|
|
3
|
-
|
|
4
|
-
let items = ['One', 'Two', 'Three', 'Four'];
|
|
5
|
-
|
|
6
|
-
let simpleRadioGroup = (
|
|
7
|
-
<div>
|
|
8
|
-
<h2>Numbers</h2>
|
|
9
|
-
<RadioGroup name="number-simple" items={items} defaultValue="One" />
|
|
10
|
-
</div>
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
let complexRadioGroup = (
|
|
14
|
-
<div>
|
|
15
|
-
<h2>Numbers</h2>
|
|
16
|
-
<RadioGroup name="number-complex" defaultValue="3">
|
|
17
|
-
<Gapped gap={40}>
|
|
18
|
-
<Gapped vertical gap={0}>
|
|
19
|
-
<b>Odd</b>
|
|
20
|
-
<Radio value="1">One</Radio>
|
|
21
|
-
<Radio value="3">Three</Radio>
|
|
22
|
-
<Radio value="5" disabled>
|
|
23
|
-
Five
|
|
24
|
-
</Radio>
|
|
25
|
-
<Radio value="7">Seven</Radio>
|
|
26
|
-
</Gapped>
|
|
27
|
-
<Gapped vertical gap={0}>
|
|
28
|
-
<b>Even</b>
|
|
29
|
-
<Radio value="2">Two</Radio>
|
|
30
|
-
<Radio value="4">Four</Radio>
|
|
31
|
-
<Radio value="6">Six</Radio>
|
|
32
|
-
<Radio value="8">Eight</Radio>
|
|
33
|
-
</Gapped>
|
|
34
|
-
</Gapped>
|
|
35
|
-
</RadioGroup>
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
<div>
|
|
40
|
-
{simpleRadioGroup}
|
|
41
|
-
{complexRadioGroup}
|
|
42
|
-
</div>;
|
|
43
|
-
```
|
|
1
|
+
```jsx harmony
|
|
2
|
+
import { Gapped, Radio } from '@skbkontur/react-ui';
|
|
3
|
+
|
|
4
|
+
let items = ['One', 'Two', 'Three', 'Four'];
|
|
5
|
+
|
|
6
|
+
let simpleRadioGroup = (
|
|
7
|
+
<div>
|
|
8
|
+
<h2>Numbers</h2>
|
|
9
|
+
<RadioGroup name="number-simple" items={items} defaultValue="One" />
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
let complexRadioGroup = (
|
|
14
|
+
<div>
|
|
15
|
+
<h2>Numbers</h2>
|
|
16
|
+
<RadioGroup name="number-complex" defaultValue="3">
|
|
17
|
+
<Gapped gap={40}>
|
|
18
|
+
<Gapped vertical gap={0}>
|
|
19
|
+
<b>Odd</b>
|
|
20
|
+
<Radio value="1">One</Radio>
|
|
21
|
+
<Radio value="3">Three</Radio>
|
|
22
|
+
<Radio value="5" disabled>
|
|
23
|
+
Five
|
|
24
|
+
</Radio>
|
|
25
|
+
<Radio value="7">Seven</Radio>
|
|
26
|
+
</Gapped>
|
|
27
|
+
<Gapped vertical gap={0}>
|
|
28
|
+
<b>Even</b>
|
|
29
|
+
<Radio value="2">Two</Radio>
|
|
30
|
+
<Radio value="4">Four</Radio>
|
|
31
|
+
<Radio value="6">Six</Radio>
|
|
32
|
+
<Radio value="8">Eight</Radio>
|
|
33
|
+
</Gapped>
|
|
34
|
+
</Gapped>
|
|
35
|
+
</RadioGroup>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
<div>
|
|
40
|
+
{simpleRadioGroup}
|
|
41
|
+
{complexRadioGroup}
|
|
42
|
+
</div>;
|
|
43
|
+
```
|
|
@@ -235,8 +235,10 @@ ScrollBar = /*#__PURE__*/function (_React$Component) {(0, _inheritsLoose2.defaul
|
|
|
235
235
|
if (!_this.inner || _this.inner[pos] === 0) {
|
|
236
236
|
return 'begin';
|
|
237
237
|
}
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
// Zoom in Chrome causes problems
|
|
239
|
+
// https://github.com/skbkontur/retail-ui/pull/2705#issue-806286945
|
|
240
|
+
var maxScrollPos = _this.inner[size] - _this.inner[clientSize];
|
|
241
|
+
if (Math.abs(maxScrollPos - _this.inner[pos]) <= 1) {
|
|
240
242
|
return 'end';
|
|
241
243
|
}
|
|
242
244
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ScrollBar.tsx"],"names":["ScrollBar","inner","theme","node","state","defaultScrollbarState","renderMain","props","active","scrollSizeParametersNames","axis","customScrollPos","customScrollSize","classNames","className","styles","scrollBar","scrollBarStyles","scrollBarInvert","invert","inlineStyles","pos","size","refScroll","handleScrollMouseDown","reflow","scrollSize","scrollPos","scrollActive","scrollState","getImmediateScrollState","onScrollStateChange","setState","setInnerElement","element","handleScrollWheel","event","addEventListener","passive","removeEventListener","offset","coord","initialCoord","target","window","document","initialScrollPos","mouseMove","mouseMoveEvent","ratio","delta","preventDefault","Object","prototype","hasOwnProperty","call","returnValue","mouseUp","scrolling","WheelEvent","shiftKey","offsetHeight","deltaY","clientSize","componentDidMount","componentDidUpdate","render","setHover","hover","scrollBarX","globalClasses","scrollbarX","scrollBarXHover","scrollBarY","scrollbarY","scrollBarYHover","React","Component"],"mappings":"iaAAA;;;;AAIA;AACA;;AAEA;AACA;AACA,6D;;;;;;;;;;;;;;;;;;;;;AAqBaA,S;AACHC,IAAAA,K;AACAC,IAAAA,K;;AAEDC,IAAAA,I;AACAC,IAAAA,K;AAC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O,iBAAGK,yBAAOsD,UAAP,CAAkB,KAAKnE,KAAvB,CAAH,EAAkCoE,gCAAcC,UAAhD,mBACJxD,yBAAOyD,eAAP,CAAuB,KAAKtE,KAA5B,CADI,IACiCE,KAAK,CAACgE,KAAN,IAAehE,KAAK,CAACsD,SADtD,QAAP,CAGD,CAED,OAAO,iBAAG3C,yBAAO0D,UAAP,CAAkB,KAAKvE,KAAvB,CAAH,EAAkCoE,gCAAcI,UAAhD,mBACJ3D,yBAAO4D,eAAP,CAAuB,KAAKzE,KAA5B,CADI,IACiCE,KAAK,CAACgE,KAAN,IAAehE,KAAK,CAACsD,SADtD,QAAP,CAGD,C,wBApH4BkB,eAAMC,S","sourcesContent":["import React from 'react';\n\nimport { Nullable } from '../../typings/utility-types';\nimport { Theme } from '../../lib/theming/Theme';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { cx } from '../../lib/theming/Emotion';\n\nimport { defaultScrollbarState, scrollSizeParametersNames } from './ScrollContainer.constants';\nimport { styles, globalClasses } from './ScrollContainer.styles';\nimport { getScrollSizeParams } from './ScrollContainer.helpers';\n\nexport type ScrollAxis = 'x' | 'y';\nexport type ScrollBarScrollState = 'begin' | 'middle' | 'end';\n\nexport interface ScrollBarState {\n active: boolean;\n hover: boolean;\n scrolling: boolean;\n size: number;\n pos: number;\n scrollState: ScrollBarScrollState;\n}\n\nexport interface ScrollBarProps {\n invert: boolean;\n axis: ScrollAxis;\n className?: string;\n onScrollStateChange?: (state: ScrollBarScrollState, axis: ScrollAxis) => void;\n}\n\nexport class ScrollBar extends React.Component<ScrollBarProps, ScrollBarState> {\n private inner: Nullable<HTMLElement>;\n private theme!: Theme;\n\n public node: Nullable<HTMLElement>;\n public state: ScrollBarState = {\n ...defaultScrollbarState,\n };\n\n public componentDidMount() {\n this.reflow();\n }\n\n public componentDidUpdate() {\n this.reflow();\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain = () => {\n const state = this.state;\n const props = this.props;\n\n if (!state.active) {\n return null;\n }\n\n const { customScrollPos, customScrollSize } = scrollSizeParametersNames[this.props.axis];\n\n const classNames = cx(props.className, styles.scrollBar(this.theme), this.scrollBarStyles, {\n [styles.scrollBarInvert(this.theme)]: props.invert,\n });\n\n const inlineStyles: React.CSSProperties = {\n [customScrollPos]: state.pos,\n [customScrollSize]: state.size,\n };\n\n return (\n <div\n ref={this.refScroll}\n style={inlineStyles}\n className={classNames}\n onMouseDown={this.handleScrollMouseDown}\n data-tid={`ScrollContainer__ScrollBar-${props.axis}`}\n />\n );\n };\n\n public reflow = () => {\n if (!this.inner) {\n return;\n }\n\n const props = this.props;\n const state = this.state;\n\n const { scrollSize, scrollPos, scrollActive } = getScrollSizeParams(this.inner, props.axis);\n\n if (!scrollActive && !state.active) {\n return;\n }\n\n if (state.active !== scrollActive || state.size !== scrollSize || state.pos !== scrollPos) {\n const scrollState = this.getImmediateScrollState();\n\n if (scrollState !== state.scrollState) {\n this.props.onScrollStateChange?.(scrollState, props.axis);\n }\n\n this.setState({\n ...this.state,\n active: scrollActive,\n size: scrollSize,\n pos: scrollPos,\n scrollState,\n });\n }\n };\n\n public setInnerElement = (inner: Nullable<HTMLElement>) => {\n this.inner = inner;\n this.reflow();\n };\n\n public setHover(hover: boolean) {\n if (this.state.active && this.state.hover !== hover) {\n this.setState({ ...this.state, hover });\n }\n }\n\n public get scrollBarState() {\n return this.state.scrollState;\n }\n\n private get scrollBarStyles() {\n const state = this.state;\n\n if (this.props.axis === 'x') {\n return cx(styles.scrollBarX(this.theme), globalClasses.scrollbarX, {\n [styles.scrollBarXHover(this.theme)]: state.hover || state.scrolling,\n });\n }\n\n return cx(styles.scrollBarY(this.theme), globalClasses.scrollbarY, {\n [styles.scrollBarYHover(this.theme)]: state.hover || state.scrolling,\n });\n }\n\n private refScroll = (element: HTMLElement | null) => {\n const handleScrollWheel = (event: Event) => this.handleScrollWheel(event, this.props.axis);\n\n if (!this.node && element) {\n element.addEventListener('wheel', handleScrollWheel, { passive: false });\n }\n if (this.node && !element) {\n this.node.removeEventListener('wheel', handleScrollWheel);\n }\n this.node = element;\n };\n\n private handleScrollMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!this.inner) {\n return;\n }\n\n const { offset, size, pos, coord } = scrollSizeParametersNames[this.props.axis];\n\n const initialCoord = event[coord];\n const target: Document = window.document;\n const initialScrollPos = this.inner[pos];\n const state = this.state;\n\n const mouseMove = (mouseMoveEvent: MouseEvent) => {\n if (!this.inner) {\n return;\n }\n\n const ratio = (this.inner[size] - this.inner[offset]) / (this.inner[offset] - state.size);\n const delta = (mouseMoveEvent[coord] - initialCoord) * ratio;\n\n this.inner[pos] = initialScrollPos + delta;\n\n if (mouseMoveEvent.preventDefault) {\n mouseMoveEvent.preventDefault();\n }\n\n if (Object.prototype.hasOwnProperty.call(mouseMoveEvent, 'returnValue')) {\n (\n mouseMoveEvent as MouseEvent & {\n returnValue: boolean;\n }\n ).returnValue = false;\n }\n };\n\n const mouseUp = () => {\n target.removeEventListener('mousemove', mouseMove);\n target.removeEventListener('mouseup', mouseUp);\n this.setState({ ...this.state, scrolling: false });\n };\n\n target.addEventListener('mousemove', mouseMove);\n target.addEventListener('mouseup', mouseUp);\n this.setState({ ...this.state, scrolling: true });\n\n event.preventDefault();\n };\n\n private handleScrollWheel = (event: Event, axis: ScrollAxis) => {\n if (!this.inner || !(event instanceof WheelEvent) || (axis === 'x' && !event.shiftKey)) {\n return;\n }\n\n const { offset, size, pos } = scrollSizeParametersNames[axis];\n\n const scrollSize = this.inner[size];\n const scrollPos = this.inner[pos];\n const offsetHeight = this.inner[offset];\n\n if (event.deltaY > 0 && scrollSize <= scrollPos + offsetHeight) {\n return;\n }\n if (event.deltaY < 0 && scrollPos <= 0) {\n return;\n }\n\n this.inner[pos] += event.deltaY;\n\n event.preventDefault();\n };\n\n private getImmediateScrollState = (): ScrollBarScrollState => {\n const { pos, size, clientSize } = scrollSizeParametersNames[this.props.axis];\n\n if (!this.inner || this.inner[pos] === 0) {\n return 'begin';\n }\n\n if (this.inner[pos] === this.inner[size] - this.inner[clientSize]) {\n return 'end';\n }\n\n return 'middle';\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["ScrollBar.tsx"],"names":["ScrollBar","inner","theme","node","state","defaultScrollbarState","renderMain","props","active","scrollSizeParametersNames","axis","customScrollPos","customScrollSize","classNames","className","styles","scrollBar","scrollBarStyles","scrollBarInvert","invert","inlineStyles","pos","size","refScroll","handleScrollMouseDown","reflow","scrollSize","scrollPos","scrollActive","scrollState","getImmediateScrollState","onScrollStateChange","setState","setInnerElement","element","handleScrollWheel","event","addEventListener","passive","removeEventListener","offset","coord","initialCoord","target","window","document","initialScrollPos","mouseMove","mouseMoveEvent","ratio","delta","preventDefault","Object","prototype","hasOwnProperty","call","returnValue","mouseUp","scrolling","WheelEvent","shiftKey","offsetHeight","deltaY","clientSize","maxScrollPos","Math","abs","componentDidMount","componentDidUpdate","render","setHover","hover","scrollBarX","globalClasses","scrollbarX","scrollBarXHover","scrollBarY","scrollbarY","scrollBarYHover","React","Component"],"mappings":"iaAAA;;;;AAIA;AACA;;AAEA;AACA;AACA,6D;;;;;;;;;;;;;;;;;;;;;AAqBaA,S;AACHC,IAAAA,K;AACAC,IAAAA,K;;AAEDC,IAAAA,I;AACAC,IAAAA,K;AACFC,0C;;;;;;;;;;;;;;;;;;;;;;AAsBGC,IAAAA,U,GAAa,YAAM;AACzB,UAAMF,KAAK,GAAG,MAAKA,KAAnB;AACA,UAAMG,KAAK,GAAG,MAAKA,KAAnB;;AAEA,UAAI,CAACH,KAAK,CAACI,MAAX,EAAmB;AACjB,eAAO,IAAP;AACD,OANwB;;AAQqBC,iDAA0B,MAAKF,KAAL,CAAWG,IAArC,CARrB,CAQjBC,eARiB,yBAQjBA,eARiB,CAQAC,gBARA,yBAQAA,gBARA;;AAUzB,UAAMC,UAAU,GAAG,iBAAGN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E,gCAAcI,UAAhD,mBACJ9D,yBAAO+D,eAAP,CAAuB,KAAK5E,KAA5B,CADI,IACiCE,KAAK,CAACmE,KAAN,IAAenE,KAAK,CAACsD,SADtD,QAAP,CAGD,C,wBApH4BqB,eAAMC,S","sourcesContent":["import React from 'react';\n\nimport { Nullable } from '../../typings/utility-types';\nimport { Theme } from '../../lib/theming/Theme';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { cx } from '../../lib/theming/Emotion';\n\nimport { defaultScrollbarState, scrollSizeParametersNames } from './ScrollContainer.constants';\nimport { styles, globalClasses } from './ScrollContainer.styles';\nimport { getScrollSizeParams } from './ScrollContainer.helpers';\n\nexport type ScrollAxis = 'x' | 'y';\nexport type ScrollBarScrollState = 'begin' | 'middle' | 'end';\n\nexport interface ScrollBarState {\n active: boolean;\n hover: boolean;\n scrolling: boolean;\n size: number;\n pos: number;\n scrollState: ScrollBarScrollState;\n}\n\nexport interface ScrollBarProps {\n invert: boolean;\n axis: ScrollAxis;\n className?: string;\n onScrollStateChange?: (state: ScrollBarScrollState, axis: ScrollAxis) => void;\n}\n\nexport class ScrollBar extends React.Component<ScrollBarProps, ScrollBarState> {\n private inner: Nullable<HTMLElement>;\n private theme!: Theme;\n\n public node: Nullable<HTMLElement>;\n public state: ScrollBarState = {\n ...defaultScrollbarState,\n };\n\n public componentDidMount() {\n this.reflow();\n }\n\n public componentDidUpdate() {\n this.reflow();\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain = () => {\n const state = this.state;\n const props = this.props;\n\n if (!state.active) {\n return null;\n }\n\n const { customScrollPos, customScrollSize } = scrollSizeParametersNames[this.props.axis];\n\n const classNames = cx(props.className, styles.scrollBar(this.theme), this.scrollBarStyles, {\n [styles.scrollBarInvert(this.theme)]: props.invert,\n });\n\n const inlineStyles: React.CSSProperties = {\n [customScrollPos]: state.pos,\n [customScrollSize]: state.size,\n };\n\n return (\n <div\n ref={this.refScroll}\n style={inlineStyles}\n className={classNames}\n onMouseDown={this.handleScrollMouseDown}\n data-tid={`ScrollContainer__ScrollBar-${props.axis}`}\n />\n );\n };\n\n public reflow = () => {\n if (!this.inner) {\n return;\n }\n\n const props = this.props;\n const state = this.state;\n\n const { scrollSize, scrollPos, scrollActive } = getScrollSizeParams(this.inner, props.axis);\n\n if (!scrollActive && !state.active) {\n return;\n }\n\n if (state.active !== scrollActive || state.size !== scrollSize || state.pos !== scrollPos) {\n const scrollState = this.getImmediateScrollState();\n\n if (scrollState !== state.scrollState) {\n this.props.onScrollStateChange?.(scrollState, props.axis);\n }\n\n this.setState({\n ...this.state,\n active: scrollActive,\n size: scrollSize,\n pos: scrollPos,\n scrollState,\n });\n }\n };\n\n public setInnerElement = (inner: Nullable<HTMLElement>) => {\n this.inner = inner;\n this.reflow();\n };\n\n public setHover(hover: boolean) {\n if (this.state.active && this.state.hover !== hover) {\n this.setState({ ...this.state, hover });\n }\n }\n\n public get scrollBarState() {\n return this.state.scrollState;\n }\n\n private get scrollBarStyles() {\n const state = this.state;\n\n if (this.props.axis === 'x') {\n return cx(styles.scrollBarX(this.theme), globalClasses.scrollbarX, {\n [styles.scrollBarXHover(this.theme)]: state.hover || state.scrolling,\n });\n }\n\n return cx(styles.scrollBarY(this.theme), globalClasses.scrollbarY, {\n [styles.scrollBarYHover(this.theme)]: state.hover || state.scrolling,\n });\n }\n\n private refScroll = (element: HTMLElement | null) => {\n const handleScrollWheel = (event: Event) => this.handleScrollWheel(event, this.props.axis);\n\n if (!this.node && element) {\n element.addEventListener('wheel', handleScrollWheel, { passive: false });\n }\n if (this.node && !element) {\n this.node.removeEventListener('wheel', handleScrollWheel);\n }\n this.node = element;\n };\n\n private handleScrollMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!this.inner) {\n return;\n }\n\n const { offset, size, pos, coord } = scrollSizeParametersNames[this.props.axis];\n\n const initialCoord = event[coord];\n const target: Document = window.document;\n const initialScrollPos = this.inner[pos];\n const state = this.state;\n\n const mouseMove = (mouseMoveEvent: MouseEvent) => {\n if (!this.inner) {\n return;\n }\n\n const ratio = (this.inner[size] - this.inner[offset]) / (this.inner[offset] - state.size);\n const delta = (mouseMoveEvent[coord] - initialCoord) * ratio;\n\n this.inner[pos] = initialScrollPos + delta;\n\n if (mouseMoveEvent.preventDefault) {\n mouseMoveEvent.preventDefault();\n }\n\n if (Object.prototype.hasOwnProperty.call(mouseMoveEvent, 'returnValue')) {\n (\n mouseMoveEvent as MouseEvent & {\n returnValue: boolean;\n }\n ).returnValue = false;\n }\n };\n\n const mouseUp = () => {\n target.removeEventListener('mousemove', mouseMove);\n target.removeEventListener('mouseup', mouseUp);\n this.setState({ ...this.state, scrolling: false });\n };\n\n target.addEventListener('mousemove', mouseMove);\n target.addEventListener('mouseup', mouseUp);\n this.setState({ ...this.state, scrolling: true });\n\n event.preventDefault();\n };\n\n private handleScrollWheel = (event: Event, axis: ScrollAxis) => {\n if (!this.inner || !(event instanceof WheelEvent) || (axis === 'x' && !event.shiftKey)) {\n return;\n }\n\n const { offset, size, pos } = scrollSizeParametersNames[axis];\n\n const scrollSize = this.inner[size];\n const scrollPos = this.inner[pos];\n const offsetHeight = this.inner[offset];\n\n if (event.deltaY > 0 && scrollSize <= scrollPos + offsetHeight) {\n return;\n }\n if (event.deltaY < 0 && scrollPos <= 0) {\n return;\n }\n\n this.inner[pos] += event.deltaY;\n\n event.preventDefault();\n };\n\n private getImmediateScrollState = (): ScrollBarScrollState => {\n const { pos, size, clientSize } = scrollSizeParametersNames[this.props.axis];\n\n if (!this.inner || this.inner[pos] === 0) {\n return 'begin';\n }\n // Zoom in Chrome causes problems\n // https://github.com/skbkontur/retail-ui/pull/2705#issue-806286945\n const maxScrollPos = this.inner[size] - this.inner[clientSize];\n if (Math.abs(maxScrollPos - this.inner[pos]) <= 1) {\n return 'end';\n }\n\n return 'middle';\n };\n}\n"]}
|
|
@@ -5,6 +5,7 @@ var LayoutEvents = _interopRequireWildcard(require("../../lib/LayoutEvents"));
|
|
|
5
5
|
var _CommonWrapper = require("../../internal/CommonWrapper");
|
|
6
6
|
|
|
7
7
|
var _Emotion = require("../../lib/theming/Emotion");
|
|
8
|
+
var _client = require("../../lib/client");
|
|
8
9
|
var _rootNode = require("../../lib/rootNode");
|
|
9
10
|
|
|
10
11
|
var _ScrollContainer = require("./ScrollContainer.styles");
|
|
@@ -104,7 +105,7 @@ ScrollContainer = (0, _rootNode.rootNode)(_class = (_temp = _class2 = /*#__PURE_
|
|
|
104
105
|
_react.default.createElement("div", {
|
|
105
106
|
style: innerStyle,
|
|
106
107
|
ref: _this.refInner,
|
|
107
|
-
className: (0, _Emotion.cx)(_ScrollContainer.styles.inner(), _ScrollContainer.globalClasses.inner),
|
|
108
|
+
className: (0, _Emotion.cx)(_ScrollContainer.styles.inner(), _ScrollContainer.globalClasses.inner, _client.isIE11 && _ScrollContainer.styles.innerIE11()),
|
|
108
109
|
"data-tid": "ScrollContainer__inner",
|
|
109
110
|
onScroll: _this.handleNativeScroll },
|
|
110
111
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ScrollContainer.tsx"],"names":["ScrollContainer","rootNode","scrollX","scrollY","inner","setRootNode","render","props","innerStyle","scrollBehavior","scrollBehaviour","maxHeight","maxWidth","scrollbarY","renderScrollbar","scrollbarX","styles","root","handleMouseMove","handleMouseLeave","refInner","globalClasses","handleNativeScroll","children","axis","refScrollBar","refScrollBarX","refScrollBarY","invert","handleScrollStateChange","scrollState","scrollXState","onScrollStateChangeX","scrollYState","onScrollStateChange","onScrollStateChangeY","scrollbar","element","preventWindowScroll","addEventListener","handleInnerScrollWheel","passive","removeEventListener","event","reflow","onScroll","preventDefault","LayoutEvents","emit","WheelEvent","shiftKey","hasScrollBar","scrollSizeParametersNames","pos","size","offset","deltaY","right","currentTarget","getBoundingClientRect","pageX","bottom","pageY","setHover","componentDidMount","setInnerElement","componentDidUpdate","prevProps","scrollTo","scrollLeft","offsetLeft","scrollTop","scrollToTop","scrollToBottom","scrollHeight","offsetHeight","scrollToLeft","scrollToRight","scrollWidth","offsetWidth","React","Component","__KONTUR_REACT_UI__","propTypes","PropTypes","bool","oneOfType","string","number","oneOf","func","defaultProps"],"mappings":"oaAAA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;;;AAKA,wC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BaA,e,OADZC,kB;;;;;;;;;;;;;;;;;;AAmBSC,IAAAA,O;AACAC,IAAAA,O;AACAC,IAAAA,K;AACAC,IAAAA,W;;;;;;;;;;;;;;;;;;AAkBDC,IAAAA,M,GAAS,YAAM;AACpB,UAAMC,KAAK,GAAG,MAAKA,KAAnB;;AAEA,UAAMC,UAA+B,GAAG;AACtCC,QAAAA,cAAc,EAAEF,KAAK,CAACG,eADgB;AAEtCC,QAAAA,SAAS,EAAEJ,KAAK,CAACI,SAFqB;AAGtCC,QAAAA,QAAQ,EAAEL,KAAK,CAACK,QAHsB,EAAxC;;;AAMA,UAAMC,UAAU,GAAG,MAAKC,eAAL,CAAqB,GAArB,CAAnB;AACA,UAAMC,UAAU,GAAG,MAAKD,eAAL,CAAqB,GAArB,CAAnB;;AAEA;AACE,qCAAC,4BAAD,2BAAe,WAAW,EAAE,MAAKT,WAAjC,IAAkD,MAAKE,KAAvD;AACE,8CAAK,SAAS,EAAES,wBAAOC,IAAP,EAAhB,EAA+B,WAAW,EAAE,MAAKC,eAAjD,EAAkE,YAAY,EAAE,MAAKC,gBAArF;AACGN,QAAAA,UADH;AAEGE,QAAAA,UAFH;AAGE;AACE,UAAA,KAAK,EAAEP,UADT;AAEE,UAAA,GAAG,EAAE,MAAKY,QAFZ;AAGE,UAAA,SAAS,EAAE,iBAAGJ,wBAAOZ,KAAP,EAAH,EAAmBiB,+BAAcjB,KAAjC,CAHb;AAIE,sBAAS,wBAJX;AAKE,UAAA,QAAQ,EAAE,MAAKkB,kB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,EAAuC,CACrC,IAAI,CAAC,KAAKpB,KAAV,EAAiB,CACf,OAAO,KAAP,CACD,CAED,OAAOoB,IAAI,KAAK,GAAT,GACH,KAAKpB,KAAL,CAAW2E,WAAX,GAAyB,KAAK3E,KAAL,CAAW0E,WADjC,GAEH,KAAK1E,KAAL,CAAWuE,YAAX,GAA0B,KAAKvE,KAAL,CAAWsE,YAFzC,CAGD,C,0BApIkCM,eAAMC,S,WAC3BC,mB,GAAsB,iB,UAEtBC,S,GAAY,EACxBvD,MAAM,EAAEwD,mBAAUC,IADM,EAExBzE,QAAQ,EAAEwE,mBAAUE,SAAV,CAAoB,CAACF,mBAAUG,MAAX,EAAmBH,mBAAUI,MAA7B,CAApB,CAFc,EAGxB7E,SAAS,EAAEyE,mBAAUE,SAAV,CAAoB,CAACF,mBAAUG,MAAX,EAAmBH,mBAAUI,MAA7B,CAApB,CAHa,EAIxB9E,eAAe,EAAE0E,mBAAUK,KAAV,CAAgB,CAAC,MAAD,EAAS,QAAT,CAAhB,CAJO,EAKxBnD,mBAAmB,EAAE8C,mBAAUC,IALP,EAMxBnD,mBAAmB,EAAEkD,mBAAUM,IANP,E,UASZC,Y,GAAe,EAC3B/D,MAAM,EAAE,KADmB,EAE3BlB,eAAe,EAAE,MAFU,EAG3B4B,mBAAmB,EAAE,KAHM,E","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport * as LayoutEvents from '../../lib/LayoutEvents';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { Nullable } from '../../typings/utility-types';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\n\nimport { styles, globalClasses } from './ScrollContainer.styles';\nimport { scrollSizeParametersNames } from './ScrollContainer.constants';\nimport {\n getScrollYOffset,\n convertScrollbarXScrollState,\n convertScrollbarYScrollState,\n} from './ScrollContainer.helpers';\nimport { ScrollAxis, ScrollBar, ScrollBarScrollState } from './ScrollBar';\n\nexport type ScrollContainerScrollStateX = 'left' | 'scroll' | 'right';\nexport type ScrollContainerScrollStateY = 'top' | 'scroll' | 'bottom';\nexport type ScrollContainerScrollState = ScrollContainerScrollStateY; // deprecated\nexport type ScrollBehaviour = 'auto' | 'smooth';\n\nexport interface ScrollContainerProps extends CommonProps {\n /**\n * Инвертировать цвет скроллбара\n * @default false\n */\n invert: boolean;\n maxHeight?: React.CSSProperties['maxHeight'];\n maxWidth?: React.CSSProperties['maxWidth'];\n /**\n * @default false\n */\n preventWindowScroll: boolean;\n /**\n * Поведение скролла (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior)\n * @default 'auto'\n */\n scrollBehaviour?: ScrollBehaviour;\n onScrollStateChangeX?: (scrollState: ScrollContainerScrollStateX) => void;\n onScrollStateChangeY?: (scrollState: ScrollContainerScrollStateY) => void;\n onScrollStateChange?: (scrollYState: ScrollContainerScrollState) => void; // deprecated\n onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;\n}\n\n@rootNode\nexport class ScrollContainer extends React.Component<ScrollContainerProps> {\n public static __KONTUR_REACT_UI__ = 'ScrollContainer';\n\n public static propTypes = {\n invert: PropTypes.bool,\n maxWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n maxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n scrollBehaviour: PropTypes.oneOf(['auto', 'smooth']),\n preventWindowScroll: PropTypes.bool,\n onScrollStateChange: PropTypes.func,\n };\n\n public static defaultProps = {\n invert: false,\n scrollBehaviour: 'auto',\n preventWindowScroll: false,\n };\n\n private scrollX: Nullable<ScrollBar>;\n private scrollY: Nullable<ScrollBar>;\n private inner: Nullable<HTMLElement>;\n private setRootNode!: TSetRootNode;\n\n public componentDidMount() {\n this.scrollX?.setInnerElement(this.inner);\n this.scrollY?.setInnerElement(this.inner);\n }\n\n public componentDidUpdate(prevProps: ScrollContainerProps) {\n if (this.inner) {\n if (prevProps.preventWindowScroll && !this.props.preventWindowScroll) {\n this.inner.removeEventListener('wheel', this.handleInnerScrollWheel);\n }\n if (!prevProps.preventWindowScroll && this.props.preventWindowScroll) {\n this.inner.addEventListener('wheel', this.handleInnerScrollWheel, { passive: false });\n }\n }\n }\n\n public render = () => {\n const props = this.props;\n\n const innerStyle: React.CSSProperties = {\n scrollBehavior: props.scrollBehaviour,\n maxHeight: props.maxHeight,\n maxWidth: props.maxWidth,\n };\n\n const scrollbarY = this.renderScrollbar('y');\n const scrollbarX = this.renderScrollbar('x');\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div className={styles.root()} onMouseMove={this.handleMouseMove} onMouseLeave={this.handleMouseLeave}>\n {scrollbarY}\n {scrollbarX}\n <div\n style={innerStyle}\n ref={this.refInner}\n className={cx(styles.inner(), globalClasses.inner)}\n data-tid=\"ScrollContainer__inner\"\n onScroll={this.handleNativeScroll}\n >\n {props.children}\n </div>\n </div>\n </CommonWrapper>\n );\n };\n\n /**\n * @public\n * @param {HTMLElement} element\n */\n public scrollTo(element: Nullable<HTMLElement>) {\n if (!element || !this.inner) {\n return;\n }\n\n this.inner.scrollLeft = element.offsetLeft;\n this.inner.scrollTop = getScrollYOffset(element, this.inner);\n }\n\n /**\n * @public\n */\n public scrollToTop() {\n if (!this.inner) {\n return;\n }\n this.inner.scrollTop = 0;\n }\n\n /**\n * @public\n */\n public scrollToBottom() {\n if (!this.inner) {\n return;\n }\n this.inner.scrollTop = this.inner.scrollHeight - this.inner.offsetHeight;\n }\n\n /**\n * @public\n */\n public scrollToLeft() {\n if (!this.inner) {\n return;\n }\n this.inner.scrollLeft = 0;\n }\n\n /**\n * @public\n */\n public scrollToRight() {\n if (!this.inner) {\n return;\n }\n\n this.inner.scrollLeft = this.inner.scrollWidth - this.inner.offsetWidth;\n }\n\n private hasScrollBar(axis: ScrollAxis) {\n if (!this.inner) {\n return false;\n }\n\n return axis === 'x'\n ? this.inner.offsetWidth < this.inner.scrollWidth\n : this.inner.offsetHeight < this.inner.scrollHeight;\n }\n\n private renderScrollbar = (axis: ScrollAxis) => {\n const refScrollBar = axis === 'x' ? this.refScrollBarX : this.refScrollBarY;\n\n return (\n <ScrollBar\n axis={axis}\n ref={refScrollBar}\n invert={this.props.invert}\n onScrollStateChange={this.handleScrollStateChange}\n />\n );\n };\n\n private handleScrollStateChange = (scrollState: ScrollBarScrollState, axis: ScrollAxis) => {\n if (!this.scrollY || !this.scrollX) {\n return;\n }\n\n if (axis === 'x') {\n const scrollXState = convertScrollbarXScrollState(scrollState);\n\n this.props.onScrollStateChangeX?.(scrollXState);\n return;\n }\n\n const scrollYState = convertScrollbarYScrollState(scrollState);\n\n this.props.onScrollStateChange?.(scrollYState);\n this.props.onScrollStateChangeY?.(scrollYState);\n };\n\n private refScrollBarY = (scrollbar: Nullable<ScrollBar>) => {\n this.scrollY = scrollbar;\n };\n\n private refScrollBarX = (scrollbar: Nullable<ScrollBar>) => {\n this.scrollX = scrollbar;\n };\n\n private refInner = (element: HTMLElement | null) => {\n if (!this.inner && element && this.props.preventWindowScroll) {\n element.addEventListener('wheel', this.handleInnerScrollWheel, { passive: false });\n }\n if (this.inner && !element) {\n this.inner.removeEventListener('wheel', this.handleInnerScrollWheel);\n }\n this.inner = element;\n };\n\n private handleNativeScroll = (event: React.UIEvent<HTMLDivElement>) => {\n this.scrollX?.reflow();\n this.scrollY?.reflow();\n\n this.props.onScroll?.(event);\n if (this.props.preventWindowScroll) {\n event.preventDefault();\n return;\n }\n LayoutEvents.emit();\n };\n\n private handleInnerScrollWheel = (event: Event) => {\n if (!this.inner || !(event instanceof WheelEvent)) {\n return;\n }\n\n const axis: ScrollAxis = event.shiftKey ? 'x' : 'y';\n\n if (this.hasScrollBar(axis)) {\n const { pos, size, offset } = scrollSizeParametersNames[axis];\n\n if (event.deltaY > 0 && this.inner[size] <= this.inner[pos] + this.inner[offset]) {\n event.preventDefault();\n return false;\n }\n if (event.deltaY < 0 && this.inner[pos] <= 0) {\n event.preventDefault();\n return false;\n }\n }\n };\n\n private handleMouseMove = (event: React.MouseEvent<HTMLDivElement>) => {\n const right = event.currentTarget.getBoundingClientRect().right - event.pageX;\n const bottom = event.currentTarget.getBoundingClientRect().bottom - event.pageY;\n\n this.scrollY?.setHover(right <= 12);\n this.scrollX?.setHover(right >= 12 && bottom <= 12);\n };\n\n private handleMouseLeave = () => {\n this.scrollY?.setHover(false);\n this.scrollX?.setHover(false);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["ScrollContainer.tsx"],"names":["ScrollContainer","rootNode","scrollX","scrollY","inner","setRootNode","render","props","innerStyle","scrollBehavior","scrollBehaviour","maxHeight","maxWidth","scrollbarY","renderScrollbar","scrollbarX","styles","root","handleMouseMove","handleMouseLeave","refInner","globalClasses","isIE11","innerIE11","handleNativeScroll","children","axis","refScrollBar","refScrollBarX","refScrollBarY","invert","handleScrollStateChange","scrollState","scrollXState","onScrollStateChangeX","scrollYState","onScrollStateChange","onScrollStateChangeY","scrollbar","element","preventWindowScroll","addEventListener","handleInnerScrollWheel","passive","removeEventListener","event","reflow","onScroll","preventDefault","LayoutEvents","emit","WheelEvent","shiftKey","hasScrollBar","scrollSizeParametersNames","pos","size","offset","deltaY","right","currentTarget","getBoundingClientRect","pageX","bottom","pageY","setHover","componentDidMount","setInnerElement","componentDidUpdate","prevProps","scrollTo","scrollLeft","offsetLeft","scrollTop","scrollToTop","scrollToBottom","scrollHeight","offsetHeight","scrollToLeft","scrollToRight","scrollWidth","offsetWidth","React","Component","__KONTUR_REACT_UI__","propTypes","PropTypes","bool","oneOfType","string","number","oneOf","func","defaultProps"],"mappings":"oaAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;;;;AAKA,wC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BaA,e,OADZC,kB;;;;;;;;;;;;;;;;;;AAmBSC,IAAAA,O;AACAC,IAAAA,O;AACAC,IAAAA,K;AACAC,IAAAA,W;;;;;;;;;;;;;;;;;;AAkBDC,IAAAA,M,GAAS,YAAM;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,MAAX,EAAmBH,mBAAUI,MAA7B,CAApB,CAFc,EAGxB/E,SAAS,EAAE2E,mBAAUE,SAAV,CAAoB,CAACF,mBAAUG,MAAX,EAAmBH,mBAAUI,MAA7B,CAApB,CAHa,EAIxBhF,eAAe,EAAE4E,mBAAUK,KAAV,CAAgB,CAAC,MAAD,EAAS,QAAT,CAAhB,CAJO,EAKxBnD,mBAAmB,EAAE8C,mBAAUC,IALP,EAMxBnD,mBAAmB,EAAEkD,mBAAUM,IANP,E,UASZC,Y,GAAe,EAC3B/D,MAAM,EAAE,KADmB,EAE3BpB,eAAe,EAAE,MAFU,EAG3B8B,mBAAmB,EAAE,KAHM,E","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport * as LayoutEvents from '../../lib/LayoutEvents';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { Nullable } from '../../typings/utility-types';\nimport { cx } from '../../lib/theming/Emotion';\nimport { isIE11 } from '../../lib/client';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\n\nimport { styles, globalClasses } from './ScrollContainer.styles';\nimport { scrollSizeParametersNames } from './ScrollContainer.constants';\nimport {\n getScrollYOffset,\n convertScrollbarXScrollState,\n convertScrollbarYScrollState,\n} from './ScrollContainer.helpers';\nimport { ScrollAxis, ScrollBar, ScrollBarScrollState } from './ScrollBar';\n\nexport type ScrollContainerScrollStateX = 'left' | 'scroll' | 'right';\nexport type ScrollContainerScrollStateY = 'top' | 'scroll' | 'bottom';\nexport type ScrollContainerScrollState = ScrollContainerScrollStateY; // deprecated\nexport type ScrollBehaviour = 'auto' | 'smooth';\n\nexport interface ScrollContainerProps extends CommonProps {\n /**\n * Инвертировать цвет скроллбара\n * @default false\n */\n invert: boolean;\n maxHeight?: React.CSSProperties['maxHeight'];\n maxWidth?: React.CSSProperties['maxWidth'];\n /**\n * @default false\n */\n preventWindowScroll: boolean;\n /**\n * Поведение скролла (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior)\n * @default 'auto'\n */\n scrollBehaviour?: ScrollBehaviour;\n onScrollStateChangeX?: (scrollState: ScrollContainerScrollStateX) => void;\n onScrollStateChangeY?: (scrollState: ScrollContainerScrollStateY) => void;\n onScrollStateChange?: (scrollYState: ScrollContainerScrollState) => void; // deprecated\n onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;\n}\n\n@rootNode\nexport class ScrollContainer extends React.Component<ScrollContainerProps> {\n public static __KONTUR_REACT_UI__ = 'ScrollContainer';\n\n public static propTypes = {\n invert: PropTypes.bool,\n maxWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n maxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n scrollBehaviour: PropTypes.oneOf(['auto', 'smooth']),\n preventWindowScroll: PropTypes.bool,\n onScrollStateChange: PropTypes.func,\n };\n\n public static defaultProps = {\n invert: false,\n scrollBehaviour: 'auto',\n preventWindowScroll: false,\n };\n\n private scrollX: Nullable<ScrollBar>;\n private scrollY: Nullable<ScrollBar>;\n private inner: Nullable<HTMLElement>;\n private setRootNode!: TSetRootNode;\n\n public componentDidMount() {\n this.scrollX?.setInnerElement(this.inner);\n this.scrollY?.setInnerElement(this.inner);\n }\n\n public componentDidUpdate(prevProps: ScrollContainerProps) {\n if (this.inner) {\n if (prevProps.preventWindowScroll && !this.props.preventWindowScroll) {\n this.inner.removeEventListener('wheel', this.handleInnerScrollWheel);\n }\n if (!prevProps.preventWindowScroll && this.props.preventWindowScroll) {\n this.inner.addEventListener('wheel', this.handleInnerScrollWheel, { passive: false });\n }\n }\n }\n\n public render = () => {\n const props = this.props;\n\n const innerStyle: React.CSSProperties = {\n scrollBehavior: props.scrollBehaviour,\n maxHeight: props.maxHeight,\n maxWidth: props.maxWidth,\n };\n\n const scrollbarY = this.renderScrollbar('y');\n const scrollbarX = this.renderScrollbar('x');\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div className={styles.root()} onMouseMove={this.handleMouseMove} onMouseLeave={this.handleMouseLeave}>\n {scrollbarY}\n {scrollbarX}\n <div\n style={innerStyle}\n ref={this.refInner}\n className={cx(styles.inner(), globalClasses.inner, isIE11 && styles.innerIE11())}\n data-tid=\"ScrollContainer__inner\"\n onScroll={this.handleNativeScroll}\n >\n {props.children}\n </div>\n </div>\n </CommonWrapper>\n );\n };\n\n /**\n * @public\n * @param {HTMLElement} element\n */\n public scrollTo(element: Nullable<HTMLElement>) {\n if (!element || !this.inner) {\n return;\n }\n\n this.inner.scrollLeft = element.offsetLeft;\n this.inner.scrollTop = getScrollYOffset(element, this.inner);\n }\n\n /**\n * @public\n */\n public scrollToTop() {\n if (!this.inner) {\n return;\n }\n this.inner.scrollTop = 0;\n }\n\n /**\n * @public\n */\n public scrollToBottom() {\n if (!this.inner) {\n return;\n }\n this.inner.scrollTop = this.inner.scrollHeight - this.inner.offsetHeight;\n }\n\n /**\n * @public\n */\n public scrollToLeft() {\n if (!this.inner) {\n return;\n }\n this.inner.scrollLeft = 0;\n }\n\n /**\n * @public\n */\n public scrollToRight() {\n if (!this.inner) {\n return;\n }\n\n this.inner.scrollLeft = this.inner.scrollWidth - this.inner.offsetWidth;\n }\n\n private hasScrollBar(axis: ScrollAxis) {\n if (!this.inner) {\n return false;\n }\n\n return axis === 'x'\n ? this.inner.offsetWidth < this.inner.scrollWidth\n : this.inner.offsetHeight < this.inner.scrollHeight;\n }\n\n private renderScrollbar = (axis: ScrollAxis) => {\n const refScrollBar = axis === 'x' ? this.refScrollBarX : this.refScrollBarY;\n\n return (\n <ScrollBar\n axis={axis}\n ref={refScrollBar}\n invert={this.props.invert}\n onScrollStateChange={this.handleScrollStateChange}\n />\n );\n };\n\n private handleScrollStateChange = (scrollState: ScrollBarScrollState, axis: ScrollAxis) => {\n if (!this.scrollY || !this.scrollX) {\n return;\n }\n\n if (axis === 'x') {\n const scrollXState = convertScrollbarXScrollState(scrollState);\n\n this.props.onScrollStateChangeX?.(scrollXState);\n return;\n }\n\n const scrollYState = convertScrollbarYScrollState(scrollState);\n\n this.props.onScrollStateChange?.(scrollYState);\n this.props.onScrollStateChangeY?.(scrollYState);\n };\n\n private refScrollBarY = (scrollbar: Nullable<ScrollBar>) => {\n this.scrollY = scrollbar;\n };\n\n private refScrollBarX = (scrollbar: Nullable<ScrollBar>) => {\n this.scrollX = scrollbar;\n };\n\n private refInner = (element: HTMLElement | null) => {\n if (!this.inner && element && this.props.preventWindowScroll) {\n element.addEventListener('wheel', this.handleInnerScrollWheel, { passive: false });\n }\n if (this.inner && !element) {\n this.inner.removeEventListener('wheel', this.handleInnerScrollWheel);\n }\n this.inner = element;\n };\n\n private handleNativeScroll = (event: React.UIEvent<HTMLDivElement>) => {\n this.scrollX?.reflow();\n this.scrollY?.reflow();\n\n this.props.onScroll?.(event);\n if (this.props.preventWindowScroll) {\n event.preventDefault();\n return;\n }\n LayoutEvents.emit();\n };\n\n private handleInnerScrollWheel = (event: Event) => {\n if (!this.inner || !(event instanceof WheelEvent)) {\n return;\n }\n\n const axis: ScrollAxis = event.shiftKey ? 'x' : 'y';\n\n if (this.hasScrollBar(axis)) {\n const { pos, size, offset } = scrollSizeParametersNames[axis];\n\n if (event.deltaY > 0 && this.inner[size] <= this.inner[pos] + this.inner[offset]) {\n event.preventDefault();\n return false;\n }\n if (event.deltaY < 0 && this.inner[pos] <= 0) {\n event.preventDefault();\n return false;\n }\n }\n };\n\n private handleMouseMove = (event: React.MouseEvent<HTMLDivElement>) => {\n const right = event.currentTarget.getBoundingClientRect().right - event.pageX;\n const bottom = event.currentTarget.getBoundingClientRect().bottom - event.pageY;\n\n this.scrollY?.setHover(right <= 12);\n this.scrollX?.setHover(right >= 12 && bottom <= 12);\n };\n\n private handleMouseLeave = () => {\n this.scrollY?.setHover(false);\n this.scrollX?.setHover(false);\n };\n}\n"]}
|