@codeleap/web 3.21.6 → 3.21.8
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
|
@@ -117,6 +117,10 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
117
117
|
useImperativeHandle(inputRef, () => {
|
|
118
118
|
return {
|
|
119
119
|
focus: () => {
|
|
120
|
+
if (isMasked) {
|
|
121
|
+
innerInputRef.current?.getInputDOMNode()?.focus()
|
|
122
|
+
}
|
|
123
|
+
|
|
120
124
|
innerInputRef.current?.focus?.()
|
|
121
125
|
},
|
|
122
126
|
isTextInput: true,
|
|
@@ -221,7 +225,9 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
221
225
|
innerWrapperProps={{
|
|
222
226
|
...(inputBaseProps.innerWrapperProps || {}),
|
|
223
227
|
[inputBaseAction]: () => {
|
|
224
|
-
|
|
228
|
+
if (isMasked) {
|
|
229
|
+
innerInputRef.current?.getInputDOMNode()?.focus()
|
|
230
|
+
}
|
|
225
231
|
innerInputRef.current?.focus?.()
|
|
226
232
|
if (isPressable) onPress?.()
|
|
227
233
|
},
|
package/src/lib/utils/index.ts
CHANGED
|
@@ -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
|
+
}
|