@codeleap/web 5.4.4 → 5.5.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.
Files changed (116) hide show
  1. package/dist/components/ActionIcon/types.d.ts +1 -1
  2. package/dist/components/Checkbox/index.js +14 -10
  3. package/dist/components/Checkbox/index.js.map +1 -1
  4. package/dist/components/Checkbox/types.d.ts +4 -2
  5. package/dist/components/DatePicker/components/DayContent.d.ts +11 -0
  6. package/dist/components/DatePicker/components/DayContent.js +43 -0
  7. package/dist/components/DatePicker/components/DayContent.js.map +1 -0
  8. package/dist/components/DatePicker/components/OuterInput.js +2 -2
  9. package/dist/components/DatePicker/components/OuterInput.js.map +1 -1
  10. package/dist/components/DatePicker/components/YearContent.d.ts +9 -0
  11. package/dist/components/DatePicker/components/YearContent.js +33 -0
  12. package/dist/components/DatePicker/components/YearContent.js.map +1 -0
  13. package/dist/components/DatePicker/components/index.d.ts +2 -0
  14. package/dist/components/DatePicker/components/index.js +2 -0
  15. package/dist/components/DatePicker/components/index.js.map +1 -1
  16. package/dist/components/DatePicker/index.js +10 -33
  17. package/dist/components/DatePicker/index.js.map +1 -1
  18. package/dist/components/DatePicker/types.d.ts +5 -6
  19. package/dist/components/InputBase/index.d.ts +2 -5
  20. package/dist/components/InputBase/index.js +19 -11
  21. package/dist/components/InputBase/index.js.map +1 -1
  22. package/dist/components/InputBase/types.d.ts +2 -1
  23. package/dist/components/InputBase/useInputBase.d.ts +60 -0
  24. package/dist/components/InputBase/useInputBase.js +55 -0
  25. package/dist/components/InputBase/useInputBase.js.map +1 -0
  26. package/dist/components/InputBase/useInputBasePartialStyles.d.ts +2 -0
  27. package/dist/components/InputBase/useInputBasePartialStyles.js +40 -0
  28. package/dist/components/InputBase/useInputBasePartialStyles.js.map +1 -0
  29. package/dist/components/Modal/index.d.ts +0 -3
  30. package/dist/components/Modal/index.js +35 -52
  31. package/dist/components/Modal/index.js.map +1 -1
  32. package/dist/components/Modal/types.d.ts +0 -4
  33. package/dist/components/NumberIncrement/index.js +18 -124
  34. package/dist/components/NumberIncrement/index.js.map +1 -1
  35. package/dist/components/NumberIncrement/types.d.ts +5 -6
  36. package/dist/components/NumberIncrement/useNumberIncrement.d.ts +60 -0
  37. package/dist/components/NumberIncrement/useNumberIncrement.js +115 -0
  38. package/dist/components/NumberIncrement/useNumberIncrement.js.map +1 -0
  39. package/dist/components/RadioInput/index.js +14 -14
  40. package/dist/components/RadioInput/index.js.map +1 -1
  41. package/dist/components/RadioInput/types.d.ts +9 -9
  42. package/dist/components/SearchInput/index.js +1 -1
  43. package/dist/components/SearchInput/index.js.map +1 -1
  44. package/dist/components/Select/index.js +5 -7
  45. package/dist/components/Select/index.js.map +1 -1
  46. package/dist/components/Select/styles.d.ts +2 -8
  47. package/dist/components/Select/styles.js.map +1 -1
  48. package/dist/components/Select/types.d.ts +10 -9
  49. package/dist/components/Slider/index.js +16 -46
  50. package/dist/components/Slider/index.js.map +1 -1
  51. package/dist/components/Slider/types.d.ts +4 -2
  52. package/dist/components/Switch/index.js +13 -11
  53. package/dist/components/Switch/index.js.map +1 -1
  54. package/dist/components/Switch/types.d.ts +4 -2
  55. package/dist/components/TextEditor/index.js +7 -14
  56. package/dist/components/TextEditor/index.js.map +1 -1
  57. package/dist/components/TextEditor/types.d.ts +2 -3
  58. package/dist/components/TextInput/index.js +31 -92
  59. package/dist/components/TextInput/index.js.map +1 -1
  60. package/dist/components/TextInput/types.d.ts +8 -7
  61. package/dist/components/TextInput/useTextInput.d.ts +90 -0
  62. package/dist/components/TextInput/useTextInput.js +74 -0
  63. package/dist/components/TextInput/useTextInput.js.map +1 -0
  64. package/dist/lib/tools/index.d.ts +0 -1
  65. package/dist/lib/tools/index.js +0 -1
  66. package/dist/lib/tools/index.js.map +1 -1
  67. package/dist/lib/tools/modal.d.ts +2 -2
  68. package/dist/lib/tools/modal.js +5 -4
  69. package/dist/lib/tools/modal.js.map +1 -1
  70. package/dist/types/utility.d.ts +1 -1
  71. package/package.json +17 -19
  72. package/package.json.bak +1 -3
  73. package/src/components/ActionIcon/types.ts +1 -1
  74. package/src/components/Checkbox/index.tsx +23 -9
  75. package/src/components/Checkbox/types.ts +4 -2
  76. package/src/components/DatePicker/components/DayContent.tsx +52 -0
  77. package/src/components/DatePicker/components/OuterInput.tsx +1 -2
  78. package/src/components/DatePicker/components/YearContent.tsx +39 -0
  79. package/src/components/DatePicker/components/index.tsx +2 -0
  80. package/src/components/DatePicker/index.tsx +33 -84
  81. package/src/components/DatePicker/types.ts +5 -6
  82. package/src/components/InputBase/index.tsx +9 -8
  83. package/src/components/InputBase/types.ts +2 -1
  84. package/src/components/InputBase/useInputBase.ts +56 -0
  85. package/src/components/InputBase/useInputBasePartialStyles.ts +37 -0
  86. package/src/components/Modal/index.tsx +64 -64
  87. package/src/components/Modal/types.ts +0 -4
  88. package/src/components/NumberIncrement/index.tsx +44 -141
  89. package/src/components/NumberIncrement/types.ts +5 -6
  90. package/src/components/NumberIncrement/useNumberIncrement.ts +149 -0
  91. package/src/components/RadioInput/index.tsx +32 -17
  92. package/src/components/RadioInput/types.ts +16 -15
  93. package/src/components/SearchInput/index.tsx +1 -1
  94. package/src/components/Select/index.tsx +6 -11
  95. package/src/components/Select/styles.ts +2 -2
  96. package/src/components/Select/types.ts +10 -9
  97. package/src/components/Slider/index.tsx +28 -52
  98. package/src/components/Slider/types.ts +4 -2
  99. package/src/components/Switch/index.tsx +19 -8
  100. package/src/components/Switch/types.ts +4 -2
  101. package/src/components/TextEditor/index.tsx +6 -14
  102. package/src/components/TextEditor/types.ts +2 -3
  103. package/src/components/TextInput/index.tsx +54 -103
  104. package/src/components/TextInput/types.ts +8 -7
  105. package/src/components/TextInput/useTextInput.ts +101 -0
  106. package/src/lib/tools/index.ts +0 -1
  107. package/src/lib/tools/modal.ts +3 -3
  108. package/src/types/utility.ts +1 -1
  109. package/dist/lib/tools/navigation/index.d.ts +0 -58
  110. package/dist/lib/tools/navigation/index.js +0 -235
  111. package/dist/lib/tools/navigation/index.js.map +0 -1
  112. package/dist/lib/tools/navigation/types.d.ts +0 -32
  113. package/dist/lib/tools/navigation/types.js +0 -3
  114. package/dist/lib/tools/navigation/types.js.map +0 -1
  115. package/src/lib/tools/navigation/index.tsx +0 -282
  116. package/src/lib/tools/navigation/types.ts +0 -53
