@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,8 +1,9 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { BadgeComposition } from '../Badge'
2
3
 
3
4
  export type TagStates = 'pressable' | 'disabled'
4
5
 
5
- type TagBadgeParts =
6
+ type TagBadgeParts =
6
7
  | `leftBadge${Capitalize<BadgeComposition>}`
7
8
  | `rightBadge${Capitalize<BadgeComposition>}`
8
9
 
@@ -13,3 +14,10 @@ export type TagParts =
13
14
  | 'rightIcon'
14
15
 
15
16
  export type TagComposition = TagParts | TagBadgeParts | `${TagParts}:${TagStates}`
17
+
18
+ const createTagStyle = createDefaultVariantFactory<TagComposition>()
19
+
20
+ export const TagPresets = includePresets((styles) => createTagStyle(() => ({
21
+ wrapper: styles,
22
+ })),
23
+ )
@@ -1,6 +1,6 @@
1
- import { AppIcon, StyledProp } from '@codeleap/styles'
1
+ import { StylesOf, ComponentVariants, IconPlaceholder } from '@codeleap/common'
2
2
  import { ReactElement } from 'react'
3
- import { TagComposition } from './styles'
3
+ import { TagComposition, TagPresets } from './styles'
4
4
  import { BadgeProps } from '../Badge'
5
5
  import { TextProps } from '../Text'
6
6
  import { IconProps } from '../Icon'
@@ -8,17 +8,17 @@ import { ComponentCommonProps } from '../../types'
8
8
  import { TouchableProps } from '../Touchable'
9
9
  import { ViewProps } from '../View'
10
10
 
