@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.
Files changed (189) hide show
  1. package/dist/cjs/a/GradientBackground/GradientBackground.js +140 -0
  2. package/dist/cjs/a/GradientBackground/index.js +15 -0
  3. package/dist/cjs/a/GradientBackground/styles.scss +191 -0
  4. package/dist/cjs/a/Popover/Popover.js +134 -0
  5. package/dist/cjs/a/Popover/common/Divider/Divider.js +67 -0
  6. package/dist/cjs/a/Popover/common/Divider/index.js +15 -0
  7. package/dist/cjs/a/Popover/common/Item/Item.js +67 -0
  8. package/dist/cjs/a/Popover/common/Item/index.js +15 -0
  9. package/dist/cjs/a/Popover/common/index.js +21 -0
  10. package/dist/cjs/a/Popover/index.js +15 -0
  11. package/dist/cjs/a/Popover/styles.scss +43 -0
  12. package/dist/cjs/a/index.js +9 -1
  13. package/dist/cjs/c/AcceptCookies/AcceptCookies.js +134 -0
  14. package/dist/cjs/c/AcceptCookies/index.js +15 -0
  15. package/dist/cjs/c/AcceptCookies/styles.scss +49 -0
  16. package/dist/cjs/c/BlogCategoryButton/BlogCategoryButton.js +95 -0
  17. package/dist/cjs/c/BlogCategoryButton/index.js +15 -0
  18. package/dist/cjs/c/BlogContext/BlogContextProvider.js +63 -0
  19. package/dist/cjs/c/BlogContext/Context.js +16 -0
  20. package/dist/cjs/c/BlogContext/ContextProvider.js +63 -0
  21. package/dist/cjs/c/BlogContext/index.js +31 -0
  22. package/dist/cjs/c/BlogContext/useBlog.js +16 -0
  23. package/dist/cjs/c/BlogPost/BlogPost.js +147 -0
  24. package/dist/cjs/c/BlogPost/index.js +15 -0
  25. package/dist/cjs/c/BlogPost/styles.scss +33 -0
  26. package/dist/cjs/c/BlogPostsList/BlogPostsList.js +73 -0
  27. package/dist/cjs/c/BlogPostsList/common/Card/Card.js +170 -0
  28. package/dist/cjs/c/BlogPostsList/common/Card/index.js +15 -0
  29. package/dist/cjs/c/BlogPostsList/common/index.js +13 -0
  30. package/dist/cjs/c/BlogPostsList/index.js +15 -0
  31. package/dist/cjs/c/BlogPostsList/styles.scss +72 -0
  32. package/dist/cjs/c/SiteFooter/SiteFooter.js +73 -0
  33. package/dist/cjs/c/SiteFooter/common/Section/Section.js +95 -0
  34. package/dist/cjs/c/SiteFooter/common/Section/index.js +15 -0
  35. package/dist/cjs/c/SiteFooter/common/index.js +13 -0
  36. package/dist/cjs/c/SiteFooter/index.js +15 -0
  37. package/dist/cjs/c/SiteFooter/styles.scss +34 -0
  38. package/dist/cjs/c/SiteHeaderCTA/SiteHeaderCTA.js +108 -0
  39. package/dist/cjs/c/SiteHeaderCTA/index.js +15 -0
  40. package/dist/cjs/c/SiteHeaderCTA/styles.scss +44 -0
  41. package/dist/cjs/c/SiteMission/SiteMission.js +113 -0
  42. package/dist/cjs/c/SiteMission/index.js +15 -0
  43. package/dist/cjs/c/SiteMission/styles.scss +30 -0
  44. package/dist/cjs/c/SiteNavigation/SiteNavigation.js +130 -0
  45. package/dist/cjs/c/SiteNavigation/index.js +15 -0
  46. package/dist/cjs/c/SiteNavigation/styles.scss +118 -0
  47. package/dist/cjs/c/SiteOnboardingStep/SiteOnboardingStep.js +98 -0
  48. package/dist/cjs/c/SiteOnboardingStep/index.js +15 -0
  49. package/dist/cjs/c/SiteOnboardingStep/styles.scss +51 -0
  50. package/dist/cjs/c/SitePricing/SitePricing.js +108 -0
  51. package/dist/cjs/c/SitePricing/index.js +15 -0
  52. package/dist/cjs/c/SitePricing/styles.scss +73 -0
  53. package/dist/cjs/c/SiteServices/SiteServices.js +211 -0
  54. package/dist/cjs/c/SiteServices/index.js +15 -0
  55. package/dist/cjs/c/SiteServices/styles.scss +138 -0
  56. package/dist/cjs/c/TeamGallery/TeamGallery.js +80 -0
  57. package/dist/cjs/c/TeamGallery/common/PersonCard/PersonCard.js +84 -0
  58. package/dist/cjs/c/TeamGallery/common/PersonCard/index.js +15 -0
  59. package/dist/cjs/c/TeamGallery/common/index.js +13 -0
  60. package/dist/cjs/c/TeamGallery/index.js +15 -0
  61. package/dist/cjs/c/TeamGallery/styles.scss +100 -0
  62. package/dist/cjs/c/Testimonials/Testimonials.js +119 -0
  63. package/dist/cjs/c/Testimonials/index.js +15 -0
  64. package/dist/cjs/c/Testimonials/styles.scss +112 -0
  65. package/dist/cjs/experimental/GradientBackground/GradientBackground.js +98 -0
  66. package/dist/cjs/experimental/GradientBackground/index.js +15 -0
  67. package/dist/cjs/experimental/GradientBackground/styles.scss +64 -0
  68. package/dist/cjs/experimental/index.js +13 -0
  69. package/dist/cjs/f/fields/CheckboxInput/CheckboxInput.js +105 -0
  70. package/dist/cjs/f/fields/CheckboxInput/index.js +15 -0
  71. package/dist/cjs/f/fields/CheckboxInput/styles.scss +28 -0
  72. package/dist/cjs/f/fields/RadioInput/RadioInput.js +110 -0
  73. package/dist/cjs/f/fields/RadioInput/index.js +15 -0
  74. package/dist/cjs/f/fields/RadioInput/styles.scss +26 -0
  75. package/dist/cjs/f/fields/TaskRecommendation/TaskRecommendation.js +129 -0
  76. package/dist/cjs/f/fields/TaskRecommendation/index.js +15 -0
  77. package/dist/cjs/f/fields/TaskRecommendation/styles.scss +37 -0
  78. package/dist/cjs/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +131 -0
  79. package/dist/cjs/f/fields/TaskRecommendationInput/index.js +15 -0
  80. package/dist/cjs/f/fields/TaskRecommendationInput/styles.scss +41 -0
  81. package/dist/cjs/f/fields/TextArea/TextArea.js +141 -0
  82. package/dist/cjs/f/fields/TextArea/index.js +15 -0
  83. package/dist/cjs/f/fields/TextArea/styles.scss +19 -0
  84. package/dist/cjs/index.js +13 -0
  85. package/dist/cjs/utils/hooks/index.js +23 -0
  86. package/dist/cjs/utils/hooks/useDynamicPosition.js +107 -0
  87. package/dist/cjs/utils/hooks/useWindowSize.js +39 -0
  88. package/dist/cjs/utils/index.js +19 -0
  89. package/dist/es/a/GradientBackground/GradientBackground.js +118 -0
  90. package/dist/es/a/GradientBackground/index.js +2 -0
  91. package/dist/es/a/GradientBackground/styles.scss +191 -0
  92. package/dist/es/a/Popover/Popover.js +118 -0
  93. package/dist/es/a/Popover/common/Divider/Divider.js +47 -0
  94. package/dist/es/a/Popover/common/Divider/index.js +2 -0
  95. package/dist/es/a/Popover/common/Item/Item.js +47 -0
  96. package/dist/es/a/Popover/common/Item/index.js +2 -0
  97. package/dist/es/a/Popover/common/index.js +2 -0
  98. package/dist/es/a/Popover/index.js +2 -0
  99. package/dist/es/a/Popover/styles.scss +43 -0
  100. package/dist/es/a/index.js +2 -1
  101. package/dist/es/c/AcceptCookies/AcceptCookies.js +117 -0
  102. package/dist/es/c/AcceptCookies/index.js +2 -0
  103. package/dist/es/c/AcceptCookies/styles.scss +49 -0
  104. package/dist/es/c/BlogCategoryButton/BlogCategoryButton.js +68 -0
  105. package/dist/es/c/BlogCategoryButton/index.js +2 -0
  106. package/dist/es/c/BlogContext/BlogContextProvider.js +45 -0
  107. package/dist/es/c/BlogContext/Context.js +2 -0
  108. package/dist/es/c/BlogContext/ContextProvider.js +45 -0
  109. package/dist/es/c/BlogContext/index.js +4 -0
  110. package/dist/es/c/BlogContext/useBlog.js +3 -0
  111. package/dist/es/c/BlogPost/BlogPost.js +128 -0
  112. package/dist/es/c/BlogPost/index.js +2 -0
  113. package/dist/es/c/BlogPost/styles.scss +33 -0
  114. package/dist/es/c/BlogPostsList/BlogPostsList.js +56 -0
  115. package/dist/es/c/BlogPostsList/common/Card/Card.js +143 -0
  116. package/dist/es/c/BlogPostsList/common/Card/index.js +2 -0
  117. package/dist/es/c/BlogPostsList/common/index.js +1 -0
  118. package/dist/es/c/BlogPostsList/index.js +2 -0
  119. package/dist/es/c/BlogPostsList/styles.scss +72 -0
  120. package/dist/es/c/SiteFooter/SiteFooter.js +56 -0
  121. package/dist/es/c/SiteFooter/common/Section/Section.js +73 -0
  122. package/dist/es/c/SiteFooter/common/Section/index.js +2 -0
  123. package/dist/es/c/SiteFooter/common/index.js +1 -0
  124. package/dist/es/c/SiteFooter/index.js +2 -0
  125. package/dist/es/c/SiteFooter/styles.scss +34 -0
  126. package/dist/es/c/SiteHeaderCTA/SiteHeaderCTA.js +92 -0
  127. package/dist/es/c/SiteHeaderCTA/index.js +2 -0
  128. package/dist/es/c/SiteHeaderCTA/styles.scss +44 -0
  129. package/dist/es/c/SiteMission/SiteMission.js +96 -0
  130. package/dist/es/c/SiteMission/index.js +2 -0
  131. package/dist/es/c/SiteMission/styles.scss +30 -0
  132. package/dist/es/c/SiteNavigation/SiteNavigation.js +111 -0
  133. package/dist/es/c/SiteNavigation/index.js +2 -0
  134. package/dist/es/c/SiteNavigation/styles.scss +118 -0
  135. package/dist/es/c/SiteOnboardingStep/SiteOnboardingStep.js +81 -0
  136. package/dist/es/c/SiteOnboardingStep/index.js +2 -0
  137. package/dist/es/c/SiteOnboardingStep/styles.scss +51 -0
  138. package/dist/es/c/SitePricing/SitePricing.js +91 -0
  139. package/dist/es/c/SitePricing/index.js +2 -0
  140. package/dist/es/c/SitePricing/styles.scss +73 -0
  141. package/dist/es/c/SiteServices/SiteServices.js +195 -0
  142. package/dist/es/c/SiteServices/index.js +2 -0
  143. package/dist/es/c/SiteServices/styles.scss +138 -0
  144. package/dist/es/c/TeamGallery/TeamGallery.js +64 -0
  145. package/dist/es/c/TeamGallery/common/PersonCard/PersonCard.js +64 -0
  146. package/dist/es/c/TeamGallery/common/PersonCard/index.js +2 -0
  147. package/dist/es/c/TeamGallery/common/index.js +1 -0
  148. package/dist/es/c/TeamGallery/index.js +2 -0
  149. package/dist/es/c/TeamGallery/styles.scss +100 -0
  150. package/dist/es/c/Testimonials/Testimonials.js +99 -0
  151. package/dist/es/c/Testimonials/index.js +2 -0
  152. package/dist/es/c/Testimonials/styles.scss +112 -0
  153. package/dist/es/experimental/GradientBackground/GradientBackground.js +76 -0
  154. package/dist/es/experimental/GradientBackground/index.js +2 -0
  155. package/dist/es/experimental/GradientBackground/styles.scss +64 -0
  156. package/dist/es/experimental/index.js +1 -0
  157. package/dist/es/f/fields/CheckboxInput/CheckboxInput.js +85 -0
  158. package/dist/es/f/fields/CheckboxInput/index.js +2 -0
  159. package/dist/es/f/fields/CheckboxInput/styles.scss +28 -0
  160. package/dist/es/f/fields/RadioInput/RadioInput.js +90 -0
  161. package/dist/es/f/fields/RadioInput/index.js +2 -0
  162. package/dist/es/f/fields/RadioInput/styles.scss +26 -0
  163. package/dist/es/f/fields/TaskRecommendation/TaskRecommendation.js +111 -0
  164. package/dist/es/f/fields/TaskRecommendation/index.js +2 -0
  165. package/dist/es/f/fields/TaskRecommendation/styles.scss +37 -0
  166. package/dist/es/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +111 -0
  167. package/dist/es/f/fields/TaskRecommendationInput/index.js +2 -0
  168. package/dist/es/f/fields/TaskRecommendationInput/styles.scss +41 -0
  169. package/dist/es/f/fields/TextArea/TextArea.js +124 -0
  170. package/dist/es/f/fields/TextArea/index.js +2 -0
  171. package/dist/es/f/fields/TextArea/styles.scss +19 -0
  172. package/dist/es/index.js +2 -1
  173. package/dist/es/utils/hooks/index.js +2 -0
  174. package/dist/es/utils/hooks/useDynamicPosition.js +93 -0
  175. package/dist/es/utils/hooks/useWindowSize.js +27 -0
  176. package/dist/es/utils/index.js +1 -0
  177. package/package.json +1 -1
  178. package/src/__snapshots__/Storyshots.test.js.snap +413 -1
  179. package/src/stories/a/Popover.stories.jsx +106 -0
  180. package/src/stories/utils/lorem.js +15 -0
  181. package/src/ui/a/Popover/Popover.jsx +157 -0
  182. package/src/ui/a/Popover/index.js +2 -0
  183. package/src/ui/a/Popover/styles.scss +43 -0
  184. package/src/ui/a/index.js +1 -0
  185. package/src/ui/index.js +1 -0
  186. package/src/ui/utils/hooks/index.js +2 -0
  187. package/src/ui/utils/hooks/useDynamicPosition.js +104 -0
  188. package/src/ui/utils/hooks/useWindowSize.js +32 -0
  189. 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,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Popover } from './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
@@ -28,3 +28,4 @@ export { OvalIllustration } from './OvalIllustration'
28
28
  export { SnapScroller } from './SnapScroller'
29
29
  export { BackgroundGradient } from './BackgroundGradient'
30
30
  export { ContentTree } from './ContentTree'
31
+ export { Popover } from './Popover'
package/src/ui/index.js CHANGED
@@ -4,3 +4,4 @@ export * from './b'
4
4
  export * from './c'
5
5
  export * from './d'
6
6
  export * from './f'
7
+ export * from './utils'
@@ -0,0 +1,2 @@
1
+ export { default as useWindowSize } from './useWindowSize'
2
+ export { default as useDynamicPosition } from './useDynamicPosition'
@@ -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'