@pareto-engineering/design-system 2.0.0-alpha.41 → 2.0.0-alpha.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a/GradientBackground/GradientBackground.js +140 -0
- package/dist/cjs/a/GradientBackground/index.js +15 -0
- package/dist/cjs/a/GradientBackground/styles.scss +191 -0
- package/dist/cjs/a/Popover/Popover.js +134 -0
- package/dist/cjs/a/Popover/common/Divider/Divider.js +67 -0
- package/dist/cjs/a/Popover/common/Divider/index.js +15 -0
- package/dist/cjs/a/Popover/common/Item/Item.js +67 -0
- package/dist/cjs/a/Popover/common/Item/index.js +15 -0
- package/dist/cjs/a/Popover/common/index.js +21 -0
- package/dist/cjs/a/Popover/index.js +15 -0
- package/dist/cjs/a/Popover/styles.scss +43 -0
- package/dist/cjs/a/index.js +9 -1
- package/dist/cjs/c/AcceptCookies/AcceptCookies.js +134 -0
- package/dist/cjs/c/AcceptCookies/index.js +15 -0
- package/dist/cjs/c/AcceptCookies/styles.scss +49 -0
- package/dist/cjs/c/BlogCategoryButton/BlogCategoryButton.js +95 -0
- package/dist/cjs/c/BlogCategoryButton/index.js +15 -0
- package/dist/cjs/c/BlogContext/BlogContextProvider.js +63 -0
- package/dist/cjs/c/BlogContext/Context.js +16 -0
- package/dist/cjs/c/BlogContext/ContextProvider.js +63 -0
- package/dist/cjs/c/BlogContext/index.js +31 -0
- package/dist/cjs/c/BlogContext/useBlog.js +16 -0
- package/dist/cjs/c/BlogPost/BlogPost.js +147 -0
- package/dist/cjs/c/BlogPost/index.js +15 -0
- package/dist/cjs/c/BlogPost/styles.scss +33 -0
- package/dist/cjs/c/BlogPostsList/BlogPostsList.js +73 -0
- package/dist/cjs/c/BlogPostsList/common/Card/Card.js +170 -0
- package/dist/cjs/c/BlogPostsList/common/Card/index.js +15 -0
- package/dist/cjs/c/BlogPostsList/common/index.js +13 -0
- package/dist/cjs/c/BlogPostsList/index.js +15 -0
- package/dist/cjs/c/BlogPostsList/styles.scss +72 -0
- package/dist/cjs/c/SiteFooter/SiteFooter.js +73 -0
- package/dist/cjs/c/SiteFooter/common/Section/Section.js +95 -0
- package/dist/cjs/c/SiteFooter/common/Section/index.js +15 -0
- package/dist/cjs/c/SiteFooter/common/index.js +13 -0
- package/dist/cjs/c/SiteFooter/index.js +15 -0
- package/dist/cjs/c/SiteFooter/styles.scss +34 -0
- package/dist/cjs/c/SiteHeaderCTA/SiteHeaderCTA.js +108 -0
- package/dist/cjs/c/SiteHeaderCTA/index.js +15 -0
- package/dist/cjs/c/SiteHeaderCTA/styles.scss +44 -0
- package/dist/cjs/c/SiteMission/SiteMission.js +113 -0
- package/dist/cjs/c/SiteMission/index.js +15 -0
- package/dist/cjs/c/SiteMission/styles.scss +30 -0
- package/dist/cjs/c/SiteNavigation/SiteNavigation.js +130 -0
- package/dist/cjs/c/SiteNavigation/index.js +15 -0
- package/dist/cjs/c/SiteNavigation/styles.scss +118 -0
- package/dist/cjs/c/SiteOnboardingStep/SiteOnboardingStep.js +98 -0
- package/dist/cjs/c/SiteOnboardingStep/index.js +15 -0
- package/dist/cjs/c/SiteOnboardingStep/styles.scss +51 -0
- package/dist/cjs/c/SitePricing/SitePricing.js +108 -0
- package/dist/cjs/c/SitePricing/index.js +15 -0
- package/dist/cjs/c/SitePricing/styles.scss +73 -0
- package/dist/cjs/c/SiteServices/SiteServices.js +211 -0
- package/dist/cjs/c/SiteServices/index.js +15 -0
- package/dist/cjs/c/SiteServices/styles.scss +138 -0
- package/dist/cjs/c/TeamGallery/TeamGallery.js +80 -0
- package/dist/cjs/c/TeamGallery/common/PersonCard/PersonCard.js +84 -0
- package/dist/cjs/c/TeamGallery/common/PersonCard/index.js +15 -0
- package/dist/cjs/c/TeamGallery/common/index.js +13 -0
- package/dist/cjs/c/TeamGallery/index.js +15 -0
- package/dist/cjs/c/TeamGallery/styles.scss +100 -0
- package/dist/cjs/c/Testimonials/Testimonials.js +119 -0
- package/dist/cjs/c/Testimonials/index.js +15 -0
- package/dist/cjs/c/Testimonials/styles.scss +112 -0
- package/dist/cjs/experimental/GradientBackground/GradientBackground.js +98 -0
- package/dist/cjs/experimental/GradientBackground/index.js +15 -0
- package/dist/cjs/experimental/GradientBackground/styles.scss +64 -0
- package/dist/cjs/experimental/index.js +13 -0
- package/dist/cjs/f/fields/CheckboxInput/CheckboxInput.js +105 -0
- package/dist/cjs/f/fields/CheckboxInput/index.js +15 -0
- package/dist/cjs/f/fields/CheckboxInput/styles.scss +28 -0
- package/dist/cjs/f/fields/RadioInput/RadioInput.js +110 -0
- package/dist/cjs/f/fields/RadioInput/index.js +15 -0
- package/dist/cjs/f/fields/RadioInput/styles.scss +26 -0
- package/dist/cjs/f/fields/TaskRecommendation/TaskRecommendation.js +129 -0
- package/dist/cjs/f/fields/TaskRecommendation/index.js +15 -0
- package/dist/cjs/f/fields/TaskRecommendation/styles.scss +37 -0
- package/dist/cjs/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +131 -0
- package/dist/cjs/f/fields/TaskRecommendationInput/index.js +15 -0
- package/dist/cjs/f/fields/TaskRecommendationInput/styles.scss +41 -0
- package/dist/cjs/f/fields/TextArea/TextArea.js +141 -0
- package/dist/cjs/f/fields/TextArea/index.js +15 -0
- package/dist/cjs/f/fields/TextArea/styles.scss +19 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/utils/hooks/index.js +23 -0
- package/dist/cjs/utils/hooks/useDynamicPosition.js +107 -0
- package/dist/cjs/utils/hooks/useWindowSize.js +39 -0
- package/dist/cjs/utils/index.js +19 -0
- package/dist/es/a/GradientBackground/GradientBackground.js +118 -0
- package/dist/es/a/GradientBackground/index.js +2 -0
- package/dist/es/a/GradientBackground/styles.scss +191 -0
- package/dist/es/a/Popover/Popover.js +118 -0
- package/dist/es/a/Popover/common/Divider/Divider.js +47 -0
- package/dist/es/a/Popover/common/Divider/index.js +2 -0
- package/dist/es/a/Popover/common/Item/Item.js +47 -0
- package/dist/es/a/Popover/common/Item/index.js +2 -0
- package/dist/es/a/Popover/common/index.js +2 -0
- package/dist/es/a/Popover/index.js +2 -0
- package/dist/es/a/Popover/styles.scss +43 -0
- package/dist/es/a/index.js +2 -1
- package/dist/es/c/AcceptCookies/AcceptCookies.js +117 -0
- package/dist/es/c/AcceptCookies/index.js +2 -0
- package/dist/es/c/AcceptCookies/styles.scss +49 -0
- package/dist/es/c/BlogCategoryButton/BlogCategoryButton.js +68 -0
- package/dist/es/c/BlogCategoryButton/index.js +2 -0
- package/dist/es/c/BlogContext/BlogContextProvider.js +45 -0
- package/dist/es/c/BlogContext/Context.js +2 -0
- package/dist/es/c/BlogContext/ContextProvider.js +45 -0
- package/dist/es/c/BlogContext/index.js +4 -0
- package/dist/es/c/BlogContext/useBlog.js +3 -0
- package/dist/es/c/BlogPost/BlogPost.js +128 -0
- package/dist/es/c/BlogPost/index.js +2 -0
- package/dist/es/c/BlogPost/styles.scss +33 -0
- package/dist/es/c/BlogPostsList/BlogPostsList.js +56 -0
- package/dist/es/c/BlogPostsList/common/Card/Card.js +143 -0
- package/dist/es/c/BlogPostsList/common/Card/index.js +2 -0
- package/dist/es/c/BlogPostsList/common/index.js +1 -0
- package/dist/es/c/BlogPostsList/index.js +2 -0
- package/dist/es/c/BlogPostsList/styles.scss +72 -0
- package/dist/es/c/SiteFooter/SiteFooter.js +56 -0
- package/dist/es/c/SiteFooter/common/Section/Section.js +73 -0
- package/dist/es/c/SiteFooter/common/Section/index.js +2 -0
- package/dist/es/c/SiteFooter/common/index.js +1 -0
- package/dist/es/c/SiteFooter/index.js +2 -0
- package/dist/es/c/SiteFooter/styles.scss +34 -0
- package/dist/es/c/SiteHeaderCTA/SiteHeaderCTA.js +92 -0
- package/dist/es/c/SiteHeaderCTA/index.js +2 -0
- package/dist/es/c/SiteHeaderCTA/styles.scss +44 -0
- package/dist/es/c/SiteMission/SiteMission.js +96 -0
- package/dist/es/c/SiteMission/index.js +2 -0
- package/dist/es/c/SiteMission/styles.scss +30 -0
- package/dist/es/c/SiteNavigation/SiteNavigation.js +111 -0
- package/dist/es/c/SiteNavigation/index.js +2 -0
- package/dist/es/c/SiteNavigation/styles.scss +118 -0
- package/dist/es/c/SiteOnboardingStep/SiteOnboardingStep.js +81 -0
- package/dist/es/c/SiteOnboardingStep/index.js +2 -0
- package/dist/es/c/SiteOnboardingStep/styles.scss +51 -0
- package/dist/es/c/SitePricing/SitePricing.js +91 -0
- package/dist/es/c/SitePricing/index.js +2 -0
- package/dist/es/c/SitePricing/styles.scss +73 -0
- package/dist/es/c/SiteServices/SiteServices.js +195 -0
- package/dist/es/c/SiteServices/index.js +2 -0
- package/dist/es/c/SiteServices/styles.scss +138 -0
- package/dist/es/c/TeamGallery/TeamGallery.js +64 -0
- package/dist/es/c/TeamGallery/common/PersonCard/PersonCard.js +64 -0
- package/dist/es/c/TeamGallery/common/PersonCard/index.js +2 -0
- package/dist/es/c/TeamGallery/common/index.js +1 -0
- package/dist/es/c/TeamGallery/index.js +2 -0
- package/dist/es/c/TeamGallery/styles.scss +100 -0
- package/dist/es/c/Testimonials/Testimonials.js +99 -0
- package/dist/es/c/Testimonials/index.js +2 -0
- package/dist/es/c/Testimonials/styles.scss +112 -0
- package/dist/es/experimental/GradientBackground/GradientBackground.js +76 -0
- package/dist/es/experimental/GradientBackground/index.js +2 -0
- package/dist/es/experimental/GradientBackground/styles.scss +64 -0
- package/dist/es/experimental/index.js +1 -0
- package/dist/es/f/fields/CheckboxInput/CheckboxInput.js +85 -0
- package/dist/es/f/fields/CheckboxInput/index.js +2 -0
- package/dist/es/f/fields/CheckboxInput/styles.scss +28 -0
- package/dist/es/f/fields/RadioInput/RadioInput.js +90 -0
- package/dist/es/f/fields/RadioInput/index.js +2 -0
- package/dist/es/f/fields/RadioInput/styles.scss +26 -0
- package/dist/es/f/fields/TaskRecommendation/TaskRecommendation.js +111 -0
- package/dist/es/f/fields/TaskRecommendation/index.js +2 -0
- package/dist/es/f/fields/TaskRecommendation/styles.scss +37 -0
- package/dist/es/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +111 -0
- package/dist/es/f/fields/TaskRecommendationInput/index.js +2 -0
- package/dist/es/f/fields/TaskRecommendationInput/styles.scss +41 -0
- package/dist/es/f/fields/TextArea/TextArea.js +124 -0
- package/dist/es/f/fields/TextArea/index.js +2 -0
- package/dist/es/f/fields/TextArea/styles.scss +19 -0
- package/dist/es/index.js +2 -1
- package/dist/es/utils/hooks/index.js +2 -0
- package/dist/es/utils/hooks/useDynamicPosition.js +93 -0
- package/dist/es/utils/hooks/useWindowSize.js +27 -0
- package/dist/es/utils/index.js +1 -0
- package/package.json +1 -1
- package/src/__snapshots__/Storyshots.test.js.snap +413 -1
- package/src/stories/a/Popover.stories.jsx +106 -0
- package/src/stories/utils/lorem.js +15 -0
- package/src/ui/a/Popover/Popover.jsx +157 -0
- package/src/ui/a/Popover/index.js +2 -0
- package/src/ui/a/Popover/styles.scss +43 -0
- package/src/ui/a/index.js +1 -0
- package/src/ui/index.js +1 -0
- package/src/ui/utils/hooks/index.js +2 -0
- package/src/ui/utils/hooks/useDynamicPosition.js +104 -0
- package/src/ui/utils/hooks/useWindowSize.js +32 -0
- package/src/ui/utils/index.js +1 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useRef, useLayoutEffect } from 'react'
|
|
5
|
+
|
|
6
|
+
import PropTypes from 'prop-types'
|
|
7
|
+
|
|
8
|
+
import styleNames from '@pareto-engineering/bem'
|
|
9
|
+
|
|
10
|
+
// Local Definitions
|
|
11
|
+
import { useDynamicPosition } from 'ui/utils'
|
|
12
|
+
|
|
13
|
+
const baseClassName = styleNames.base
|
|
14
|
+
|
|
15
|
+
const componentClassName = 'popover'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is the component description.
|
|
19
|
+
*/
|
|
20
|
+
const Popover = ({
|
|
21
|
+
id,
|
|
22
|
+
className:userClassName,
|
|
23
|
+
style,
|
|
24
|
+
color,
|
|
25
|
+
children,
|
|
26
|
+
isOpen,
|
|
27
|
+
parentRef,
|
|
28
|
+
preferredPrimaryOrder,
|
|
29
|
+
preferredSecondaryOrder,
|
|
30
|
+
offsetXPx,
|
|
31
|
+
offsetYPx,
|
|
32
|
+
// ...otherProps
|
|
33
|
+
}) => {
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
import('./styles.scss')
|
|
36
|
+
}, [])
|
|
37
|
+
|
|
38
|
+
const popoverRef = useRef(null)
|
|
39
|
+
const {
|
|
40
|
+
primaryPosition,
|
|
41
|
+
secondaryPosition,
|
|
42
|
+
} = useDynamicPosition({
|
|
43
|
+
preferredPrimaryOrder,
|
|
44
|
+
preferredSecondaryOrder,
|
|
45
|
+
elementRef:popoverRef,
|
|
46
|
+
parentRef,
|
|
47
|
+
offsetXPx,
|
|
48
|
+
offsetYPx,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
id={id}
|
|
54
|
+
className={[
|
|
55
|
+
baseClassName,
|
|
56
|
+
componentClassName,
|
|
57
|
+
userClassName,
|
|
58
|
+
isOpen && 'open',
|
|
59
|
+
`x-${color}`,
|
|
60
|
+
primaryPosition,
|
|
61
|
+
secondaryPosition,
|
|
62
|
+
]
|
|
63
|
+
.filter((e) => e)
|
|
64
|
+
.join(' ')}
|
|
65
|
+
style={style}
|
|
66
|
+
ref={popoverRef}
|
|
67
|
+
// {...otherProps}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Popover.propTypes = {
|
|
75
|
+
/**
|
|
76
|
+
* The HTML id for this element
|
|
77
|
+
*/
|
|
78
|
+
id:PropTypes.string,
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The HTML class names for this element
|
|
82
|
+
*/
|
|
83
|
+
className:PropTypes.string,
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The React-written, css properties for this element.
|
|
87
|
+
*/
|
|
88
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The children JSX
|
|
92
|
+
*/
|
|
93
|
+
children:PropTypes.node,
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The base color of the popover
|
|
97
|
+
*/
|
|
98
|
+
color:PropTypes.string,
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether the popover should be visible or not
|
|
102
|
+
*/
|
|
103
|
+
isOpen:PropTypes.bool,
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The preferred primary position order of the popover
|
|
107
|
+
*/
|
|
108
|
+
preferredPrimaryOrder:PropTypes.arrayOf(
|
|
109
|
+
PropTypes.oneOf([
|
|
110
|
+
'bottom',
|
|
111
|
+
'top',
|
|
112
|
+
'right',
|
|
113
|
+
'left',
|
|
114
|
+
]),
|
|
115
|
+
),
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The preferred secondary position order of the popover
|
|
119
|
+
*/
|
|
120
|
+
preferredSecondaryOrder:PropTypes.arrayOf(
|
|
121
|
+
PropTypes.oneOf([
|
|
122
|
+
'left',
|
|
123
|
+
'right',
|
|
124
|
+
'bottom',
|
|
125
|
+
'top',
|
|
126
|
+
]),
|
|
127
|
+
),
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The horizonal offset in pixels from the anchor point to the popover
|
|
131
|
+
*/
|
|
132
|
+
offsetXPx:PropTypes.number,
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The vertical offset in pixels from the anchor point to the popover
|
|
136
|
+
*/
|
|
137
|
+
offsetYPx:PropTypes.number,
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The reference to the parent element
|
|
141
|
+
*/
|
|
142
|
+
parentRef:PropTypes.oneOfType([
|
|
143
|
+
PropTypes.func,
|
|
144
|
+
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
|
|
145
|
+
]),
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
Popover.defaultProps = {
|
|
149
|
+
color :'background1',
|
|
150
|
+
isOpen :false,
|
|
151
|
+
preferredPrimaryOrder :['bottom', 'top', 'right', 'left'],
|
|
152
|
+
preferredSecondaryOrder:['left', 'right', 'bottom', 'top'],
|
|
153
|
+
offsetXPx :16,
|
|
154
|
+
offsetYPx :0,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export default Popover
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
@use "@pareto-engineering/bem";
|
|
3
|
+
|
|
4
|
+
$default-padding: 1em;
|
|
5
|
+
$default-margin: 1em;
|
|
6
|
+
$default-border: var(--theme-border-style) var(--metadata);
|
|
7
|
+
|
|
8
|
+
.#{bem.$base}.popover{
|
|
9
|
+
position: absolute;
|
|
10
|
+
z-index: 1;
|
|
11
|
+
background-color: var(--x);
|
|
12
|
+
padding: $default-padding;
|
|
13
|
+
border: $default-border;
|
|
14
|
+
|
|
15
|
+
&:not(.open) {
|
|
16
|
+
display: none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
> *:not(:last-child) {
|
|
20
|
+
margin-bottom: $default-margin / 2;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.bottom {
|
|
24
|
+
top: 100%;
|
|
25
|
+
// bottom: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&.left {
|
|
29
|
+
left: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&.right {
|
|
33
|
+
right: 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&.top {
|
|
37
|
+
bottom: 100%;
|
|
38
|
+
top: auto;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
package/src/ui/a/index.js
CHANGED
package/src/ui/index.js
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState, useEffect, useMemo, useCallback,
|
|
3
|
+
} from 'react'
|
|
4
|
+
import throttle from 'lodash/throttle'
|
|
5
|
+
import useWindowSize from './useWindowSize'
|
|
6
|
+
|
|
7
|
+
const verticalPositions = ['top', 'bottom']
|
|
8
|
+
const horizontalPositions = ['left', 'right']
|
|
9
|
+
|
|
10
|
+
const findCompatiblePositions = (primary, secondaryArray) => {
|
|
11
|
+
if (verticalPositions.includes(primary)) {
|
|
12
|
+
return secondaryArray.filter((secondary) => horizontalPositions.includes(secondary))
|
|
13
|
+
} if (horizontalPositions.includes(primary)) {
|
|
14
|
+
return secondaryArray.filter((secondary) => verticalPositions.includes(secondary))
|
|
15
|
+
}
|
|
16
|
+
return []
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const useDynamicPosition = ({
|
|
20
|
+
elementRef,
|
|
21
|
+
parentRef,
|
|
22
|
+
preferredPrimaryOrder,
|
|
23
|
+
preferredSecondaryOrder,
|
|
24
|
+
// offsetYPx,
|
|
25
|
+
offsetXPx,
|
|
26
|
+
throttleMs = 200,
|
|
27
|
+
}) => {
|
|
28
|
+
const isClient = typeof window === 'object'
|
|
29
|
+
const {
|
|
30
|
+
height:currentHeight,
|
|
31
|
+
width:currentWidth,
|
|
32
|
+
} = useWindowSize()
|
|
33
|
+
|
|
34
|
+
const [primaryPosition, setPrimaryPosition] = useState(preferredPrimaryOrder[0])
|
|
35
|
+
const compatibleSecondaryPositions = useMemo(
|
|
36
|
+
() => findCompatiblePositions(
|
|
37
|
+
primaryPosition,
|
|
38
|
+
preferredSecondaryOrder,
|
|
39
|
+
), [primaryPosition, preferredSecondaryOrder],
|
|
40
|
+
)
|
|
41
|
+
const [secondaryPosition, setSecondaryPosition] = useState(compatibleSecondaryPositions[0])
|
|
42
|
+
|
|
43
|
+
const handle = useCallback(
|
|
44
|
+
throttle(() => {
|
|
45
|
+
const parentNode = parentRef?.current
|
|
46
|
+
const elementNode = elementRef?.current
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
top:parentTop,
|
|
50
|
+
bottom: parentBottom,
|
|
51
|
+
right: parentRight,
|
|
52
|
+
left: parentLeft,
|
|
53
|
+
} = parentNode?.getBoundingClientRect() || {}
|
|
54
|
+
|
|
55
|
+
const {
|
|
56
|
+
width:elementWidth,
|
|
57
|
+
height:elementHeight,
|
|
58
|
+
} = elementNode?.getBoundingClientRect() || {}
|
|
59
|
+
|
|
60
|
+
const availablePositions = {
|
|
61
|
+
top :parentTop >= elementHeight,
|
|
62
|
+
bottom:currentHeight - parentBottom >= elementHeight,
|
|
63
|
+
right :parentRight >= elementWidth,
|
|
64
|
+
left :currentWidth - parentLeft >= elementWidth,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < preferredPrimaryOrder.length; i += 1) {
|
|
68
|
+
const position = preferredPrimaryOrder[i]
|
|
69
|
+
if (availablePositions[position]) {
|
|
70
|
+
setPrimaryPosition(position)
|
|
71
|
+
break
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (let i = 0; i < compatibleSecondaryPositions.length; i += 1) {
|
|
76
|
+
const position = compatibleSecondaryPositions[i]
|
|
77
|
+
if (availablePositions[position]) {
|
|
78
|
+
setSecondaryPosition(position)
|
|
79
|
+
break
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, throttleMs),
|
|
83
|
+
[elementRef, offsetXPx, throttleMs],
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (!isClient) {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
handle()
|
|
92
|
+
window.addEventListener('scroll', handle)
|
|
93
|
+
window.addEventListener('resize', handle)
|
|
94
|
+
|
|
95
|
+
return () => {
|
|
96
|
+
window.removeEventListener('scroll', handle)
|
|
97
|
+
window.removeEventListener('resize', handle)
|
|
98
|
+
}
|
|
99
|
+
}, [handle])
|
|
100
|
+
|
|
101
|
+
return { primaryPosition, secondaryPosition }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default useDynamicPosition
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useCallback, useState, useEffect } from 'react'
|
|
2
|
+
import debounce from 'lodash/debounce'
|
|
3
|
+
|
|
4
|
+
const useWindowSize = (debounceMs = 700) => {
|
|
5
|
+
const isClient = typeof window === 'object'
|
|
6
|
+
|
|
7
|
+
const getSize = () => ({
|
|
8
|
+
width :isClient ? window.innerWidth : undefined,
|
|
9
|
+
height:isClient ? window.innerHeight : undefined,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const [windowSize, setWindowSize] = useState(getSize)
|
|
13
|
+
|
|
14
|
+
const handle = useCallback(
|
|
15
|
+
debounce(() => {
|
|
16
|
+
setWindowSize(getSize())
|
|
17
|
+
}, debounceMs),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!isClient) {
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
window.addEventListener('resize', handle)
|
|
26
|
+
return () => window.removeEventListener('resize', handle)
|
|
27
|
+
}, [getSize, handle, isClient])
|
|
28
|
+
|
|
29
|
+
return windowSize
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default useWindowSize
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useWindowSize, useDynamicPosition } from './hooks'
|