@pareto-engineering/design-system 2.0.0-alpha.40 → 2.0.0-alpha.43

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 (198) 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 +33 -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/ContentSlides/common/HorizontalMenu/HorizontalMenu.js +11 -4
  33. package/dist/cjs/c/SiteFooter/SiteFooter.js +73 -0
  34. package/dist/cjs/c/SiteFooter/common/Section/Section.js +95 -0
  35. package/dist/cjs/c/SiteFooter/common/Section/index.js +15 -0
  36. package/dist/cjs/c/SiteFooter/common/index.js +13 -0
  37. package/dist/cjs/c/SiteFooter/index.js +15 -0
  38. package/dist/cjs/c/SiteFooter/styles.scss +34 -0
  39. package/dist/cjs/c/SiteHeaderCTA/SiteHeaderCTA.js +108 -0
  40. package/dist/cjs/c/SiteHeaderCTA/index.js +15 -0
  41. package/dist/cjs/c/SiteHeaderCTA/styles.scss +44 -0
  42. package/dist/cjs/c/SiteMission/SiteMission.js +113 -0
  43. package/dist/cjs/c/SiteMission/index.js +15 -0
  44. package/dist/cjs/c/SiteMission/styles.scss +30 -0
  45. package/dist/cjs/c/SiteNavigation/SiteNavigation.js +130 -0
  46. package/dist/cjs/c/SiteNavigation/index.js +15 -0
  47. package/dist/cjs/c/SiteNavigation/styles.scss +118 -0
  48. package/dist/cjs/c/SiteOnboardingStep/SiteOnboardingStep.js +98 -0
  49. package/dist/cjs/c/SiteOnboardingStep/index.js +15 -0
  50. package/dist/cjs/c/SiteOnboardingStep/styles.scss +51 -0
  51. package/dist/cjs/c/SitePricing/SitePricing.js +108 -0
  52. package/dist/cjs/c/SitePricing/index.js +15 -0
  53. package/dist/cjs/c/SitePricing/styles.scss +73 -0
  54. package/dist/cjs/c/SiteServices/SiteServices.js +211 -0
  55. package/dist/cjs/c/SiteServices/index.js +15 -0
  56. package/dist/cjs/c/SiteServices/styles.scss +138 -0
  57. package/dist/cjs/c/TeamGallery/TeamGallery.js +80 -0
  58. package/dist/cjs/c/TeamGallery/common/PersonCard/PersonCard.js +84 -0
  59. package/dist/cjs/c/TeamGallery/common/PersonCard/index.js +15 -0
  60. package/dist/cjs/c/TeamGallery/common/index.js +13 -0
  61. package/dist/cjs/c/TeamGallery/index.js +15 -0
  62. package/dist/cjs/c/TeamGallery/styles.scss +100 -0
  63. package/dist/cjs/c/Testimonials/Testimonials.js +119 -0
  64. package/dist/cjs/c/Testimonials/index.js +15 -0
  65. package/dist/cjs/c/Testimonials/styles.scss +112 -0
  66. package/dist/cjs/experimental/GradientBackground/GradientBackground.js +98 -0
  67. package/dist/cjs/experimental/GradientBackground/index.js +15 -0
  68. package/dist/cjs/experimental/GradientBackground/styles.scss +64 -0
  69. package/dist/cjs/experimental/index.js +13 -0
  70. package/dist/cjs/f/fields/CheckboxInput/CheckboxInput.js +105 -0
  71. package/dist/cjs/f/fields/CheckboxInput/index.js +15 -0
  72. package/dist/cjs/f/fields/CheckboxInput/styles.scss +28 -0
  73. package/dist/cjs/f/fields/RadioInput/RadioInput.js +110 -0
  74. package/dist/cjs/f/fields/RadioInput/index.js +15 -0
  75. package/dist/cjs/f/fields/RadioInput/styles.scss +26 -0
  76. package/dist/cjs/f/fields/RatingsInput/RatingsInput.js +10 -2
  77. package/dist/cjs/f/fields/TaskRecommendation/TaskRecommendation.js +129 -0
  78. package/dist/cjs/f/fields/TaskRecommendation/index.js +15 -0
  79. package/dist/cjs/f/fields/TaskRecommendation/styles.scss +37 -0
  80. package/dist/cjs/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +131 -0
  81. package/dist/cjs/f/fields/TaskRecommendationInput/index.js +15 -0
  82. package/dist/cjs/f/fields/TaskRecommendationInput/styles.scss +41 -0
  83. package/dist/cjs/f/fields/TextArea/TextArea.js +141 -0
  84. package/dist/cjs/f/fields/TextArea/index.js +15 -0
  85. package/dist/cjs/f/fields/TextArea/styles.scss +19 -0
  86. package/dist/cjs/f/fields/TextInput/TextInput.js +10 -3
  87. package/dist/cjs/index.js +13 -0
  88. package/dist/cjs/utils/hooks/index.js +23 -0
  89. package/dist/cjs/utils/hooks/useDynamicPosition.js +107 -0
  90. package/dist/cjs/utils/hooks/useWindowSize.js +39 -0
  91. package/dist/cjs/utils/index.js +19 -0
  92. package/dist/es/a/GradientBackground/GradientBackground.js +118 -0
  93. package/dist/es/a/GradientBackground/index.js +2 -0
  94. package/dist/es/a/GradientBackground/styles.scss +191 -0
  95. package/dist/es/a/Popover/Popover.js +118 -0
  96. package/dist/es/a/Popover/common/Divider/Divider.js +47 -0
  97. package/dist/es/a/Popover/common/Divider/index.js +2 -0
  98. package/dist/es/a/Popover/common/Item/Item.js +47 -0
  99. package/dist/es/a/Popover/common/Item/index.js +2 -0
  100. package/dist/es/a/Popover/common/index.js +2 -0
  101. package/dist/es/a/Popover/index.js +2 -0
  102. package/dist/es/a/Popover/styles.scss +33 -0
  103. package/dist/es/a/index.js +2 -1
  104. package/dist/es/c/AcceptCookies/AcceptCookies.js +117 -0
  105. package/dist/es/c/AcceptCookies/index.js +2 -0
  106. package/dist/es/c/AcceptCookies/styles.scss +49 -0
  107. package/dist/es/c/BlogCategoryButton/BlogCategoryButton.js +68 -0
  108. package/dist/es/c/BlogCategoryButton/index.js +2 -0
  109. package/dist/es/c/BlogContext/BlogContextProvider.js +45 -0
  110. package/dist/es/c/BlogContext/Context.js +2 -0
  111. package/dist/es/c/BlogContext/ContextProvider.js +45 -0
  112. package/dist/es/c/BlogContext/index.js +4 -0
  113. package/dist/es/c/BlogContext/useBlog.js +3 -0
  114. package/dist/es/c/BlogPost/BlogPost.js +128 -0
  115. package/dist/es/c/BlogPost/index.js +2 -0
  116. package/dist/es/c/BlogPost/styles.scss +33 -0
  117. package/dist/es/c/BlogPostsList/BlogPostsList.js +56 -0
  118. package/dist/es/c/BlogPostsList/common/Card/Card.js +143 -0
  119. package/dist/es/c/BlogPostsList/common/Card/index.js +2 -0
  120. package/dist/es/c/BlogPostsList/common/index.js +1 -0
  121. package/dist/es/c/BlogPostsList/index.js +2 -0
  122. package/dist/es/c/BlogPostsList/styles.scss +72 -0
  123. package/dist/es/c/ContentSlides/common/HorizontalMenu/HorizontalMenu.js +11 -4
  124. package/dist/es/c/SiteFooter/SiteFooter.js +56 -0
  125. package/dist/es/c/SiteFooter/common/Section/Section.js +73 -0
  126. package/dist/es/c/SiteFooter/common/Section/index.js +2 -0
  127. package/dist/es/c/SiteFooter/common/index.js +1 -0
  128. package/dist/es/c/SiteFooter/index.js +2 -0
  129. package/dist/es/c/SiteFooter/styles.scss +34 -0
  130. package/dist/es/c/SiteHeaderCTA/SiteHeaderCTA.js +92 -0
  131. package/dist/es/c/SiteHeaderCTA/index.js +2 -0
  132. package/dist/es/c/SiteHeaderCTA/styles.scss +44 -0
  133. package/dist/es/c/SiteMission/SiteMission.js +96 -0
  134. package/dist/es/c/SiteMission/index.js +2 -0
  135. package/dist/es/c/SiteMission/styles.scss +30 -0
  136. package/dist/es/c/SiteNavigation/SiteNavigation.js +111 -0
  137. package/dist/es/c/SiteNavigation/index.js +2 -0
  138. package/dist/es/c/SiteNavigation/styles.scss +118 -0
  139. package/dist/es/c/SiteOnboardingStep/SiteOnboardingStep.js +81 -0
  140. package/dist/es/c/SiteOnboardingStep/index.js +2 -0
  141. package/dist/es/c/SiteOnboardingStep/styles.scss +51 -0
  142. package/dist/es/c/SitePricing/SitePricing.js +91 -0
  143. package/dist/es/c/SitePricing/index.js +2 -0
  144. package/dist/es/c/SitePricing/styles.scss +73 -0
  145. package/dist/es/c/SiteServices/SiteServices.js +195 -0
  146. package/dist/es/c/SiteServices/index.js +2 -0
  147. package/dist/es/c/SiteServices/styles.scss +138 -0
  148. package/dist/es/c/TeamGallery/TeamGallery.js +64 -0
  149. package/dist/es/c/TeamGallery/common/PersonCard/PersonCard.js +64 -0
  150. package/dist/es/c/TeamGallery/common/PersonCard/index.js +2 -0
  151. package/dist/es/c/TeamGallery/common/index.js +1 -0
  152. package/dist/es/c/TeamGallery/index.js +2 -0
  153. package/dist/es/c/TeamGallery/styles.scss +100 -0
  154. package/dist/es/c/Testimonials/Testimonials.js +99 -0
  155. package/dist/es/c/Testimonials/index.js +2 -0
  156. package/dist/es/c/Testimonials/styles.scss +112 -0
  157. package/dist/es/experimental/GradientBackground/GradientBackground.js +76 -0
  158. package/dist/es/experimental/GradientBackground/index.js +2 -0
  159. package/dist/es/experimental/GradientBackground/styles.scss +64 -0
  160. package/dist/es/experimental/index.js +1 -0
  161. package/dist/es/f/fields/CheckboxInput/CheckboxInput.js +85 -0
  162. package/dist/es/f/fields/CheckboxInput/index.js +2 -0
  163. package/dist/es/f/fields/CheckboxInput/styles.scss +28 -0
  164. package/dist/es/f/fields/RadioInput/RadioInput.js +90 -0
  165. package/dist/es/f/fields/RadioInput/index.js +2 -0
  166. package/dist/es/f/fields/RadioInput/styles.scss +26 -0
  167. package/dist/es/f/fields/RatingsInput/RatingsInput.js +10 -2
  168. package/dist/es/f/fields/TaskRecommendation/TaskRecommendation.js +111 -0
  169. package/dist/es/f/fields/TaskRecommendation/index.js +2 -0
  170. package/dist/es/f/fields/TaskRecommendation/styles.scss +37 -0
  171. package/dist/es/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +111 -0
  172. package/dist/es/f/fields/TaskRecommendationInput/index.js +2 -0
  173. package/dist/es/f/fields/TaskRecommendationInput/styles.scss +41 -0
  174. package/dist/es/f/fields/TextArea/TextArea.js +124 -0
  175. package/dist/es/f/fields/TextArea/index.js +2 -0
  176. package/dist/es/f/fields/TextArea/styles.scss +19 -0
  177. package/dist/es/f/fields/TextInput/TextInput.js +10 -3
  178. package/dist/es/index.js +2 -1
  179. package/dist/es/utils/hooks/index.js +2 -0
  180. package/dist/es/utils/hooks/useDynamicPosition.js +93 -0
  181. package/dist/es/utils/hooks/useWindowSize.js +27 -0
  182. package/dist/es/utils/index.js +1 -0
  183. package/package.json +1 -1
  184. package/src/__snapshots__/Storyshots.test.js.snap +413 -1
  185. package/src/stories/a/Popover.stories.jsx +106 -0
  186. package/src/stories/utils/lorem.js +15 -0
  187. package/src/ui/a/Popover/Popover.jsx +157 -0
  188. package/src/ui/a/Popover/index.js +2 -0
  189. package/src/ui/a/Popover/styles.scss +33 -0
  190. package/src/ui/a/index.js +1 -0
  191. package/src/ui/c/ContentSlides/common/HorizontalMenu/HorizontalMenu.jsx +8 -1
  192. package/src/ui/f/fields/RatingsInput/RatingsInput.jsx +10 -2
  193. package/src/ui/f/fields/TextInput/TextInput.jsx +7 -0
  194. package/src/ui/index.js +1 -0
  195. package/src/ui/utils/hooks/index.js +2 -0
  196. package/src/ui/utils/hooks/useDynamicPosition.js +104 -0
  197. package/src/ui/utils/hooks/useWindowSize.js +32 -0
  198. 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,33 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ @use "@pareto-engineering/bem";
