@dr.pogodin/react-utils 1.46.2 → 1.47.0-alpha.11
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/babel.config.js +1 -0
- package/babel.libweb.config.js +16 -0
- package/babel.module.config.js +11 -0
- package/bin/build.js +21 -11
- package/bin/setup.js +11 -9
- package/build/development/client/getInj.js +57 -44
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +15 -21
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +2 -6
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +3 -177
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +1 -8
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +22 -45
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +84 -86
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +58 -60
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +8 -31
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -9
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +15 -22
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +14 -21
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +9 -11
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +21 -27
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +6 -13
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +24 -28
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +6 -13
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +13 -20
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +28 -31
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +13 -20
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +13 -18
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +23 -30
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +19 -26
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +16 -130
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +19 -20
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +35 -39
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +31 -31
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +19 -24
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +1 -7
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js +3 -27
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/config.js +40 -21
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +3 -8
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +12 -89
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +7 -32
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +34 -37
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +1 -7
- package/build/development/shared/utils/jest/global.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +20 -44
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +54 -45
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +22 -31
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +17 -16
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +13 -11
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +3 -3
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +2 -2
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +2 -3
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +3 -3
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +8 -8
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +24 -25
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +9 -11
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -9
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +2 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +4 -4
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +4 -4
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +5 -5
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +3 -3
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +7 -7
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +2 -2
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +5 -5
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +4 -4
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +4 -4
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +3 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/components/selectors/common.js +2 -2
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/components/selectors/index.js +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/config.js +8 -6
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +2 -2
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js +4 -4
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +16 -15
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +1 -1
- package/build/production/shared/utils/jest/global.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +11 -11
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +11 -22
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +3 -3
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +6 -6
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +1 -2
- package/build/types-code/client/index.d.ts +1 -1
- package/build/types-code/index.d.ts +1 -7
- package/build/types-code/server/index.d.ts +6 -11
- package/build/types-code/server/utils/index.d.ts +1 -1
- package/build/types-code/shared/utils/config.d.ts +4 -2
- package/build/types-code/shared/utils/index.d.ts +2 -2
- package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
- package/build/web/client/getInj.js +65 -0
- package/build/web/client/getInj.js.map +1 -0
- package/{src/client/index.tsx → build/web/client/index.js} +13 -24
- package/build/web/client/index.js.map +1 -0
- package/{src/client/init.ts → build/web/client/init.js} +9 -14
- package/build/web/client/init.js.map +1 -0
- package/build/web/index.js +11 -0
- package/build/web/index.js.map +1 -0
- package/{src/server/Cache.ts → build/web/server/Cache.js} +15 -22
- package/build/web/server/Cache.js.map +1 -0
- package/{src/server/index.ts → build/web/server/index.js} +32 -81
- package/build/web/server/index.js.map +1 -0
- package/{src/server/renderer.tsx → build/web/server/renderer.js} +188 -333
- package/build/web/server/renderer.js.map +1 -0
- package/{src/server/server.ts → build/web/server/server.js} +82 -182
- package/build/web/server/server.js.map +1 -0
- package/{src/server/utils/errors.ts → build/web/server/utils/errors.js} +6 -25
- package/build/web/server/utils/errors.js.map +1 -0
- package/build/web/server/utils/index.js +4 -0
- package/build/web/server/utils/index.js.map +1 -0
- package/build/web/shared/components/Button/index.js +90 -0
- package/build/web/shared/components/Button/index.js.map +1 -0
- package/build/web/shared/components/Checkbox/index.js +35 -0
- package/build/web/shared/components/Checkbox/index.js.map +1 -0
- package/{src/shared/components/GenericLink/index.tsx → build/web/shared/components/GenericLink/index.js} +44 -78
- package/build/web/shared/components/GenericLink/index.js.map +1 -0
- package/build/web/shared/components/Input/index.js +71 -0
- package/build/web/shared/components/Input/index.js.map +1 -0
- package/build/web/shared/components/Link.js +20 -0
- package/build/web/shared/components/Link.js.map +1 -0
- package/{src → build/web}/shared/components/Modal/base-theme.scss +1 -1
- package/build/web/shared/components/Modal/index.js +128 -0
- package/build/web/shared/components/Modal/index.js.map +1 -0
- package/build/web/shared/components/NavLink.js +13 -0
- package/build/web/shared/components/NavLink.js.map +1 -0
- package/{src → build/web}/shared/components/PageLayout/base-theme.scss +1 -1
- package/{src/shared/components/PageLayout/index.tsx → build/web/shared/components/PageLayout/index.js} +20 -33
- package/build/web/shared/components/PageLayout/index.js.map +1 -0
- package/build/web/shared/components/TextArea/index.js +106 -0
- package/build/web/shared/components/TextArea/index.js.map +1 -0
- package/build/web/shared/components/Throbber/index.js +26 -0
- package/build/web/shared/components/Throbber/index.js.map +1 -0
- package/{src/shared/components/WithTooltip/Tooltip.tsx → build/web/shared/components/WithTooltip/Tooltip.js} +61 -109
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -0
- package/build/web/shared/components/WithTooltip/index.js +117 -0
- package/build/web/shared/components/WithTooltip/index.js.map +1 -0
- package/{src/shared/components/YouTubeVideo/index.tsx → build/web/shared/components/YouTubeVideo/index.js} +23 -40
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -0
- package/build/web/shared/components/index.js +18 -0
- package/build/web/shared/components/index.js.map +1 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +82 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -0
- package/{src/shared/components/selectors/CustomDropdown/index.tsx → build/web/shared/components/selectors/CustomDropdown/index.js} +56 -80
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -0
- package/{src/shared/components/selectors/NativeDropdown/index.tsx → build/web/shared/components/selectors/NativeDropdown/index.js} +39 -44
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -0
- package/build/web/shared/components/selectors/Switch/index.js +50 -0
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -0
- package/build/web/shared/components/selectors/common.js +12 -0
- package/build/web/shared/components/selectors/common.js.map +1 -0
- package/build/web/shared/components/selectors/index.js +4 -0
- package/build/web/shared/components/selectors/index.js.map +1 -0
- package/build/web/shared/utils/config.js +45 -0
- package/build/web/shared/utils/config.js.map +1 -0
- package/build/web/shared/utils/globalState.js +15 -0
- package/build/web/shared/utils/globalState.js.map +1 -0
- package/build/web/shared/utils/index.js +13 -0
- package/build/web/shared/utils/index.js.map +1 -0
- package/{src/shared/utils/isomorphy/buildInfo.ts → build/web/shared/utils/isomorphy/buildInfo.js} +4 -10
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -0
- package/build/web/shared/utils/isomorphy/environment-check.js +17 -0
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -0
- package/{src/shared/utils/isomorphy/index.ts → build/web/shared/utils/isomorphy/index.js} +6 -6
- package/build/web/shared/utils/isomorphy/index.js.map +1 -0
- package/{src/shared/utils/jest/E2eSsrEnv.ts → build/web/shared/utils/jest/E2eSsrEnv.js} +73 -140
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -0
- package/build/web/shared/utils/jest/global.js +4 -0
- package/build/web/shared/utils/jest/global.js.map +1 -0
- package/{src/shared/utils/jest/index.ts → build/web/shared/utils/jest/index.js} +33 -83
- package/build/web/shared/utils/jest/index.js.map +1 -0
- package/{src/shared/utils/splitComponent.tsx → build/web/shared/utils/splitComponent.js} +77 -124
- package/build/web/shared/utils/splitComponent.js.map +1 -0
- package/{src/shared/utils/time.ts → build/web/shared/utils/time.js} +21 -37
- package/build/web/shared/utils/time.js.map +1 -0
- package/build/web/shared/utils/webpack.js +67 -0
- package/build/web/shared/utils/webpack.js.map +1 -0
- package/config/babel/node-ssr.js +12 -3
- package/config/babel/webpack.js +6 -1
- package/config/jest/default.js +8 -2
- package/config/jest/setup.js +8 -1
- package/config/webpack/app-base.js +25 -14
- package/config/webpack/app-development.js +2 -2
- package/config/webpack/lib-base.js +1 -2
- package/package.json +41 -42
- package/types.d.ts +1 -6
- package/build/development/__chunk_groups__.json +0 -6
- package/build/development/style.css +0 -909
- package/build/development/web.bundle.js +0 -752
- package/build/production/__chunk_groups__.json +0 -6
- package/build/production/style.css +0 -2
- package/build/production/style.css.map +0 -1
- package/build/production/web.bundle.js +0 -3
- package/build/production/web.bundle.js.LICENSE.txt +0 -9
- package/build/production/web.bundle.js.map +0 -1
- package/dev-styles.js +0 -1
- package/node-entry.js +0 -15
- package/null.js +0 -1
- package/prod-styles.js +0 -1
- package/src/client/getInj.ts +0 -51
- package/src/index.ts +0 -73
- package/src/server/utils/index.ts +0 -3
- package/src/shared/components/Button/index.tsx +0 -130
- package/src/shared/components/Checkbox/index.tsx +0 -53
- package/src/shared/components/Input/index.tsx +0 -96
- package/src/shared/components/Link.tsx +0 -25
- package/src/shared/components/Modal/index.tsx +0 -177
- package/src/shared/components/NavLink.tsx +0 -18
- package/src/shared/components/TextArea/index.tsx +0 -139
- package/src/shared/components/Throbber/index.tsx +0 -28
- package/src/shared/components/WithTooltip/index.tsx +0 -186
- package/src/shared/components/index.ts +0 -20
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
- package/src/shared/components/selectors/Switch/index.tsx +0 -74
- package/src/shared/components/selectors/common.ts +0 -57
- package/src/shared/components/selectors/index.ts +0 -8
- package/src/shared/utils/config.ts +0 -28
- package/src/shared/utils/globalState.ts +0 -44
- package/src/shared/utils/index.ts +0 -45
- package/src/shared/utils/isomorphy/environment-check.ts +0 -18
- package/src/shared/utils/jest/global.ts +0 -17
- package/src/shared/utils/webpack.ts +0 -74
- /package/{src → build/web}/shared/components/Button/style.scss +0 -0
- /package/{src → build/web}/shared/components/Checkbox/theme.scss +0 -0
- /package/{src → build/web}/shared/components/GenericLink/style.scss +0 -0
- /package/{src → build/web}/shared/components/Input/theme.scss +0 -0
- /package/{src → build/web}/shared/components/Modal/styles.scss +0 -0
- /package/{src → build/web}/shared/components/TextArea/style.scss +0 -0
- /package/{src → build/web}/shared/components/Throbber/theme.scss +0 -0
- /package/{src → build/web}/shared/components/WithTooltip/default-theme.scss +0 -0
- /package/{src → build/web}/shared/components/YouTubeVideo/base.scss +0 -0
- /package/{src → build/web}/shared/components/YouTubeVideo/throbber.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/CustomDropdown/Options/style.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/CustomDropdown/theme.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/NativeDropdown/theme.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/Switch/theme.scss +0 -0
- /package/{src → build/web}/styles/_global/reset.css +0 -0
- /package/{src → build/web}/styles/_mixins/fonts.scss +0 -0
- /package/{src → build/web}/styles/_mixins/media.scss +0 -0
- /package/{src → build/web}/styles/_mixins/typography.scss +0 -0
- /package/{src → build/web}/styles/global.scss +0 -0
- /package/{src → build/web}/styles/mixins.scss +0 -0
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import baseTheme from './base-theme.scss';
|
|
6
|
-
|
|
7
|
-
type ThemeKeyT = 'container' | 'leftSidePanel' | 'mainPanel' | 'rightSidePanel'
|
|
8
|
-
| 'sidePanel';
|
|
9
|
-
|
|
10
|
-
type PropsT = {
|
|
11
|
-
children?: ReactNode;
|
|
12
|
-
leftSidePanelContent?: ReactNode;
|
|
13
|
-
rightSidePanelContent?: ReactNode;
|
|
14
|
-
theme: Theme<ThemeKeyT>;
|
|
15
|
-
};
|
|
16
|
-
|
|
1
|
+
import themed from '@dr.pogodin/react-themes';
|
|
2
|
+
import baseTheme from "./base-theme.scss";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
4
|
/**
|
|
18
5
|
* Simple and themeable page layout. It keeps the main content centered in
|
|
19
6
|
* a column of limited width, which fills entire viewport on small screens
|
|
@@ -29,23 +16,23 @@ type PropsT = {
|
|
|
29
16
|
* @param {...any} [props....]
|
|
30
17
|
* [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
|
|
31
18
|
*/
|
|
32
|
-
const PageLayout
|
|
19
|
+
const PageLayout = ({
|
|
33
20
|
children,
|
|
34
21
|
leftSidePanelContent,
|
|
35
22
|
rightSidePanelContent,
|
|
36
|
-
theme
|
|
37
|
-
}) => (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
theme
|
|
24
|
+
}) => /*#__PURE__*/_jsxs("div", {
|
|
25
|
+
className: theme.container,
|
|
26
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
27
|
+
className: [theme.sidePanel, theme.leftSidePanel].join(' '),
|
|
28
|
+
children: leftSidePanelContent
|
|
29
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
30
|
+
className: theme.mainPanel,
|
|
31
|
+
children: children
|
|
32
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
33
|
+
className: [theme.sidePanel, theme.rightSidePanel].join(' '),
|
|
34
|
+
children: rightSidePanelContent
|
|
35
|
+
})]
|
|
36
|
+
});
|
|
37
|
+
export default /* #__PURE__ */themed(PageLayout, 'PageLayout', baseTheme);
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["themed","baseTheme","jsx","_jsx","jsxs","_jsxs","PageLayout","children","leftSidePanelContent","rightSidePanelContent","theme","className","container","sidePanel","leftSidePanel","join","mainPanel","rightSidePanel"],"sources":["../../../../../src/shared/components/PageLayout/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport baseTheme from './base-theme.scss';\n\ntype ThemeKeyT = 'container' | 'leftSidePanel' | 'mainPanel' | 'rightSidePanel'\n | 'sidePanel';\n\ntype PropsT = {\n children?: ReactNode;\n leftSidePanelContent?: ReactNode;\n rightSidePanelContent?: ReactNode;\n theme: Theme<ThemeKeyT>;\n};\n\n/**\n * Simple and themeable page layout. It keeps the main content centered in\n * a column of limited width, which fills entire viewport on small screens\n * (under `$screen-md = 1024px` size). At larger screens the column keeps\n * `$screen-md` size, and it is centered at the page, surrounded by side\n * panels, where additional content can be displayed.\n *\n * **Children:** Component children are rendered as the content of main panel.\n * @param {object} [props] Component properties.\n * @param {Node} [props.leftSidePanelContent] The content for left side panel.\n * @param {Node} [props.rightSidePanelContent] The content for right side panel.\n * @param {PageLayoutTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst PageLayout: React.FunctionComponent<PropsT> = ({\n children,\n leftSidePanelContent,\n rightSidePanelContent,\n theme,\n}) => (\n <div className={theme.container}>\n <div className={[theme.sidePanel, theme.leftSidePanel].join(' ')}>\n {leftSidePanelContent}\n </div>\n <div className={theme.mainPanel}>\n {children}\n </div>\n <div className={[theme.sidePanel, theme.rightSidePanel].join(' ')}>\n {rightSidePanelContent}\n </div>\n </div>\n);\n\nexport default /* #__PURE__ */ themed(PageLayout, 'PageLayout', baseTheme);\n"],"mappings":"AAEA,OAAOA,MAAM,MAAsB,0BAA0B;AAE7D,OAAOC,SAAS;AAA0B,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAY1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,UAA2C,GAAGA,CAAC;EACnDC,QAAQ;EACRC,oBAAoB;EACpBC,qBAAqB;EACrBC;AACF,CAAC,kBACCL,KAAA;EAAKM,SAAS,EAAED,KAAK,CAACE,SAAU;EAAAL,QAAA,gBAC9BJ,IAAA;IAAKQ,SAAS,EAAE,CAACD,KAAK,CAACG,SAAS,EAAEH,KAAK,CAACI,aAAa,CAAC,CAACC,IAAI,CAAC,GAAG,CAAE;IAAAR,QAAA,EAC9DC;EAAoB,CAClB,CAAC,eACNL,IAAA;IAAKQ,SAAS,EAAED,KAAK,CAACM,SAAU;IAAAT,QAAA,EAC7BA;EAAQ,CACN,CAAC,eACNJ,IAAA;IAAKQ,SAAS,EAAE,CAACD,KAAK,CAACG,SAAS,EAAEH,KAAK,CAACO,cAAc,CAAC,CAACF,IAAI,CAAC,GAAG,CAAE;IAAAR,QAAA,EAC/DE;EAAqB,CACnB,CAAC;AAAA,CACH,CACN;AAED,eAAe,eAAgBT,MAAM,CAACM,UAAU,EAAE,YAAY,EAAEL,SAAS,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import themed from '@dr.pogodin/react-themes';
|
|
3
|
+
import defaultTheme from "./style.scss";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
const TextArea = ({
|
|
6
|
+
disabled,
|
|
7
|
+
error,
|
|
8
|
+
label,
|
|
9
|
+
onBlur,
|
|
10
|
+
onChange,
|
|
11
|
+
onKeyDown,
|
|
12
|
+
placeholder,
|
|
13
|
+
testId,
|
|
14
|
+
theme,
|
|
15
|
+
value
|
|
16
|
+
}) => {
|
|
17
|
+
const hiddenAreaRef = useRef(null);
|
|
18
|
+
const [height, setHeight] = useState();
|
|
19
|
+
const textAreaRef = useRef(null);
|
|
20
|
+
const [localValue, setLocalValue] = useState(value ?? '');
|
|
21
|
+
if (value !== undefined && localValue !== value) setLocalValue(value);
|
|
22
|
+
|
|
23
|
+
// This resizes text area's height when its width is changed for any reason.
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const el = hiddenAreaRef.current;
|
|
26
|
+
if (!el) return undefined;
|
|
27
|
+
const cb = () => {
|
|
28
|
+
setHeight(el.scrollHeight);
|
|
29
|
+
};
|
|
30
|
+
const observer = new ResizeObserver(cb);
|
|
31
|
+
observer.observe(el);
|
|
32
|
+
return () => {
|
|
33
|
+
observer.disconnect();
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
// Resizes the text area when its content is modified.
|
|
38
|
+
//
|
|
39
|
+
// NOTE: useLayoutEffect() instead of useEffect() makes difference here,
|
|
40
|
+
// as it helps to avoid visible "content/height" jumps (i.e. with just
|
|
41
|
+
// useEffect() it becomes visible how the content is modified first,
|
|
42
|
+
// and then input height is incremented, if necessary).
|
|
43
|
+
// See: https://github.com/birdofpreyru/react-utils/issues/313
|
|
44
|
+
useLayoutEffect(() => {
|
|
45
|
+
const el = hiddenAreaRef.current;
|
|
46
|
+
if (el) setHeight(el.scrollHeight);
|
|
47
|
+
}, [localValue]);
|
|
48
|
+
let containerClassName = theme.container;
|
|
49
|
+
if (error) containerClassName += ` ${theme.error}`;
|
|
50
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
51
|
+
className: containerClassName,
|
|
52
|
+
onFocus: () => {
|
|
53
|
+
textAreaRef.current?.focus();
|
|
54
|
+
},
|
|
55
|
+
children: [label === undefined ? null : /*#__PURE__*/_jsx("div", {
|
|
56
|
+
className: theme.label,
|
|
57
|
+
children: label
|
|
58
|
+
}), /*#__PURE__*/_jsx("textarea", {
|
|
59
|
+
className: `${theme.textarea} ${theme.hidden}`
|
|
60
|
+
|
|
61
|
+
// This text area is hidden underneath the primary one below,
|
|
62
|
+
// and it is used for text measurements, to implement auto-scaling
|
|
63
|
+
// of the primary textarea's height.
|
|
64
|
+
,
|
|
65
|
+
readOnly: true,
|
|
66
|
+
ref: hiddenAreaRef
|
|
67
|
+
|
|
68
|
+
// The "-1" value of "tabIndex" removes this hidden text area from
|
|
69
|
+
// the tab-focus-chain.
|
|
70
|
+
,
|
|
71
|
+
tabIndex: -1
|
|
72
|
+
|
|
73
|
+
// NOTE: With empty string value ("") the scrolling height of this text
|
|
74
|
+
// area is zero, thus collapsing <TextArea> height below the single line
|
|
75
|
+
// input height. To avoid it we fallback to whitespace (" ") character
|
|
76
|
+
// here.
|
|
77
|
+
,
|
|
78
|
+
value: localValue || ' '
|
|
79
|
+
}), /*#__PURE__*/_jsx("textarea", {
|
|
80
|
+
className: theme.textarea,
|
|
81
|
+
"data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
|
|
82
|
+
disabled: disabled,
|
|
83
|
+
onBlur: onBlur
|
|
84
|
+
|
|
85
|
+
// When value is "undefined" the text area is not-managed, and we should
|
|
86
|
+
// manage it internally for the measurement / resizing functionality
|
|
87
|
+
// to work.
|
|
88
|
+
,
|
|
89
|
+
onChange: value === undefined ? e => {
|
|
90
|
+
setLocalValue(e.target.value);
|
|
91
|
+
} : onChange,
|
|
92
|
+
onKeyDown: onKeyDown,
|
|
93
|
+
placeholder: placeholder,
|
|
94
|
+
ref: textAreaRef,
|
|
95
|
+
style: {
|
|
96
|
+
height
|
|
97
|
+
},
|
|
98
|
+
value: localValue
|
|
99
|
+
}), error && error !== true ? /*#__PURE__*/_jsx("div", {
|
|
100
|
+
className: theme.errorMessage,
|
|
101
|
+
children: error
|
|
102
|
+
}) : null]
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
export default /* #__PURE__ */themed(TextArea, 'TextArea', defaultTheme);
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["useEffect","useLayoutEffect","useRef","useState","themed","defaultTheme","jsx","_jsx","jsxs","_jsxs","TextArea","disabled","error","label","onBlur","onChange","onKeyDown","placeholder","testId","theme","value","hiddenAreaRef","height","setHeight","textAreaRef","localValue","setLocalValue","undefined","el","current","cb","scrollHeight","observer","ResizeObserver","observe","disconnect","containerClassName","container","className","onFocus","focus","children","textarea","hidden","readOnly","ref","tabIndex","process","env","NODE_ENV","e","target","style","errorMessage"],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import {\n type ChangeEventHandler,\n type FocusEventHandler,\n type FunctionComponent,\n type KeyboardEventHandler,\n type ReactNode,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n error?: ReactNode;\n label?: string;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n testId?: string;\n theme: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: FunctionComponent<Props> = ({\n disabled,\n error,\n label,\n onBlur,\n onChange,\n onKeyDown,\n placeholder,\n testId,\n theme,\n value,\n}) => {\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [localValue, setLocalValue] = useState(value ?? '');\n if (value !== undefined && localValue !== value) setLocalValue(value);\n\n // This resizes text area's height when its width is changed for any reason.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (!el) return undefined;\n\n const cb = () => {\n setHeight(el.scrollHeight);\n };\n const observer = new ResizeObserver(cb);\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n // Resizes the text area when its content is modified.\n //\n // NOTE: useLayoutEffect() instead of useEffect() makes difference here,\n // as it helps to avoid visible \"content/height\" jumps (i.e. with just\n // useEffect() it becomes visible how the content is modified first,\n // and then input height is incremented, if necessary).\n // See: https://github.com/birdofpreyru/react-utils/issues/313\n useLayoutEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n let containerClassName = theme.container;\n if (error) containerClassName += ` ${theme.error}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n textAreaRef.current?.focus();\n }}\n >\n {label === undefined ? null : <div className={theme.label}>{label}</div>}\n <textarea\n className={`${theme.textarea} ${theme.hidden}`}\n\n // This text area is hidden underneath the primary one below,\n // and it is used for text measurements, to implement auto-scaling\n // of the primary textarea's height.\n readOnly\n ref={hiddenAreaRef}\n\n // The \"-1\" value of \"tabIndex\" removes this hidden text area from\n // the tab-focus-chain.\n tabIndex={-1}\n\n // NOTE: With empty string value (\"\") the scrolling height of this text\n // area is zero, thus collapsing <TextArea> height below the single line\n // input height. To avoid it we fallback to whitespace (\" \") character\n // here.\n value={localValue || ' '}\n />\n <textarea\n className={theme.textarea}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onBlur={onBlur}\n\n // When value is \"undefined\" the text area is not-managed, and we should\n // manage it internally for the measurement / resizing functionality\n // to work.\n onChange={\n value === undefined\n ? (e) => {\n setLocalValue(e.target.value);\n } : onChange\n }\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n ref={textAreaRef}\n style={{ height }}\n value={localValue}\n />\n {error && error !== true\n ? <div className={theme.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default /* #__PURE__ */ themed(TextArea, 'TextArea', defaultTheme);\n"],"mappings":"AAAA,SAMEA,SAAS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;QAAE9B;MAAO,CAAE;MAClBF,KAAK,EAAEK;IAAW,CACnB,CAAC,EACDb,KAAK,IAAIA,KAAK,KAAK,IAAI,gBACpBL,IAAA;MAAK+B,SAAS,EAAEnB,KAAK,CAACkC,YAAa;MAAAZ,QAAA,EAAE7B;IAAK,CAAM,CAAC,GACjD,IAAI;EAAA,CACL,CAAC;AAEV,CAAC;AAED,eAAe,eAAgBR,MAAM,CAACM,QAAQ,EAAE,UAAU,EAAEL,YAAY,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import themed from '@dr.pogodin/react-themes';
|
|
2
|
+
import defaultTheme from "./theme.scss";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* Throbber is an "action in progress" indicator, which renders
|
|
6
|
+
* three bouncing circles as a simple pending activity indicator,
|
|
7
|
+
* and can be further themed to a certain degree.
|
|
8
|
+
* @param {object} [props] Component properties.
|
|
9
|
+
* @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.
|
|
10
|
+
* @param {...any} [props....]
|
|
11
|
+
* [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
|
|
12
|
+
*/
|
|
13
|
+
const Throbber = ({
|
|
14
|
+
theme
|
|
15
|
+
}) => /*#__PURE__*/_jsxs("span", {
|
|
16
|
+
className: theme.container,
|
|
17
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
18
|
+
className: theme.circle
|
|
19
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
20
|
+
className: theme.circle
|
|
21
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
22
|
+
className: theme.circle
|
|
23
|
+
})]
|
|
24
|
+
});
|
|
25
|
+
export default /* #__PURE__ */themed(Throbber, 'Throbber', defaultTheme);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["themed","defaultTheme","jsx","_jsx","jsxs","_jsxs","Throbber","theme","className","container","children","circle"],"sources":["../../../../../src/shared/components/Throbber/index.tsx"],"sourcesContent":["import themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'bouncing' | 'circle' | 'container';\n\ntype PropsT = {\n theme: Theme<ThemeKeyT>;\n};\n\n/**\n * Throbber is an \"action in progress\" indicator, which renders\n * three bouncing circles as a simple pending activity indicator,\n * and can be further themed to a certain degree.\n * @param {object} [props] Component properties.\n * @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Throbber: React.FunctionComponent<PropsT> = ({ theme }) => (\n <span className={theme.container}>\n <span className={theme.circle} />\n <span className={theme.circle} />\n <span className={theme.circle} />\n </span>\n);\n\nexport default /* #__PURE__ */ themed(Throbber, 'Throbber', defaultTheme);\n"],"mappings":"AAAA,OAAOA,MAAM,MAAsB,0BAA0B;AAE7D,OAAOC,YAAY;AAAqB,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAQxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAyC,GAAGA,CAAC;EAAEC;AAAM,CAAC,kBAC1DF,KAAA;EAAMG,SAAS,EAAED,KAAK,CAACE,SAAU;EAAAC,QAAA,gBAC/BP,IAAA;IAAMK,SAAS,EAAED,KAAK,CAACI;EAAO,CAAE,CAAC,eACjCR,IAAA;IAAMK,SAAS,EAAED,KAAK,CAACI;EAAO,CAAE,CAAC,eACjCR,IAAA;IAAMK,SAAS,EAAED,KAAK,CAACI;EAAO,CAAE,CAAC;AAAA,CAC7B,CACP;AAED,eAAe,eAAgBX,MAAM,CAACM,QAAQ,EAAE,UAAU,EAAEL,YAAY,CAAC","ignoreList":[]}
|
|
@@ -4,56 +4,22 @@
|
|
|
4
4
|
* performance during animation.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
type FunctionComponent,
|
|
9
|
-
type ReactNode,
|
|
10
|
-
type RefObject,
|
|
11
|
-
useImperativeHandle,
|
|
12
|
-
useRef,
|
|
13
|
-
} from 'react';
|
|
14
|
-
|
|
7
|
+
import { useImperativeHandle, useRef } from 'react';
|
|
15
8
|
import { createPortal } from 'react-dom';
|
|
16
|
-
|
|
17
|
-
import type { Theme } from '@dr.pogodin/react-themes';
|
|
18
|
-
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
10
|
/**
|
|
20
11
|
* Valid placements of the rendered tooltip. They will be overriden when
|
|
21
12
|
* necessary to fit the tooltip within the viewport.
|
|
22
13
|
*/
|
|
23
|
-
export
|
|
24
|
-
ABOVE_CURSOR =
|
|
25
|
-
ABOVE_ELEMENT =
|
|
26
|
-
BELOW_CURSOR =
|
|
27
|
-
BELOW_ELEMENT =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const ARROW_STYLE_DOWN = [
|
|
31
|
-
|
|
32
|
-
'border-left-color:transparent',
|
|
33
|
-
'border-right-color:transparent',
|
|
34
|
-
].join(';');
|
|
35
|
-
|
|
36
|
-
const ARROW_STYLE_UP = [
|
|
37
|
-
'border-top-color:transparent',
|
|
38
|
-
'border-left-color:transparent',
|
|
39
|
-
'border-right-color:transparent',
|
|
40
|
-
].join(';');
|
|
41
|
-
|
|
42
|
-
type ComponentsT = {
|
|
43
|
-
container: HTMLDivElement;
|
|
44
|
-
arrow: HTMLDivElement;
|
|
45
|
-
content: HTMLDivElement;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type ThemeKeysT = 'appearance' | 'arrow' | 'content' | 'container';
|
|
49
|
-
|
|
50
|
-
type TooltipThemeT = Theme<ThemeKeysT>;
|
|
51
|
-
|
|
52
|
-
type TooltipRectsT = {
|
|
53
|
-
arrow: DOMRect;
|
|
54
|
-
container: DOMRect;
|
|
55
|
-
};
|
|
56
|
-
|
|
14
|
+
export let PLACEMENTS = /*#__PURE__*/function (PLACEMENTS) {
|
|
15
|
+
PLACEMENTS["ABOVE_CURSOR"] = "ABOVE_CURSOR";
|
|
16
|
+
PLACEMENTS["ABOVE_ELEMENT"] = "ABOVE_ELEMENT";
|
|
17
|
+
PLACEMENTS["BELOW_CURSOR"] = "BELOW_CURSOR";
|
|
18
|
+
PLACEMENTS["BELOW_ELEMENT"] = "BELOW_ELEMENT";
|
|
19
|
+
return PLACEMENTS;
|
|
20
|
+
}({});
|
|
21
|
+
const ARROW_STYLE_DOWN = ['border-bottom-color:transparent', 'border-left-color:transparent', 'border-right-color:transparent'].join(';');
|
|
22
|
+
const ARROW_STYLE_UP = ['border-top-color:transparent', 'border-left-color:transparent', 'border-right-color:transparent'].join(';');
|
|
57
23
|
/**
|
|
58
24
|
* Generates bounding client rectangles for tooltip components.
|
|
59
25
|
* @ignore
|
|
@@ -63,10 +29,10 @@ type TooltipRectsT = {
|
|
|
63
29
|
* @return Object holding tooltip rectangles in
|
|
64
30
|
* two fields.
|
|
65
31
|
*/
|
|
66
|
-
function calcTooltipRects(tooltip
|
|
32
|
+
function calcTooltipRects(tooltip) {
|
|
67
33
|
return {
|
|
68
34
|
arrow: tooltip.arrow.getBoundingClientRect(),
|
|
69
|
-
container: tooltip.container.getBoundingClientRect()
|
|
35
|
+
container: tooltip.container.getBoundingClientRect()
|
|
70
36
|
};
|
|
71
37
|
}
|
|
72
38
|
|
|
@@ -76,13 +42,21 @@ function calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {
|
|
|
76
42
|
* @return {{x, y, width, height}}
|
|
77
43
|
*/
|
|
78
44
|
function calcViewportRect() {
|
|
79
|
-
const {
|
|
80
|
-
|
|
45
|
+
const {
|
|
46
|
+
scrollX,
|
|
47
|
+
scrollY
|
|
48
|
+
} = window;
|
|
49
|
+
const {
|
|
50
|
+
documentElement: {
|
|
51
|
+
clientHeight,
|
|
52
|
+
clientWidth
|
|
53
|
+
}
|
|
54
|
+
} = document;
|
|
81
55
|
return {
|
|
82
56
|
bottom: scrollY + clientHeight,
|
|
83
57
|
left: scrollX,
|
|
84
58
|
right: scrollX + clientWidth,
|
|
85
|
-
top: scrollY
|
|
59
|
+
top: scrollY
|
|
86
60
|
};
|
|
87
61
|
}
|
|
88
62
|
|
|
@@ -102,22 +76,20 @@ function calcViewportRect() {
|
|
|
102
76
|
* - {number} containerY
|
|
103
77
|
* - {string} baseArrowStyle
|
|
104
78
|
*/
|
|
105
|
-
function calcPositionAboveXY(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const { arrow, container } = tooltipRects;
|
|
79
|
+
function calcPositionAboveXY(x, y, tooltipRects) {
|
|
80
|
+
const {
|
|
81
|
+
arrow,
|
|
82
|
+
container
|
|
83
|
+
} = tooltipRects;
|
|
111
84
|
return {
|
|
112
85
|
arrowX: 0.5 * (container.width - arrow.width),
|
|
113
86
|
arrowY: container.height,
|
|
114
87
|
containerX: x - container.width / 2,
|
|
115
88
|
containerY: y - container.height - arrow.height / 1.5,
|
|
116
|
-
|
|
117
89
|
// TODO: Instead of already setting the base style here, we should
|
|
118
90
|
// introduce a set of constants for arrow directions, which will help
|
|
119
91
|
// to do checks dependant on the arrow direction.
|
|
120
|
-
baseArrowStyle: ARROW_STYLE_DOWN
|
|
92
|
+
baseArrowStyle: ARROW_STYLE_DOWN
|
|
121
93
|
};
|
|
122
94
|
}
|
|
123
95
|
|
|
@@ -180,95 +152,75 @@ function calcPositionAboveXY(
|
|
|
180
152
|
* @param tooltip.arrow DOM reference to the tooltip arrow.
|
|
181
153
|
* @param tooltip.container DOM reference to the tooltip container.
|
|
182
154
|
*/
|
|
183
|
-
function setComponentPositions(
|
|
184
|
-
pageX: number,
|
|
185
|
-
pageY: number,
|
|
186
|
-
placement: PLACEMENTS | undefined,
|
|
187
|
-
element: HTMLElement | undefined,
|
|
188
|
-
tooltip: ComponentsT,
|
|
189
|
-
) {
|
|
155
|
+
function setComponentPositions(pageX, pageY, placement, element, tooltip) {
|
|
190
156
|
const tooltipRects = calcTooltipRects(tooltip);
|
|
191
157
|
const viewportRect = calcViewportRect();
|
|
192
158
|
|
|
193
159
|
/* Default container coords: tooltip at the top. */
|
|
194
160
|
const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);
|
|
195
|
-
|
|
196
161
|
if (pos.containerX < viewportRect.left + 6) {
|
|
197
162
|
pos.containerX = viewportRect.left + 6;
|
|
198
|
-
pos.arrowX = Math.max(
|
|
199
|
-
6,
|
|
200
|
-
pageX - pos.containerX - tooltipRects.arrow.width / 2,
|
|
201
|
-
);
|
|
163
|
+
pos.arrowX = Math.max(6, pageX - pos.containerX - tooltipRects.arrow.width / 2);
|
|
202
164
|
} else {
|
|
203
165
|
const maxX = viewportRect.right - 6 - tooltipRects.container.width;
|
|
204
166
|
if (pos.containerX > maxX) {
|
|
205
167
|
pos.containerX = maxX;
|
|
206
|
-
pos.arrowX = Math.min(
|
|
207
|
-
tooltipRects.container.width - 6,
|
|
208
|
-
pageX - pos.containerX - tooltipRects.arrow.width / 2,
|
|
209
|
-
);
|
|
168
|
+
pos.arrowX = Math.min(tooltipRects.container.width - 6, pageX - pos.containerX - tooltipRects.arrow.width / 2);
|
|
210
169
|
}
|
|
211
170
|
}
|
|
212
171
|
|
|
213
172
|
/* If tooltip has not enough space on top - make it bottom tooltip. */
|
|
214
173
|
if (pos.containerY < viewportRect.top + 6) {
|
|
215
|
-
pos.containerY += tooltipRects.container.height
|
|
216
|
-
|
|
217
|
-
pos.arrowY -= tooltipRects.container.height
|
|
218
|
-
+ tooltipRects.arrow.height;
|
|
174
|
+
pos.containerY += tooltipRects.container.height + 2 * tooltipRects.arrow.height;
|
|
175
|
+
pos.arrowY -= tooltipRects.container.height + tooltipRects.arrow.height;
|
|
219
176
|
pos.baseArrowStyle = ARROW_STYLE_UP;
|
|
220
177
|
}
|
|
221
|
-
|
|
222
178
|
const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;
|
|
223
179
|
tooltip.container.setAttribute('style', containerStyle);
|
|
224
|
-
|
|
225
180
|
const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;
|
|
226
181
|
tooltip.arrow.setAttribute('style', arrowStyle);
|
|
227
182
|
}
|
|
228
183
|
|
|
229
184
|
/* The Tooltip component itself. */
|
|
230
|
-
const Tooltip
|
|
231
|
-
children
|
|
232
|
-
ref
|
|
233
|
-
theme
|
|
234
|
-
}
|
|
185
|
+
const Tooltip = ({
|
|
186
|
+
children,
|
|
187
|
+
ref,
|
|
188
|
+
theme
|
|
189
|
+
}) => {
|
|
235
190
|
// NOTE: The way it has to be implemented, for clean mounting and unmounting
|
|
236
191
|
// at the client side, the <Tooltip> is fully mounted into DOM in the next
|
|
237
192
|
// rendering cycles, and only then it can be correctly measured and positioned.
|
|
238
193
|
// Thus, when we create the <Tooltip> we have to record its target positioning
|
|
239
194
|
// details, and then apply them when it is created.
|
|
240
195
|
|
|
241
|
-
const arrowRef = useRef
|
|
242
|
-
const containerRef = useRef
|
|
243
|
-
const contentRef = useRef
|
|
244
|
-
|
|
245
|
-
const pointTo = (
|
|
246
|
-
pageX: number,
|
|
247
|
-
pageY: number,
|
|
248
|
-
placement: PLACEMENTS,
|
|
249
|
-
element: HTMLElement,
|
|
250
|
-
) => {
|
|
196
|
+
const arrowRef = useRef(null);
|
|
197
|
+
const containerRef = useRef(null);
|
|
198
|
+
const contentRef = useRef(null);
|
|
199
|
+
const pointTo = (pageX, pageY, placement, element) => {
|
|
251
200
|
if (!arrowRef.current || !containerRef.current || !contentRef.current) {
|
|
252
201
|
throw Error('Internal error');
|
|
253
202
|
}
|
|
254
|
-
|
|
255
203
|
setComponentPositions(pageX, pageY, placement, element, {
|
|
256
204
|
arrow: arrowRef.current,
|
|
257
205
|
container: containerRef.current,
|
|
258
|
-
content: contentRef.current
|
|
206
|
+
content: contentRef.current
|
|
259
207
|
});
|
|
260
208
|
};
|
|
261
|
-
useImperativeHandle(ref, () => ({
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
209
|
+
useImperativeHandle(ref, () => ({
|
|
210
|
+
pointTo
|
|
211
|
+
}));
|
|
212
|
+
return /*#__PURE__*/createPortal(/*#__PURE__*/_jsxs("div", {
|
|
213
|
+
className: theme.container,
|
|
214
|
+
ref: containerRef,
|
|
215
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
216
|
+
className: theme.arrow,
|
|
217
|
+
ref: arrowRef
|
|
218
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
219
|
+
className: theme.content,
|
|
220
|
+
ref: contentRef,
|
|
221
|
+
children: children
|
|
222
|
+
})]
|
|
223
|
+
}), document.body);
|
|
272
224
|
};
|
|
273
|
-
|
|
274
225
|
export default Tooltip;
|
|
226
|
+
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":["useImperativeHandle","useRef","createPortal","jsx","_jsx","jsxs","_jsxs","PLACEMENTS","ARROW_STYLE_DOWN","join","ARROW_STYLE_UP","calcTooltipRects","tooltip","arrow","getBoundingClientRect","container","calcViewportRect","scrollX","scrollY","window","documentElement","clientHeight","clientWidth","document","bottom","left","right","top","calcPositionAboveXY","x","y","tooltipRects","arrowX","width","arrowY","height","containerX","containerY","baseArrowStyle","setComponentPositions","pageX","pageY","placement","element","viewportRect","pos","Math","max","maxX","min","containerStyle","setAttribute","arrowStyle","Tooltip","children","ref","theme","arrowRef","containerRef","contentRef","pointTo","current","Error","content","className","body"],"sources":["../../../../../src/shared/components/WithTooltip/Tooltip.tsx"],"sourcesContent":["/**\n * The actual tooltip component. It is rendered outside the regular document\n * hierarchy, and with sub-components managed without React to achieve the best\n * performance during animation.\n */\n\nimport {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/**\n * Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport.\n */\nexport enum PLACEMENTS {\n ABOVE_CURSOR = 'ABOVE_CURSOR',\n ABOVE_ELEMENT = 'ABOVE_ELEMENT',\n BELOW_CURSOR = 'BELOW_CURSOR',\n BELOW_ELEMENT = 'BELOW_ELEMENT',\n}\n\nconst ARROW_STYLE_DOWN = [\n 'border-bottom-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\nconst ARROW_STYLE_UP = [\n 'border-top-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\ntype ComponentsT = {\n container: HTMLDivElement;\n arrow: HTMLDivElement;\n content: HTMLDivElement;\n};\n\nexport type ThemeKeysT = 'appearance' | 'arrow' | 'content' | 'container';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\n\ntype TooltipRectsT = {\n arrow: DOMRect;\n container: DOMRect;\n};\n\n/**\n * Generates bounding client rectangles for tooltip components.\n * @ignore\n * @param tooltip DOM references to the tooltip components.\n * @param tooltip.arrow\n * @param tooltip.container\n * @return Object holding tooltip rectangles in\n * two fields.\n */\nfunction calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {\n return {\n arrow: tooltip.arrow.getBoundingClientRect(),\n container: tooltip.container.getBoundingClientRect(),\n };\n}\n\n/**\n * Calculates the document viewport size.\n * @ignore\n * @return {{x, y, width, height}}\n */\nfunction calcViewportRect() {\n const { scrollX, scrollY } = window;\n const { documentElement: { clientHeight, clientWidth } } = document;\n return {\n bottom: scrollY + clientHeight,\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\n };\n}\n\n/**\n * Calculates tooltip and arrow positions for the placement just above\n * the cursor.\n * @ignore\n * @param {number} x Cursor page-x position.\n * @param {number} y Cursor page-y position.\n * @param {object} tooltipRects Bounding client rectangles of tooltip parts.\n * @param {object} tooltipRects.arrow\n * @param {object} tooltipRects.container\n * @return {object} Contains the following fields:\n * - {number} arrowX\n * - {number} arrowY\n * - {number} containerX\n * - {number} containerY\n * - {string} baseArrowStyle\n */\nfunction calcPositionAboveXY(\n x: number,\n y: number,\n tooltipRects: TooltipRectsT,\n) {\n const { arrow, container } = tooltipRects;\n return {\n arrowX: 0.5 * (container.width - arrow.width),\n arrowY: container.height,\n containerX: x - container.width / 2,\n containerY: y - container.height - arrow.height / 1.5,\n\n // TODO: Instead of already setting the base style here, we should\n // introduce a set of constants for arrow directions, which will help\n // to do checks dependant on the arrow direction.\n baseArrowStyle: ARROW_STYLE_DOWN,\n };\n}\n\n// const HIT = {\n// NONE: false,\n// LEFT: 'LEFT',\n// RIGHT: 'RIGHT',\n// TOP: 'TOP',\n// BOTTOM: 'BOTTOM',\n// };\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n// function checkViewportFit(pos, tooltipRects, viewportRect) {\n// const { containerX, containerY } = pos;\n// if (containerX < viewportRect.left + 6) return HIT.LEFT;\n// if (containerX > viewportRect.right - 6) return HIT.RIGHT;\n// return HIT.NONE;\n// }\n\n/**\n * Shifts tooltip horizontally to fit into the viewport, while keeping\n * the arrow pointed to the XY point.\n * @param {number} x\n * @param {number} y\n * @param {object} pos\n * @param {number} pageXOffset\n * @param {number} pageXWidth\n */\n// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {\n// if (pos.containerX < pageXOffset + 6) {\n// pos.containerX = pageXOffset + 6;\n// pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);\n// } else {\n// const maxX = pageXOffset + docRect.width - containerRect.width - 6;\n// if (containerX > maxX) {\n// containerX = maxX;\n// arrowX = Math.min(\n// containerRect.width - 6,\n// pageX - containerX - arrowRect.width / 2,\n// );\n// }\n// }\n// }\n\n/**\n * Sets positions of tooltip components to point the tooltip to the specified\n * page point.\n * @ignore\n * @param pageX\n * @param pageY\n * @param placement\n * @param element DOM reference to the element wrapped by the tooltip.\n * @param tooltip\n * @param tooltip.arrow DOM reference to the tooltip arrow.\n * @param tooltip.container DOM reference to the tooltip container.\n */\nfunction setComponentPositions(\n pageX: number,\n pageY: number,\n placement: PLACEMENTS | undefined,\n element: HTMLElement | undefined,\n tooltip: ComponentsT,\n) {\n const tooltipRects = calcTooltipRects(tooltip);\n const viewportRect = calcViewportRect();\n\n /* Default container coords: tooltip at the top. */\n const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);\n\n if (pos.containerX < viewportRect.left + 6) {\n pos.containerX = viewportRect.left + 6;\n pos.arrowX = Math.max(\n 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n } else {\n const maxX = viewportRect.right - 6 - tooltipRects.container.width;\n if (pos.containerX > maxX) {\n pos.containerX = maxX;\n pos.arrowX = Math.min(\n tooltipRects.container.width - 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n }\n }\n\n /* If tooltip has not enough space on top - make it bottom tooltip. */\n if (pos.containerY < viewportRect.top + 6) {\n pos.containerY += tooltipRects.container.height\n + 2 * tooltipRects.arrow.height;\n pos.arrowY -= tooltipRects.container.height\n + tooltipRects.arrow.height;\n pos.baseArrowStyle = ARROW_STYLE_UP;\n }\n\n const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip: FunctionComponent<{\n children?: ReactNode;\n ref?: RefObject<unknown>;\n theme: TooltipThemeT;\n}> = ({ children, ref, theme }) => {\n // NOTE: The way it has to be implemented, for clean mounting and unmounting\n // at the client side, the <Tooltip> is fully mounted into DOM in the next\n // rendering cycles, and only then it can be correctly measured and positioned.\n // Thus, when we create the <Tooltip> we have to record its target positioning\n // details, and then apply them when it is created.\n\n const arrowRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n if (!arrowRef.current || !containerRef.current || !contentRef.current) {\n throw Error('Internal error');\n }\n\n setComponentPositions(pageX, pageY, placement, element, {\n arrow: arrowRef.current,\n container: containerRef.current,\n content: contentRef.current,\n });\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n return createPortal(\n (\n <div className={theme.container} ref={containerRef}>\n <div className={theme.arrow} ref={arrowRef} />\n <div className={theme.content} ref={contentRef}>{children}</div>\n </div>\n ),\n document.body,\n );\n};\n\nexport default Tooltip;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAIEA,mBAAmB,EACnBC,MAAM,QACD,OAAO;AAEd,SAASC,YAAY,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAIzC;AACA;AACA;AACA;AACA,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAOtB,MAAMC,gBAAgB,GAAG,CACvB,iCAAiC,EACjC,+BAA+B,EAC/B,gCAAgC,CACjC,CAACC,IAAI,CAAC,GAAG,CAAC;AAEX,MAAMC,cAAc,GAAG,CACrB,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,CACjC,CAACD,IAAI,CAAC,GAAG,CAAC;AAiBX;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,gBAAgBA,CAACC,OAAoB,EAAiB;EAC7D,OAAO;IACLC,KAAK,EAAED,OAAO,CAACC,KAAK,CAACC,qBAAqB,CAAC,CAAC;IAC5CC,SAAS,EAAEH,OAAO,CAACG,SAAS,CAACD,qBAAqB,CAAC;EACrD,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASE,gBAAgBA,CAAA,EAAG;EAC1B,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGC,MAAM;EACnC,MAAM;IAAEC,eAAe,EAAE;MAAEC,YAAY;MAAEC;IAAY;EAAE,CAAC,GAAGC,QAAQ;EACnE,OAAO;IACLC,MAAM,EAAEN,OAAO,GAAGG,YAAY;IAC9BI,IAAI,EAAER,OAAO;IACbS,KAAK,EAAET,OAAO,GAAGK,WAAW;IAC5BK,GAAG,EAAET;EACP,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASU,mBAAmBA,CAC1BC,CAAS,EACTC,CAAS,EACTC,YAA2B,EAC3B;EACA,MAAM;IAAElB,KAAK;IAAEE;EAAU,CAAC,GAAGgB,YAAY;EACzC,OAAO;IACLC,MAAM,EAAE,GAAG,IAAIjB,SAAS,CAACkB,KAAK,GAAGpB,KAAK,CAACoB,KAAK,CAAC;IAC7CC,MAAM,EAAEnB,SAAS,CAACoB,MAAM;IACxBC,UAAU,EAAEP,CAAC,GAAGd,SAAS,CAACkB,KAAK,GAAG,CAAC;IACnCI,UAAU,EAAEP,CAAC,GAAGf,SAAS,CAACoB,MAAM,GAAGtB,KAAK,CAACsB,MAAM,GAAG,GAAG;IAErD;IACA;IACA;IACAG,cAAc,EAAE9B;EAClB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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uD,GAAG,EAAE,OAAO;IAAEK;EAAQ,CAAC,CAAC,CAAC;EAE7C,oBAAO1D,YAAY,cAEfI,KAAA;IAAK0D,SAAS,EAAER,KAAK,CAACzC,SAAU;IAACwC,GAAG,EAAEG,YAAa;IAAAJ,QAAA,gBACjDlD,IAAA;MAAK4D,SAAS,EAAER,KAAK,CAAC3C,KAAM;MAAC0C,GAAG,EAAEE;IAAS,CAAE,CAAC,eAC9CrD,IAAA;MAAK4D,SAAS,EAAER,KAAK,CAACO,OAAQ;MAACR,GAAG,EAAEI,UAAW;MAAAL,QAAA,EAAEA;IAAQ,CAAM,CAAC;EAAA,CAC7D,CAAC,EAER/B,QAAQ,CAAC0C,IACX,CAAC;AACH,CAAC;AAED,eAAeZ,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* global window */
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import themed from '@dr.pogodin/react-themes';
|
|
5
|
+
import Tooltip, { PLACEMENTS } from "./Tooltip";
|
|
6
|
+
import defaultTheme from "./default-theme.scss";
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
/**
|
|
9
|
+
* Implements a simple to use and themeable tooltip component, _e.g._
|
|
10
|
+
* ```js
|
|
11
|
+
* <WithTooltip tip="This is example tooltip.">
|
|
12
|
+
* <p>Hover to see the tooltip.</p>
|
|
13
|
+
* </WithTooltip>
|
|
14
|
+
* ```
|
|
15
|
+
* **Children:** Children are rendered in the place of `<WithTooltip>`,
|
|
16
|
+
* and when hovered the tooltip is shown. By default the wrapper itself is
|
|
17
|
+
* `<div>` block with `display: inline-block`.
|
|
18
|
+
* @param tip – Anything React is able to render,
|
|
19
|
+
* _e.g._ a tooltip text. This will be the tooltip content.
|
|
20
|
+
* @param {WithTooltipTheme} props.theme _Ad hoc_ theme.
|
|
21
|
+
*/
|
|
22
|
+
const Wrapper = ({
|
|
23
|
+
children,
|
|
24
|
+
placement = PLACEMENTS.ABOVE_CURSOR,
|
|
25
|
+
tip,
|
|
26
|
+
theme
|
|
27
|
+
}) => {
|
|
28
|
+
const {
|
|
29
|
+
current: heap
|
|
30
|
+
} = useRef({
|
|
31
|
+
lastCursorX: 0,
|
|
32
|
+
lastCursorY: 0,
|
|
33
|
+
timerId: undefined,
|
|
34
|
+
triggeredByTouch: false
|
|
35
|
+
});
|
|
36
|
+
const tooltipRef = useRef(null);
|
|
37
|
+
const wrapperRef = useRef(null);
|
|
38
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
39
|
+
const updatePortalPosition = (cursorX, cursorY) => {
|
|
40
|
+
if (showTooltip) {
|
|
41
|
+
const wrapperRect = wrapperRef.current.getBoundingClientRect();
|
|
42
|
+
if (cursorX < wrapperRect.left || cursorX > wrapperRect.right || cursorY < wrapperRect.top || cursorY > wrapperRect.bottom) {
|
|
43
|
+
setShowTooltip(false);
|
|
44
|
+
} else if (tooltipRef.current) {
|
|
45
|
+
tooltipRef.current.pointTo(cursorX + window.scrollX, cursorY + window.scrollY, placement, wrapperRef.current);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
heap.lastCursorX = cursorX;
|
|
49
|
+
heap.lastCursorY = cursorY;
|
|
50
|
+
|
|
51
|
+
// If tooltip was triggered by a touch, we delay its opening by a bit,
|
|
52
|
+
// to ensure it was not a touch-click - in the case of touch click we
|
|
53
|
+
// want to do the click, rather than show the tooltip, and the delay
|
|
54
|
+
// gives click handler a chance to abort the tooltip openning.
|
|
55
|
+
if (heap.triggeredByTouch) {
|
|
56
|
+
heap.timerId ??= setTimeout(() => {
|
|
57
|
+
heap.triggeredByTouch = false;
|
|
58
|
+
heap.timerId = undefined;
|
|
59
|
+
setShowTooltip(true);
|
|
60
|
+
}, 300);
|
|
61
|
+
|
|
62
|
+
// Otherwise we can just open the tooltip right away.
|
|
63
|
+
} else setShowTooltip(true);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (showTooltip && tip !== null) {
|
|
68
|
+
// This is necessary to ensure that even when a single mouse event
|
|
69
|
+
// arrives to a tool-tipped component, the tooltip is correctly positioned
|
|
70
|
+
// once opened (because similar call above does not have effect until
|
|
71
|
+
// the tooltip is fully mounted, and that is delayed to future rendering
|
|
72
|
+
// cycle due to the implementation).
|
|
73
|
+
if (tooltipRef.current) {
|
|
74
|
+
tooltipRef.current.pointTo(heap.lastCursorX + window.scrollX, heap.lastCursorY + window.scrollY, placement, wrapperRef.current);
|
|
75
|
+
}
|
|
76
|
+
const listener = () => {
|
|
77
|
+
setShowTooltip(false);
|
|
78
|
+
};
|
|
79
|
+
window.addEventListener('scroll', listener);
|
|
80
|
+
return () => {
|
|
81
|
+
window.removeEventListener('scroll', listener);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}, [heap.lastCursorX, heap.lastCursorY, placement, showTooltip, tip]);
|
|
86
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
87
|
+
className: theme.wrapper,
|
|
88
|
+
onClick: () => {
|
|
89
|
+
if (heap.timerId) {
|
|
90
|
+
clearTimeout(heap.timerId);
|
|
91
|
+
heap.timerId = undefined;
|
|
92
|
+
heap.triggeredByTouch = false;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
onMouseLeave: () => {
|
|
96
|
+
setShowTooltip(false);
|
|
97
|
+
},
|
|
98
|
+
onMouseMove: e => {
|
|
99
|
+
updatePortalPosition(e.clientX, e.clientY);
|
|
100
|
+
},
|
|
101
|
+
onTouchStart: () => {
|
|
102
|
+
heap.triggeredByTouch = true;
|
|
103
|
+
},
|
|
104
|
+
ref: wrapperRef,
|
|
105
|
+
role: "presentation",
|
|
106
|
+
children: [showTooltip && tip !== null ? /*#__PURE__*/_jsx(Tooltip, {
|
|
107
|
+
ref: tooltipRef,
|
|
108
|
+
theme: theme,
|
|
109
|
+
children: tip
|
|
110
|
+
}) : null, children]
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const ThemedWrapper = /* #__PURE__ */themed(Wrapper, 'WithTooltip', defaultTheme);
|
|
114
|
+
const e = ThemedWrapper;
|
|
115
|
+
e.PLACEMENTS = PLACEMENTS;
|
|
116
|
+
export default e;
|
|
117
|
+
//# sourceMappingURL=index.js.map
|