@@ -1,33 +1,32 @@
1
- import * as React from 'react'
1
+ import React from 'react'
2
2
  import { TypeGuards } from '@codeleap/types'
3
- import { onUpdate, useState, useRef } from '@codeleap/hooks'
4
- import { useValidate } from '@codeleap/deprecated'
5
3
  import { InputBase, selectInputBaseProps } from '../InputBase'
6
4
  import { Text } from '../Text'
7
- import { PatternFormat, NumericFormat, NumericFormatProps as NFProps, NumberFormatBase } from 'react-number-format'
5
+ import { PatternFormat, NumericFormat, NumberFormatBase } from 'react-number-format'
8
6
  import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
9
7
  import { NumberIncrementProps } from './types'
10
8
  import { AnyRecord, AppIcon, IJSX, StyledComponentProps } from '@codeleap/styles'
11
9
  import { useStylesFor } from '../../lib/hooks/useStylesFor'
10
+ import { useInputBasePartialStyles } from '../InputBase/useInputBasePartialStyles'
11
+ import { useNumberIncrement } from './useNumberIncrement'
12
12
 
13
13
  export * from './types'
14
14
  export * from './styles'
15
15
 
16
16
  export const NumberIncrement = (props: NumberIncrementProps) => {
17
+ const allProps = {
18
+ ...NumberIncrement.defaultProps,
19
+ ...props
20
+ }
21
+
17
22
  const {
18
23
  inputBaseProps,
19
- others: numberIncrementProps,
20
- } = selectInputBaseProps({ ...NumberIncrement.defaultProps, ...props })
24
+ others,
25
+ } = selectInputBaseProps(allProps)
21
26
 
