@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.
Files changed (150) hide show
  1. package/package.json +1 -2
  2. package/src/components/ActionIcon/index.tsx +52 -51
  3. package/src/components/ActionIcon/styles.ts +5 -1
  4. package/src/components/ActivityIndicator/index.tsx +55 -34
  5. package/src/components/ActivityIndicator/styles.ts +6 -0
  6. package/src/components/Badge/index.tsx +80 -43
  7. package/src/components/Badge/styles.ts +11 -1
  8. package/src/components/Button/index.tsx +89 -46
  9. package/src/components/Button/styles.ts +5 -0
  10. package/src/components/Checkbox/index.tsx +97 -83
  11. package/src/components/Checkbox/styles.ts +5 -1
  12. package/src/components/Collapse/index.tsx +83 -41
  13. package/src/components/Collapse/styles.ts +6 -3
  14. package/src/components/ColorPicker/index.tsx +48 -95
  15. package/src/components/ColorPicker/styles.ts +11 -11
  16. package/src/components/ColorPicker/types.ts +12 -26
  17. package/src/components/CropPicker/index.tsx +104 -100
  18. package/src/components/CropPicker/styles.ts +7 -0
  19. package/src/components/CropPicker/types.ts +17 -8
  20. package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
  21. package/src/components/CropPicker/utils.ts +51 -0
  22. package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
  23. package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
  24. package/src/components/DatePicker/index.tsx +124 -110
  25. package/src/components/DatePicker/styles.ts +12 -1
  26. package/src/components/DatePicker/types.ts +33 -16
  27. package/src/components/Drawer/index.tsx +125 -133
  28. package/src/components/Drawer/styles.ts +5 -0
  29. package/src/components/Dropzone/index.tsx +63 -87
  30. package/src/components/Dropzone/styles.ts +6 -0
  31. package/src/components/Dropzone/types.ts +37 -29
  32. package/src/components/EmptyPlaceholder/index.tsx +83 -63
  33. package/src/components/EmptyPlaceholder/styles.ts +5 -0
  34. package/src/components/FileInput.tsx +91 -0
  35. package/src/components/Grid/index.tsx +41 -40
  36. package/src/components/Grid/styles.ts +9 -2
  37. package/src/components/Grid/types.ts +12 -10
  38. package/src/components/Icon/index.tsx +47 -45
  39. package/src/components/Icon/styles.ts +8 -0
  40. package/src/components/InputBase/index.tsx +42 -71
  41. package/src/components/InputBase/styles.ts +47 -37
  42. package/src/components/InputBase/types.ts +7 -19
  43. package/src/components/InputBase/utils.ts +23 -3
  44. package/src/components/List/ListLayout.tsx +37 -20
  45. package/src/components/List/PaginationIndicator.tsx +102 -0
  46. package/src/components/List/index.tsx +41 -36
  47. package/src/components/List/styles.ts +11 -5
  48. package/src/components/List/types.ts +20 -30
  49. package/src/components/List/useInfiniteScroll.ts +159 -0
  50. package/src/components/LoadingOverlay/index.tsx +33 -31
  51. package/src/components/LoadingOverlay/styles.ts +8 -3
  52. package/src/components/Modal/index.tsx +160 -98
  53. package/src/components/Modal/styles.ts +5 -0
  54. package/src/components/NumberIncrement/index.tsx +98 -67
  55. package/src/components/NumberIncrement/styles.ts +5 -0
  56. package/src/components/Overlay/index.tsx +35 -37
  57. package/src/components/Overlay/styles.ts +5 -3
  58. package/src/components/Pager/index.tsx +81 -65
  59. package/src/components/Pager/styles.ts +9 -3
  60. package/src/components/Progress/Bar/index.tsx +50 -45
  61. package/src/components/Progress/Bar/styles.tsx +7 -0
  62. package/src/components/Progress/Bar/types.tsx +30 -0
  63. package/src/components/Progress/Circle/index.tsx +48 -45
  64. package/src/components/Progress/Circle/styles.ts +8 -1
  65. package/src/components/Progress/Circle/types.ts +22 -10
  66. package/src/components/RadioInput/index.tsx +124 -78
  67. package/src/components/RadioInput/styles.ts +6 -0
  68. package/src/components/Scroll/index.tsx +32 -0
  69. package/src/components/Scroll/styles.ts +8 -0
  70. package/src/components/SearchInput/index.tsx +10 -10
  71. package/src/components/SectionFilters/index.tsx +36 -47
  72. package/src/components/SectionFilters/styles.ts +5 -1
  73. package/src/components/SectionFilters/types.ts +13 -14
  74. package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
  75. package/src/components/SegmentedControl/index.tsx +89 -111
  76. package/src/components/SegmentedControl/styles.ts +21 -7
  77. package/src/components/Select/index.tsx +57 -91
  78. package/src/components/Select/styles.ts +36 -19
  79. package/src/components/Select/types.ts +13 -17
  80. package/src/components/Slider/index.tsx +93 -85
  81. package/src/components/Slider/styles.ts +6 -13
  82. package/src/components/Switch/index.tsx +74 -63
  83. package/src/components/Switch/styles.ts +6 -1
  84. package/src/components/Tag/index.tsx +44 -39
  85. package/src/components/Tag/styles.ts +9 -1
  86. package/src/components/Tag/types.ts +10 -10
  87. package/src/components/Text/index.tsx +48 -37
  88. package/src/components/Text/styles.ts +8 -0
  89. package/src/components/Text/types.ts +8 -8
  90. package/src/components/TextEditor/index.tsx +28 -49
  91. package/src/components/TextEditor/styles.ts +8 -1
  92. package/src/components/TextEditor/types.ts +6 -11
  93. package/src/components/TextInput/index.tsx +96 -58
  94. package/src/components/TextInput/mask.tsx +50 -2
  95. package/src/components/TextInput/styles.ts +8 -3
  96. package/src/components/Tooltip/index.tsx +84 -61
  97. package/src/components/Tooltip/styles.ts +10 -3
  98. package/src/components/Touchable/index.tsx +86 -43
  99. package/src/components/Touchable/styles.ts +6 -0
  100. package/src/components/View/index.tsx +50 -36
  101. package/src/components/View/styles.ts +6 -0
  102. package/src/components/View/types.ts +15 -14
  103. package/src/components/components.ts +3 -2
  104. package/src/components/defaultStyles.ts +79 -0
  105. package/src/index.ts +0 -1
  106. package/src/lib/hooks/index.ts +0 -5
  107. package/src/lib/hooks/useBreakpointMatch.ts +7 -8
  108. package/src/lib/hooks/useMediaQuery.ts +3 -4
  109. package/src/lib/hooks/usePagination.ts +63 -79
  110. package/src/lib/index.ts +0 -1
  111. package/src/lib/utils/index.ts +0 -1
  112. package/src/lib/utils/test.ts +2 -2
  113. package/src/components/ActionIcon/types.ts +0 -15
  114. package/src/components/ActivityIndicator/types.ts +0 -12
  115. package/src/components/Badge/types.ts +0 -28
  116. package/src/components/Button/types.ts +0 -25
  117. package/src/components/Checkbox/types.ts +0 -15
  118. package/src/components/Collapse/types.ts +0 -11
  119. package/src/components/Drawer/types.ts +0 -23
  120. package/src/components/EmptyPlaceholder/types.ts +0 -32
  121. package/src/components/FileInput/index.tsx +0 -72
  122. package/src/components/FileInput/types.ts +0 -14
  123. package/src/components/Icon/types.ts +0 -15
  124. package/src/components/LoadingOverlay/types.ts +0 -16
  125. package/src/components/Modal/types.ts +0 -55
  126. package/src/components/NumberIncrement/types.ts +0 -29
  127. package/src/components/Overlay/types.ts +0 -13
  128. package/src/components/Pager/types.ts +0 -35
  129. package/src/components/PaginationButtons/index.tsx +0 -173
  130. package/src/components/PaginationButtons/styles.ts +0 -7
  131. package/src/components/PaginationButtons/types.ts +0 -26
  132. package/src/components/PaginationIndicator/index.tsx +0 -69
  133. package/src/components/PaginationIndicator/styles.ts +0 -3
  134. package/src/components/PaginationIndicator/types.ts +0 -18
  135. package/src/components/Progress/Bar/styles.ts +0 -10
  136. package/src/components/Progress/Bar/types.ts +0 -26
  137. package/src/components/RadioInput/types.ts +0 -29
  138. package/src/components/SegmentedControl/types.ts +0 -44
  139. package/src/components/Slider/types.ts +0 -29
  140. package/src/components/Switch/types.ts +0 -13
  141. package/src/components/TextInput/types.ts +0 -85
  142. package/src/components/Tooltip/types.ts +0 -46
  143. package/src/components/Touchable/types.ts +0 -22
  144. package/src/lib/WebStyleRegistry.ts +0 -51
  145. package/src/lib/hooks/useFileInput.ts +0 -15
  146. package/src/lib/hooks/useInfiniteScroll.ts +0 -77
  147. package/src/lib/hooks/useRefresh.ts +0 -87
  148. package/src/lib/hooks/useStylesFor.ts +0 -13
  149. package/src/lib/utils/cache.ts +0 -9
  150. /package/src/components/DatePicker/{components → defaultComponents}/index.tsx +0 -0
