@codeleap/web 3.25.0 → 3.25.2

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 +58 -92
  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,5 +1,53 @@
1
- import { TypeGuards } from '@codeleap/common'
2
- import { FormatChar, InputMaskProps, MaskProps, TextInputMaskTypeProp } from './types'
1
+ import { FormTypes, TypeGuards } from '@codeleap/common'
2
+
3
+ type beforeMaskedValueChangeArgs = {
4
+ state: {
5
+ value: string | undefined
6
+ selection: {
7
+ start: number
8
+ end: number
9
+ length?: number
10
+ }
11
+ }
12
+ userInput: null | string
13
+ }
14
+
15
+ type FormatChar = `[${string}]`
16
+
17
+ export type MaskProps = {
18
+ obfuscated?: boolean
19
+ mask?: string
20
+ placeholder?: string
21
+ maskChar?: string
22
+ formatChars?: Record<string, FormatChar>
23
+ alwaysShowMask?: boolean
24
+ validator?: FormTypes.ValidatorFunctionWithoutForm
25
+ maskType?: 'BRL' | 'INTERNATIONAL'
26
+ getRawValue?: (value: any) => string
27
+ }
28
+
29
+ export type TextInputMaskTypeProp =
30
+ | 'credit-card'
31
+ | 'cpf'
32
+ | 'cnpj'
33
+ | 'zip-code'
34
+ | 'cel-phone'
35
+ | 'custom'
36
+
37
+ export interface TextInputMaskingProps {
38
+ type: TextInputMaskTypeProp
39
+ options?: MaskProps
40
+ onChangeMask?: (
41
+ newState: beforeMaskedValueChangeArgs['state'],
42
+ oldState: beforeMaskedValueChangeArgs['state'],
43
+ userInput: beforeMaskedValueChangeArgs['userInput']
44
+ ) => beforeMaskedValueChangeArgs['state']
45
+ saveFormatted?: boolean
46
+ }
47
+
48
+ type InputMaskProps = {
49
+ masking: TextInputMaskingProps
50
+ }
3
51
 
