@codeleap/web 3.21.5 → 3.21.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.21.5",
3
+ "version": "3.21.7",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -126,6 +126,7 @@ const PagerComponent = (
126
126
  return (
127
127
  <View css={[variantStyles.wrapper, style]}>
128
128
  <Slider
129
+ adaptiveHeight={true}
129
130
  {...rest}
130
131
  arrows={false}
131
132
  ref={sliderRef}
@@ -1,5 +1,6 @@
1
1
  export * from './pollyfils/scroll'
2
2
  export * from './stopPropagation'
3
+ export * from './useMaxContentWidth'
3
4
  export { default as url } from 'url-parse'
4
5
  export { default as Cookies } from './cookies'
5
6
 
@@ -0,0 +1,49 @@
1
+ import { useCodeleapContext } from '@codeleap/common'
2
+ import { useWindowSize } from '../hooks'
3
+
4
+ export const useMaxContentWidth = () => {
5
+
6
+ const { Theme } = useCodeleapContext()
7
+ const [width, height] = useWindowSize()
8
+
9
+ const breakpoints: Record<string, number> = Theme.breakpoints
10
+
11
+ const safeHorizontalPaddings = Theme.safeHorizontalPaddings()
12
+
13
+ const entries = Object.keys(safeHorizontalPaddings)
14
+
15
+ const sortedBreakpointsValues = Object.entries(breakpoints).sort((a, b) => b?.[1] - a?.[1])
16
+ const highestBreakpoint = sortedBreakpointsValues[0]
17
+
18
+ let currentBreakpoint = null
19
+ let maxContentWidth = Theme.values.maxContentWidth
20
+
21
+ const maxBreakpointEntryName = highestBreakpoint[0]
22
+
23
+ const maxPaddingApplied = width >= breakpoints[maxBreakpointEntryName]
24
+ const hasScreenReachedMaxWidth = width >= Theme.values.maxContentWidth
25
+
26
+ entries.forEach(breakpoint => {
27
+ if (window?.innerWidth <= breakpoints[breakpoint]) {
28
+ currentBreakpoint = breakpoint
29
+ }
30
+ })
31
+
32
+ if (maxPaddingApplied) {
33
+ maxContentWidth = Theme.values.maxContentWidth - (safeHorizontalPaddings[maxBreakpointEntryName] * 2)
34
+ } else {
35
+ if (currentBreakpoint === maxBreakpointEntryName) {
36
+ maxContentWidth = Theme.values.maxContentWidth
37
+ } else {
38
+ maxContentWidth = (hasScreenReachedMaxWidth ? Theme.values.maxContentWidth : width) - (safeHorizontalPaddings[currentBreakpoint] * 2)
39
+ }
40
+ }
41
+
42
+ const padding = (width - maxContentWidth) / 2
43
+
44
+ return {
45
+ width: maxContentWidth,
46
+ padding,
47
+ }
48
+
49
+ }