11
- export type TagProps =
12
- Omit<ViewProps, 'style'> &
13
- Omit<TouchableProps, 'style'> &
14
- ComponentCommonProps &
15
- {
16
- style?: StyledProp<TagComposition>
11
+ export type TagProps =
12
+ Omit<ViewProps<'div'>, 'styles' | 'variants' | 'responsiveVariants'> &
13
+ Omit<TouchableProps, 'styles' | 'variants' | 'responsiveVariants'> &
14
+ ComponentVariants<typeof TagPresets> &
15
+ ComponentCommonProps & {
16
+ styles?: StylesOf<TagComposition>
17
17
  text?: TextProps<'p'>['text'] | ReactElement
18
18
  textProps?: Partial<TextProps<'p'>>
19
- leftIcon?: AppIcon
19
+ leftIcon?: IconPlaceholder
20
20
  leftIconProps?: Partial<IconProps>
21
- rightIcon?: AppIcon
21
+ rightIcon?: IconPlaceholder
22
22
  rightIconProps?: Partial<IconProps>
23
23
  leftComponent?: ReactElement
24
24
  rightComponent?: ReactElement
@@ -1,21 +1,38 @@
1
- import { TypeGuards } from '@codeleap/common'
1
+ import { TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
2
2
  import { motion } from 'framer-motion'
3
- import React, { ElementType, forwardRef } from 'react'
3
+ import React, { ElementType } from 'react'
4
+ import { TextPresets } from './styles'
4
5
  import { TextProps } from './types'
5
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
6
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
7
- import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
8
6
 
9
7
  export * from './styles'
10
8
  export * from './types'
11
9
 
12
- export const Text = forwardRef<HTMLParagraphElement, TextProps>((textProps, ref) => {
10
+ const defaultProps: Partial<TextProps<'p'>> = {
11
+ debugName: 'Text component',
12
+ component: 'p',
13
+ debounce: null,
14
+ pressDisabled: false,
15
+ animated: false,
16
+ animatedProps: {},
17
+ }
18
+
19
+ export const Text = <T extends ElementType>(textProps: TextProps<T>) => {
20
+ const allProps = {
21
+ ...Text.defaultProps,
22
+ ...textProps,
23
+ }
24
+
13
25
  const {
14
- style,
15
- text,
26
+ variants = [],
27
+ responsiveVariants = {},
28
+ styles = {},
29
+ style = {},
30
+ css,
31
+ text = null,
16
32
  children,
17
33
  component,
18
34
  debugName,
35
+ msg = null,
19
36
  onPress,
20
37
  debounce,
21
38
  pressDisabled,
@@ -23,17 +40,19 @@ export const Text = forwardRef<HTMLParagraphElement, TextProps>((textProps, ref)
23
40
  animated,
24
41
  animatedProps,
25
42
  ...props
26
- } = {
27
- ...Text.defaultProps,
28
- ...textProps,
29
- }
30
-
31
- const styles = useStylesFor(Text.styleRegistryName, style)
43
+ } = allProps
32
44
 
33
- const Component: ElementType = animated ? (motion?.[component as string] || motion.p) : (component || 'p')
45
+ const Component = animated ? (motion?.[component] || motion.p) : (component || 'p')
34
46
 
35
47
  const pressedRef = React.useRef(false)
36
48
 
49
+ const variantStyles = useDefaultComponentStyle<'u:Text', typeof TextPresets>('u:Text', {
50
+ responsiveVariants,
51
+ variants,
52
+ styles,
53
+ rootElement: 'text',
54
+ })
55
+
37
56
  const isPressable = (TypeGuards.isFunction(onPress) || TypeGuards.isFunction(onClick)) && !pressDisabled
38
57
 
39
58
  const disabled = isPressable === false
@@ -61,39 +80,31 @@ export const Text = forwardRef<HTMLParagraphElement, TextProps>((textProps, ref)
61
80
  }
62
81
  }
63
82
 
83
+ const _styles = React.useMemo(() => ([
84
+ variantStyles.text,
85
+ disabled && variantStyles['text:disabled'],
86
+ css,
87
+ style,
88
+ ]), [css, style, disabled])
89
+
64
90
  const pressProps = isPressable ? {
65
91
  onClick: disabled ? null : _onPress,
66
92
  } : {}
67
93
 
68
- const componentProps: AnyRecord = {
94
+ const componentProps: any = {
69
95
  ...props,
70
96
  ...pressProps,
71
- ...animatedProps,
97
+ ...animatedProps
72
98
  }
73
99
 
74
100
  return (
75
- <Component {...componentProps} ref={ref} css={[styles.text, disabled && styles['text:disabled']]}>
101
+ <Component
102
+ css={_styles}
103
+ {...componentProps}
104
+ >
76
105
  {text || children}
77
106
  </Component>
78
107
  )
79
- }) as StyledComponentWithProps<TextProps>
80
-
81
- Text.styleRegistryName = 'Text'
82
- Text.elements = ['text']
83
- Text.rootElement = 'text'
84
-
85
- Text.withVariantTypes = <S extends AnyRecord>(styles: S) => {
86
- return Text as <T extends ElementType = 'p'>(props: StyledComponentProps<TextProps<T>, typeof styles>) => IJSX
87
108
  }
88
109
 
89
- Text.defaultProps = {
90
- debugName: 'Text component',
91
- component: 'p',
92
- text: null,
93
- debounce: null,
94
- pressDisabled: false,
95
- animated: false,
96
- animatedProps: {},
97
- } as Partial<TextProps>
98
-
99
- WebStyleRegistry.registerComponent(Text)
110
+ Text.defaultProps = defaultProps
@@ -1 +1,9 @@
1
+ import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
2
+
1
3
  export type TextComposition = 'text' | 'text:disabled'
4
+
5
+ const createTextStyle = createDefaultVariantFactory<TextComposition>()
6
+
7
+ export const TextPresets = includePresets((styles) => createTextStyle(() => ({
8
+ text: styles
9
+ })))
@@ -1,14 +1,14 @@
1
- import { ComponentPropsWithoutRef, ElementType } from 'react'
2
- import { TextComposition } from './styles'
3
- import { AnyRecord, StyledProp } from '@codeleap/styles'
1
+ import { StylesOf, ComponentVariants } from '@codeleap/common'
4
2
  import { MotionProps } from 'framer-motion'
3
+ import { ComponentPropsWithoutRef, ElementType } from 'react'
4
+ import { TextComposition, TextPresets } from './styles'
5
5
 
6
- export type TextProps<T extends ElementType = 'p'> =
7
- Omit<ComponentPropsWithoutRef<T>, 'style'> &
8
- {
9
- component?: ElementType<AnyRecord>
6
+ export type TextProps<T extends ElementType> = ComponentPropsWithoutRef<T> &
7
+ ComponentVariants<typeof TextPresets> & {
8
+ component?: T
10
9
  text?: string
11
- style?: StyledProp<TextComposition>
10
+ styles?: StylesOf<TextComposition>
11
+ msg?: string
12
12
  debugName?: string
13
13
  debounce?: number
14
14
  pressDisabled?: boolean
@@ -1,12 +1,9 @@
1
1
  import React from 'react'
2
- import { onUpdate, useCallback, useState, useValidate } from '@codeleap/common'
2
+ import { onUpdate, useCallback, useDefaultComponentStyle, useState, useValidate } from '@codeleap/common'
3
3
  import { BubbleMenu, FloatingMenu, EditorContent } from '@tiptap/react'
4
4
  import { FileInput, Text, View } from '../components'
5
5
  import { TextEditorProps } from './types'
6
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
7
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
8
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
9
-
6
+ import { TextEditorPresets } from './styles'
10
7
  export * from './styles'
11
8
  export * from './types'
12
9
 
@@ -14,19 +11,17 @@ export const TextEditor = (props: TextEditorProps) => {
14
11
  const {
15
12
  children,
16
13
  editor,
17
- style,
14
+ variants = [],
15
+ styles = {},
16
+ responsiveVariants = {},
17
+ style = {},
18
18
  bubbleMenuProps,
19
19
  floatingMenuProps,
20
20
  toolbarComponent,
21
21
  fileInputRef,
22
22
  _error,
23
23
  validate,
24
- } = {
25
- ...TextEditor.defaultProps,
26
- ...props,
27
- }
28
-
29
- const styles = useStylesFor(TextEditor.styleRegistryName, style)
24
+ } = props
30
25
 
31
26
  const [_isFocused, setIsFocused] = useState(false)
32
27
  const validation = useValidate(editor?.getText() ?? '', validate)
@@ -35,6 +30,12 @@ export const TextEditor = (props: TextEditorProps) => {
35
30
  const errorMessage = validation.message || _error
36
31
  const isDisabled = !editor?.isEditable ?? null
37
32
 
33
+ const variantStyles = useDefaultComponentStyle<'u:TextEditor', typeof TextEditorPresets>('u:TextEditor', {
34
+ variants,
35
+ styles,
36
+ responsiveVariants,
37
+ })
38
+
38
39
  const handleBlur = React.useCallback(() => {
39
40
  validation?.onInputBlurred()
40
41
  setIsFocused(false)
@@ -57,9 +58,8 @@ export const TextEditor = (props: TextEditorProps) => {
57
58
 
58
59
  const _BubbleMenu = useCallback(() => {
59
60
  return (
60
- // @ts-expect-error icss type
61
- <BubbleMenu css={[styles.bubbleMenu]} {...bubbleMenuProps} editor={editor}>
62
- <View style={styles.bubbleMenuInnerWrapper}>
61
+ <BubbleMenu css={[variantStyles.bubbleMenu]} {...bubbleMenuProps} editor={editor}>
62
+ <View style={variantStyles.bubbleMenuInnerWrapper}>
63
63
  {bubbleMenuProps?.renderContent}
64
64
  </View>
65
65
  </BubbleMenu>
@@ -68,9 +68,8 @@ export const TextEditor = (props: TextEditorProps) => {
68
68
 
69
69
  const _FloatingMenu = useCallback(() => {
70
70
  return (
71
- // @ts-expect-error icss type
72
- <FloatingMenu css={[styles.floatingMenu]} {...floatingMenuProps} editor={editor}>
73
- <View style={styles.floatingMenuInnerWrapper}>
71
+ <FloatingMenu css={[variantStyles.floatingMenu]} {...floatingMenuProps} editor={editor}>
72
+ <View style={variantStyles.floatingMenuInnerWrapper}>
74
73
  {floatingMenuProps?.renderContent}
75
74
  </View>
76
75
  </FloatingMenu>
@@ -78,21 +77,21 @@ export const TextEditor = (props: TextEditorProps) => {
78
77
  }, [editor])
79
78
 
80
79
  const editorStyles = [
81
- styles.editor,
82
- hasError && styles['editor:error'],
83
- isDisabled && styles['editor:disabled'],
80
+ variantStyles.editor,
81
+ hasError && variantStyles['editor:error'],
82
+ isDisabled && variantStyles['editor:disabled'],
84
83
  ]
85
84
 
86
85
  if (!editor) return null
87
-
88
86
  return (
89
87
  <View
90
- style={[
91
- styles.wrapper,
92
- hasError && styles['wrapper:error'],
88
+ css={[
89
+ variantStyles.wrapper,
90
+ hasError && variantStyles['wrapper:error'],
93
91
  {
94
92
  '.tiptap': editorStyles,
95
93
  },
94
+ style,
96
95
  ]}
97
96
  >
98
97
  {toolbarComponent}
@@ -100,30 +99,10 @@ export const TextEditor = (props: TextEditorProps) => {
100
99
  <_BubbleMenu />
101
100
  <_FloatingMenu />
102
101
  <EditorContent editor={editor} />
103
- {hasError ? <Text text={errorMessage as string} style={styles['errorMessage:error']} /> : null}
104
- <FileInput ref={fileInputRef} />
102
+ {hasError ? <Text text={errorMessage as string} css={variantStyles['errorMessage:error']} /> : null}
103
+ <FileInput
104
+ ref={fileInputRef}
105
+ />
105
106
  </View>
106
107
  )
107
108
  }
108
-
109
- TextEditor.styleRegistryName = 'TextEditor'
110
-
111
- TextEditor.elements = [
112
- 'wrapper',
113
- 'editor',
114
- 'floatingMenu',
115
- 'bubbleMenu',
116
- 'bubbleMenuInnerWrapper',
117
- 'floatingMenuInnerWrapper',
118
- 'errorMessage',
119
- ]
120
-
121
- TextEditor.rootElement = 'wrapper'
122
-
123
- TextEditor.withVariantTypes = <S extends AnyRecord>(styles: S) => {
124
- return TextEditor as (props: StyledComponentProps<TextEditorProps, typeof styles>) => IJSX
125
- }
126
-
127
- TextEditor.defaultProps = {} as Partial<TextEditorProps>
128
-
129
- WebStyleRegistry.registerComponent(TextEditor)
@@ -1,5 +1,12 @@
1
- export type TextEditorStates = 'error' | 'disabled'
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
2
 
3
+ export type TextEditorStates = 'error' | 'disabled'
3
4
  export type TextEditorParts = 'wrapper' | 'editor' | 'floatingMenu' | 'bubbleMenu' | 'bubbleMenuInnerWrapper' | 'floatingMenuInnerWrapper' | 'errorMessage'
4
5
 
5
6
  export type TextEditorComposition = `${TextEditorParts}:${TextEditorStates}` | TextEditorParts
7
+
8
+ const createTextEditorStyle = createDefaultVariantFactory<TextEditorComposition>()
9
+
10
+ export const TextEditorPresets = includePresets((styles) => createTextEditorStyle(() => ({
11
+ wrapper: styles,
12
+ })))
@@ -1,22 +1,17 @@
1
1
  import { RefObject } from 'react'
2
- import { AnyFunction, FormTypes, yup } from '@codeleap/common'
3
- import { StyledProp } from '@codeleap/styles'
2
+ import { ComponentVariants, FormTypes, StylesOf, yup } from '@codeleap/common'
4
3
  import { BubbleMenuProps, Editor, FloatingMenuProps } from '@tiptap/react'
5
4
  import { FileInputRef } from '../FileInput'
6
- import { TextEditorComposition } from './styles'
5
+ import { TextEditorComposition, TextEditorPresets } from './styles'
7
6
 
8
7
  export type TextEditorProps = React.PropsWithChildren<{
9
- editor: Editor & {
10
- getText: AnyFunction
11
- isEditable: boolean
12
- on: AnyFunction
13
- off: AnyFunction
14
- }
15
- style?: StyledProp<TextEditorComposition>
8
+ editor: Editor
9
+ styles?: StylesOf<TextEditorComposition>
10
+ style?: React.CSSProperties
16
11
  bubbleMenuProps?: BubbleMenuProps & { renderContent: React.ReactNode }
17
12
  floatingMenuProps?: FloatingMenuProps & { renderContent: React.ReactNode }
18
13
  toolbarComponent?: JSX.Element
19
14
  fileInputRef?: RefObject<FileInputRef>
20
15
  _error?: boolean
21
16
  validate?: FormTypes.ValidatorWithoutForm<string> | yup.SchemaOf<string>
22
- }>
17
+ } & ComponentVariants<typeof TextEditorPresets>>
@@ -1,4 +1,17 @@
1
- import { TypeGuards, useBooleanToggle, useValidate } from '@codeleap/common'
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react'
3
+
4
+ import {
5
+ ComponentVariants,
6
+ FormTypes,
7
+ IconPlaceholder,
8
+ TextInputComposition,
9
+ TypeGuards,
10
+ useBooleanToggle,
11
+ useDefaultComponentStyle,
12
+ useValidate,
13
+ yup,
14
+ } from '@codeleap/common'
2
15
  import React, {
3
16
  forwardRef,
4
17
  useImperativeHandle,
@@ -7,21 +20,53 @@ import React, {
7
20
  } from 'react'
8
21
  import TextareaAutosize from 'react-autosize-textarea'
9
22
  import InputMask from 'react-input-mask'
10
- import { Touchable } from '../Touchable'
11
- import { InputBase, selectInputBaseProps } from '../InputBase'
12
- import { getMaskInputProps } from './mask'
23
+ import { Touchable, TouchableProps } from '../Touchable'
24
+ import { StylesOf, HTMLProps, ComponentWithDefaultProps } from '../../types/utility'
25
+ import { InputBase, InputBaseProps, selectInputBaseProps } from '../InputBase'
26
+ import { TextInputPresets } from './styles'
27
+ import { getMaskInputProps, TextInputMaskingProps } from './mask'
13
28
  import { getTestId } from '../../lib/utils/test'
14
- import { InputRef, TextInputProps } from './types'
15
- import { FileInputRef } from '../FileInput'
16
- import { AnyRecord, AppIcon, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
17
- import { useStylesFor } from '../../lib/hooks/useStylesFor'
18
- import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
19
29
 
20
- export * from './types'
21
30
  export * from './styles'
22
31
  export * from './mask'
23
32
 
24
- export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputRef) => {
33
+ type NativeTextInputProps = HTMLProps<'input'>
34
+
35
+ export type TextInputProps =
36
+ Omit<InputBaseProps, 'styles' | 'variants'> &
37
+ Omit<NativeTextInputProps, 'value' | 'crossOrigin' | 'ref'> & {
38
+ styles?: StylesOf<TextInputComposition>
39
+ password?: boolean
40
+ validate?: FormTypes.ValidatorWithoutForm<string> | yup.SchemaOf<string>
41
+ debugName?: string
42
+ visibilityToggle?: boolean
43
+ value?: NativeTextInputProps['value']
44
+ multiline?: boolean
45
+ onPress?: TouchableProps['onPress']
46
+ onChangeText?: (textValue: string) => void
47
+ caretColor?: string
48
+ focused?: boolean
49
+ _error?: boolean
50
+ rows?: number
51
+ masking?: TextInputMaskingProps
52
+ visibleIcon?: IconPlaceholder
53
+ hiddenIcon?: IconPlaceholder
54
+ } & ComponentVariants<typeof TextInputPresets>
55
+
56
+ type InputRef = {
57
+ isTextInput?: boolean
58
+ focus: () => void
59
+ getInputRef: () => HTMLInputElement
60
+ }
61
+
62
+ const defaultProps: Partial<TextInputProps> = {
63
+ hiddenIcon: 'input-visiblity:hidden' as IconPlaceholder,
64
+ visibleIcon: 'input-visiblity:visible' as IconPlaceholder,
65
+ }
66
+
67
+ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, inputRef) => {
68
+ const innerInputRef = useRef<InputRef>(null)
69
+
25
70
  const {
26
71
  inputBaseProps,
27
72
  others,
@@ -31,7 +76,9 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
31
76
  })
32
77
 
33
78
  const {
34
- style,
79
+ variants = [],
80
+ responsiveVariants = {},
81
+ styles = {},
35
82
  value,
36
83
  validate,
37
84
  debugName,
@@ -42,16 +89,12 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
42
89
  caretColor,
43
90
  focused,
44
91
  _error,
45
- masking,
92
+ masking = null,
46
93
  visibleIcon,
47
94
  hiddenIcon,
48
95
  ...textInputProps
49
96
  } = others as TextInputProps
50
97
 
51
- const innerInputRef = useRef<InputRef>(null)
52
-
53
- const styles = useStylesFor(TextInput.styleRegistryName, style)
54
-
55
98
  const [_isFocused, setIsFocused] = useState(false)
56
99
 
57
100
  const isFocused = _isFocused || focused
@@ -65,6 +108,12 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
65
108
 
66
109
  const InputElement = isMasked ? InputMask : isMultiline ? TextareaAutosize : 'input'
67
110
 
111
+ const variantStyles = useDefaultComponentStyle<'u:TextInput', typeof TextInputPresets>('u:TextInput', {
112
+ responsiveVariants,
113
+ variants,
114
+ styles,
115
+ })
116
+
68
117
  // @ts-ignore
69
118
  useImperativeHandle(inputRef, () => {
70
119
  return {
@@ -73,6 +122,7 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
73
122
  // @ts-expect-error
74
123
  innerInputRef.current?.getInputDOMNode()?.focus()
75
124
  }
125
+
76
126
  innerInputRef.current?.focus?.()
77
127
  },
78
128
  isTextInput: true,
@@ -116,7 +166,7 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
116
166
 
117
167
  const visibilityToggleProps = visibilityToggle ? {
118
168
  onPress: toggleSecureTextEntry,
119
- icon: (secureTextEntry ? hiddenIcon : visibleIcon) as AppIcon,
169
+ icon: (secureTextEntry ? hiddenIcon : visibleIcon) as IconPlaceholder,
120
170
  debugName: `${debugName} toggle visibility`,
121
171
  } : null
122
172
 
@@ -135,17 +185,17 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
135
185
  const errorMessage = validation.message || _error
136
186
 
137
187
  const placeholderStyles = [
138
- styles.placeholder,
139
- isFocused && styles['placeholder:focus'],
140
- hasError && styles['placeholder:error'],
141
- isDisabled && styles['placeholder:disabled'],
188
+ variantStyles.placeholder,
189
+ isFocused && variantStyles['placeholder:focus'],
190
+ hasError && variantStyles['placeholder:error'],
191
+ isDisabled && variantStyles['placeholder:disabled'],
142
192
  ]
143
193
 
144
194
  const selectionStyles = [
145
- styles.selection,
146
- isFocused && styles['selection:focus'],
147
- hasError && styles['selection:error'],
148
- isDisabled && styles['selection:disabled'],
195
+ variantStyles.selection,
196
+ isFocused && variantStyles['selection:focus'],
197
+ hasError && variantStyles['selection:error'],
198
+ isDisabled && variantStyles['selection:disabled'],
149
199
  ]
150
200
 
151
201
  const secureTextProps = (password && secureTextEntry) && {
@@ -158,7 +208,7 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
158
208
 
159
209
  const inputBaseAction = isPressable ? 'onPress' : 'onClick'
160
210
 
161
- const testId = getTestId(textInputProps)
211
+ const testId = getTestId(others)
162
212
 
163
213
  return (
164
214
  <InputBase
@@ -166,13 +216,13 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
166
216
  {...inputBaseProps}
167
217
  debugName={debugName}
168
218
  error={hasError ? errorMessage : null}
169
- style={{
170
- ...styles,
171
- innerWrapper: {
172
- ...styles.innerWrapper,
173
- ...(isMultiline ? styles['innerWrapper:multiline'] : {}),
174
- ...(hasMultipleLines ? styles['innerWrapper:hasMultipleLines'] : {}),
175
- },
219
+ styles={{
220
+ ...variantStyles,
221
+ innerWrapper: [
222
+ variantStyles.innerWrapper,
223
+ isMultiline && variantStyles['innerWrapper:multiline'],
224
+ hasMultipleLines && variantStyles['innerWrapper:hasMultipleLines'],
225
+ ],
176
226
  }}
177
227
  innerWrapperProps={{
178
228
  ...(inputBaseProps.innerWrapperProps || {}),
@@ -186,9 +236,10 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
186
236
  },
187
237
  debugName,
188
238
  }}
189
- rightIcon={rightIcon as any}
239
+ rightIcon={rightIcon}
190
240
  focused={isFocused}
191
241
  >
242
+
192
243
  <InputElement
193
244
  editable={`${!isPressable && !isDisabled}`}
194
245
  {...buttonModeProps}
@@ -201,12 +252,12 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
201
252
  // @ts-ignore
202
253
  onFocus={handleFocus}
203
254
  css={[
204
- styles.input,
205
- isMultiline && styles['input:multiline'],
206
- isFocused && styles['input:focus'],
207
- hasError && styles['input:error'],
208
- isDisabled && styles['input:disabled'],
209
- hasMultipleLines && styles['input:hasMultipleLines'],
255
+ variantStyles.input,
256
+ isMultiline && variantStyles['input:multiline'],
257
+ isFocused && variantStyles['input:focus'],
258
+ hasError && variantStyles['input:error'],
259
+ isDisabled && variantStyles['input:disabled'],
260
+ hasMultipleLines && variantStyles['input:hasMultipleLines'],
210
261
  {
211
262
  '&::placeholder': placeholderStyles,
212
263
  },
@@ -216,7 +267,7 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
216
267
  {
217
268
  '&:focus': [
218
269
  { outline: 'none', borderWidth: 0, borderColor: 'transparent' },
219
- isFocused && styles['input:focus'],
270
+ isFocused && variantStyles['input:focus'],
220
271
  caretColorStyle,
221
272
  ],
222
273
  },
@@ -227,21 +278,8 @@ export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputR
227
278
  />
228
279
  </InputBase>
229
280
  )
281
+ })
230
282
 
231
- }) as StyledComponentWithProps<TextInputProps>
232
-
233
- TextInput.styleRegistryName = 'TextInput'
234
- TextInput.elements = [...InputBase.elements, 'input', 'placeholder', 'selection']
235
- TextInput.rootElement = 'wrapper'
236
-
237
- TextInput.withVariantTypes = <S extends AnyRecord>(styles: S) => {
238
- return TextInput as (props: StyledComponentProps<TextInputProps, typeof styles>) => IJSX
239
- }
240
-
241
- TextInput.defaultProps = {
242
- hiddenIcon: 'input-visiblity:hidden' as AppIcon,
243
- visibleIcon: 'input-visiblity:visible' as AppIcon,
244
- masking: null,
245
- } as TextInputProps
283
+ export const TextInput = TextInputComponent as unknown as ComponentWithDefaultProps<TextInputProps>
246
284
 
247
- WebStyleRegistry.registerComponent(TextInput)
285
+ TextInput.defaultProps = defaultProps as TextInputProps