@codeleap/web 3.25.0 → 3.25.3
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 +1 -2
- package/src/components/ActionIcon/index.tsx +52 -51
- package/src/components/ActionIcon/styles.ts +5 -1
- package/src/components/ActivityIndicator/index.tsx +55 -34
- package/src/components/ActivityIndicator/styles.ts +6 -0
- package/src/components/Badge/index.tsx +80 -43
- package/src/components/Badge/styles.ts +11 -1
- package/src/components/Button/index.tsx +89 -46
- package/src/components/Button/styles.ts +5 -0
- package/src/components/Checkbox/index.tsx +97 -83
- package/src/components/Checkbox/styles.ts +5 -1
- package/src/components/Collapse/index.tsx +83 -41
- package/src/components/Collapse/styles.ts +6 -3
- package/src/components/ColorPicker/index.tsx +48 -95
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +12 -26
- package/src/components/CropPicker/index.tsx +104 -100
- package/src/components/CropPicker/styles.ts +7 -0
- package/src/components/CropPicker/types.ts +17 -8
- package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
- package/src/components/CropPicker/utils.ts +51 -0
- package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
- package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
- package/src/components/DatePicker/index.tsx +124 -110
- package/src/components/DatePicker/styles.ts +12 -1
- package/src/components/DatePicker/types.ts +33 -16
- package/src/components/Drawer/index.tsx +125 -133
- package/src/components/Drawer/styles.ts +5 -0
- package/src/components/Dropzone/index.tsx +63 -87
- package/src/components/Dropzone/styles.ts +6 -0
- package/src/components/Dropzone/types.ts +37 -29
- package/src/components/EmptyPlaceholder/index.tsx +83 -63
- package/src/components/EmptyPlaceholder/styles.ts +5 -0
- package/src/components/FileInput.tsx +91 -0
- package/src/components/Grid/index.tsx +41 -40
- package/src/components/Grid/styles.ts +9 -2
- package/src/components/Grid/types.ts +12 -10
- package/src/components/Icon/index.tsx +47 -45
- package/src/components/Icon/styles.ts +8 -0
- package/src/components/InputBase/index.tsx +42 -71
- package/src/components/InputBase/styles.ts +47 -37
- package/src/components/InputBase/types.ts +7 -19
- package/src/components/InputBase/utils.ts +23 -3
- package/src/components/List/ListLayout.tsx +37 -20
- package/src/components/List/PaginationIndicator.tsx +102 -0
- package/src/components/List/index.tsx +41 -36
- package/src/components/List/styles.ts +11 -5
- package/src/components/List/types.ts +20 -30
- package/src/components/List/useInfiniteScroll.ts +159 -0
- package/src/components/LoadingOverlay/index.tsx +33 -31
- package/src/components/LoadingOverlay/styles.ts +8 -3
- package/src/components/Modal/index.tsx +160 -98
- package/src/components/Modal/styles.ts +5 -0
- package/src/components/NumberIncrement/index.tsx +98 -67
- package/src/components/NumberIncrement/styles.ts +5 -0
- package/src/components/Overlay/index.tsx +35 -37
- package/src/components/Overlay/styles.ts +5 -3
- package/src/components/Pager/index.tsx +81 -65
- package/src/components/Pager/styles.ts +9 -3
- package/src/components/Progress/Bar/index.tsx +50 -45
- package/src/components/Progress/Bar/styles.tsx +7 -0
- package/src/components/Progress/Bar/types.tsx +30 -0
- package/src/components/Progress/Circle/index.tsx +48 -45
- package/src/components/Progress/Circle/styles.ts +8 -1
- package/src/components/Progress/Circle/types.ts +22 -10
- package/src/components/RadioInput/index.tsx +124 -78
- package/src/components/RadioInput/styles.ts +6 -0
- package/src/components/Scroll/index.tsx +32 -0
- package/src/components/Scroll/styles.ts +8 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +36 -47
- package/src/components/SectionFilters/styles.ts +5 -1
- package/src/components/SectionFilters/types.ts +13 -14
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
- package/src/components/SegmentedControl/index.tsx +89 -111
- package/src/components/SegmentedControl/styles.ts +21 -7
- package/src/components/Select/index.tsx +57 -91
- package/src/components/Select/styles.ts +36 -19
- package/src/components/Select/types.ts +13 -17
- package/src/components/Slider/index.tsx +93 -85
- package/src/components/Slider/styles.ts +6 -13
- package/src/components/Switch/index.tsx +74 -63
- package/src/components/Switch/styles.ts +6 -1
- package/src/components/Tag/index.tsx +44 -39
- package/src/components/Tag/styles.ts +9 -1
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +48 -37
- package/src/components/Text/styles.ts +8 -0
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +28 -49
- package/src/components/TextEditor/styles.ts +8 -1
- package/src/components/TextEditor/types.ts +6 -11
- package/src/components/TextInput/index.tsx +96 -58
- package/src/components/TextInput/mask.tsx +50 -2
- package/src/components/TextInput/styles.ts +8 -3
- package/src/components/Tooltip/index.tsx +84 -61
- package/src/components/Tooltip/styles.ts +10 -3
- package/src/components/Touchable/index.tsx +86 -43
- package/src/components/Touchable/styles.ts +6 -0
- package/src/components/View/index.tsx +50 -36
- package/src/components/View/styles.ts +6 -0
- package/src/components/View/types.ts +15 -14
- package/src/components/components.ts +3 -2
- package/src/components/defaultStyles.ts +79 -0
- package/src/index.ts +0 -1
- package/src/lib/hooks/index.ts +0 -5
- package/src/lib/hooks/useBreakpointMatch.ts +7 -8
- package/src/lib/hooks/useMediaQuery.ts +3 -4
- package/src/lib/hooks/usePagination.ts +63 -79
- package/src/lib/index.ts +0 -1
- package/src/lib/utils/index.ts +0 -1
- package/src/lib/utils/test.ts +2 -2
- package/src/components/ActionIcon/types.ts +0 -15
- package/src/components/ActivityIndicator/types.ts +0 -12
- package/src/components/Badge/types.ts +0 -28
- package/src/components/Button/types.ts +0 -25
- package/src/components/Checkbox/types.ts +0 -15
- package/src/components/Collapse/types.ts +0 -11
- package/src/components/Drawer/types.ts +0 -23
- package/src/components/EmptyPlaceholder/types.ts +0 -32
- package/src/components/FileInput/index.tsx +0 -72
- package/src/components/FileInput/types.ts +0 -14
- package/src/components/Icon/types.ts +0 -15
- package/src/components/LoadingOverlay/types.ts +0 -16
- package/src/components/Modal/types.ts +0 -55
- package/src/components/NumberIncrement/types.ts +0 -29
- package/src/components/Overlay/types.ts +0 -13
- package/src/components/Pager/types.ts +0 -35
- package/src/components/PaginationButtons/index.tsx +0 -173
- package/src/components/PaginationButtons/styles.ts +0 -7
- package/src/components/PaginationButtons/types.ts +0 -26
- package/src/components/PaginationIndicator/index.tsx +0 -69
- package/src/components/PaginationIndicator/styles.ts +0 -3
- package/src/components/PaginationIndicator/types.ts +0 -18
- package/src/components/Progress/Bar/styles.ts +0 -10
- package/src/components/Progress/Bar/types.ts +0 -26
- package/src/components/RadioInput/types.ts +0 -29
- package/src/components/SegmentedControl/types.ts +0 -44
- package/src/components/Slider/types.ts +0 -29
- package/src/components/Switch/types.ts +0 -13
- package/src/components/TextInput/types.ts +0 -85
- package/src/components/Tooltip/types.ts +0 -46
- package/src/components/Touchable/types.ts +0 -22
- package/src/lib/WebStyleRegistry.ts +0 -51
- package/src/lib/hooks/useFileInput.ts +0 -15
- package/src/lib/hooks/useInfiniteScroll.ts +0 -77
- package/src/lib/hooks/useRefresh.ts +0 -87
- package/src/lib/hooks/useStylesFor.ts +0 -13
- package/src/lib/utils/cache.ts +0 -9
- /package/src/components/DatePicker/{components → defaultComponents}/index.tsx +0 -0
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
import { BaseViewProps, BreakpointPlaceholder, ComponentVariants } from '@codeleap/common'
|
|
2
|
+
import { HTMLProps, NativeHTMLElement } from '../../types'
|
|
1
3
|
import { AnimationProps, MotionProps } from 'framer-motion'
|
|
2
|
-
import {
|
|
3
|
-
import { ViewComposition } from './styles'
|
|
4
|
-
import { ComponentPropsWithRef, ElementType } from 'react'
|
|
4
|
+
import { ViewPresets } from './styles'
|
|
5
5
|
|
|
6
|
-
export type ViewProps<T extends
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type ViewProps<T extends NativeHTMLElement> =
|
|
7
|
+
HTMLProps<T> &
|
|
8
|
+
ComponentVariants<typeof ViewPresets> &
|
|
9
|
+
Omit<AnimationProps, 'variants'> &
|
|
9
10
|
{
|
|
10
|
-
component?:
|
|
11
|
+
component?: T
|
|
12
|
+
scroll?: boolean
|
|
11
13
|
debugName?: string
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
debug?: boolean
|
|
15
|
+
is?: BreakpointPlaceholder
|
|
16
|
+
not?: BreakpointPlaceholder
|
|
17
|
+
up?: BreakpointPlaceholder
|
|
18
|
+
down?: BreakpointPlaceholder
|
|
16
19
|
onHover?: (isMouseOverElement: boolean) => void
|
|
17
20
|
animated?: boolean
|
|
18
21
|
animatedProps?: Partial<MotionProps>
|
|
19
|
-
|
|
20
|
-
children?: React.ReactNode
|
|
21
|
-
}
|
|
22
|
+
} & BaseViewProps
|
|
@@ -3,6 +3,7 @@ export * from './Icon'
|
|
|
3
3
|
export * from './Touchable'
|
|
4
4
|
export * from './Text'
|
|
5
5
|
export * from './Slider'
|
|
6
|
+
export * from './Scroll'
|
|
6
7
|
export * from './List'
|
|
7
8
|
export * from './ActivityIndicator'
|
|
8
9
|
export * from './Button'
|
|
@@ -36,6 +37,6 @@ export * from './Progress'
|
|
|
36
37
|
export * from './Tag'
|
|
37
38
|
export * from './TextEditor'
|
|
38
39
|
export * from './ColorPicker'
|
|
39
|
-
export * from './PaginationButtons'
|
|
40
40
|
export * from './SectionFilters'
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
export * from './defaultStyles'
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ViewPresets } from './View/styles'
|
|
2
|
+
import { IconPresets } from './Icon/styles'
|
|
3
|
+
import { TouchablePresets } from './Touchable/styles'
|
|
4
|
+
import { TextPresets } from './Text/styles'
|
|
5
|
+
import { ScrollPresets } from './Scroll/styles'
|
|
6
|
+
import { ActivityIndicatorPresets } from './ActivityIndicator/styles'
|
|
7
|
+
import { ButtonPresets } from './Button/styles'
|
|
8
|
+
import { ActionIconPresets } from './ActionIcon/styles'
|
|
9
|
+
import { ModalPresets } from './Modal/styles'
|
|
10
|
+
import { CheckboxPresets } from './Checkbox/styles'
|
|
11
|
+
import { CollapsePresets } from './Collapse/styles'
|
|
12
|
+
import { DrawerPresets } from './Drawer/styles'
|
|
13
|
+
import { OverlayPresets } from './Overlay/styles'
|
|
14
|
+
import { TextInputPresets } from './TextInput/styles'
|
|
15
|
+
import { RadioInputPresets } from './RadioInput/styles'
|
|
16
|
+
import { SelectPresets } from './Select/styles'
|
|
17
|
+
import { ListPresets, PaginationIndicatorStyles } from './List'
|
|
18
|
+
import { SliderPresets } from './Slider/styles'
|
|
19
|
+
import { LoadingOverlayPresets } from './LoadingOverlay/styles'
|
|
20
|
+
import { InputBasePresets } from './InputBase'
|
|
21
|
+
import { SwitchPresets } from './Switch/styles'
|
|
22
|
+
import { NumberIncrementPresets } from './NumberIncrement/styles'
|
|
23
|
+
import { TooltipPresets } from './Tooltip/styles'
|
|
24
|
+
import { SegmentedControlPresets } from './SegmentedControl/styles'
|
|
25
|
+
import { PagerPresets } from './Pager/styles'
|
|
26
|
+
import { EmptyPlaceholderPresets } from './EmptyPlaceholder/styles'
|
|
27
|
+
import { GridPresets } from './Grid/styles'
|
|
28
|
+
import { BadgePresets } from './Badge/styles'
|
|
29
|
+
import { CropPickerPresets } from './CropPicker'
|
|
30
|
+
import { TagPresets } from './Tag/styles'
|
|
31
|
+
import { SectionFilterPresets } from './SectionFilters/styles'
|
|
32
|
+
|
|
33
|
+
export const defaultStyles = {
|
|
34
|
+
View: ViewPresets,
|
|
35
|
+
Icon: IconPresets,
|
|
36
|
+
Touchable: TouchablePresets,
|
|
37
|
+
Text: TextPresets,
|
|
38
|
+
ActivityIndicator: ActivityIndicatorPresets,
|
|
39
|
+
ActionIcon: ActionIconPresets,
|
|
40
|
+
Scroll: ScrollPresets,
|
|
41
|
+
|
|
42
|
+
Button: ButtonPresets,
|
|
43
|
+
Modal: ModalPresets,
|
|
44
|
+
Checkbox: CheckboxPresets,
|
|
45
|
+
Collapse: CollapsePresets,
|
|
46
|
+
Drawer: DrawerPresets,
|
|
47
|
+
Overlay: OverlayPresets,
|
|
48
|
+
TextInput: TextInputPresets,
|
|
49
|
+
RadioInput: RadioInputPresets,
|
|
50
|
+
Select: SelectPresets,
|
|
51
|
+
List: ListPresets,
|
|
52
|
+
Slider: SliderPresets,
|
|
53
|
+
LoadingOverlay: LoadingOverlayPresets,
|
|
54
|
+
InputBase: InputBasePresets,
|
|
55
|
+
Switch: SwitchPresets,
|
|
56
|
+
NumberIncrement: NumberIncrementPresets,
|
|
57
|
+
Tooltip: TooltipPresets,
|
|
58
|
+
SegmentedControlPresets: SegmentedControlPresets,
|
|
59
|
+
Pager: PagerPresets,
|
|
60
|
+
EmptyPlaceholder: EmptyPlaceholderPresets,
|
|
61
|
+
PaginationIndicator: PaginationIndicatorStyles,
|
|
62
|
+
Grid: GridPresets,
|
|
63
|
+
Badge: BadgePresets,
|
|
64
|
+
Dropzone: DropzonePresets,
|
|
65
|
+
CropPicker: CropPickerPresets,
|
|
66
|
+
Tag: TagPresets,
|
|
67
|
+
SectionFilters: SectionFilterPresets,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
import createCache from '@emotion/cache'
|
|
71
|
+
import { DropzonePresets } from './Dropzone/styles'
|
|
72
|
+
|
|
73
|
+
export const createCodeleapWebCache = () => {
|
|
74
|
+
return createCache({
|
|
75
|
+
key: 'codeleap-web',
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const codeleapWebCache = createCodeleapWebCache()
|
package/src/index.ts
CHANGED
package/src/lib/hooks/index.ts
CHANGED
|
@@ -14,8 +14,3 @@ export * from './useStaticAnimationStyles'
|
|
|
14
14
|
export * from './useWindowFocus'
|
|
15
15
|
export * from './useWindowSize'
|
|
16
16
|
export * from './useKeydown'
|
|
17
|
-
export * from './useInfiniteScroll'
|
|
18
|
-
export * from './useRefresh'
|
|
19
|
-
export * from './useCropPicker'
|
|
20
|
-
export * from './useFileInput'
|
|
21
|
-
export * from './useStylesFor'
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { useMemo } from 'react'
|
|
2
|
-
import { TypeGuards } from '@codeleap/common'
|
|
3
|
-
import { AppTheme, Theme, useTheme } from '@codeleap/styles'
|
|
2
|
+
import { TypeGuards, useCodeleapContext } from '@codeleap/common'
|
|
4
3
|
import { useMediaQuery } from './useMediaQuery'
|
|
5
4
|
|
|
6
5
|
export type BreakpointsMatch<T extends string = string> = Record<T, any>
|
|
7
6
|
|
|
8
7
|
export function useBreakpointMatch<T extends string = string>(values: Partial<BreakpointsMatch<T>>) {
|
|
9
|
-
const
|
|
8
|
+
const { Theme } = useCodeleapContext()
|
|
10
9
|
|
|
11
|
-
const themeBreakpoints: Record<string, number> =
|
|
10
|
+
const themeBreakpoints: Record<string, number> = Theme?.breakpoints
|
|
12
11
|
|
|
13
12
|
const breakpoints: Record<string, number> = useMemo(() => {
|
|
14
|
-
|
|
13
|
+
const breaks = Object.entries(themeBreakpoints)
|
|
15
14
|
|
|
16
|
-
breaks
|
|
15
|
+
breaks?.sort((a, b) => a?.[1] - b?.[1])
|
|
17
16
|
|
|
18
17
|
const sortBreakpoints = Object.fromEntries(breaks)
|
|
19
18
|
|
|
@@ -29,8 +28,8 @@ export function useBreakpointMatch<T extends string = string>(values: Partial<Br
|
|
|
29
28
|
const breakpointMatches = {}
|
|
30
29
|
|
|
31
30
|
for (const breakpoint in breakpoints) {
|
|
32
|
-
const matchesDown = useMediaQuery(
|
|
33
|
-
const matchesUp = useMediaQuery(
|
|
31
|
+
const matchesDown = useMediaQuery(Theme.media.down(breakpoint), { getInitialValueInEffect: false })
|
|
32
|
+
const matchesUp = useMediaQuery(Theme.media.up(breakpoint), { getInitialValueInEffect: false })
|
|
34
33
|
|
|
35
34
|
breakpointMatches[breakpoint] = !matchesUp && matchesDown
|
|
36
35
|
}
|
|
@@ -16,18 +16,17 @@ export function useMediaQuery(
|
|
|
16
16
|
} = queryOptions
|
|
17
17
|
|
|
18
18
|
const _query = useMemo(() => {
|
|
19
|
-
|
|
20
|
-
return query?.trim()?.replace('@media screen and ', '')
|
|
19
|
+
return query.trim().replace('@media screen and ', '')
|
|
21
20
|
}, [query])
|
|
22
21
|
|
|
23
22
|
const [matches, setMatches] = useState(
|
|
24
|
-
|
|
23
|
+
getInitialValueInEffect ? initialValue : isMediaQuery(query, initialValue),
|
|
25
24
|
)
|
|
26
25
|
|
|
27
26
|
const queryRef = useRef<MediaQueryList>()
|
|
28
27
|
|
|
29
28
|
useEffect(() => {
|
|
30
|
-
if (query
|
|
29
|
+
if (query.trim() === '') return
|
|
31
30
|
|
|
32
31
|
if ('matchMedia' in window) {
|
|
33
32
|
queryRef.current = window.matchMedia(_query)
|
|
@@ -1,65 +1,49 @@
|
|
|
1
1
|
import { range, useMemo, useUncontrolled } from '@codeleap/common'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface PaginationParams {
|
|
4
|
+
/** Page selected on initial render, defaults to 1 */
|
|
4
5
|
initialPage?: number
|
|
6
|
+
|
|
7
|
+
/** Controlled active page number */
|
|
5
8
|
page?: number
|
|
9
|
+
|
|
10
|
+
/** Total amount of pages */
|
|
6
11
|
total: number
|
|
7
|
-
boundaries?: number
|
|
8
|
-
onChangePage?: (page: number) => void
|
|
9
|
-
shouldAbbreviate?: boolean
|
|
10
|
-
abbreviationMinimumAmount?: number
|
|
11
|
-
displayLeftArrow?: boolean
|
|
12
|
-
displayRightArrow?: boolean
|
|
13
|
-
isMobile?: boolean
|
|
14
|
-
abbreviationSymbol?: any
|
|
15
|
-
}
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
/** Siblings amount on left/right side of selected page, defaults to 1 */
|
|
14
|
+
siblings?: number
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
/** Amount of elements visible on left/right edges, defaults to 1 */
|
|
17
|
+
boundaries?: number
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
initialPage = 1,
|
|
25
|
-
page,
|
|
26
|
-
onChangePage,
|
|
27
|
-
shouldAbbreviate = true,
|
|
28
|
-
abbreviationMinimumAmount = isMobile ? 5 : 10,
|
|
29
|
-
displayLeftArrow = true,
|
|
30
|
-
displayRightArrow = true,
|
|
31
|
-
abbreviationSymbol,
|
|
32
|
-
} = props
|
|
19
|
+
/** Callback fired after change of each page */
|
|
20
|
+
onChange?: (page: number) => void
|
|
21
|
+
}
|
|
33
22
|
|
|
23
|
+
export function usePagination({
|
|
24
|
+
total,
|
|
25
|
+
siblings = 1,
|
|
26
|
+
boundaries = 1,
|
|
27
|
+
page,
|
|
28
|
+
initialPage = 1,
|
|
29
|
+
onChange,
|
|
30
|
+
}: PaginationParams) {
|
|
34
31
|
const [activePage, setActivePage] = useUncontrolled({
|
|
35
32
|
value: page,
|
|
36
|
-
onChange
|
|
33
|
+
onChange,
|
|
37
34
|
defaultValue: initialPage,
|
|
38
35
|
finalValue: initialPage,
|
|
39
36
|
rule: (_page) => typeof _page === 'number' && _page <= total,
|
|
40
37
|
})
|
|
41
38
|
|
|
42
|
-
const _boundaries = isMobile ? 2 : boundaries
|
|
43
|
-
|
|
44
|
-
const canAbreviateItems = (shouldAbbreviate || isMobile) && total > abbreviationMinimumAmount
|
|
45
|
-
const displayLastNumbers = activePage + _boundaries + (isMobile ? 0 : 2) >= total
|
|
46
|
-
const isCenterSelected = canAbreviateItems && activePage > _boundaries && !displayLastNumbers
|
|
47
|
-
|
|
48
|
-
const dotsDisplay = isCenterSelected ? abbreviationSymbol : null
|
|
49
|
-
|
|
50
39
|
const setPage = (pageNumber: number) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
].some(x => x)
|
|
59
|
-
|
|
60
|
-
if (nonSelectableItems) return activePage
|
|
61
|
-
|
|
62
|
-
setActivePage(pageNumber)
|
|
40
|
+
if (pageNumber <= 0) {
|
|
41
|
+
setActivePage(1)
|
|
42
|
+
} else if (pageNumber > total) {
|
|
43
|
+
setActivePage(total)
|
|
44
|
+
} else {
|
|
45
|
+
setActivePage(pageNumber)
|
|
46
|
+
}
|
|
63
47
|
}
|
|
64
48
|
|
|
65
49
|
const next = () => setPage(activePage + 1)
|
|
@@ -67,54 +51,54 @@ export function usePagination(props: PaginationParams) {
|
|
|
67
51
|
const first = () => setPage(1)
|
|
68
52
|
const last = () => setPage(total)
|
|
69
53
|
|
|
70
|
-
const
|
|
71
|
-
if (isCenterSelected) {
|
|
72
|
-
return 'abreviated'
|
|
73
|
-
}
|
|
54
|
+
const DOTS = 'dots'
|
|
74
55
|
|
|
75
|
-
|
|
76
|
-
|
|
56
|
+
const paginationRange = useMemo((): (number | 'dots')[] => {
|
|
57
|
+
// Pages count is determined as siblings (left/right) + boundaries(left/right) + currentPage + 2*DOTS
|
|
58
|
+
const totalPageNumbers = siblings * 2 + 3 + boundaries * 2
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* If the number of pages is less than the page numbers we want to show in our
|
|
62
|
+
* paginationComponent, we return the range [1..total]
|
|
63
|
+
*/
|
|
64
|
+
if (totalPageNumbers >= total) {
|
|
65
|
+
return range(1, total)
|
|
77
66
|
}
|
|
78
67
|
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
const leftSiblingIndex = Math.max(activePage - siblings, boundaries)
|
|
69
|
+
const rightSiblingIndex = Math.min(activePage + siblings, total - boundaries)
|
|
81
70
|
|
|
82
|
-
|
|
71
|
+
/*
|
|
72
|
+
* We do not want to show dots if there is only one position left
|
|
73
|
+
* after/before the left/right page count as that would lead to a change if our Pagination
|
|
74
|
+
* component size which we do not want
|
|
75
|
+
*/
|
|
76
|
+
const shouldShowLeftDots = leftSiblingIndex > boundaries + 2
|
|
77
|
+
const shouldShowRightDots = rightSiblingIndex < total - (boundaries + 1)
|
|
83
78
|
|
|
84
|
-
if (!
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
].filter(Boolean)
|
|
79
|
+
if (!shouldShowLeftDots && shouldShowRightDots) {
|
|
80
|
+
const leftItemCount = siblings * 2 + boundaries + 2
|
|
81
|
+
return [...range(1, leftItemCount), DOTS, ...range(total - (boundaries - 1), total)]
|
|
88
82
|
}
|
|
89
83
|
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
1,
|
|
94
|
-
abbreviationSymbol,
|
|
95
|
-
]
|
|
96
|
-
|
|
97
|
-
return [
|
|
98
|
-
...extraItems,
|
|
99
|
-
...range(total - (_boundaries + extraItems?.length - (isMobile ? 2 : 0)), total),
|
|
100
|
-
].filter(Boolean)
|
|
84
|
+
if (shouldShowLeftDots && !shouldShowRightDots) {
|
|
85
|
+
const rightItemCount = boundaries + 1 + 2 * siblings
|
|
86
|
+
return [...range(1, boundaries), DOTS, ...range(total - rightItemCount, total)]
|
|
101
87
|
}
|
|
102
88
|
|
|
103
89
|
return [
|
|
104
|
-
...range(1,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
...range(total -
|
|
109
|
-
]
|
|
110
|
-
|
|
111
|
-
}, [total, activePage, displayLastNumbers, isCenterSelected, canAbreviateItems])
|
|
90
|
+
...range(1, boundaries),
|
|
91
|
+
DOTS,
|
|
92
|
+
...range(leftSiblingIndex, rightSiblingIndex),
|
|
93
|
+
DOTS,
|
|
94
|
+
...range(total - boundaries + 1, total),
|
|
95
|
+
]
|
|
96
|
+
}, [total, siblings, activePage])
|
|
112
97
|
|
|
113
98
|
return {
|
|
114
99
|
range: paginationRange,
|
|
115
|
-
|
|
100
|
+
active: activePage,
|
|
116
101
|
setPage,
|
|
117
|
-
status,
|
|
118
102
|
next,
|
|
119
103
|
previous,
|
|
120
104
|
first,
|
package/src/lib/index.ts
CHANGED
package/src/lib/utils/index.ts
CHANGED
package/src/lib/utils/test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TypeGuards } from '@codeleap/common'
|
|
2
2
|
|
|
3
3
|
export const getTestId = (props: Record<string, any>) => {
|
|
4
|
-
let id = props
|
|
4
|
+
let id = props.testId || props['data-testid'] || props.id || props.debugName
|
|
5
5
|
|
|
6
6
|
if (TypeGuards.isString(id)) {
|
|
7
|
-
id = id
|
|
7
|
+
id = id.replace(/\s/g, '_').toLowerCase()
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
return id
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ComponentCommonProps } from '../../types'
|
|
2
|
-
import { TouchableProps } from '../Touchable'
|
|
3
|
-
import { ActionIconComposition } from './styles'
|
|
4
|
-
import { IconProps } from '../Icon'
|
|
5
|
-
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
6
|
-
|
|
7
|
-
export type ActionIconProps =
|
|
8
|
-
Omit<TouchableProps, 'style'> &
|
|
9
|
-
ComponentCommonProps &
|
|
10
|
-
{
|
|
11
|
-
iconProps?: Partial<IconProps>
|
|
12
|
-
icon?: AppIcon
|
|
13
|
-
name?: AppIcon
|
|
14
|
-
style?: StyledProp<ActionIconComposition>
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { StyledProp } from '@codeleap/styles'
|
|
3
|
-
import { ComponentCommonProps } from '../../types'
|
|
4
|
-
import { ActivityIndicatorComposition } from './styles'
|
|
5
|
-
|
|
6
|
-
export type ActivityIndicatorProps =
|
|
7
|
-
ComponentCommonProps &
|
|
8
|
-
{
|
|
9
|
-
style?: StyledProp<ActivityIndicatorComposition>
|
|
10
|
-
component?: React.ComponentType<Omit<ActivityIndicatorProps & { ref?: React.Ref<HTMLDivElement> }, 'component'>>
|
|
11
|
-
size?: number
|
|
12
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { TextProps } from '../Text'
|
|
2
|
-
import { ViewProps } from '../View'
|
|
3
|
-
import { BadgeComposition } from './styles'
|
|
4
|
-
import { ComponentCommonProps } from '../../types'
|
|
5
|
-
import { StyledProp } from '@codeleap/styles'
|
|
6
|
-
|
|
7
|
-
export type BadgeProps =
|
|
8
|
-
Omit<ViewProps, 'style'> &
|
|
9
|
-
ComponentCommonProps &
|
|
10
|
-
{
|
|
11
|
-
style?: StyledProp<BadgeComposition>
|
|
12
|
-
maxCount?: number
|
|
13
|
-
minCount?: number
|
|
14
|
-
debugName?: string
|
|
15
|
-
innerWrapperProps?: Partial<ViewProps>
|
|
16
|
-
textProps?: Partial<TextProps>
|
|
17
|
-
getBadgeContent?: (props: BadgeContent) => string
|
|
18
|
-
renderBadgeContent?: (props: BadgeContent & { content: string }) => JSX.Element
|
|
19
|
-
disabled?: boolean
|
|
20
|
-
badge?: number | boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type BadgeContent = BadgeProps & { count: number }
|
|
24
|
-
|
|
25
|
-
export type BadgeComponentProps = {
|
|
26
|
-
badge?: BadgeProps['badge']
|
|
27
|
-
badgeProps?: Partial<BadgeProps>
|
|
28
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { AnyFunction } from '@codeleap/common'
|
|
3
|
-
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
4
|
-
import { TouchableProps } from '../Touchable'
|
|
5
|
-
import { ActivityIndicatorProps } from '../ActivityIndicator'
|
|
6
|
-
import { ButtonComposition } from './styles'
|
|
7
|
-
import { ComponentCommonProps } from '../../types'
|
|
8
|
-
|
|
9
|
-
export type ButtonProps =
|
|
10
|
-
Omit<TouchableProps, 'style'> &
|
|
11
|
-
ComponentCommonProps &
|
|
12
|
-
{
|
|
13
|
-
text?: string
|
|
14
|
-
rightIcon?: AppIcon
|
|
15
|
-
icon?: AppIcon
|
|
16
|
-
onPress?: AnyFunction
|
|
17
|
-
style?: StyledProp<ButtonComposition>
|
|
18
|
-
loading?: boolean
|
|
19
|
-
loadingShowText?: boolean
|
|
20
|
-
debugName: string
|
|
21
|
-
debounce?: number
|
|
22
|
-
selected?: boolean
|
|
23
|
-
children?: React.ReactNode
|
|
24
|
-
loaderProps?: Partial<ActivityIndicatorProps>
|
|
25
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CheckboxComposition } from './styles'
|
|
2
|
-
import { InputBaseProps } from '../InputBase'
|
|
3
|
-
import { ComponentCommonProps } from '../../types'
|
|
4
|
-
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
5
|
-
|
|
6
|
-
export type CheckboxProps =
|
|
7
|
-
Pick<InputBaseProps, 'disabled' | 'label'> &
|
|
8
|
-
ComponentCommonProps &
|
|
9
|
-
{
|
|
10
|
-
style?: StyledProp<CheckboxComposition>
|
|
11
|
-
value: boolean
|
|
12
|
-
onValueChange: (value: boolean) => void
|
|
13
|
-
checkboxOnLeft?: boolean
|
|
14
|
-
checkIcon?: AppIcon
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { StyledProp } from '@codeleap/styles'
|
|
2
|
-
import { MotionProps } from 'framer-motion'
|
|
3
|
-
import { CollapseComposition } from './styles'
|
|
4
|
-
|
|
5
|
-
export type CollapseProps =
|
|
6
|
-
Omit<MotionProps, 'style'> &
|
|
7
|
-
{
|
|
8
|
-
open: boolean
|
|
9
|
-
style?: StyledProp<CollapseComposition>
|
|
10
|
-
children?: React.ReactNode
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { AnyFunction } from '@codeleap/common'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import { ComponentCommonProps } from '../../types/utility'
|
|
4
|
-
import { DrawerComposition } from './styles'
|
|
5
|
-
import { ActionIconProps } from '../ActionIcon'
|
|
6
|
-
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
7
|
-
|
|
8
|
-
export type DrawerProps =
|
|
9
|
-
ComponentCommonProps &
|
|
10
|
-
{
|
|
11
|
-
open: boolean
|
|
12
|
-
toggle: AnyFunction
|
|
13
|
-
darkenBackground?: boolean
|
|
14
|
-
size?: number
|
|
15
|
-
showCloseButton?: boolean
|
|
16
|
-
title?: React.ReactNode | string
|
|
17
|
-
footer?: React.ReactNode
|
|
18
|
-
position?: 'left' | 'right' | 'top' | 'bottom'
|
|
19
|
-
style?: StyledProp<DrawerComposition>
|
|
20
|
-
closeButtonProps?: Partial<ActionIconProps>
|
|
21
|
-
closeIcon?: AppIcon
|
|
22
|
-
children?: React.ReactNode
|
|
23
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React, { ImgHTMLAttributes } from 'react'
|
|
2
|
-
import { ViewProps } from '../View'
|
|
3
|
-
import { ActivityIndicatorComposition, ActivityIndicatorProps } from '../ActivityIndicator'
|
|
4
|
-
import { EmptyPlaceholderComposition } from './styles'
|
|
5
|
-
import { StylesOf } from '@codeleap/common'
|
|
6
|
-
import { ComponentCommonProps } from '../../types'
|
|
7
|
-
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
8
|
-
|
|
9
|
-
type RenderEmptyProps = {
|
|
10
|
-
emptyText: string | React.ReactElement
|
|
11
|
-
emptyIconName?: AppIcon
|
|
12
|
-
styles: StylesOf<EmptyPlaceholderComposition> & {
|
|
13
|
-
activityIndicatorStyles: StylesOf<ActivityIndicatorComposition>
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type EmptyPlaceholderProps =
|
|
18
|
-
ComponentCommonProps &
|
|
19
|
-
{
|
|
20
|
-
itemName?: string
|
|
21
|
-
title?: React.ReactElement | string
|
|
22
|
-
description?: React.ReactElement | string
|
|
23
|
-
icon?: AppIcon | ((props: EmptyPlaceholderProps) => JSX.Element)
|
|
24
|
-
image?: string
|
|
25
|
-
imageProps?: ImgHTMLAttributes<HTMLImageElement>
|
|
26
|
-
loading?: boolean
|
|
27
|
-
style?: StyledProp<EmptyPlaceholderComposition>
|
|
28
|
-
renderEmpty?: (props: RenderEmptyProps) => JSX.Element
|
|
29
|
-
wrapperProps?: ViewProps
|
|
30
|
-
imageWrapperProps?: ViewProps
|
|
31
|
-
indicatorProps?: Partial<ActivityIndicatorProps>
|
|
32
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, useImperativeHandle, useRef } from 'react'
|
|
2
|
-
import { WebInputFile, useCallback, TypeGuards } from '@codeleap/common'
|
|
3
|
-
import { FileInputProps, FileInputRef } from './types'
|
|
4
|
-
|
|
5
|
-
export * from './types'
|
|
6
|
-
|
|
7
|
-
export const FileInput = forwardRef<FileInputRef, FileInputProps>((props, ref) => {
|
|
8
|
-
const inputRef = useRef<HTMLInputElement>(null)
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
onFileSelect,
|
|
12
|
-
autoClear,
|
|
13
|
-
onChange,
|
|
14
|
-
...inputProps
|
|
15
|
-
} = {
|
|
16
|
-
...FileInput.defaultProps,
|
|
17
|
-
...props,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const resolveWithFile = useRef<(file: WebInputFile[]) => any>()
|
|
21
|
-
|
|
22
|
-
const clearInput = useCallback(() => {
|
|
23
|
-
if (!inputRef.current) return
|
|
24
|
-
inputRef.current.value = null
|
|
25
|
-
}, [])
|
|
26
|
-
|
|
27
|
-
useImperativeHandle(ref, () => ({
|
|
28
|
-
openFilePicker: () => {
|
|
29
|
-
inputRef.current.click()
|
|
30
|
-
|
|
31
|
-
return new Promise<WebInputFile[]>((resolve) => {
|
|
32
|
-
resolveWithFile.current = resolve
|
|
33
|
-
})
|
|
34
|
-
},
|
|
35
|
-
clear: clearInput,
|
|
36
|
-
}))
|
|
37
|
-
|
|
38
|
-
async function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
|
|
39
|
-
if (!e.target.files.length) return
|
|
40
|
-
if (TypeGuards.isFunction(onChange)) onChange(e)
|
|
41
|
-
|
|
42
|
-
const fileArray = Array.from(e.target?.files || []) as File[]
|
|
43
|
-
|
|
44
|
-
const files: WebInputFile[] = fileArray.map((obj) => ({
|
|
45
|
-
file: obj,
|
|
46
|
-
preview: URL.createObjectURL(obj),
|
|
47
|
-
}))
|
|
48
|
-
|
|
49
|
-
onFileSelect && onFileSelect(files)
|
|
50
|
-
|
|
51
|
-
if (resolveWithFile.current) {
|
|
52
|
-
await resolveWithFile.current(files)
|
|
53
|
-
resolveWithFile.current = undefined
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (autoClear) clearInput()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<input
|
|
61
|
-
type={'file'}
|
|
62
|
-
style={{ visibility: 'hidden', width: 0, height: 0, opacity: 0, display: 'none' }}
|
|
63
|
-
{...inputProps}
|
|
64
|
-
ref={inputRef}
|
|
65
|
-
onChange={handleChange}
|
|
66
|
-
/>
|
|
67
|
-
)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
FileInput.defaultProps = {
|
|
71
|
-
autoClear: true,
|
|
72
|
-
} as Partial<FileInputProps>
|