@codeleap/web 3.4.0 → 3.6.0
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 +3 -1
- package/src/components/ActionIcon/index.tsx +49 -30
- package/src/components/ActionIcon/styles.ts +8 -5
- package/src/components/ActivityIndicator/index.tsx +6 -5
- package/src/components/Badge/index.tsx +135 -0
- package/src/components/Badge/styles.ts +15 -0
- package/src/components/Button/index.tsx +79 -69
- package/src/components/Button/styles.ts +10 -14
- package/src/components/Checkbox/index.tsx +9 -3
- package/src/components/Collapse/index.tsx +6 -3
- package/src/components/Drawer/index.tsx +72 -44
- package/src/components/Drawer/styles.ts +11 -3
- package/src/components/EmptyPlaceholder/index.tsx +135 -0
- package/src/components/EmptyPlaceholder/styles.ts +16 -0
- package/src/components/Grid/index.tsx +169 -0
- package/src/components/Grid/styles.ts +10 -0
- package/src/components/Grid/types.ts +24 -0
- package/src/components/Icon/index.tsx +7 -4
- package/src/components/InputBase/styles.ts +8 -56
- package/src/components/InputBase/utils.ts +63 -0
- package/src/components/List/ListLayout.tsx +98 -0
- package/src/components/List/PaginationIndicator.tsx +102 -0
- package/src/components/List/index.tsx +104 -91
- package/src/components/List/styles.ts +17 -5
- package/src/components/List/types.ts +51 -0
- package/src/components/List/useInfiniteScroll.ts +113 -0
- package/src/components/LoadingOverlay/index.tsx +5 -3
- package/src/components/Modal/index.tsx +30 -29
- package/src/components/NumberIncrement/index.tsx +3 -2
- package/src/components/Overlay/index.tsx +12 -2
- package/src/components/Pager/index.tsx +5 -1
- package/src/components/RadioInput/index.tsx +4 -3
- package/src/components/SearchInput/index.tsx +93 -0
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +15 -9
- package/src/components/SegmentedControl/index.tsx +12 -5
- package/src/components/Select/index.tsx +18 -14
- package/src/components/Select/styles.ts +4 -3
- package/src/components/Select/types.ts +4 -3
- package/src/components/Slider/index.tsx +3 -2
- package/src/components/Switch/index.tsx +4 -2
- package/src/components/Text/index.tsx +98 -25
- package/src/components/Text/styles.ts +4 -4
- package/src/components/TextInput/index.tsx +6 -15
- package/src/components/Tooltip/index.tsx +163 -131
- package/src/components/Tooltip/styles.ts +13 -9
- package/src/components/Touchable/index.tsx +88 -26
- package/src/components/Touchable/styles.ts +4 -6
- package/src/components/View/index.tsx +1 -1
- package/src/components/components.ts +5 -1
- package/src/components/defaultStyles.ts +10 -3
- package/src/index.ts +3 -0
- package/src/lib/hooks.ts +27 -13
- package/src/lib/index.ts +4 -1
- package/src/lib/useBreakpointMatch.ts +33 -0
- package/src/lib/usePopState.ts +30 -0
- package/src/lib/useSearchParams.ts +54 -0
- package/src/lib/utils/stopPropagation.ts +3 -3
- package/src/types/index.ts +1 -1
- package/src/types/utility.ts +4 -0
package/src/lib/index.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCodeleapContext, useMemo } from '@codeleap/common'
|
|
2
|
+
import { useMediaQuery } from './hooks'
|
|
3
|
+
|
|
4
|
+
export type BreakpointsMatch = Record<string, any> & {
|
|
5
|
+
defaultMedia: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useBreakpointMatch = (values: BreakpointsMatch) => {
|
|
9
|
+
const { Theme } = useCodeleapContext()
|
|
10
|
+
|
|
11
|
+
const breakpoints = useMemo(() => {
|
|
12
|
+
const breaks = Object.entries(Theme.breakpoints as Record<string, number>)
|
|
13
|
+
|
|
14
|
+
breaks?.sort((a, b) => a?.[1] - b?.[1])
|
|
15
|
+
|
|
16
|
+
const sortBreakpoints = Object.fromEntries(breaks)
|
|
17
|
+
|
|
18
|
+
return sortBreakpoints
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
const breakpointMatches = {}
|
|
22
|
+
|
|
23
|
+
for (const breakpoint in breakpoints) {
|
|
24
|
+
const matchesDown = useMediaQuery(Theme.media.down(breakpoint))
|
|
25
|
+
const matchesUp = useMediaQuery(Theme.media.up(breakpoint))
|
|
26
|
+
|
|
27
|
+
breakpointMatches[breakpoint] = !matchesUp && matchesDown
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const breakpoint = Object.keys(breakpointMatches).find((key) => breakpointMatches[key])
|
|
31
|
+
|
|
32
|
+
return values[breakpoint] ?? values[values.defaultMedia]
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnyFunction, useIsomorphicEffect, useUnmount } from '@codeleap/common'
|
|
2
|
+
|
|
3
|
+
export const usePopState = (dependence: boolean, handler: AnyFunction, scrollLocked = true) => {
|
|
4
|
+
useIsomorphicEffect(() => {
|
|
5
|
+
if (dependence) {
|
|
6
|
+
if (scrollLocked) {
|
|
7
|
+
document.body.style.overflow = 'hidden'
|
|
8
|
+
document.body.style.overflowX = 'hidden'
|
|
9
|
+
document.body.style.overflowY = 'hidden'
|
|
10
|
+
document.body.style.maxHeight = '100vh'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
window.history.pushState(null, null, window.location.pathname)
|
|
14
|
+
window.addEventListener('popstate', handler)
|
|
15
|
+
} else {
|
|
16
|
+
if (scrollLocked) {
|
|
17
|
+
document.body.style.overflow = 'hidden'
|
|
18
|
+
document.body.style.overflowX = 'hidden'
|
|
19
|
+
document.body.style.overflowY = 'auto'
|
|
20
|
+
document.body.style.maxHeight = 'auto'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
window.removeEventListener('popstate', handler)
|
|
24
|
+
}
|
|
25
|
+
}, [dependence])
|
|
26
|
+
|
|
27
|
+
useUnmount(() => {
|
|
28
|
+
window.removeEventListener('popstate', handler)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { usePrevious } from '@codeleap/common'
|
|
3
|
+
|
|
4
|
+
export type UseSearchParamsReturn<T> = [
|
|
5
|
+
T,
|
|
6
|
+
React.Dispatch<React.SetStateAction<T>>,
|
|
7
|
+
() => void,
|
|
8
|
+
URLSearchParams
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
export function useSearchParams<
|
|
12
|
+
T extends Record<string, string> = Record<string, string>
|
|
13
|
+
>(initial?: T): UseSearchParamsReturn<T> {
|
|
14
|
+
const searchParams = useRef(new URLSearchParams(typeof window === 'undefined' ? '' : location.search))
|
|
15
|
+
const [params, setParams] = useState<T>(() => {
|
|
16
|
+
|
|
17
|
+
const initialParams = Object.fromEntries(searchParams.current as any) as T
|
|
18
|
+
|
|
19
|
+
for (const key in initial) {
|
|
20
|
+
if (initialParams[key] === '' || typeof initialParams[key] === 'undefined') {
|
|
21
|
+
initialParams[key] = initial[key]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return initialParams
|
|
26
|
+
})
|
|
27
|
+
const previousParams = usePrevious(params)
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (window.history) {
|
|
31
|
+
Object.entries({ ...previousParams, ...params }).forEach(([k, v]) => {
|
|
32
|
+
if (!!previousParams?.[k] && !params?.[k]) {
|
|
33
|
+
searchParams.current.delete(k)
|
|
34
|
+
} else if (v) {
|
|
35
|
+
searchParams.current.set(k, v)
|
|
36
|
+
} else {
|
|
37
|
+
searchParams.current.delete(k)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const url =
|
|
42
|
+
window.location.origin +
|
|
43
|
+
window.location.pathname +
|
|
44
|
+
`?${searchParams.current?.toString()}`
|
|
45
|
+
window.history.replaceState({ path: url }, '', url)
|
|
46
|
+
}
|
|
47
|
+
}, [params])
|
|
48
|
+
|
|
49
|
+
function reset() {
|
|
50
|
+
setParams(initial)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return [params, setParams, reset, searchParams.current]
|
|
54
|
+
}
|
|
@@ -2,9 +2,9 @@ import { AnyFunction } from '@codeleap/common'
|
|
|
2
2
|
|
|
3
3
|
export function stopPropagation(event: any) {
|
|
4
4
|
const tryCalls = [
|
|
5
|
-
event?.stopPropagation,
|
|
6
|
-
event?.preventDefault,
|
|
7
|
-
event.nativeEvent?.stopImmediatePropagation as AnyFunction,
|
|
5
|
+
event?.stopPropagation.bind(event),
|
|
6
|
+
event?.preventDefault.bind(event),
|
|
7
|
+
event.nativeEvent?.stopImmediatePropagation.bind(event.nativeEvent) as AnyFunction,
|
|
8
8
|
]
|
|
9
9
|
|
|
10
10
|
for (const call of tryCalls) {
|
package/src/types/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './utility'
|
|
1
|
+
export * from './utility'
|
package/src/types/utility.ts
CHANGED
|
@@ -30,3 +30,7 @@ export type NativeHTMLElement = keyof ElementMap
|
|
|
30
30
|
export type HTMLProps<T extends NativeHTMLElement> = ElementMap[T]
|
|
31
31
|
|
|
32
32
|
export type ComponentWithDefaultProps<P> = ((props: P) => JSX.Element) & { defaultProps?: Partial<P> }
|
|
33
|
+
|
|
34
|
+
export type ComponentCommonProps = {
|
|
35
|
+
debugName: string
|
|
36
|
+
}
|