3
+
4
+ $default-border: var(--theme-border-style) var(--metadata);
5
+
6
+ .#{bem.$base}.popover {
7
+ position: absolute;
8
+ z-index: 1;
9
+ background-color: var(--x);
10
+ border: $default-border;
11
+
12
+ &:not(.open) {
13
+ display: none;
14
+ }
15
+
16
+ &.bottom {
17
+ top: 100%;
18
+ // bottom: 0;
19
+ }
20
+
21
+ &.left {
22
+ left: 0;
23
+ }
24
+
25
+ &.right {
26
+ right: 0;
27
+ }
28
+
29
+ &.top {
30
+ bottom: 100%;
31
+ top: auto;
32
+ }
33
+ }
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'
@@ -24,6 +24,7 @@ const HorizontalMenu = ({
24
24
  hideBackIcon,
25
25
  stepsBackwards,
26
26
  customPrevStep,
27
+ color,
27
28
  // ...otherProps
28
29
  }) => {
29
30
  const {
@@ -59,7 +60,7 @@ const HorizontalMenu = ({
59
60
  >
60
61
  {
61
62
  (currentStep?.progress > 0)
62
- && <ProgressBar progress={currentStep.progress} attached height=".4em" color="main2" className="y-background1 b-dark-y" />
63
+ && <ProgressBar progress={currentStep.progress} attached height=".4em" color={color} className="y-background1 b-dark-y" />
63
64
  }
64
65
  <div className={styleNames.elementContent}>
65
66
  <div className="left">
@@ -128,11 +129,17 @@ HorizontalMenu.propTypes = {
128
129
  * Hide back icon boolean
129
130
  */
130
131
  hideBackIcon:PropTypes.bool,
132
+
133
+ /**
134
+ * String that will represent color for Progress bar
135
+ */
136
+ color:PropTypes.string,
131
137
  }
132
138
 
133
139
  HorizontalMenu.defaultProps = {
134
140
  logoColor :'paragraph',
135
141
  stepsBackwards:1,
142
+ color :'main2',
136
143
  }
137
144
 
138
145
  export default HorizontalMenu
@@ -28,6 +28,7 @@ const RatingsInput = ({
28
28
  showRatingValue,
29
29
  oneInputLabel,
30
30
  label,
31
+ labelColor,
31
32
  labelMax,
32
33
  labelMin,
33
34
  displayRatingsLabel,
@@ -58,6 +59,7 @@ const RatingsInput = ({
58
59
  .filter((e) => e)
59
60
  .join(' ')}
60
61
  name={name}
62
+ color={labelColor}
61
63
  optional={optional}
62
64
  >
63
65
  { label }
@@ -136,11 +138,17 @@ RatingsInput.propTypes = {
136
138
  * If the slide will only have one input
137
139
  */
138
140
  oneInputLabel :PropTypes.bool,
141
+
142
+ /**
143
+ * String that will represent color for the label
144
+ */
145
+ labelColor:PropTypes.string,
139
146
  }
140
147
 
141
148
  RatingsInput.defaultProps = {
142
- labelMin:'not satisfied.',
143
- labelMax:'very satisfied.',
149
+ labelMin :'not satisfied.',
150
+ labelMax :'very satisfied.',
151
+ labelColor:'main2',
144
152
  }
145
153
 
146
154
  export default memo(RatingsInput)
@@ -34,6 +34,7 @@ const TextInput = ({
34
34
  description,
35
35
  disabled,
36
36
  placeholder,
37
+ optional,
37
38
  // ...otherProps
38
39
  }) => {
39
40
  useLayoutEffect(() => {
@@ -62,6 +63,7 @@ const TextInput = ({
62
63
  .join(' ')}
63
64
  name={name}
64
65
  color={labelColor}
66
+ optional={optional}
65
67
  >
66
68
  { label }
67
69
  </FormLabel>
@@ -156,6 +158,11 @@ TextInput.propTypes = {
156
158
  * The text input color
157
159
  */
158
160
  color:PropTypes.string,
161
+
162
+ /**
163
+ * Whether the input is optional or not
164
+ */
165
+ optional:PropTypes.bool,
159
166
  }
160
167
 
161
168
  TextInput.defaultProps = {
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'