22
27
  const {
23
28
  style,
24
- value,
25
29
  disabled,
26
- onValueChange,
27
- onChangeText,
28
- max,
29
- min,
30
- step,
31
30
  editable,
32
31
  hasSeparator,
33
32
  format,
@@ -35,129 +34,36 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
35
34
  suffix,
36
35
  separator,
37
36
  prefix,
38
- validate,
39
- _error,
40
37
  formatter,
41
38
  placeholder,
42
- } = numberIncrementProps
39
+ } = others
43
40
 
44
41
  const styles = useStylesFor(NumberIncrement.styleRegistryName, style)
45
42
 
46
- const [isFocused, setIsFocused] = useState(false)
47
-
48
- const innerWrapperRef = useRef(null)
49
- const innerInputRef = useRef<HTMLInputElement>(null)
50
-
51
- const validation = useValidate(value, validate)
52
-
53
- const hasError = !validation.isValid || _error
54
- const errorMessage = validation.message || _error
55
-
56
- const incrementDisabled = React.useMemo(() => {
57
- if (TypeGuards.isNumber(max) && (Number(value) >= max)) {
58
- return true
59
- }
60
- return false
61
- }, [value])
62
-
63
- const decrementDisabled = React.useMemo(() => {
64
- if (TypeGuards.isNumber(min) && (Number(value) <= min)) {
65
- return true
66
- }
67
- return false
68
- }, [value])
69
-
70
- const onChange = (newValue: number) => {
71
- if (onValueChange) onValueChange?.(newValue)
72
- if (onChangeText) onChangeText?.(newValue)
73
- }
74
-
75
- const handleChange = React.useCallback((action: 'increment' | 'decrement') => {
76
- validation?.onInputFocused()
77
-
78
- if (action === 'increment' && !incrementDisabled) {
79
- const newValue = Number(value) + step
80
- onChange(newValue)
81
- return
82
- } else if (action === 'decrement' && !decrementDisabled) {
83
- const newValue = Number(value) - step
84
- onChange(newValue)
85
- return
86
- }
87
-
88
- validation?.onInputBlurred()
89
- }, [validation?.onInputBlurred, validation?.onInputFocused, value])
90
-
91
- const inputTextStyle = React.useMemo(() => {
92
- return [
93
- styles.input,
94
- isFocused ? styles['input:focus'] : null,
95
- hasError ? styles['input:error'] : null,
96
- disabled ? styles['input:disabled'] : null,
97
- ].filter(Boolean)
98
- }, [disabled, isFocused, hasError])
99
-
100
- const placeholderStyles = [
101
- styles.placeholder,
102
- isFocused ? styles['placeholder:focus'] : null,
103
- hasError ? styles['placeholder:error'] : null,
104
- disabled ? styles['placeholder:disabled'] : null,
105
- ].filter(Boolean)
106
-
107
- const handleBlur = React.useCallback(() => {
108
- if (TypeGuards.isNumber(max) && (value >= max)) {
109
- onChange(max)
110
- return
111
- } else if (TypeGuards.isNumber(min) && (value <= min) || !value) {
112
- onChange(min)
113
- return
114
- }
115
-
116
- validation?.onInputBlurred()
117
- }, [validation?.onInputBlurred, value])
118
-
119
- const handleFocus = React.useCallback(() => {
120
- validation?.onInputFocused()
121
- setIsFocused(true)
122
- }, [validation?.onInputFocused])
123
-
124
- onUpdate(() => {
125
- function handleKeyboardEvent(event: KeyboardEvent) {
126
- if (!isFocused) return
127
-
128
- if (event.keyCode === 39 || event.key === 'ArrowRight') {
129
- handleChange('increment')
130
- } else if (event.keyCode === 37 || event.key === 'ArrowLeft') {
131
- handleChange('decrement')
132
- }
133
- }
134
-
135
- document.addEventListener('keydown', handleKeyboardEvent)
136
-
137
- return () => {
138
- document.removeEventListener('keydown', handleKeyboardEvent)
139
- }
140
- }, [handleChange, isFocused])
141
-
142
- onUpdate(() => {
143
- function handleClickOutside(event: MouseEvent) {
144
- if (innerWrapperRef.current && !innerWrapperRef.current.contains(event.target)) {
145
- setIsFocused(false)
146
- }
147
- }
148
-
149
- document.addEventListener('mousedown', handleClickOutside)
150
-
151
- return () => {
152
- document.removeEventListener('mousedown', handleClickOutside)
153
- }
154
- }, [innerWrapperRef])
155
-
156
- const handleChangeInput: NFProps['onValueChange'] = (values) => {
157
- const { floatValue } = values
158
-
159
- onChange(Number(floatValue))
160
- }
43
+ const {
44
+ isFocused,
45
+ hasError,
46
+ hasValue,
47
+ errorMessage,
48
+ incrementDisabled,
49
+ decrementDisabled,
50
+ innerInputRef,
51
+ innerWrapperRef,
52
+ wrapperRef,
53
+ handleBlur,
54
+ handleFocus,
55
+ handleChange,
56
+ handleChangeInput,
57
+ onPressInnerWrapper,
58
+ inputValue,
59
+ } = useNumberIncrement(allProps)
60
+
61
+ const partialStyles = useInputBasePartialStyles(styles, ['input', 'placeholder'], {
62
+ disabled,
63
+ error: hasError,
64
+ focus: isFocused,
65
+ typed: hasValue,
66
+ })
161
67
 
