@codeleap/web 3.24.2 → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/components/ActionIcon/index.tsx +51 -52
- package/src/components/ActionIcon/styles.ts +1 -5
- package/src/components/ActionIcon/types.ts +15 -0
- package/src/components/ActivityIndicator/index.tsx +34 -55
- package/src/components/ActivityIndicator/styles.ts +0 -6
- package/src/components/ActivityIndicator/types.ts +12 -0
- package/src/components/Badge/index.tsx +43 -80
- package/src/components/Badge/styles.ts +1 -11
- package/src/components/Badge/types.ts +28 -0
- package/src/components/Button/index.tsx +46 -89
- package/src/components/Button/styles.ts +0 -5
- package/src/components/Button/types.ts +25 -0
- package/src/components/Checkbox/index.tsx +83 -97
- package/src/components/Checkbox/styles.ts +1 -5
- package/src/components/Checkbox/types.ts +15 -0
- package/src/components/Collapse/index.tsx +41 -83
- package/src/components/Collapse/styles.ts +3 -6
- package/src/components/Collapse/types.ts +11 -0
- package/src/components/ColorPicker/index.tsx +95 -48
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +26 -12
- package/src/components/CropPicker/index.tsx +100 -102
- package/src/components/CropPicker/styles.ts +0 -7
- package/src/components/CropPicker/types.ts +10 -15
- package/src/components/DatePicker/{defaultComponents → components}/Header.tsx +9 -17
- package/src/components/DatePicker/{defaultComponents → components}/OuterInput.tsx +6 -7
- package/src/components/DatePicker/index.tsx +110 -124
- package/src/components/DatePicker/styles.ts +1 -12
- package/src/components/DatePicker/types.ts +16 -33
- package/src/components/Drawer/index.tsx +133 -125
- package/src/components/Drawer/styles.ts +0 -5
- package/src/components/Drawer/types.ts +23 -0
- package/src/components/Dropzone/index.tsx +87 -63
- package/src/components/Dropzone/styles.ts +0 -6
- package/src/components/Dropzone/types.ts +29 -37
- package/src/components/EmptyPlaceholder/index.tsx +63 -83
- package/src/components/EmptyPlaceholder/styles.ts +0 -5
- package/src/components/EmptyPlaceholder/types.ts +32 -0
- package/src/components/FileInput/index.tsx +72 -0
- package/src/components/FileInput/types.ts +14 -0
- package/src/components/Grid/index.tsx +40 -41
- package/src/components/Grid/styles.ts +2 -9
- package/src/components/Grid/types.ts +10 -12
- package/src/components/Icon/index.tsx +45 -47
- package/src/components/Icon/styles.ts +0 -8
- package/src/components/Icon/types.ts +15 -0
- package/src/components/InputBase/index.tsx +71 -42
- package/src/components/InputBase/styles.ts +37 -47
- package/src/components/InputBase/types.ts +19 -7
- package/src/components/InputBase/utils.ts +3 -23
- package/src/components/List/ListLayout.tsx +20 -37
- package/src/components/List/index.tsx +36 -41
- package/src/components/List/styles.ts +5 -11
- package/src/components/List/types.ts +30 -20
- package/src/components/LoadingOverlay/index.tsx +31 -33
- package/src/components/LoadingOverlay/styles.ts +3 -8
- package/src/components/LoadingOverlay/types.ts +16 -0
- package/src/components/Modal/index.tsx +98 -160
- package/src/components/Modal/styles.ts +0 -5
- package/src/components/Modal/types.ts +55 -0
- package/src/components/NumberIncrement/index.tsx +67 -98
- package/src/components/NumberIncrement/styles.ts +0 -5
- package/src/components/NumberIncrement/types.ts +29 -0
- package/src/components/Overlay/index.tsx +37 -35
- package/src/components/Overlay/styles.ts +3 -5
- package/src/components/Overlay/types.ts +13 -0
- package/src/components/Pager/index.tsx +65 -81
- package/src/components/Pager/styles.ts +3 -9
- package/src/components/Pager/types.ts +35 -0
- package/src/components/PaginationButtons/index.tsx +173 -0
- package/src/components/PaginationButtons/styles.ts +7 -0
- package/src/components/PaginationButtons/types.ts +26 -0
- package/src/components/PaginationIndicator/index.tsx +69 -0
- package/src/components/PaginationIndicator/styles.ts +3 -0
- package/src/components/PaginationIndicator/types.ts +18 -0
- package/src/components/Progress/Bar/index.tsx +45 -50
- package/src/components/Progress/Bar/styles.ts +10 -0
- package/src/components/Progress/Bar/types.ts +26 -0
- package/src/components/Progress/Circle/index.tsx +45 -48
- package/src/components/Progress/Circle/styles.ts +1 -8
- package/src/components/Progress/Circle/types.ts +10 -22
- package/src/components/RadioInput/index.tsx +78 -124
- package/src/components/RadioInput/styles.ts +0 -6
- package/src/components/RadioInput/types.ts +29 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +47 -36
- package/src/components/SectionFilters/styles.ts +1 -5
- package/src/components/SectionFilters/types.ts +14 -13
- package/src/components/SegmentedControl/index.tsx +111 -89
- package/src/components/SegmentedControl/styles.ts +7 -21
- package/src/components/SegmentedControl/types.ts +44 -0
- package/src/components/Select/index.tsx +92 -56
- package/src/components/Select/styles.ts +19 -36
- package/src/components/Select/types.ts +15 -10
- package/src/components/Slider/index.tsx +85 -93
- package/src/components/Slider/styles.ts +13 -6
- package/src/components/Slider/types.ts +29 -0
- package/src/components/Switch/index.tsx +63 -74
- package/src/components/Switch/styles.ts +1 -6
- package/src/components/Switch/types.ts +13 -0
- package/src/components/Tag/index.tsx +39 -44
- package/src/components/Tag/styles.ts +1 -9
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +37 -48
- package/src/components/Text/styles.ts +0 -8
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +49 -28
- package/src/components/TextEditor/styles.ts +1 -8
- package/src/components/TextEditor/types.ts +11 -6
- package/src/components/TextInput/index.tsx +58 -96
- package/src/components/TextInput/mask.tsx +2 -50
- package/src/components/TextInput/styles.ts +3 -8
- package/src/components/TextInput/types.ts +85 -0
- package/src/components/Tooltip/index.tsx +61 -84
- package/src/components/Tooltip/styles.ts +3 -10
- package/src/components/Tooltip/types.ts +46 -0
- package/src/components/Touchable/index.tsx +43 -86
- package/src/components/Touchable/styles.ts +0 -6
- package/src/components/Touchable/types.ts +22 -0
- package/src/components/View/index.tsx +36 -50
- package/src/components/View/styles.ts +0 -6
- package/src/components/View/types.ts +14 -15
- package/src/components/components.ts +2 -3
- package/src/index.ts +1 -0
- package/src/lib/WebStyleRegistry.ts +51 -0
- package/src/lib/hooks/index.ts +5 -0
- package/src/lib/hooks/useBreakpointMatch.ts +8 -7
- package/src/{components/CropPicker/useCropPicker.tsx → lib/hooks/useCropPicker.ts} +66 -13
- package/src/lib/hooks/useFileInput.ts +15 -0
- package/src/lib/hooks/useInfiniteScroll.ts +77 -0
- package/src/lib/hooks/useMediaQuery.ts +4 -3
- package/src/lib/hooks/usePagination.ts +79 -63
- package/src/lib/hooks/useRefresh.ts +87 -0
- package/src/lib/hooks/useStylesFor.ts +13 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils/cache.ts +9 -0
- package/src/lib/utils/index.ts +1 -0
- package/src/lib/utils/test.ts +2 -2
- package/src/components/CropPicker/utils.ts +0 -51
- package/src/components/FileInput.tsx +0 -91
- package/src/components/List/PaginationIndicator.tsx +0 -102
- package/src/components/List/useInfiniteScroll.ts +0 -159
- package/src/components/Progress/Bar/styles.tsx +0 -7
- package/src/components/Progress/Bar/types.tsx +0 -30
- package/src/components/Scroll/index.tsx +0 -32
- package/src/components/Scroll/styles.ts +0 -8
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +0 -84
- package/src/components/defaultStyles.ts +0 -79
- /package/src/components/DatePicker/{defaultComponents → components}/index.tsx +0 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { onUpdate, useCallback,
|
|
2
|
+
import { onUpdate, useCallback, 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 {
|
|
6
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
8
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
9
|
+
|
|
7
10
|
export * from './styles'
|
|
8
11
|
export * from './types'
|
|
9
12
|
|
|
@@ -11,17 +14,19 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
11
14
|
const {
|
|
12
15
|
children,
|
|
13
16
|
editor,
|
|
14
|
-
|
|
15
|
-
styles = {},
|
|
16
|
-
responsiveVariants = {},
|
|
17
|
-
style = {},
|
|
17
|
+
style,
|
|
18
18
|
bubbleMenuProps,
|
|
19
19
|
floatingMenuProps,
|
|
20
20
|
toolbarComponent,
|
|
21
21
|
fileInputRef,
|
|
22
22
|
_error,
|
|
23
23
|
validate,
|
|
24
|
-
} =
|
|
24
|
+
} = {
|
|
25
|
+
...TextEditor.defaultProps,
|
|
26
|
+
...props,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const styles = useStylesFor(TextEditor.styleRegistryName, style)
|
|
25
30
|
|
|
26
31
|
const [_isFocused, setIsFocused] = useState(false)
|
|
27
32
|
const validation = useValidate(editor?.getText() ?? '', validate)
|
|
@@ -30,12 +35,6 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
30
35
|
const errorMessage = validation.message || _error
|
|
31
36
|
const isDisabled = !editor?.isEditable ?? null
|
|
32
37
|
|
|
33
|
-
const variantStyles = useDefaultComponentStyle<'u:TextEditor', typeof TextEditorPresets>('u:TextEditor', {
|
|
34
|
-
variants,
|
|
35
|
-
styles,
|
|
36
|
-
responsiveVariants,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
38
|
const handleBlur = React.useCallback(() => {
|
|
40
39
|
validation?.onInputBlurred()
|
|
41
40
|
setIsFocused(false)
|
|
@@ -58,8 +57,9 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
58
57
|
|
|
59
58
|
const _BubbleMenu = useCallback(() => {
|
|
60
59
|
return (
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
// @ts-expect-error icss type
|
|
61
|
+
<BubbleMenu css={[styles.bubbleMenu]} {...bubbleMenuProps} editor={editor}>
|
|
62
|
+
<View style={styles.bubbleMenuInnerWrapper}>
|
|
63
63
|
{bubbleMenuProps?.renderContent}
|
|
64
64
|
</View>
|
|
65
65
|
</BubbleMenu>
|
|
@@ -68,8 +68,9 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
68
68
|
|
|
69
69
|
const _FloatingMenu = useCallback(() => {
|
|
70
70
|
return (
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
// @ts-expect-error icss type
|
|
72
|
+
<FloatingMenu css={[styles.floatingMenu]} {...floatingMenuProps} editor={editor}>
|
|
73
|
+
<View style={styles.floatingMenuInnerWrapper}>
|
|
73
74
|
{floatingMenuProps?.renderContent}
|
|
74
75
|
</View>
|
|
75
76
|
</FloatingMenu>
|
|
@@ -77,21 +78,21 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
77
78
|
}, [editor])
|
|
78
79
|
|
|
79
80
|
const editorStyles = [
|
|
80
|
-
|
|
81
|
-
hasError &&
|
|
82
|
-
isDisabled &&
|
|
81
|
+
styles.editor,
|
|
82
|
+
hasError && styles['editor:error'],
|
|
83
|
+
isDisabled && styles['editor:disabled'],
|
|
83
84
|
]
|
|
84
85
|
|
|
85
86
|
if (!editor) return null
|
|
87
|
+
|
|
86
88
|
return (
|
|
87
89
|
<View
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
hasError &&
|
|
90
|
+
style={[
|
|
91
|
+
styles.wrapper,
|
|
92
|
+
hasError && styles['wrapper:error'],
|
|
91
93
|
{
|
|
92
94
|
'.tiptap': editorStyles,
|
|
93
95
|
},
|
|
94
|
-
style,
|
|
95
96
|
]}
|
|
96
97
|
>
|
|
97
98
|
{toolbarComponent}
|
|
@@ -99,10 +100,30 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
99
100
|
<_BubbleMenu />
|
|
100
101
|
<_FloatingMenu />
|
|
101
102
|
<EditorContent editor={editor} />
|
|
102
|
-
{hasError ? <Text text={errorMessage as string}
|
|
103
|
-
<FileInput
|
|
104
|
-
ref={fileInputRef}
|
|
105
|
-
/>
|
|
103
|
+
{hasError ? <Text text={errorMessage as string} style={styles['errorMessage:error']} /> : null}
|
|
104
|
+
<FileInput ref={fileInputRef} />
|
|
106
105
|
</View>
|
|
107
106
|
)
|
|
108
107
|
}
|
|
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,12 +1,5 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
-
|
|
3
1
|
export type TextEditorStates = 'error' | 'disabled'
|
|
2
|
+
|
|
4
3
|
export type TextEditorParts = 'wrapper' | 'editor' | 'floatingMenu' | 'bubbleMenu' | 'bubbleMenuInnerWrapper' | 'floatingMenuInnerWrapper' | 'errorMessage'
|
|
5
4
|
|
|
6
5
|
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,17 +1,22 @@
|
|
|
1
1
|
import { RefObject } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { AnyFunction, FormTypes, yup } from '@codeleap/common'
|
|
3
|
+
import { StyledProp } from '@codeleap/styles'
|
|
3
4
|
import { BubbleMenuProps, Editor, FloatingMenuProps } from '@tiptap/react'
|
|
4
5
|
import { FileInputRef } from '../FileInput'
|
|
5
|
-
import { TextEditorComposition
|
|
6
|
+
import { TextEditorComposition } from './styles'
|
|
6
7
|
|
|
7
8
|
export type TextEditorProps = React.PropsWithChildren<{
|
|
8
|
-
editor: Editor
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
editor: Editor & {
|
|
10
|
+
getText: AnyFunction
|
|
11
|
+
isEditable: boolean
|
|
12
|
+
on: AnyFunction
|
|
13
|
+
off: AnyFunction
|
|
14
|
+
}
|
|
15
|
+
style?: StyledProp<TextEditorComposition>
|
|
11
16
|
bubbleMenuProps?: BubbleMenuProps & { renderContent: React.ReactNode }
|
|
12
17
|
floatingMenuProps?: FloatingMenuProps & { renderContent: React.ReactNode }
|
|
13
18
|
toolbarComponent?: JSX.Element
|
|
14
19
|
fileInputRef?: RefObject<FileInputRef>
|
|
15
20
|
_error?: boolean
|
|
16
21
|
validate?: FormTypes.ValidatorWithoutForm<string> | yup.SchemaOf<string>
|
|
17
|
-
}
|
|
22
|
+
}>
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
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'
|
|
1
|
+
import { TypeGuards, useBooleanToggle, useValidate } from '@codeleap/common'
|
|
15
2
|
import React, {
|
|
16
3
|
forwardRef,
|
|
17
4
|
useImperativeHandle,
|
|
@@ -20,53 +7,21 @@ import React, {
|
|
|
20
7
|
} from 'react'
|
|
21
8
|
import TextareaAutosize from 'react-autosize-textarea'
|
|
22
9
|
import InputMask from 'react-input-mask'
|
|
23
|
-
import { Touchable
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { TextInputPresets } from './styles'
|
|
27
|
-
import { getMaskInputProps, TextInputMaskingProps } from './mask'
|
|
10
|
+
import { Touchable } from '../Touchable'
|
|
11
|
+
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
12
|
+
import { getMaskInputProps } from './mask'
|
|
28
13
|
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'
|
|
29
19
|
|
|
20
|
+
export * from './types'
|
|
30
21
|
export * from './styles'
|
|
31
22
|
export * from './mask'
|
|
32
23
|
|
|
33
|
-
|
|
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
|
-
|
|
24
|
+
export const TextInput = forwardRef<FileInputRef, TextInputProps>((props, inputRef) => {
|
|
70
25
|
const {
|
|
71
26
|
inputBaseProps,
|
|
72
27
|
others,
|
|
@@ -76,9 +31,7 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
76
31
|
})
|
|
77
32
|
|
|
78
33
|
const {
|
|
79
|
-
|
|
80
|
-
responsiveVariants = {},
|
|
81
|
-
styles = {},
|
|
34
|
+
style,
|
|
82
35
|
value,
|
|
83
36
|
validate,
|
|
84
37
|
debugName,
|
|
@@ -89,12 +42,16 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
89
42
|
caretColor,
|
|
90
43
|
focused,
|
|
91
44
|
_error,
|
|
92
|
-
masking
|
|
45
|
+
masking,
|
|
93
46
|
visibleIcon,
|
|
94
47
|
hiddenIcon,
|
|
95
48
|
...textInputProps
|
|
96
49
|
} = others as TextInputProps
|
|
97
50
|
|
|
51
|
+
const innerInputRef = useRef<InputRef>(null)
|
|
52
|
+
|
|
53
|
+
const styles = useStylesFor(TextInput.styleRegistryName, style)
|
|
54
|
+
|
|
98
55
|
const [_isFocused, setIsFocused] = useState(false)
|
|
99
56
|
|
|
100
57
|
const isFocused = _isFocused || focused
|
|
@@ -108,12 +65,6 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
108
65
|
|
|
109
66
|
const InputElement = isMasked ? InputMask : isMultiline ? TextareaAutosize : 'input'
|
|
110
67
|
|
|
111
|
-
const variantStyles = useDefaultComponentStyle<'u:TextInput', typeof TextInputPresets>('u:TextInput', {
|
|
112
|
-
responsiveVariants,
|
|
113
|
-
variants,
|
|
114
|
-
styles,
|
|
115
|
-
})
|
|
116
|
-
|
|
117
68
|
// @ts-ignore
|
|
118
69
|
useImperativeHandle(inputRef, () => {
|
|
119
70
|
return {
|
|
@@ -122,7 +73,6 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
122
73
|
// @ts-expect-error
|
|
123
74
|
innerInputRef.current?.getInputDOMNode()?.focus()
|
|
124
75
|
}
|
|
125
|
-
|
|
126
76
|
innerInputRef.current?.focus?.()
|
|
127
77
|
},
|
|
128
78
|
isTextInput: true,
|
|
@@ -166,7 +116,7 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
166
116
|
|
|
167
117
|
const visibilityToggleProps = visibilityToggle ? {
|
|
168
118
|
onPress: toggleSecureTextEntry,
|
|
169
|
-
icon: (secureTextEntry ? hiddenIcon : visibleIcon) as
|
|
119
|
+
icon: (secureTextEntry ? hiddenIcon : visibleIcon) as AppIcon,
|
|
170
120
|
debugName: `${debugName} toggle visibility`,
|
|
171
121
|
} : null
|
|
172
122
|
|
|
@@ -185,17 +135,17 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
185
135
|
const errorMessage = validation.message || _error
|
|
186
136
|
|
|
187
137
|
const placeholderStyles = [
|
|
188
|
-
|
|
189
|
-
isFocused &&
|
|
190
|
-
hasError &&
|
|
191
|
-
isDisabled &&
|
|
138
|
+
styles.placeholder,
|
|
139
|
+
isFocused && styles['placeholder:focus'],
|
|
140
|
+
hasError && styles['placeholder:error'],
|
|
141
|
+
isDisabled && styles['placeholder:disabled'],
|
|
192
142
|
]
|
|
193
143
|
|
|
194
144
|
const selectionStyles = [
|
|
195
|
-
|
|
196
|
-
isFocused &&
|
|
197
|
-
hasError &&
|
|
198
|
-
isDisabled &&
|
|
145
|
+
styles.selection,
|
|
146
|
+
isFocused && styles['selection:focus'],
|
|
147
|
+
hasError && styles['selection:error'],
|
|
148
|
+
isDisabled && styles['selection:disabled'],
|
|
199
149
|
]
|
|
200
150
|
|
|
201
151
|
const secureTextProps = (password && secureTextEntry) && {
|
|
@@ -208,7 +158,7 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
208
158
|
|
|
209
159
|
const inputBaseAction = isPressable ? 'onPress' : 'onClick'
|
|
210
160
|
|
|
211
|
-
const testId = getTestId(
|
|
161
|
+
const testId = getTestId(textInputProps)
|
|
212
162
|
|
|
213
163
|
return (
|
|
214
164
|
<InputBase
|
|
@@ -216,13 +166,13 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
216
166
|
{...inputBaseProps}
|
|
217
167
|
debugName={debugName}
|
|
218
168
|
error={hasError ? errorMessage : null}
|
|
219
|
-
|
|
220
|
-
...
|
|
221
|
-
innerWrapper:
|
|
222
|
-
|
|
223
|
-
isMultiline
|
|
224
|
-
hasMultipleLines
|
|
225
|
-
|
|
169
|
+
style={{
|
|
170
|
+
...styles,
|
|
171
|
+
innerWrapper: {
|
|
172
|
+
...styles.innerWrapper,
|
|
173
|
+
...(isMultiline ? styles['innerWrapper:multiline'] : {}),
|
|
174
|
+
...(hasMultipleLines ? styles['innerWrapper:hasMultipleLines'] : {}),
|
|
175
|
+
},
|
|
226
176
|
}}
|
|
227
177
|
innerWrapperProps={{
|
|
228
178
|
...(inputBaseProps.innerWrapperProps || {}),
|
|
@@ -236,10 +186,9 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
236
186
|
},
|
|
237
187
|
debugName,
|
|
238
188
|
}}
|
|
239
|
-
rightIcon={rightIcon}
|
|
189
|
+
rightIcon={rightIcon as any}
|
|
240
190
|
focused={isFocused}
|
|
241
191
|
>
|
|
242
|
-
|
|
243
192
|
<InputElement
|
|
244
193
|
editable={`${!isPressable && !isDisabled}`}
|
|
245
194
|
{...buttonModeProps}
|
|
@@ -252,12 +201,12 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
252
201
|
// @ts-ignore
|
|
253
202
|
onFocus={handleFocus}
|
|
254
203
|
css={[
|
|
255
|
-
|
|
256
|
-
isMultiline &&
|
|
257
|
-
isFocused &&
|
|
258
|
-
hasError &&
|
|
259
|
-
isDisabled &&
|
|
260
|
-
hasMultipleLines &&
|
|
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'],
|
|
261
210
|
{
|
|
262
211
|
'&::placeholder': placeholderStyles,
|
|
263
212
|
},
|
|
@@ -267,7 +216,7 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
267
216
|
{
|
|
268
217
|
'&:focus': [
|
|
269
218
|
{ outline: 'none', borderWidth: 0, borderColor: 'transparent' },
|
|
270
|
-
isFocused &&
|
|
219
|
+
isFocused && styles['input:focus'],
|
|
271
220
|
caretColorStyle,
|
|
272
221
|
],
|
|
273
222
|
},
|
|
@@ -278,8 +227,21 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
|
|
|
278
227
|
/>
|
|
279
228
|
</InputBase>
|
|
280
229
|
)
|
|
281
|
-
})
|
|
282
230
|
|
|
283
|
-
|
|
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
|
|
284
246
|
|
|
285
|
-
TextInput
|
|
247
|
+
WebStyleRegistry.registerComponent(TextInput)
|
|
@@ -1,53 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
-
}
|
|
1
|
+
import { TypeGuards } from '@codeleap/common'
|
|
2
|
+
import { FormatChar, InputMaskProps, MaskProps, TextInputMaskTypeProp } from './types'
|
|
51
3
|
|
|
52
4
|
export const getMaskInputProps = ({ masking }: InputMaskProps): MaskProps & { notSaveFormatted: boolean } => {
|
|
53
5
|
const {
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { ActionIconParts } from '../ActionIcon'
|
|
3
2
|
import { InputBaseParts, InputBaseStates } from '../InputBase'
|
|
4
3
|
|
|
5
|
-
type TextInputParts =
|
|
4
|
+
type TextInputParts = InputBaseParts | 'input' | 'placeholder' | 'selection'
|
|
5
|
+
|
|
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 =
|
|
11
|
-
|
|
12
|
-
const createTextInputStyle =
|
|
13
|
-
createDefaultVariantFactory<TextInputComposition>()
|
|
14
|
-
|
|
15
|
-
export const TextInputPresets = includePresets((styles) => createTextInputStyle(() => ({ wrapper: styles })))
|
|
10
|
+
export type TextInputComposition = `${TextInputParts}:${TextInputStates}` | TextInputParts
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
}
|