@@ -1,85 +0,0 @@
1
- import { FormTypes, yup } from '@codeleap/common'
2
- import { TouchableProps } from '../Touchable'
3
- import { AppIcon, StyledProp } from '@codeleap/styles'
4
- import { InputBaseProps } from '../InputBase'
5
- import { HTMLProps } from '../../types'
6
- import { TextInputComposition } from './styles'
7
-
8
- type NativeTextInputProps = HTMLProps<'input'>
9
-
10
- export type TextInputProps =
11
- Omit<InputBaseProps, 'style'> &
12
- Omit<NativeTextInputProps, 'value' | 'crossOrigin' | 'ref' | 'style'> &
13
- {
14
- style?: StyledProp<TextInputComposition>
15
- password?: boolean
16
- validate?: FormTypes.ValidatorWithoutForm<string> | yup.SchemaOf<string>
17
- debugName?: string
18
- visibilityToggle?: boolean
19
- value?: NativeTextInputProps['value']
20
- multiline?: boolean
21
- onPress?: TouchableProps['onPress']
22
- onChangeText?: (textValue: string) => void
23
- caretColor?: string
24
- focused?: boolean
25
- _error?: boolean
26
- rows?: number
27
- masking?: TextInputMaskingProps
28
- visibleIcon?: AppIcon
29
- hiddenIcon?: AppIcon
30
- }
31
-
32
- export type InputRef = {
33
- isTextInput?: boolean
34
- focus: () => void
35
- getInputRef: () => HTMLInputElement
36
- }
37
-
38
- type beforeMaskedValueChangeArgs = {
39
- state: {
40
- value: string | undefined
41
- selection: {
42
- start: number
43
- end: number
44
- length?: number
45
- }
46
- }
47
- userInput: null | string
48
- }
49
-
50
- export type FormatChar = `[${string}]`
51
-
52
- export type MaskProps = {
53
- obfuscated?: boolean
54
- mask?: string
55
- placeholder?: string
56
- maskChar?: string
57
- formatChars?: Record<string, FormatChar>
58
- alwaysShowMask?: boolean
59
- validator?: FormTypes.ValidatorFunctionWithoutForm
60
- maskType?: 'BRL' | 'INTERNATIONAL'
61
- getRawValue?: (value: any) => string
62
- }
63
-
64
- export type TextInputMaskTypeProp =
65
- | 'credit-card'
66
- | 'cpf'
67
- | 'cnpj'
68
- | 'zip-code'
69
- | 'cel-phone'
70
- | 'custom'
71
-
72
- export interface TextInputMaskingProps {
73
- type: TextInputMaskTypeProp
74
- options?: MaskProps
75
- onChangeMask?: (
76
- newState: beforeMaskedValueChangeArgs['state'],
77
- oldState: beforeMaskedValueChangeArgs['state'],
78
- userInput: beforeMaskedValueChangeArgs['userInput']
79
- ) => beforeMaskedValueChangeArgs['state']
80
- saveFormatted?: boolean
81
- }
82
-
83
- export type InputMaskProps = {
84
- masking: TextInputMaskingProps
85
- }
@@ -1,46 +0,0 @@
1
- import React from 'react'
2
- import {
3
- TooltipProps as PrimitiveTooltipProps,
4
- TooltipContentProps,
5
- TooltipPortalProps,
6
- TooltipArrowProps,
7
- TooltipTriggerProps,
8
- TooltipProviderProps,
9
- } from '@radix-ui/react-tooltip'
10
- import { AnyFunction, StylesOf } from '@codeleap/common'
11
- import { TooltipComposition } from './styles'
12
- import { ViewProps } from '../View'
13
- import { StyledProp } from '@codeleap/styles'
14
-
15
- type TooltipComponentProps = {
16
- contentProps?: TooltipContentProps
17
- portalProps?: TooltipPortalProps
18
- arrowProps?: TooltipArrowProps
19
- triggerProps?: TooltipTriggerProps
20
- providerProps?: TooltipProviderProps
21
- }
22
-
23
- export type TooltipProps =
24
- Omit<PrimitiveTooltipProps, 'style'> &
25
- Omit<TooltipComponentProps, 'style'> &
26
- {
27
- toggle?: AnyFunction
28
- visible?: boolean
29
- content: React.ReactNode | ((props: TooltipProps & { variantsStyles: StylesOf<TooltipComposition> }) => JSX.Element)
30
- triggerWrapper?: React.ElementType
31
- triggerWrapperProps?: Partial<ViewProps>
32
- style?: StyledProp<TooltipComposition>
33
- side?: 'left' | 'right' | 'bottom' | 'top'
34
- openOnPress?: boolean
35
- openOnHover?: boolean
36
- disabled?: boolean
37
- delayDuration?: number
38
- closeOnClickOutside?: boolean
39
- onOpen?: AnyFunction
40
- onClose?: AnyFunction
41
- onValueChange?: (value: boolean) => void
42
- onHover?: (hoverType: 'enter' | 'leave', value: boolean) => void
43
- onPress?: (value: boolean) => void
44
- children?: React.ReactNode
45
- debugName?: string
46
- }
@@ -1,22 +0,0 @@
1
- import { AnyFunction } from '@codeleap/common'
2
- import { ComponentPropsWithRef, ElementType } from 'react'
3
- import { TouchableComposition } from './styles'
4
- import { AnyRecord, StyledProp } from '@codeleap/styles'
5
-
6
- export type TouchableProps<T extends ElementType = 'button'> =
7
- Omit<ComponentPropsWithRef<T>, 'style'> &
8
- {
9
- component?: ElementType<AnyRecord>
10
- disabled?: boolean
11
- propagate?: boolean
12
- onPress?: AnyFunction
13
- debugName: string
14
- debugComponent?: string
15
- style?: StyledProp<TouchableComposition>
16
- debounce?: number
17
- leadingDebounce?: boolean
18
- setPressed?: (pressed: boolean) => void
19
- analyticsEnabled?: boolean
20
- analyticsName?: string
21
- analyticsData?: Record<string, any>
22
- }
@@ -1,51 +0,0 @@
1
- import { AnyStyledComponent, CodeleapStyleRegistry, ICSS, StylePersistor } from '@codeleap/styles'
2
-
3
- const persistor = new StylePersistor({
4
- set(key, value) {
5
- if (typeof window === 'undefined') return null
6
- return localStorage?.setItem(key, value)
7
- },
8
- get(key) {
9
- if (typeof window === 'undefined') return null
10
- return localStorage?.getItem(key)
11
- },
12
- del(key) {
13
- if (typeof window === 'undefined') return null
14
- return localStorage?.removeItem(key)
15
- },
16
- })
17
-
18
- let instance: WebStyleRegistry
19
-
20
- const components: CodeleapStyleRegistry['components'][string][] = []
21
-
22
- export class WebStyleRegistry extends CodeleapStyleRegistry {
23
- constructor() {
24
- super(persistor)
25
-
26
- components.forEach((component) => {
27
- this.registerComponent(component)
28
- })
29
-
30
- if (!instance) {
31
- instance = this
32
- }
33
-
34
- return instance
35
- }
36
-
37
- createStyle(css: ICSS): ICSS {
38
- return css
39
- }
40
-
41
- static get current() {
42
- return instance
43
- }
44
-
45
- static registerComponent(component: AnyStyledComponent) {
46
- components.push(component)
47
- if (instance) {
48
- instance.registerComponent(component)
49
- }
50
- }
51
- }
@@ -1,15 +0,0 @@
1
- import { useRef } from 'react'
2
- import { FileInputRef } from '../../components/FileInput/types'
3
-
4
- export const useFileInput = () => {
5
- const inputRef = useRef<FileInputRef | null>(null)
6
-
7
- const openFilePicker = () => {
8
- return inputRef.current?.openFilePicker()
9
- }
10
-
11
- return {
12
- openFilePicker,
13
- ref: inputRef,
14
- }
15
- }
@@ -1,77 +0,0 @@
1
- import React from 'react'
2
- import { AnyFunction, TypeGuards } from '@codeleap/common'
3
- import { LoadMoreItemsCallback, UseInfiniteLoaderOptions, useInfiniteLoader } from 'masonic'
4
- import { ListProps } from '../../components/List'
5
- import { GridProps } from '../../components/Grid'
6
- import { useRefresh } from './useRefresh'
7
-
8
- export type UseInfiniteScrollArgs<Item extends Element = any> = {
9
- threshold?: number
10
- onLoadMore?: AnyFunction
11
- loadMoreOptions?: Partial<UseInfiniteLoaderOptions<Item>>
12
- }
13
-
14
- export type UseInfiniteScrollProps<Item extends Element = any> =
15
- Partial<ListProps> &
16
- Partial<GridProps> &
17
- UseInfiniteScrollArgs<Item>
18
-
19
- export type UseInfiniteScrollReturn<Item extends Element = any> = {
20
- onLoadMore: LoadMoreItemsCallback<Item>
21
- isRefresh: boolean
22
- layoutProps: {
23
- isEmpty: boolean
24
- refreshing: boolean
25
- scrollableRef: React.MutableRefObject<undefined>
26
- }
27
- onRefreshItems: AnyFunction
28
- }
29
-
30
- export function useInfiniteScroll<Item extends Element = any>(props: UseInfiniteScrollProps<Item>): UseInfiniteScrollReturn<Item> {
31
- const {
32
- onRefresh,
33
- data,
34
- hasNextPage,
35
- refresh: refreshEnabled,
36
- fetchNextPage,
37
- refreshThreshold,
38
- refreshDebounce,
39
- loadMoreOptions = {},
40
- onLoadMore,
41
- threshold = 16,
42
- } = props
43
-
44
- const infiniteLoader = useInfiniteLoader(
45
- async (args) => {
46
- if (hasNextPage) await fetchNextPage?.()
47
- if (TypeGuards.isFunction(onLoadMore)) await onLoadMore?.(args)
48
- },
49
- {
50
- isItemLoaded: (index, items) => !!items?.[index],
51
- threshold: threshold,
52
- ...loadMoreOptions,
53
- },
54
- )
55
-
56
- const refreshHookReturn = useRefresh(
57
- onRefresh,
58
- {
59
- threshold: refreshThreshold,
60
- debounce: refreshDebounce,
61
- enabled: refreshEnabled,
62
- },
63
- )
64
-
65
- const isEmpty = React.useMemo(() => (!data || !data?.length), [data?.length])
66
-
67
- return {
68
- onLoadMore: infiniteLoader,
69
- isRefresh: refreshHookReturn.refresh,
70
- layoutProps: {
71
- scrollableRef: refreshHookReturn.scrollableRef,
72
- refreshing: refreshHookReturn.refresh,
73
- isEmpty,
74
- },
75
- onRefreshItems: refreshHookReturn.refresher,
76
- }
77
- }
@@ -1,87 +0,0 @@
1
- import React from 'react'
2
- import { AnyFunction, useEffect } from '@codeleap/common'
3
-
4
- type UseRefreshOptions = {
5
- threshold: number
6
- debounce: number
7
- enabled: boolean
8
- }
9
-
10
- const scrollDebounce = (func, delay) => {
11
- const timerRef = React.useRef(null)
12
-
13
- const scrollDebounce = (...args) => {
14
- clearTimeout(timerRef.current)
15
- timerRef.current = setTimeout(() => {
16
- func(...args)
17
- }, delay)
18
- }
19
-
20
- return scrollDebounce
21
- }
22
-
23
- export const useRefresh = (onRefresh = () => null, options: UseRefreshOptions) => {
24
-
25
- const {
26
- threshold,
27
- debounce,
28
- enabled,
29
- } = options
30
-
31
- const [refresh, setRefresh] = React.useState(false)
32
-
33
- const pushToTopRef = React.useRef(0)
34
-
35
- const refresher = React.useCallback(async (_onRefresh: AnyFunction) => {
36
- setRefresh(true)
37
- await _onRefresh?.()
38
-
39
- setTimeout(() => {
40
- setRefresh(false)
41
- pushToTopRef.current = 0
42
- }, 2500)
43
- }, [])
44
-
45
- const containerRef = React.useRef(null)
46
-
47
- const onScroll = scrollDebounce(() => {
48
- if (containerRef.current) {
49
- const rect = containerRef.current?.getBoundingClientRect()
50
- const scrollTop = window?.pageYOffset || document?.documentElement?.scrollTop
51
-
52
- const containerTop = rect.top + scrollTop
53
- const containerHeight = rect.height
54
-
55
- const distanceFromTop = Math.max(0, scrollTop - containerTop)
56
- const distanceFromBottom = Math.max(0, containerTop + containerHeight - scrollTop)
57
-
58
- const totalDistance = containerHeight + distanceFromTop + distanceFromBottom
59
- const percentage = (distanceFromTop / totalDistance) * 100
60
-
61
- if (percentage < threshold) {
62
- if (pushToTopRef.current === 2) {
63
- refresher(onRefresh)
64
- }
65
-
66
- pushToTopRef.current = pushToTopRef.current + 1
67
- }
68
- }
69
- }, debounce)
70
-
71
- useEffect(() => {
72
- if (enabled) {
73
- window.addEventListener('scroll', onScroll)
74
-
75
- return () => {
76
- window.removeEventListener('scroll', onScroll)
77
- }
78
- }
79
- }, [enabled])
80
-
81
- return {
82
- refresh,
83
- scrollableRef: containerRef,
84
- refresher,
85
- }
86
- }
87
-
@@ -1,13 +0,0 @@
1
- import { StyleProp, useStyleObserver } from '@codeleap/styles'
2
- import { useMemo } from 'react'
3
- import { WebStyleRegistry } from '../WebStyleRegistry'
4
-
5
- export const useStylesFor = <T = unknown>(componentName: string, style: StyleProp<T, string>): T => {
6
- const styleObserver = useStyleObserver(style)
7
-
8
- const styles = useMemo(() => {
9
- return WebStyleRegistry.current.styleFor(componentName, style)
10
- }, [styleObserver])
11
-
12
- return styles
13
- }
@@ -1,9 +0,0 @@
1
- import createCache from '@emotion/cache'
2
-
3
- export const createCodeleapWebCache = () => {
4
- return createCache({
5
- key: 'codeleap-web',
6
- })
7
- }
8
-
9
- export const codeleapWebCache = createCodeleapWebCache()