162
68
  const InputFormat = TypeGuards.isString(format) || TypeGuards.isString(mask)
163
69
  ? PatternFormat
@@ -170,6 +76,7 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
170
76
  return (
171
77
  <InputBase
172
78
  {...inputBaseProps}
79
+ ref={wrapperRef}
173
80
  error={hasError ? errorMessage : null}
174
81
  style={{
175
82
  ...styles,
@@ -196,10 +103,7 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
196
103
  focused={isFocused}
197
104
  innerWrapperProps={{
198
105
  ...(inputBaseProps.innerWrapperProps || {}),
199
- onClick: () => {
200
- setIsFocused(true)
201
- innerInputRef.current?.focus?.()
202
- },
106
+ onClick: onPressInnerWrapper,
203
107
  }}
204
108
  innerWrapperRef={innerWrapperRef}
205
109
  >
@@ -207,13 +111,12 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
207
111
  <Input
208
112
  displayType='input'
209
113
  css={[
210
- // @ts-expect-error
211
- ...inputTextStyle,
212
- // @ts-expect-error
114
+ // @ts-ignore
115
+ partialStyles?.input,
116
+ // @ts-ignore
213
117
  {
214
- '&::placeholder': placeholderStyles,
118
+ '&::placeholder': partialStyles?.placeholder,
215
119
  },
216
- // @ts-expect-error
217
120
  {
218
121
  '&:focus': [
219
122
  {
@@ -228,7 +131,7 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
228
131
  onValueChange={handleChangeInput}
229
132
  onBlur={handleBlur}
230
133
  onFocus={handleFocus}
231
- value={value}
134
+ value={inputValue}
232
135
  thousandSeparator={separator}
233
136
  thousandsGroupStyle={hasSeparator || TypeGuards.isString(separator) ? 'thousand' : 'none'}
234
137
  suffix={suffix}
@@ -238,7 +141,7 @@ export const NumberIncrement = (props: NumberIncrementProps) => {
238
141
  placeholder={placeholder}
239
142
  getInputRef={innerInputRef}
240
143
  />
241
- ) : <Text text={String(value)} style={inputTextStyle} />}
144
+ ) : <Text text={String(inputValue)} style={partialStyles?.input} />}
242
145
  </InputBase>
243
146
  )
244
147
  }
@@ -1,17 +1,13 @@
1
- import { yup, FormTypes } from '@codeleap/deprecated'
2
1
  import { NumberIncrementComposition } from './styles'
3
2
  import { InputBaseProps } from '../InputBase'
4
3
  import { PatternFormatProps as PFProps, NumericFormatProps as NFProps } from 'react-number-format'
5
4
  import { FormatInputValueFunction } from 'react-number-format/types/types'
6
5
  import { StyledProp } from '@codeleap/styles'
6
+ import { NumberField } from '@codeleap/form'
7
7
 
8
8
  export type NumberIncrementProps =
9
9
  Pick<InputBaseProps, 'debugName' | 'disabled' | 'label'> &
10
10
  {
11
- value: number
12
- onValueChange: (value: number) => void
13
- onChangeText?: (value: number) => void
14
- validate?: FormTypes.ValidatorWithoutForm<string> | yup.Schema<string>
15
11
  style?: StyledProp<NumberIncrementComposition>
16
12
  max?: number
17
13
  min?: number
@@ -23,7 +19,10 @@ export type NumberIncrementProps =
23
19
  format?: PFProps['format']
24
20
  mask?: PFProps['mask']
25
21
  hasSeparator?: boolean
26
- _error?: string
22
+ forceError?: string
27
23
  formatter?: FormatInputValueFunction
28
24
  placeholder?: string
25
+ field?: NumberField<any>
26
+ value?: number
27
+ onValueChange?: (value: number) => void
29
28
  }
@@ -0,0 +1,149 @@
1
+ import React, { useRef, useState, useCallback, useEffect, useMemo } from 'react'
2
+ import { NumberIncrementProps } from './types'
3
+ import { useInputBase } from '../InputBase/useInputBase'
4
+ import { Field, fields } from '@codeleap/form'
5
+ import { TypeGuards } from '@codeleap/types'
6
+ import { NumericFormatProps as NFProps } from 'react-number-format'
7
+
8
+ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
9
+ const {
10
+ value,
11
+ onValueChange,
12
+ field,
13
+ min,
14
+ max,
15
+ forceError,
16
+ step,
17
+ } = props
18
+
19
+ const [isFocused, setIsFocused] = useState(false)
20
+
21
+ const {
22
+ fieldHandle,
23
+ validation,
24
+ innerInputRef,
25
+ wrapperRef,
26
+ inputValue,
27
+ onInputValueChange,
28
+ } = useInputBase(
29
+ field as Field<number, any, any>,
30
+ fields.number as () => Field<number, any, any>,
31
+ { value, onValueChange }
32
+ )
33
+
34
+ const innerWrapperRef = useRef(null)
35
+
36
+ const hasValue = TypeGuards.isString(inputValue)
37
+ ? (inputValue as string)?.length > 0
38
+ : !TypeGuards.isNil(inputValue)
39
+
40
+ const hasError = validation?.showError || !!forceError
41
+
42
+ const errorMessage = validation?.message || forceError
43
+
44
+ const incrementDisabled = useMemo(() => {
45
+ if (TypeGuards.isNumber(max) && (Number(inputValue) >= max)) {
46
+ return true
47
+ }
48
+ return false
49
+ }, [inputValue])
50
+
51
+ const decrementDisabled = useMemo(() => {
52
+ if (TypeGuards.isNumber(min) && (Number(inputValue) <= min)) {
53
+ return true
54
+ }
55
+ return false
56
+ }, [inputValue])
57
+
58
+ const handleChange = useCallback((action: 'increment' | 'decrement') => {
59
+ if (action === 'increment' && !incrementDisabled) {
60
+ const newValue = Number(inputValue || min) + step
61
+ onInputValueChange(newValue)
62
+ return
63
+ } else if (action === 'decrement' && !decrementDisabled) {
64
+ const newValue = Number(inputValue || min) - step
65
+ onInputValueChange(newValue)
66
+ return
67
+ }
68
+
69
+ validation?.onInputBlurred?.()
70
+ }, [validation?.onInputBlurred, inputValue])
71
+
72
+ const handleBlur = useCallback(() => {
73
+ if (TypeGuards.isNumber(max) && (inputValue >= max)) {
74
+ onInputValueChange(max)
75
+ return
76
+ } else if (TypeGuards.isNumber(min) && (inputValue <= min) || !inputValue) {
77
+ onInputValueChange(min)
78
+ return
79
+ }
80
+
81
+ validation?.onInputBlurred?.()
82
+ }, [validation?.onInputBlurred, inputValue])
83
+
84
+ const handleFocus = useCallback(() => {
85
+ setIsFocused(true)
86
+ }, [])
87
+
88
+ useEffect(() => {
89
+ function handleKeyboardEvent(event: KeyboardEvent) {
90
+ if (!isFocused) return
91
+
92
+ if (event.keyCode === 39 || event.key === 'ArrowRight') {
93
+ handleChange('increment')
94
+ } else if (event.keyCode === 37 || event.key === 'ArrowLeft') {
95
+ handleChange('decrement')
96
+ }
97
+ }
98
+
99
+ document.addEventListener('keydown', handleKeyboardEvent)
100
+
101
+ return () => {
102
+ document.removeEventListener('keydown', handleKeyboardEvent)
103
+ }
104
+ }, [handleChange, isFocused])
105
+
106
+ useEffect(() => {
107
+ function handleClickOutside(event: MouseEvent) {
108
+ if (innerWrapperRef.current && !innerWrapperRef.current.contains(event.target)) {
109
+ setIsFocused(false)
110
+ }
111
+ }
112
+
113
+ document.addEventListener('mousedown', handleClickOutside)
114
+
115
+ return () => {
116
+ document.removeEventListener('mousedown', handleClickOutside)
117
+ }
118
+ }, [innerWrapperRef])
119
+
120
+ const handleChangeInput: NFProps['onValueChange'] = (values) => {
121
+ const { floatValue } = values
122
+
123
+ onInputValueChange(Number(floatValue))
124
+ }
125
+
126
+ const onPressInnerWrapper = () => {
127
+ setIsFocused(true)
128
+ innerInputRef.current?.focus?.()
129
+ }
130
+
131
+ return {
132
+ hasValue,
133
+ hasError,
134
+ errorMessage,
135
+ inputValue: inputValue || min,
136
+ isFocused,
137
+ incrementDisabled,
138
+ decrementDisabled,
139
+ innerInputRef,
140
+ innerWrapperRef,
141
+ handleBlur,
142
+ handleFocus,
143
+ handleChange,
144
+ handleChangeInput,
145
+ onPressInnerWrapper,
146
+ fieldHandle,
147
+ wrapperRef,
148
+ }
149
+ }
@@ -5,10 +5,12 @@ import { TypeGuards } from '@codeleap/types'
5
5
  import { View } from '../View'
6
6
  import { InputBase, selectInputBaseProps } from '../InputBase'
7
7
  import { RadioOptionProps, RadioInputProps } from './types'
8
- import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
8
+ import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
9
9
  import { useStylesFor } from '../../lib/hooks/useStylesFor'
10
10
  import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
11
- import { RadioInputComposition } from './styles'
11
+ import { useInputBasePartialStyles } from '../InputBase/useInputBasePartialStyles'
12
+ import { useInputBase } from '../InputBase/useInputBase'
13
+ import { SelectableField, fields } from '@codeleap/form'
12
14
 
13
15
  export * from './styles'
14
16
  export * from './types'
@@ -26,29 +28,29 @@ const Option = <T extends string | number>(props: RadioOptionProps<T>) => {
26
28
 
27
29
  const isDisabled = disabled || item?.disabled
28
30
 
29
- const getStyle = (key: RadioInputComposition) => {
30
- let style = null
31
-
32
- if (isDisabled && selected) style = styles[`${key}:selectedDisabled`]
33
- else if (isDisabled) style = styles[`${key}:disabled`]
34
- else if (selected) style = styles[`${key}:selected`]
35
-
36
- return mergeStyles([styles[key], style])
37
- }
31
+ const partialStyles = useInputBasePartialStyles(
32
+ styles,
33
+ ['optionLabel', 'optionWrapper', 'optionIndicator', 'optionIndicatorInner'],
34
+ {
35
+ selectedDisabled: isDisabled && selected,
36
+ disabled: isDisabled,
37
+ selected,
38
+ }
39
+ )
38
40
 
39
41
  return (
40
42
  <React.Fragment>
41
43
  <Touchable
42
44
  debugName={`${debugName} option ${item.value}`}
43
- style={getStyle('optionWrapper')}
45
+ style={partialStyles.optionWrapper}
44
46
  onPress={onSelect}
45
47
  disabled={isDisabled}
46
48
  >
47
- <View style={getStyle('optionIndicator')}>
48
- <View style={getStyle('optionIndicatorInner')} />
49
+ <View style={partialStyles.optionIndicator}>
50
+ <View style={partialStyles.optionIndicatorInner} />
49
51
  </View>
50
52
 
51
- {TypeGuards.isString(item.label) ? <Text style={getStyle('optionLabel')} text={item.label} /> : item.label}
53
+ {TypeGuards.isString(item.label) ? <Text style={partialStyles.optionLabel} text={item.label} /> : item.label}
52
54
  </Touchable>
53
55
 
54
56
  {separator ? <View style={styles.optionSeparator} /> : null}
@@ -66,6 +68,7 @@ export const RadioInput = <T extends string | number>(props: RadioInputProps<T>)
66
68
  })
67
69
 
68
70
  const {
71
+ field,
69
72
  options,
70
73
  value,
71
74
  onValueChange,
@@ -76,9 +79,21 @@ export const RadioInput = <T extends string | number>(props: RadioInputProps<T>)
76
79
 
77
80
  const styles = useStylesFor(RadioInput.styleRegistryName, style)
78
81
 
82
+ const {
83
+ wrapperRef,
84
+ inputValue,
85
+ onInputValueChange,
86
+ } = useInputBase(
87
+ // @ts-ignore
88
+ field as SelectableField<T, any>,
89
+ fields.selectable as () => SelectableField<T, any>,
90
+ { value, onValueChange }
91
+ )
92
+
79
93
  return (
80
94
  <InputBase
81
95
  {...inputBaseProps}
96
+ ref={wrapperRef}
82
97
  disabled={disabled}
83
98
  style={styles}
84
99
  debugName={debugName}
@@ -90,8 +105,8 @@ export const RadioInput = <T extends string | number>(props: RadioInputProps<T>)
90
105
  key={idx}
91
106
  disabled={disabled}
92
107
  styles={styles}
93
- selected={value === item?.value}
94
- onSelect={() => onValueChange(item?.value)}
108
+ selected={inputValue === item.value}
109
+ onSelect={() => onInputValueChange(item.value)}
95
110
  separator={idx < options?.length - 1}
96
111
  />
97
112
  ))}
@@ -1,29 +1,30 @@
1
- import { StylesOf } from '@codeleap/types'
2
- import { FormTypes } from '@codeleap/deprecated'
1
+ import { Option } from '@codeleap/types'
3
2
  import { InputBaseProps } from '../InputBase'
4
3
  import { ReactNode } from 'react'
5
- import { StyledProp } from '@codeleap/styles'
4
+ import { ICSS, StyledProp } from '@codeleap/styles'
6
5
  import { RadioInputComposition } from './styles'
6
+ import { SelectableField } from '@codeleap/form'
7
7
 
8
- type WrapperProps = InputBaseProps
9
-
10
- type RadioOption<T> = FormTypes.Options<T>[number] & {
8
+ type RadioOption<T extends string | number> = Option<T> & {
11
9
  disabled?: boolean
12
10
  }
13
11
 
14
- export type RadioInputProps<T extends string|number> = Omit<WrapperProps, 'style'> & {
15
- options: RadioOption<T>[]
16
- value: T
17
- onValueChange(value: T): void
18
- label: ReactNode
19
- style?: StyledProp<RadioInputComposition>
20
- }
12
+ export type RadioInputProps<T extends string | number> =
13
+ Omit<InputBaseProps, 'style'> &
14
+ {
15
+ options: RadioOption<T>[]
16
+ label: ReactNode
17
+ style?: StyledProp<RadioInputComposition>
18
+ field?: SelectableField<T, any>
19
+ value?: T
20
+ onValueChange?: (value: T) => void
21
+ }
21
22
 
22
- export type RadioOptionProps<T extends string|number> = {
23
+ export type RadioOptionProps<T extends string | number> = {
23
24
  item: RadioOption<T>
24
25
  selected: boolean
25
26
  onSelect(): void
26
- styles?: StylesOf<RadioInputComposition>
27
+ styles?: Record<RadioInputComposition, ICSS>
27
28
  debugName?: string
28
29
  disabled?: boolean
29
30
  separator?: boolean
@@ -69,7 +69,7 @@ export const SearchInput = (props: SearchInputProps) => {
69
69
  <TextInput
70
70
  value={search}
71
71
  placeholder={placeholder}
72
- onChangeText={(value) => {
72
+ onValueChange={(value) => {
73
73
  onTypingChange?.(true)
74
74
  handleChangeSearch(value)
75
75
  }}
@@ -1,7 +1,6 @@
1
1
  import React, { useRef, forwardRef, useImperativeHandle } from 'react'
2
2
  import { useState, onUpdate, useEffect } from '@codeleap/hooks'
3
- import { TypeGuards } from '@codeleap/types'
4
- import { FormTypes, useValidate } from '@codeleap/deprecated'
3
+ import { Option, TypeGuards } from '@codeleap/types'
5
4
  import _Select, { components, MenuListProps, MenuProps, MultiValueProps, NoticeProps } from 'react-select'
6
5
  import Async from 'react-select/async'
7
6
  import { useSelectStyles } from './styles'
@@ -14,6 +13,7 @@ import { ActivityIndicator } from '../ActivityIndicator'
14
13
  import { Icon } from '../Icon'
15
14
  import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
16
15
  import { AnyRecord, AppIcon, ICSS, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
16
+ import { useValidate } from '@codeleap/form'
17
17
 
18
18
  export * from './styles'
19
19
  export * from './types'
@@ -165,9 +165,6 @@ const defaultFormatPlaceholderNoItems = (props: PlaceholderProps & { text: strin
165
165
  export const Select = forwardRef<HTMLInputElement, SelectProps>(
166
166
  <T extends string | number = string, Multi extends boolean = false>
167
167
  (props: SelectProps<T, Multi>, inputRef: React.ForwardedRef<HTMLInputElement>) => {
168
-
169
- type Option = FormTypes.Option<T>
170
-
171
168
  const {
172
169
  inputBaseProps,
173
170
  others: selectProps,
@@ -244,13 +241,12 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
244
241
 
245
242
  const isFocused = _isFocused || focused
246
243
 
247
- // @ts-ignore
248
244
  const validation = useValidate(value, validate)
249
245
 
250
246
  const isDisabled = !!inputBaseProps.disabled
251
247
 
252
- const hasError = !validation.isValid || _error
253
- const errorMessage = validation.message || _error
248
+ const hasError = validation?.showError || _error
249
+ const errorMessage = validation?.message || _error
254
250
 
255
251
  const {
256
252
  reactSelectStyles,
@@ -301,7 +297,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
301
297
  }
302
298
  }
303
299
 
304
- const handleChange = (opt: Multi extends true ? Option[] : Option) => {
300
+ const handleChange = (opt: Multi extends true ? Option<T>[] : Option<T>) => {
305
301
  if (TypeGuards.isArray(opt)) {
306
302
  // @ts-ignore
307
303
  if (TypeGuards.isNumber(limit) && opt?.length > limit && opt?.length > selectedOption?.length) {
@@ -326,10 +322,9 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
326
322
  }, [validation?.onInputBlurred, props?.onBlur])
327
323
 
328
324
  const handleFocus: SelectProps['onFocus'] = React.useCallback((e) => {
329
- validation?.onInputFocused()
330
325
  setIsFocused(true)
331
326
  props?.onFocus?.(e)
332
- }, [validation?.onInputFocused, props?.onFocus])
327
+ }, [props?.onFocus])
333
328
 
334
329
  const SelectComponent = !!loadOptions ? Async : _Select
335
330
 
@@ -1,4 +1,3 @@
1
- import { FormTypes } from '@codeleap/deprecated'
2
1
  import { capitalize } from '@codeleap/utils'
3
2
  import { ICSS, useNestedStylesByKey } from '@codeleap/styles'
4
3
  import { CSSObjectWithLabel, GroupBase, StylesConfig } from 'react-select'
@@ -6,6 +5,7 @@ import { ButtonParts as _ButtonParts } from '../Button'
6
5
  import { InputBaseParts } from '../InputBase'
7
6
  import { SelectProps, UseSelectStylesProps } from './types'
8
7
  import { useStylesFor } from '../../lib/hooks/useStylesFor'
8
+ import { Option } from '@codeleap/types'
9
9
 
10
10
  type ButtonParts = _ButtonParts
11
11
 
@@ -130,7 +130,7 @@ export function useSelectStyles<T, Multi extends boolean>(props: UseSelectStyles
130
130
  }
131
131
  }
132
132
 
133
- const reactSelectStyles: StylesConfig<FormTypes.Option<T>, Multi, GroupBase<FormTypes.Option<T>>> = {
133
+ const reactSelectStyles: StylesConfig<Option<T>, Multi, GroupBase<Option<T>>> = {
134
134
  container: (baseStyles) => stylesKey('inputContainer', baseStyles),
135
135
  control: () => stylesKey('inputContainer'),
136
136
  menuPortal: (baseStyles) => stylesKey('listPortal', parseMenuPortalStyles(baseStyles)),