4
52
  export const getMaskInputProps = ({ masking }: InputMaskProps): MaskProps & { notSaveFormatted: boolean } => {
5
53
  const {
@@ -1,10 +1,15 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { ActionIconParts } from '../ActionIcon'
2
3
  import { InputBaseParts, InputBaseStates } from '../InputBase'
3
4
 
4
- type TextInputParts = InputBaseParts | 'input' | 'placeholder' | 'selection'
5
-
5
+ type TextInputParts = InputBaseParts | 'input' | 'placeholder' | 'selection'
6
6
  export type TextInputStates = InputBaseStates | 'multiline' | 'hasMultipleLines'
7
7
 
8
8
  export type IconParts = Exclude<ActionIconParts, 'icon' | 'icon:disabled'>
9
9
 
10
- export type TextInputComposition = `${TextInputParts}:${TextInputStates}` | TextInputParts
10
+ export type TextInputComposition = `${TextInputParts}:${TextInputStates}` | TextInputParts
11
+
12
+ const createTextInputStyle =
13
+ createDefaultVariantFactory<TextInputComposition>()
14
+
15
+ export const TextInputPresets = includePresets((styles) => createTextInputStyle(() => ({ wrapper: styles })))
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { useState } from 'react'
2
2
  import {
3
3
  Provider as TooltipContainer,
4
4
  Root as TooltipWrapper,
@@ -6,30 +6,72 @@ import {
6
6
  Portal as TooltipPortal,
7
7
  Content as TooltipContent,
8
8
  Arrow as TooltipArrow,
9
+ TooltipProps as PrimitiveTooltipProps,
10
+ TooltipContentProps,
11
+ TooltipPortalProps,
12
+ TooltipArrowProps,
13
+ TooltipTriggerProps,
14
+ TooltipProviderProps,
9
15
  } from '@radix-ui/react-tooltip'
10
- import { TypeGuards, useConditionalState } from '@codeleap/common'
11
- import { View } from '../View'
16
+
17
+ import { AnyFunction, ComponentVariants, StylesOf, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
18
+ import { TooltipComposition, TooltipPresets } from './styles'
19
+ import { ComponentCommonProps, ComponentWithDefaultProps } from '../../types/utility'
20
+ import { View, ViewProps } from '../View'
12
21
  import { useClickOutsideElement } from '../../lib'
13
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
14
- import { TooltipProps } from './types'
15
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
16
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
17
22
 
18
- export * from './styles'
19
- export * from './types'
23
+ type TooltipComponentProps = {
24
+ contentProps?: TooltipContentProps
25
+ portalProps?: TooltipPortalProps
26
+ arrowProps?: TooltipArrowProps
27
+ triggerProps?: TooltipTriggerProps
28
+ providerProps?: TooltipProviderProps
29
+ }
20
30
 
21
- export const Tooltip = (props: TooltipProps) => {
31
+ export type TooltipProps = PrimitiveTooltipProps & TooltipComponentProps & {
32
+ toggle?: AnyFunction
33
+ visible?: boolean
34
+ content: React.ReactNode | ((props: TooltipProps & { variantsStyles: StylesOf<TooltipComposition> }) => JSX.Element)
35
+ triggerWrapper?: React.ElementType
36
+ triggerWrapperProps?: Partial<ViewProps<'div'>>
37
+ styles?: StylesOf<TooltipComposition>
38
+ side?: 'left' | 'right' | 'bottom' | 'top'
39
+ openOnPress?: boolean
40
+ openOnHover?: boolean
41
+ disabled?: boolean
42
+ delayDuration?: number
43
+ closeOnClickOutside?: boolean
44
+ onOpen?: AnyFunction
45
+ onClose?: AnyFunction
46
+ onValueChange?: (value: boolean) => void
47
+ onHover?: (hoverType: 'enter' | 'leave', value: boolean) => void
48
+ onPress?: (value: boolean) => void
49
+ children?: React.ReactNode
50
+ style?: React.CSSProperties
51
+ } & ComponentVariants<typeof TooltipPresets> & ComponentCommonProps
52
+
53
+ const defaultProps: Partial<TooltipProps> = {
54
+ openOnPress: true,
55
+ openOnHover: true,
56
+ disabled: false,
57
+ delayDuration: 0,
58
+ closeOnClickOutside: false,
59
+ side: 'bottom',
60
+ triggerWrapper: View as unknown as React.ElementType,
61
+ }
62
+
63
+ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipProps) => {
22
64
  const allProps = {
23
65
  ...Tooltip.defaultProps,
24
66
  ...props,
25
67
  }
26
68
 
27
69
  const {
28
- toggle: _toggle,
29
- visible: _visible,
70
+ toggle: _toggle = null,
71
+ visible: _visible = null,
30
72
  children,
31
73
  content: Content,
32
- triggerWrapperProps,
74
+ triggerWrapperProps = {},
33
75
  triggerWrapper: TriggerWrapper,
34
76
  side,
35
77
  disabled,
@@ -41,23 +83,32 @@ export const Tooltip = (props: TooltipProps) => {
41
83
  onValueChange,
42
84
  onHover,
43
85
  onPress,
44
- contentProps,
45
- portalProps,
46
- arrowProps,
47
- triggerProps,
48
- providerProps,
86
+ contentProps = {},
87
+ portalProps = {},
88
+ arrowProps = {},
89
+ triggerProps = {},
90
+ providerProps = {},
91
+ variants = [],
92
+ responsiveVariants = {},
93
+ styles = {},
49
94
  closeOnClickOutside,
50
95
  style,
51
96
  ...rest
52
97
  } = allProps
53
98
 
54
- const styles = useStylesFor(Tooltip.styleRegistryName, style)
99
+ const variantsStyles = useDefaultComponentStyle<'u:Tooltip', typeof TooltipPresets>('u:Tooltip', {
100
+ responsiveVariants,
101
+ variants,
102
+ styles,
103
+ })
104
+
105
+ const hasStateProps = !TypeGuards.isNil(_visible) && TypeGuards.isFunction(_toggle)
55
106
 
56
- const [visible, toggle] = useConditionalState(_visible, _toggle, { initialValue: false })
107
+ const [visible, toggle] = hasStateProps ? [_visible, _toggle] : useState(false)
57
108
 
58
109
  const tooltipDirectionStyle = React.useMemo(() => {
59
- return side ? styles[`content:${side}`] : styles.content
60
- }, [side, styles])
110
+ return side ? variantsStyles[`content:${side}`] : variantsStyles.content
111
+ }, [side, variantsStyles])
61
112
 
62
113
  function handleToggle(_value: boolean, isToggle = true) {
63
114
  if (disabled) return
@@ -112,7 +163,8 @@ export const Tooltip = (props: TooltipProps) => {
112
163
  open={visible}
113
164
  onOpenChange={onOpenChange}
114
165
  {...rest}
115
- // @ts-ignore
166
+ // @ts-ignore expected error
167
+ css={[variantsStyles.wrapper, style]}
116
168
  >
117
169
  <TooltipTrigger
118
170
  onClick={_onPress}
@@ -121,35 +173,29 @@ export const Tooltip = (props: TooltipProps) => {
121
173
  asChild
122
174
  ref={triggerRef}
123
175
  {...triggerProps}
124
- //@ts-expect-error
125
- css={styles.triggerWrapper}
176
+ style={variantsStyles.triggerWrapper}
126
177
  >
127
- <TriggerWrapper
128
- {...allProps as any}
178
+ <TriggerWrapper
179
+ {...allProps as any}
129
180
  {...triggerWrapperProps}
130
- css={styles.triggerInnerWrapper}
181
+ style={variantsStyles.triggerInnerWrapper}
131
182
  >
132
183
  {children}
133
184
  </TriggerWrapper>
134
185
  </TooltipTrigger>
135
186
  <TooltipPortal {...portalProps}>
136
- {/* @ts-expect-error icss type */}
137
- <TooltipContent ref={contentRef} css={[tooltipDirectionStyle, styles.content]} sideOffset={2} side={side} {...contentProps}>
187
+ <TooltipContent ref={contentRef} css={[tooltipDirectionStyle, variantsStyles.content]} sideOffset={2} side={side} {...contentProps}>
138
188
  {
139
189
  TypeGuards.isFunction(Content)
140
190
  ? <Content
141
191
  {...allProps}
142
192
  visible={visible}
143
193
  toggle={toggle}
144
- variantsStyles={styles}
194
+ variantsStyles={variantsStyles}
145
195
  />
146
196
  : Content
147
197
  }
148
- <TooltipArrow
149
- {...arrowProps}
150
- //@ts-expect-error icss type
151
- css={styles.arrow}
152
- />
198
+ <TooltipArrow {...arrowProps} style={variantsStyles.arrow} />
153
199
  </TooltipContent>
154
200
  </TooltipPortal>
155
201
  </TooltipWrapper>
@@ -158,29 +204,6 @@ export const Tooltip = (props: TooltipProps) => {
158
204
  )
159
205
  }
160
206
 
161
- Tooltip.styleRegistryName = 'Tooltip'
207
+ Tooltip.defaultProps = defaultProps
162
208
 
163
- Tooltip.elements = [
164
- 'content',
165
- 'arrow',
166
- 'triggerWrapper',
167
- 'triggerInnerWrapper',
168
- ]
169
-
170
- Tooltip.rootElement = 'content'
171
-
172
- Tooltip.withVariantTypes = <S extends AnyRecord>(styles: S) => {
173
- return Tooltip as (props: StyledComponentProps<TooltipProps, typeof styles>) => IJSX
174
- }
175
-
176
- Tooltip.defaultProps = {
177
- openOnPress: true,
178
- openOnHover: true,
179
- disabled: false,
180
- delayDuration: 0,
181
- closeOnClickOutside: false,
182
- side: 'bottom',
183
- triggerWrapper: View as unknown as React.ElementType,
184
- } as Partial<TooltipProps>
185
-
186
- WebStyleRegistry.registerComponent(Tooltip)
209
+ export * from './styles'
@@ -1,11 +1,18 @@
1
- export type TooltipSide = 'left' | 'right' | 'bottom' | 'top'
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
2
 
3
+ export type TooltipSide = 'left' | 'right' | 'bottom' | 'top'
3
4
  export type TooltipState = 'delayed-open' | 'closed' | 'instant-open' | 'disabled'
4
-
5
- export type TooltipParts =
5
+ export type TooltipParts =
6
+ 'wrapper' |
6
7
  'arrow' |
7
8
  'content' |
8
9
  'triggerWrapper' |
9
10
  'triggerInnerWrapper'
10
11
 
11
12
  export type TooltipComposition = `content:${TooltipSide}` | TooltipParts
13
+
14
+ const createTooltipStyle = createDefaultVariantFactory<TooltipComposition>()
15
+
16
+ export const TooltipPresets = includePresets((styles) => createTooltipStyle(() => ({
17
+ wrapper: styles,
18
+ })))
@@ -1,45 +1,77 @@
1
- import { onMount, TypeGuards, useGlobalContext } from '@codeleap/common'
2
- import React, { ComponentType, ElementType, forwardRef, HTMLAttributes } from 'react'
1
+ import { AnyFunction, ComponentVariants, onMount, TypeGuards, useCodeleapContext, useDefaultComponentStyle } from '@codeleap/common'
2
+ import React, { ComponentPropsWithRef, ElementType, forwardRef } from 'react'
3
3
  import { stopPropagation } from '../../lib'
4
+ import { View } from '../View'
5
+ import { TouchableComposition, TouchablePresets } from './styles'
6
+ import { CSSInterpolation } from '@emotion/css'
7
+ import { StylesOf, NativeHTMLElement } from '../../types'
4
8
  import { getTestId } from '../../lib/utils/test'
5
- import { TouchableProps } from './types'
6
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
7
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
8
- import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
9
-
10
9
  export * from './styles'
11
- export * from './types'
12
10
 
13
- export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchableProps: TouchableProps, ref) => {
14
- const allProps = {
15
- ...Touchable.defaultProps,
16
- ...touchableProps,
11
+ export type TouchableProps<T extends ElementType = 'button'> = ComponentPropsWithRef<T> & {
12
+ css?: CSSInterpolation | CSSInterpolation[]
13
+ component?: T
14
+ disabled?: boolean
15
+ propagate?: boolean
16
+ style?: React.CSSProperties
17
+ onPress?: AnyFunction
18
+ debugName: string
19
+ debugComponent?: string
20
+ styles?: StylesOf<TouchableComposition>
21
+ debounce?: number
22
+ leadingDebounce?: boolean
23
+ setPressed?: (pressed: boolean) => void
24
+ analyticsEnabled?: boolean
25
+ analyticsName?: string
26
+ analyticsData?: Record<string, any>
27
+ } & ComponentVariants<typeof TouchablePresets>
28
+
29
+ const defaultProps: Partial<TouchableProps<'button'>> = {
30
+ propagate: true,
31
+ debounce: null,
32
+ component: View as unknown as 'button',
33
+ style: {},
34
+ styles: {},
35
+ responsiveVariants: {},
36
+ variants: [],
37
+ css: [],
38
+ analyticsEnabled: false,
39
+ analyticsName: null,
40
+ analyticsData: {},
41
+ tabIndex: 0,
42
+ }
43
+ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
44
+ touchableProps: TouchableProps<T>,
45
+ ref,
46
+ ) => {
47
+ const mergedProps = {
48
+ ...(defaultProps),
49
+ ...(touchableProps),
17
50
  }
18
-
19
51
  const {
20
52
  propagate,
21
53
  debounce,
22
54
  leadingDebounce,
23
55
  setPressed,
24
- component,
56
+ component: Component,
25
57
  disabled,
26
58
  onPress,
27
59
  onClick,
28
60
  debugName,
29
61
  debugComponent,
30
62
  style,
63
+ styles,
64
+ responsiveVariants,
65
+ variants,
66
+ css,
31
67
  analyticsEnabled,
32
68
  analyticsName,
33
69
  analyticsData,
34
70
  ...props
35
- } = allProps
36
-
37
- const styles = useStylesFor(Touchable.styleRegistryName, style)
71
+ } = mergedProps
38
72
 
39
73
  const pressed = React.useRef(!!leadingDebounce)
40
74
 
41
- const { logger } = useGlobalContext()
42
-
43
75
  onMount(() => {
44
76
  if (!!leadingDebounce && !!debounce) {
45
77
  setTimeout(() => {
@@ -48,7 +80,14 @@ export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchabl
48
80
  }
49
81
  })
50
82
 
51
- const Component = component as unknown as ComponentType<HTMLAttributes<HTMLButtonElement>>
83
+ const variantStyles = useDefaultComponentStyle<'u:Touchable', typeof TouchablePresets>('u:Touchable', {
84
+ responsiveVariants,
85
+ variants,
86
+ styles,
87
+ rootElement: 'wrapper',
88
+ })
89
+
90
+ const { logger } = useCodeleapContext()
52
91
 
53
92
  const notPressable = !TypeGuards.isFunction(onPress) && !TypeGuards.isFunction(onClick)
54
93
 
@@ -57,7 +96,14 @@ export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchabl
57
96
 
58
97
  if (!propagate) stopPropagation(event)
59
98
 
60
- if (notPressable) return
99
+ if (notPressable) {
100
+ logger.warn(
101
+ 'No onPress passed to touchable',
102
+ touchableProps,
103
+ 'User interaction',
104
+ )
105
+ return
106
+ }
61
107
 
62
108
  const _onPress = () => {
63
109
  if (event && (event?.type !== 'click' && event?.keyCode !== 13 && event?.key !== 'Enter')) return null
@@ -94,37 +140,34 @@ export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchabl
94
140
  }
95
141
  }
96
142
 
97
- const testId = getTestId(allProps)
143
+ const _styles = React.useMemo(() => ([
144
+ variantStyles.wrapper,
145
+ disabled && variantStyles['wrapper:disabled'],
146
+ css,
147
+ style,
148
+ ]), [variantStyles, disabled, style])
149
+
150
+ const testId = getTestId(mergedProps)
98
151
 
99
152
  return (
100
- <Component
153
+ // @ts-ignore
154
+ <View
155
+ component={Component || 'button'}
101
156
  {...props}
157
+ debugName={debugName}
102
158
  onClick={handleClick}
103
159
  onKeyDown={handleClick}
104
160
  ref={ref}
105
- // @ts-expect-error icss type
106
- css={[styles.wrapper, disabled && styles['wrapper:disabled']]}
161
+ css={_styles}
107
162
  data-testid={testId}
108
163
  />
109
164
  )
110
- }) as StyledComponentWithProps<TouchableProps>
111
-
112
- Touchable.styleRegistryName = 'Touchable'
113
- Touchable.elements = ['wrapper']
114
- Touchable.rootElement = 'wrapper'
115
-
116
- Touchable.withVariantTypes = <S extends AnyRecord>(styles: S) => {
117
- return Touchable as <T extends ElementType = 'button'>(props: StyledComponentProps<TouchableProps<T>, typeof styles>) => IJSX
118
165
  }
119
166
 
120
- Touchable.defaultProps = {
121
- propagate: true,
122
- debounce: null,
123
- component: 'div',
124
- analyticsEnabled: false,
125
- analyticsName: null,
126
- analyticsData: {},
127
- tabIndex: 0,
128
- } as Partial<TouchableProps>
167
+ export const Touchable = forwardRef(TouchableCP) as (<T extends NativeHTMLElement = 'button'>(
168
+ touchableProps: TouchableProps<T>
169
+ ) => JSX.Element) & {
170
+ defaultProps: Partial<TouchableProps<'button'>>
171
+ }
129
172
 
130
- WebStyleRegistry.registerComponent(Touchable)
173
+ Touchable.defaultProps = defaultProps
@@ -1,3 +1,9 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
1
3
  export type TouchableState = 'disabled'
2
4
  export type TouchableParts = 'wrapper'
3
5
  export type TouchableComposition = TouchableParts | `${TouchableParts}:${TouchableState}`
6
+
7
+ const createTouchableStyle = createDefaultVariantFactory<TouchableComposition>()
8
+
9
+ export const TouchablePresets = includePresets((styles) => createTouchableStyle(() => ({ wrapper: styles })))
@@ -1,19 +1,25 @@
1
- import { useMemo, TypeGuards } from '@codeleap/common'
2
- import React, { ElementType, forwardRef } from 'react'
1
+ /** @jsx jsx */
2
+ import { jsx, CSSObject } from '@emotion/react'
3
+ import { useDefaultComponentStyle, useCodeleapContext, useMemo, TypeGuards } from '@codeleap/common'
4
+ import React, { forwardRef, Ref } from 'react'
5
+ import { ViewPresets } from './styles'
3
6
  import { useMediaQuery } from '../../lib/hooks'
7
+ import { NativeHTMLElement } from '../../types'
4
8
  import { motion } from 'framer-motion'
5
9
  import { ViewProps } from './types'
6
10
  import { getTestId } from '../../lib/utils/test'
7
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
8
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
9
- import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps, useTheme } from '@codeleap/styles'
10
11
 
11
12
  export * from './styles'
12
13
  export * from './types'
13
14
 
14
- export const View = forwardRef<HTMLDivElement, ViewProps>((viewProps, ref) => {
15
+ export const ViewCP = (
16
+ viewProps: ViewProps<'div'>,
17
+ ref: React.Ref<any>,
18
+ ) => {
15
19
  const {
16
- component,
20
+ responsiveVariants = {},
21
+ variants = [],
22
+ component = 'div',
17
23
  children,
18
24
  is,
19
25
  not,
@@ -21,28 +27,32 @@ export const View = forwardRef<HTMLDivElement, ViewProps>((viewProps, ref) => {
21
27
  onHover,
22
28
  debugName,
23
29
  down,
30
+ scroll = false,
31
+ debug = false,
24
32
  style,
25
- animated,
26
- animatedProps,
33
+ animated = false,
34
+ animatedProps = {},
35
+ css = [],
27
36
  ...props
28
- } = {
29
- ...View.defaultProps,
30
- ...viewProps,
31
- }
37
+ } = viewProps
32
38
 
33
- const styles = useStylesFor(View.styleRegistryName, style)
39
+ const Component = animated ? (motion?.[component] || motion.div) : (component || 'div')
34
40
 
35
- const Component: ElementType = animated ? (motion?.[component as string] || motion.div) : (component || 'div')
41
+ const variantStyles = useDefaultComponentStyle<'u:View', typeof ViewPresets>('u:View', {
42
+ responsiveVariants,
43
+ variants,
44
+ styles: { wrapper: style },
45
+ rootElement: 'wrapper',
46
+ })
36
47
 
37
- const theme = useTheme(store => store.current)
48
+ const { Theme, logger } = useCodeleapContext()
38
49
 
39
50
  function handleHover(isMouseOverElement: boolean) {
40
51
  onHover?.(isMouseOverElement)
41
52
  }
42
53
 
43
54
  const platformMediaQuery = useMemo(() => {
44
- // @ts-expect-error theme type
45
- return theme?.media?.renderToPlatformQuery({
55
+ return Theme.media.renderToPlatformQuery({
46
56
  is,
47
57
  not,
48
58
  up,
@@ -52,38 +62,42 @@ export const View = forwardRef<HTMLDivElement, ViewProps>((viewProps, ref) => {
52
62
 
53
63
  const matches = useMediaQuery(platformMediaQuery)
54
64
 
55
- const hoverProps = TypeGuards.isFunction(onHover) && {
65
+ const componentStyles = useMemo(() => {
66
+ return [
67
+ variantStyles.wrapper,
68
+ scroll && { overflowY: 'scroll' },
69
+ matches && { display: 'none' },
70
+ style,
71
+ css,
72
+ ]
73
+ }, [variantStyles, scroll, matches, css])
74
+
75
+ const onHoverProps = TypeGuards.isFunction(onHover) && {
56
76
  onMouseEnter: () => handleHover(true),
57
77
  onMouseLeave: () => handleHover(false),
58
78
  }
59
79
 
80
+ if (debug) {
81
+ logger.log(debugName, { componentStyles, platformMediaQuery, matches })
82
+ }
83
+
60
84
  const testId = getTestId(viewProps)
61
85
 
62
86
  return (
63
87
  <Component
64
- {...hoverProps}
88
+ css={componentStyles}
89
+ // @ts-expect-error
90
+ ref={ref}
91
+ {...onHoverProps}
65
92
  {...props}
66
93
  {...animatedProps}
67
- ref={ref}
68
94
  data-testid={testId}
69
- css={[styles.wrapper, matches && { display: 'none' }]}
70
95
  >
71
96
  {children}
72
97
  </Component>
73
98
  )
74
- }) as StyledComponentWithProps<ViewProps>
75
-
76
- View.styleRegistryName = 'View'
77
- View.elements = ['wrapper']
78
- View.rootElement = 'wrapper'
79
-
80
- View.withVariantTypes = <S extends AnyRecord>(styles: S) => {
81
- return View as <T extends ElementType = 'div'>(props: StyledComponentProps<ViewProps<T>, typeof styles>) => IJSX
82
99
  }
83
100
 
84
- View.defaultProps = {
85
- component: 'div',
86
- animated: false,
87
- } as Partial<ViewProps>
88
-
89
- WebStyleRegistry.registerComponent(View)
101
+ export const View = forwardRef(ViewCP) as unknown as <T extends NativeHTMLElement = 'div'>(
102
+ props: ViewProps<T>
103
+ ) => JSX.Element
@@ -1 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
1
3
  export type ViewComposition = 'wrapper'
4
+
5
+ const createViewStyle = createDefaultVariantFactory<ViewComposition>()
6
+
7
+ export const ViewPresets = includePresets((styles) => createViewStyle(() => ({ wrapper: styles })))