@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.
- package/package.json +1 -2
- package/src/components/ActionIcon/index.tsx +52 -51
- package/src/components/ActionIcon/styles.ts +5 -1
- package/src/components/ActivityIndicator/index.tsx +55 -34
- package/src/components/ActivityIndicator/styles.ts +6 -0
- package/src/components/Badge/index.tsx +80 -43
- package/src/components/Badge/styles.ts +11 -1
- package/src/components/Button/index.tsx +89 -46
- package/src/components/Button/styles.ts +5 -0
- package/src/components/Checkbox/index.tsx +97 -83
- package/src/components/Checkbox/styles.ts +5 -1
- package/src/components/Collapse/index.tsx +83 -41
- package/src/components/Collapse/styles.ts +6 -3
- package/src/components/ColorPicker/index.tsx +48 -95
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +12 -26
- package/src/components/CropPicker/index.tsx +104 -100
- package/src/components/CropPicker/styles.ts +7 -0
- package/src/components/CropPicker/types.ts +17 -8
- package/src/{lib/hooks/useCropPicker.ts → components/CropPicker/useCropPicker.tsx} +15 -68
- package/src/components/CropPicker/utils.ts +51 -0
- package/src/components/DatePicker/{components → defaultComponents}/Header.tsx +17 -9
- package/src/components/DatePicker/{components → defaultComponents}/OuterInput.tsx +7 -6
- package/src/components/DatePicker/index.tsx +124 -110
- package/src/components/DatePicker/styles.ts +12 -1
- package/src/components/DatePicker/types.ts +33 -16
- package/src/components/Drawer/index.tsx +125 -133
- package/src/components/Drawer/styles.ts +5 -0
- package/src/components/Dropzone/index.tsx +63 -87
- package/src/components/Dropzone/styles.ts +6 -0
- package/src/components/Dropzone/types.ts +37 -29
- package/src/components/EmptyPlaceholder/index.tsx +83 -63
- package/src/components/EmptyPlaceholder/styles.ts +5 -0
- package/src/components/FileInput.tsx +91 -0
- package/src/components/Grid/index.tsx +41 -40
- package/src/components/Grid/styles.ts +9 -2
- package/src/components/Grid/types.ts +12 -10
- package/src/components/Icon/index.tsx +47 -45
- package/src/components/Icon/styles.ts +8 -0
- package/src/components/InputBase/index.tsx +42 -71
- package/src/components/InputBase/styles.ts +47 -37
- package/src/components/InputBase/types.ts +7 -19
- package/src/components/InputBase/utils.ts +23 -3
- package/src/components/List/ListLayout.tsx +37 -20
- package/src/components/List/PaginationIndicator.tsx +102 -0
- package/src/components/List/index.tsx +41 -36
- package/src/components/List/styles.ts +11 -5
- package/src/components/List/types.ts +20 -30
- package/src/components/List/useInfiniteScroll.ts +159 -0
- package/src/components/LoadingOverlay/index.tsx +33 -31
- package/src/components/LoadingOverlay/styles.ts +8 -3
- package/src/components/Modal/index.tsx +160 -98
- package/src/components/Modal/styles.ts +5 -0
- package/src/components/NumberIncrement/index.tsx +98 -67
- package/src/components/NumberIncrement/styles.ts +5 -0
- package/src/components/Overlay/index.tsx +35 -37
- package/src/components/Overlay/styles.ts +5 -3
- package/src/components/Pager/index.tsx +81 -65
- package/src/components/Pager/styles.ts +9 -3
- package/src/components/Progress/Bar/index.tsx +50 -45
- package/src/components/Progress/Bar/styles.tsx +7 -0
- package/src/components/Progress/Bar/types.tsx +30 -0
- package/src/components/Progress/Circle/index.tsx +48 -45
- package/src/components/Progress/Circle/styles.ts +8 -1
- package/src/components/Progress/Circle/types.ts +22 -10
- package/src/components/RadioInput/index.tsx +124 -78
- package/src/components/RadioInput/styles.ts +6 -0
- package/src/components/Scroll/index.tsx +32 -0
- package/src/components/Scroll/styles.ts +8 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +36 -47
- package/src/components/SectionFilters/styles.ts +5 -1
- package/src/components/SectionFilters/types.ts +13 -14
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +84 -0
- package/src/components/SegmentedControl/index.tsx +89 -111
- package/src/components/SegmentedControl/styles.ts +21 -7
- package/src/components/Select/index.tsx +58 -92
- package/src/components/Select/styles.ts +36 -19
- package/src/components/Select/types.ts +13 -17
- package/src/components/Slider/index.tsx +93 -85
- package/src/components/Slider/styles.ts +6 -13
- package/src/components/Switch/index.tsx +74 -63
- package/src/components/Switch/styles.ts +6 -1
- package/src/components/Tag/index.tsx +44 -39
- package/src/components/Tag/styles.ts +9 -1
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +48 -37
- package/src/components/Text/styles.ts +8 -0
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +28 -49
- package/src/components/TextEditor/styles.ts +8 -1
- package/src/components/TextEditor/types.ts +6 -11
- package/src/components/TextInput/index.tsx +96 -58
- package/src/components/TextInput/mask.tsx +50 -2
- package/src/components/TextInput/styles.ts +8 -3
- package/src/components/Tooltip/index.tsx +84 -61
- package/src/components/Tooltip/styles.ts +10 -3
- package/src/components/Touchable/index.tsx +86 -43
- package/src/components/Touchable/styles.ts +6 -0
- package/src/components/View/index.tsx +50 -36
- package/src/components/View/styles.ts +6 -0
- package/src/components/View/types.ts +15 -14
- package/src/components/components.ts +3 -2
- package/src/components/defaultStyles.ts +79 -0
- package/src/index.ts +0 -1
- package/src/lib/hooks/index.ts +0 -5
- package/src/lib/hooks/useBreakpointMatch.ts +7 -8
- package/src/lib/hooks/useMediaQuery.ts +3 -4
- package/src/lib/hooks/usePagination.ts +63 -79
- package/src/lib/index.ts +0 -1
- package/src/lib/utils/index.ts +0 -1
- package/src/lib/utils/test.ts +2 -2
- package/src/components/ActionIcon/types.ts +0 -15
- package/src/components/ActivityIndicator/types.ts +0 -12
- package/src/components/Badge/types.ts +0 -28
- package/src/components/Button/types.ts +0 -25
- package/src/components/Checkbox/types.ts +0 -15
- package/src/components/Collapse/types.ts +0 -11
- package/src/components/Drawer/types.ts +0 -23
- package/src/components/EmptyPlaceholder/types.ts +0 -32
- package/src/components/FileInput/index.tsx +0 -72
- package/src/components/FileInput/types.ts +0 -14
- package/src/components/Icon/types.ts +0 -15
- package/src/components/LoadingOverlay/types.ts +0 -16
- package/src/components/Modal/types.ts +0 -55
- package/src/components/NumberIncrement/types.ts +0 -29
- package/src/components/Overlay/types.ts +0 -13
- package/src/components/Pager/types.ts +0 -35
- package/src/components/PaginationButtons/index.tsx +0 -173
- package/src/components/PaginationButtons/styles.ts +0 -7
- package/src/components/PaginationButtons/types.ts +0 -26
- package/src/components/PaginationIndicator/index.tsx +0 -69
- package/src/components/PaginationIndicator/styles.ts +0 -3
- package/src/components/PaginationIndicator/types.ts +0 -18
- package/src/components/Progress/Bar/styles.ts +0 -10
- package/src/components/Progress/Bar/types.ts +0 -26
- package/src/components/RadioInput/types.ts +0 -29
- package/src/components/SegmentedControl/types.ts +0 -44
- package/src/components/Slider/types.ts +0 -29
- package/src/components/Switch/types.ts +0 -13
- package/src/components/TextInput/types.ts +0 -85
- package/src/components/Tooltip/types.ts +0 -46
- package/src/components/Touchable/types.ts +0 -22
- package/src/lib/WebStyleRegistry.ts +0 -51
- package/src/lib/hooks/useFileInput.ts +0 -15
- package/src/lib/hooks/useInfiniteScroll.ts +0 -77
- package/src/lib/hooks/useRefresh.ts +0 -87
- package/src/lib/hooks/useStylesFor.ts +0 -13
- package/src/lib/utils/cache.ts +0 -9
- /package/src/components/DatePicker/{components → defaultComponents}/index.tsx +0 -0
|
@@ -1,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 {
|
|
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
|
|
13
|
-
Omit<TouchableProps, '
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
|
|
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?:
|
|
19
|
+
leftIcon?: IconPlaceholder
|
|
20
20
|
leftIconProps?: Partial<IconProps>
|
|
21
|
-
rightIcon?:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
|
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:
|
|
94
|
+
const componentProps: any = {
|
|
69
95
|
...props,
|
|
70
96
|
...pressProps,
|
|
71
|
-
...animatedProps
|
|
97
|
+
...animatedProps
|
|
72
98
|
}
|
|
73
99
|
|
|
74
100
|
return (
|
|
75
|
-
<Component
|
|
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 {
|
|
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 =
|
|
7
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
|
|
82
|
-
hasError &&
|
|
83
|
-
isDisabled &&
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
hasError &&
|
|
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}
|
|
104
|
-
<FileInput
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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 {
|
|
12
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
139
|
-
isFocused &&
|
|
140
|
-
hasError &&
|
|
141
|
-
isDisabled &&
|
|
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
|
-
|
|
146
|
-
isFocused &&
|
|
147
|
-
hasError &&
|
|
148
|
-
isDisabled &&
|
|
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(
|
|
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
|
-
|
|
170
|
-
...
|
|
171
|
-
innerWrapper:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
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
|
-
|
|
205
|
-
isMultiline &&
|
|
206
|
-
isFocused &&
|
|
207
|
-
hasError &&
|
|
208
|
-
isDisabled &&
|
|
209
|
-
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 &&
|
|
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
|
-
|
|
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
|
-
|
|
285
|
+
TextInput.defaultProps = defaultProps as TextInputProps
|