@momo-kits/native-kits 0.152.4-scale.4 → 0.152.5-klib.1

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 (117) hide show
  1. package/README.md +175 -5
  2. package/ios/native-kits.podspec +18 -16
  3. package/package.json +2 -4
  4. package/CODE_OF_CONDUCT.md +0 -133
  5. package/CONTRIBUTING.md +0 -114
  6. package/LICENSE +0 -20
  7. package/build.gradle.kts +0 -32
  8. package/compose/MoMoComposeKits.podspec +0 -54
  9. package/compose/build.gradle.kts +0 -149
  10. package/compose/src/androidMain/AndroidManifest.xml +0 -2
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -105
  12. package/compose/src/commonMain/composeResources/files/lottie_circle_loader.json +0 -1
  13. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  14. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  21. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  22. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  23. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  24. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  25. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  26. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +0 -57
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +0 -201
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +0 -222
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +0 -48
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +0 -86
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +0 -76
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +0 -76
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +0 -308
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +0 -33
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -715
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +0 -214
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -404
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +0 -69
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -78
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -27
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -334
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -345
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -90
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -133
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -543
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -23
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -69
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -143
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -179
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -111
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -395
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -164
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -234
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -226
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -227
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -241
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -235
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -364
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -50
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -34
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -85
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -33
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -338
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -95
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -64
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -89
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -91
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -91
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -208
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -172
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -199
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -237
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -191
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -306
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -13
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -189
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -293
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -2
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -35
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -2
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -59
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -68
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -49
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -232
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -111
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -94
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -159
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -302
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScaleSizeScope.kt +0 -22
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -483
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -169
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -217
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -180
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -251
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -80
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -306
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -31
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -385
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -125
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -38
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -62
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -88
  111. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -144
  112. package/gradle.properties +0 -19
  113. package/gradlew +0 -240
  114. package/gradlew.bat +0 -91
  115. package/ios/Theme.md +0 -18
  116. package/local.properties +0 -8
  117. package/settings.gradle.kts +0 -25
@@ -1,234 +0,0 @@
1
- package vn.momo.kits.components
2
-
3
- import androidx.compose.foundation.background
4
- import androidx.compose.foundation.border
5
- import androidx.compose.foundation.clickable
6
- import androidx.compose.foundation.interaction.MutableInteractionSource
7
- import androidx.compose.foundation.layout.Box
8
- import androidx.compose.foundation.layout.Column
9
- import androidx.compose.foundation.layout.Row
10
- import androidx.compose.foundation.layout.Spacer
11
- import androidx.compose.foundation.layout.fillMaxWidth
12
- import androidx.compose.foundation.layout.height
13
- import androidx.compose.foundation.layout.offset
14
- import androidx.compose.foundation.layout.padding
15
- import androidx.compose.foundation.layout.width
16
- import androidx.compose.foundation.layout.wrapContentSize
17
- import androidx.compose.foundation.shape.RoundedCornerShape
18
- import androidx.compose.foundation.text.BasicTextField
19
- import androidx.compose.foundation.text.KeyboardOptions
20
- import androidx.compose.runtime.Composable
21
- import androidx.compose.runtime.MutableState
22
- import androidx.compose.runtime.getValue
23
- import androidx.compose.runtime.mutableStateOf
24
- import androidx.compose.runtime.remember
25
- import androidx.compose.runtime.setValue
26
- import androidx.compose.ui.Alignment
27
- import androidx.compose.ui.Modifier
28
- import androidx.compose.ui.focus.onFocusChanged
29
- import androidx.compose.ui.graphics.Color
30
- import androidx.compose.ui.semantics.contentDescription
31
- import androidx.compose.ui.semantics.semantics
32
- import androidx.compose.ui.semantics.testTag
33
- import androidx.compose.ui.text.AnnotatedString
34
- import androidx.compose.ui.text.TextStyle
35
- import androidx.compose.ui.text.input.KeyboardType
36
- import androidx.compose.ui.text.input.OffsetMapping
37
- import androidx.compose.ui.text.input.TransformedText
38
- import androidx.compose.ui.text.input.VisualTransformation
39
- import androidx.compose.ui.unit.dp
40
- import androidx.compose.ui.unit.sp
41
- import androidx.compose.ui.zIndex
42
- import vn.momo.kits.const.AppTheme
43
- import vn.momo.kits.const.Spacing
44
- import vn.momo.kits.const.Typography
45
- import vn.momo.kits.utils.formatNumberToMoney
46
-
47
- class CustomConverter : VisualTransformation {
48
- override fun filter(text: AnnotatedString): TransformedText {
49
- if (text.text.isEmpty() || text.text == "0") {
50
- return TransformedText(AnnotatedString("0"), OffsetMapping.Identity)
51
- }
52
- val formattedText = formatNumberToMoney(text.text.toLong())
53
-
54
- return TransformedText(
55
- AnnotatedString(formattedText),
56
- object : OffsetMapping {
57
- override fun originalToTransformed(offset: Int): Int = formattedText.length
58
- override fun transformedToOriginal(offset: Int): Int = text.length
59
- }
60
- )
61
- }
62
- }
63
-
64
- @Composable
65
- fun InputMoney(
66
- text: MutableState<String> = remember { mutableStateOf("0") },
67
- floatingValue: String = "",
68
- floatingValueColor: Color = AppTheme.current.colors.text.hint,
69
- floatingIcon: String = "",
70
- floatingIconColor: Color = AppTheme.current.colors.text.default,
71
- placeholder: String = "0đ",
72
- size: InputSize = InputSize.SMALL,
73
- onChangeText: (String) -> Unit = {},
74
- error: String = "",
75
- errorSpacing: Boolean = false,
76
- disabled: Boolean = false,
77
- icon: String = "",
78
- iconColor: Color = AppTheme.current.colors.text.default,
79
- onPressIcon: () -> Unit = {},
80
- leadingIcon: String = "",
81
- leadingIconColor: Color = AppTheme.current.colors.text.hint,
82
- onFocus: () -> Unit = {},
83
- onBlur: () -> Unit = {},
84
- loading: Boolean = false,
85
- required: Boolean = false,
86
- fontWeight: InputFontWeight = InputFontWeight.BOLD,
87
- keyboardType: KeyboardType = KeyboardType.Number,
88
- ) {
89
- var isFocused by remember { mutableStateOf(false) }
90
- var isBlurred = false
91
- val disabledColor = AppTheme.current.colors.text.disable
92
- var textColor = AppTheme.current.colors.text.default
93
- var placeholderColor = AppTheme.current.colors.text.hint
94
- var iconTintColor = iconColor
95
- val floatingTitleColor = when {
96
- disabled -> AppTheme.current.colors.text.disable
97
- else -> floatingValueColor
98
- }
99
- val floatingIconTintColor = when {
100
- disabled -> AppTheme.current.colors.text.disable
101
- else -> floatingIconColor
102
- }
103
-
104
- if (disabled) {
105
- textColor = disabledColor
106
- placeholderColor = disabledColor
107
- iconTintColor = disabledColor
108
- }
109
-
110
- val testId = if (disabled) "input_${floatingValue}_disabled" else "input_$floatingValue"
111
-
112
- Column(modifier = Modifier.semantics {
113
- contentDescription = floatingValue; testTag = testId
114
- }) {
115
- BasicTextField(
116
- enabled = !disabled,
117
- singleLine = true,
118
- value = text.value,
119
- textStyle = TextStyle(
120
- color = textColor,
121
- fontSize = 20.sp,
122
- lineHeight = 24.sp,
123
- fontWeight = fontWeight.value
124
- ),
125
- visualTransformation = CustomConverter(),
126
- keyboardOptions = KeyboardOptions.Default.copy(keyboardType = keyboardType),
127
- modifier = Modifier.height(size.values.height).onFocusChanged {
128
- isFocused = it.isFocused
129
- if (it.isFocused) {
130
- onFocus()
131
- }
132
- if (!it.isFocused && isBlurred) onBlur()
133
- if (it.isFocused && !isBlurred) isBlurred = true
134
- },
135
- onValueChange = {
136
- val numericValue = it.filter { char -> char.isDigit() }
137
- onChangeText(numericValue)
138
- },
139
- decorationBox = { innerTextField ->
140
- // Floating Icon
141
- if (floatingValue.isNotEmpty() || floatingIcon.isNotEmpty()) {
142
- Box(
143
- modifier = Modifier.wrapContentSize()
144
- .offset(y = (-size.values.height / 2), x = (Spacing.S))
145
- .background(AppTheme.current.colors.background.surface)
146
- .zIndex(10f),
147
- ) {
148
- Row(
149
- modifier = Modifier.padding(horizontal = Spacing.S),
150
- ) {
151
- Text(
152
- floatingValue,
153
- style = Typography.labelSMedium,
154
- color = floatingTitleColor
155
- )
156
- if (required) {
157
- Text(
158
- "*",
159
- style = Typography.labelSMedium,
160
- color = AppTheme.current.colors.error.primary,
161
- )
162
- }
163
- if (floatingIcon.isNotEmpty()) {
164
- Icon(
165
- source = floatingIcon,
166
- modifier = Modifier.padding(start = Spacing.XS),
167
- size = 16.dp,
168
- color = floatingIconTintColor
169
- )
170
- }
171
- }
172
- }
173
- }
174
- //input box wrapper
175
- Box(
176
- modifier = Modifier.fillMaxWidth()
177
- .border(
178
- 1.dp,
179
- getBorderColor(isFocused, error, disabled),
180
- RoundedCornerShape(size.values.borderRadius)
181
- ),
182
- contentAlignment = Alignment.CenterStart
183
- ) {
184
- Row(
185
- modifier = Modifier.padding(horizontal = Spacing.M),
186
- verticalAlignment = Alignment.CenterVertically
187
- ) {
188
- //leading icon
189
- if (leadingIcon.isNotEmpty()) {
190
- Icon(
191
- source = leadingIcon,
192
- modifier = Modifier.padding(end = Spacing.XS),
193
- size = if (size.name == InputSize.SMALL.name) 24.dp else 32.dp,
194
- color = leadingIconColor
195
- )
196
- }
197
- Box(Modifier.weight(9f).padding(start = 0.dp)) {
198
- if (text.value.isEmpty()) {
199
- Text(
200
- text = placeholder,
201
- style = TextStyle(
202
- fontSize = 20.sp,
203
- lineHeight = 24.sp,
204
- fontWeight = fontWeight.value
205
- ),
206
- color = placeholderColor
207
- )
208
- } else {
209
- innerTextField()
210
- }
211
- }
212
- if (isFocused && text.value.isNotEmpty()) {
213
- Row {
214
- Spacer(Modifier.width(Spacing.XS))
215
- Icon(
216
- source = "24_navigation_close_circle_full",
217
- size = 16.dp,
218
- color = AppTheme.current.colors.text.hint,
219
- modifier = Modifier.clickable(
220
- onClick = { text.value = "" },
221
- interactionSource = remember { MutableInteractionSource() },
222
- indication = null
223
- )
224
- )
225
- }
226
- }
227
- RenderRightIcon(loading, icon, iconTintColor, onPressIcon)
228
- }
229
- }
230
- },
231
- )
232
- ErrorView(error, errorSpacing, "")
233
- }
234
- }
@@ -1,226 +0,0 @@
1
- package vn.momo.kits.components
2
-
3
- import androidx.compose.animation.core.LinearEasing
4
- import androidx.compose.animation.core.RepeatMode
5
- import androidx.compose.animation.core.animateFloat
6
- import androidx.compose.animation.core.infiniteRepeatable
7
- import androidx.compose.animation.core.rememberInfiniteTransition
8
- import androidx.compose.animation.core.tween
9
- import androidx.compose.foundation.background
10
- import androidx.compose.foundation.border
11
- import androidx.compose.foundation.clickable
12
- import androidx.compose.foundation.layout.Arrangement
13
- import androidx.compose.foundation.layout.Box
14
- import androidx.compose.foundation.layout.Column
15
- import androidx.compose.foundation.layout.Row
16
- import androidx.compose.foundation.layout.Spacer
17
- import androidx.compose.foundation.layout.fillMaxWidth
18
- import androidx.compose.foundation.layout.height
19
- import androidx.compose.foundation.layout.offset
20
- import androidx.compose.foundation.layout.padding
21
- import androidx.compose.foundation.layout.size
22
- import androidx.compose.foundation.layout.width
23
- import androidx.compose.foundation.layout.wrapContentSize
24
- import androidx.compose.foundation.shape.RoundedCornerShape
25
- import androidx.compose.foundation.text.BasicTextField
26
- import androidx.compose.foundation.text.KeyboardOptions
27
- import androidx.compose.runtime.Composable
28
- import androidx.compose.runtime.getValue
29
- import androidx.compose.runtime.mutableStateOf
30
- import androidx.compose.runtime.remember
31
- import androidx.compose.runtime.setValue
32
- import androidx.compose.ui.Alignment
33
- import androidx.compose.ui.Modifier
34
- import androidx.compose.ui.focus.onFocusChanged
35
- import androidx.compose.ui.text.TextStyle
36
- import androidx.compose.ui.text.input.KeyboardType
37
- import androidx.compose.ui.unit.dp
38
- import androidx.compose.ui.unit.sp
39
- import androidx.compose.ui.zIndex
40
- import vn.momo.kits.const.AppTheme
41
- import vn.momo.kits.const.Radius
42
- import vn.momo.kits.const.Spacing
43
- import vn.momo.kits.const.Typography
44
- import vn.momo.kits.const.scaleSize
45
-
46
- @Composable
47
- fun OTPCaret() {
48
- val duration = 500
49
- val backgroundColor = AppTheme.current.colors.primary
50
-
51
- val infiniteTransition = rememberInfiniteTransition()
52
- val alpha by infiniteTransition.animateFloat(
53
- initialValue = 1f,
54
- targetValue = 0f,
55
- animationSpec = infiniteRepeatable(
56
- animation = tween(
57
- durationMillis = duration,
58
- delayMillis = duration,
59
- easing = LinearEasing
60
- ),
61
- repeatMode = RepeatMode.Reverse
62
- )
63
- )
64
-
65
- Row(verticalAlignment = Alignment.CenterVertically) {
66
- Box(
67
- modifier = Modifier
68
- .size(1.dp, scaleSize(12f).dp)
69
- .background(backgroundColor.copy(alpha = alpha))
70
- )
71
- Text(
72
- text = "-",
73
- color = AppTheme.current.colors.text.hint,
74
- style = Typography.descriptionDefaultRegular
75
- )
76
- }
77
- }
78
-
79
- @Composable
80
- fun InputOTP(
81
- value: String = "",
82
- length: Int? = null,
83
- errorMessage: String = "",
84
- errorSpacing: Boolean = false,
85
- floatingValue: String = "Label",
86
- placeholder: String = "",
87
- onChangeText: (String) -> Unit,
88
- onFocus: () -> Unit = {},
89
- onBlur: () -> Unit = {},
90
- dataType: String = "number",
91
- modifier: Modifier = Modifier
92
- ) {
93
- val maxLength = length ?: 10
94
- var isFocused by remember { mutableStateOf(false) }
95
- var isBlurred = false
96
-
97
- val handleChangeText: (String) -> Unit = { text ->
98
- if (text.length <= maxLength &&
99
- (dataType != "number" || !text.any { !it.isDigit() }) &&
100
- (text.length < value.length || value.length < text.length)
101
- ) {
102
- onChangeText(text)
103
- }
104
- }
105
-
106
- fun onClearText(){
107
- handleChangeText("")
108
- }
109
-
110
- val fontSize = scaleSize(20.sp)
111
-
112
- Column {
113
- BasicTextField(
114
- value = value,
115
- textStyle = TextStyle(fontSize = fontSize),
116
- onValueChange = handleChangeText,
117
- singleLine = true,
118
- keyboardOptions = KeyboardOptions.Default.copy(keyboardType = if (dataType == "number") KeyboardType.Number else KeyboardType.Ascii),
119
- modifier = modifier.height(56.dp).onFocusChanged {
120
- isFocused = it.isFocused
121
- if (it.isFocused) {
122
- onFocus()
123
- }
124
- if (!it.isFocused && isBlurred) onBlur()
125
- if (it.isFocused && !isBlurred) isBlurred = true
126
- },
127
- decorationBox = { _ ->
128
- Box {
129
- if (floatingValue.isNotEmpty()) {
130
- Box(
131
- modifier = Modifier.wrapContentSize()
132
- .offset(y = ((-56).dp / 2))
133
- .align(Alignment.Center)
134
- .background(AppTheme.current.colors.background.surface)
135
- .zIndex(10f),
136
- ) {
137
- Row(
138
- modifier = Modifier
139
- .padding(horizontal = Spacing.S),
140
- verticalAlignment = Alignment.Bottom
141
- ) {
142
- Text(
143
- floatingValue,
144
- style = Typography.labelSMedium,
145
- color = AppTheme.current.colors.text.hint
146
- )
147
- }
148
- }
149
- }
150
- Box(
151
- modifier = Modifier
152
- .fillMaxWidth()
153
- .height(56.dp)
154
- .border(
155
- 1.dp,
156
- getBorderColor(isFocused, errorMessage, false),
157
- RoundedCornerShape(
158
- Radius.S
159
- )
160
- ), contentAlignment = Alignment.Center
161
- ) {
162
- Row(
163
- modifier = Modifier.padding(vertical = 8.dp),
164
- horizontalArrangement = Arrangement.SpaceBetween,
165
- verticalAlignment = Alignment.CenterVertically
166
- ) {
167
- if (length != null) {
168
- for (i in 0 until length) {
169
- if (isFocused && value.length == i) {
170
- OTPCaret()
171
- } else {
172
- val textColor =
173
- if (value.getOrNull(i) != null) AppTheme.current.colors.text.default else AppTheme.current.colors.text.hint
174
- val typo =
175
- if (value.getOrNull(i) != null) Typography.headerDefaultBold else Typography.descriptionDefaultRegular
176
- Text(
177
- text = value.getOrNull(i)?.toString() ?: "-",
178
- color = textColor,
179
- style = typo
180
- )
181
- }
182
- if (i != length - 1) Spacer(Modifier.width(Spacing.L))
183
- }
184
- } else {
185
- if (value.isEmpty() && !isFocused && placeholder.isNotEmpty()) {
186
- return@BasicTextField Text(
187
- text = placeholder,
188
- color = AppTheme.current.colors.text.hint
189
- )
190
- } else {
191
- for (i in value.indices) {
192
- Text(
193
- style = Typography.headerDefaultBold,
194
- text = value[i].toString()
195
- )
196
- if (i != value.length - 1 || (isFocused && value.length != MAX_LENGTH)) {
197
- Spacer(Modifier.width(Spacing.L))
198
- }
199
- }
200
- if (isFocused && value.length != MAX_LENGTH) OTPCaret()
201
- }
202
- }
203
- }
204
- }
205
- Box(
206
- modifier = Modifier.align(Alignment.Center).zIndex(10f)
207
- ) {
208
- Row(
209
- horizontalArrangement = Arrangement.End,
210
- modifier = Modifier.fillMaxWidth()
211
- ) {
212
- Icon(
213
- "24_navigation_close_circle_full",
214
- size = 12.dp,
215
- modifier = Modifier.padding(end = 12.dp).clickable {
216
- onClearText()
217
- }
218
- )
219
- }
220
- }
221
- }
222
- }
223
- )
224
- ErrorView(errorMessage, errorSpacing, "")
225
- }
226
- }
@@ -1,227 +0,0 @@
1
- package vn.momo.kits.components
2
-
3
- import androidx.compose.foundation.background
4
- import androidx.compose.foundation.border
5
- import androidx.compose.foundation.clickable
6
- import androidx.compose.foundation.interaction.MutableInteractionSource
7
- import androidx.compose.foundation.layout.Box
8
- import androidx.compose.foundation.layout.Column
9
- import androidx.compose.foundation.layout.Row
10
- import androidx.compose.foundation.layout.fillMaxWidth
11
- import androidx.compose.foundation.layout.height
12
- import androidx.compose.foundation.layout.padding
13
- import androidx.compose.foundation.layout.size
14
- import androidx.compose.foundation.layout.width
15
- import androidx.compose.foundation.shape.RoundedCornerShape
16
- import androidx.compose.foundation.text.BasicTextField
17
- import androidx.compose.foundation.text.KeyboardOptions
18
- import androidx.compose.runtime.Composable
19
- import androidx.compose.runtime.MutableState
20
- import androidx.compose.runtime.getValue
21
- import androidx.compose.runtime.mutableStateOf
22
- import androidx.compose.runtime.remember
23
- import androidx.compose.runtime.setValue
24
- import androidx.compose.ui.Alignment
25
- import androidx.compose.ui.Modifier
26
- import androidx.compose.ui.focus.onFocusChanged
27
- import androidx.compose.ui.graphics.Color
28
- import androidx.compose.ui.graphics.SolidColor
29
- import androidx.compose.ui.layout.ContentScale
30
- import androidx.compose.ui.text.TextStyle
31
- import androidx.compose.ui.text.input.KeyboardType
32
- import androidx.compose.ui.unit.Dp
33
- import androidx.compose.ui.unit.dp
34
- import vn.momo.kits.const.AppTheme
35
- import vn.momo.kits.const.Colors
36
- import vn.momo.kits.const.Radius
37
- import vn.momo.kits.const.Spacing
38
- import vn.momo.kits.const.Typography
39
- import vn.momo.kits.const.scaleSize
40
- import vn.momo.kits.modifier.setAutomationId
41
- import vn.momo.kits.navigation.ScaleSizeScope
42
-
43
- data class InputPhoneNumberSizeDetail(
44
- val borderWidth: Dp,
45
- val borderRadius: Dp,
46
- val height: Dp,
47
- val textStyle: TextStyle,
48
- val dividerHeight: Dp,
49
- )
50
-
51
- enum class InputPhoneNumberSize(val values: InputPhoneNumberSizeDetail) {
52
- SMALL(
53
- InputPhoneNumberSizeDetail(
54
- borderWidth = 1.dp,
55
- borderRadius = Radius.S,
56
- height = 48.dp,
57
- textStyle = Typography.headerSSemibold,
58
- dividerHeight = 24.dp
59
- )
60
- ),
61
- LARGE(
62
- InputPhoneNumberSizeDetail(
63
- borderWidth = 1.dp,
64
- borderRadius = Radius.S,
65
- height = 56.dp,
66
- textStyle = Typography.headerMBold,
67
- dividerHeight = 32.dp
68
- )
69
- )
70
- }
71
-
72
- @Composable
73
- fun getBorderColor(isFocused: Boolean, error: String): Color {
74
- val theme = AppTheme.current
75
- return remember(isFocused, error, theme) {
76
- when {
77
- error.isNotEmpty() -> theme.colors.error.primary
78
- isFocused -> theme.colors.primary
79
- else -> theme.colors.border.default
80
- }
81
- }
82
- }
83
-
84
- @Composable
85
- fun InputPhoneNumber(
86
- text: MutableState<String> = remember { mutableStateOf("") },
87
- placeholder: String = "0123456789",
88
- size: InputPhoneNumberSize = InputPhoneNumberSize.SMALL,
89
- onChangeText: (String) -> Unit = {},
90
- hintText: String = "",
91
- error: String = "",
92
- errorSpacing: Boolean = false,
93
- icon: String = "",
94
- iconColor: Color = AppTheme.current.colors.text.default,
95
- onRightIconPressed: () -> Unit = {},
96
- onFocus: () -> Unit = {},
97
- onBlur: () -> Unit = {},
98
- loading: Boolean = false,
99
- modifier: Modifier = Modifier,
100
- ) {
101
- // Consolidated state management
102
- var inputState by remember { mutableStateOf(InputState()) }
103
-
104
- // Memoized color calculations
105
- val theme = AppTheme.current
106
- val colors = remember( theme) {
107
- Triple(
108
- theme.colors.text.default, // textColor
109
- theme.colors.text.hint, // placeholderColor
110
- iconColor // iconTintColor
111
- )
112
- }
113
-
114
- val (textColor, placeholderColor, iconTintColor) = colors
115
-
116
- val testId = "input_phone_number"
117
-
118
- val textStyle = scaleSize(size.values.textStyle.copy(color = textColor))
119
- val placeholderStyle = scaleSize(size.values.textStyle.copy(color = placeholderColor))
120
-
121
- Column(modifier = modifier.setAutomationId(testId)) {
122
- BasicTextField(
123
- singleLine = true,
124
- value = text.value,
125
- textStyle = textStyle,
126
- keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),
127
- cursorBrush = SolidColor(AppTheme.current.colors.primary),
128
- modifier = Modifier
129
- .height(size.values.height)
130
- .onFocusChanged { focusState ->
131
- val wasFocused = inputState.isFocused
132
- inputState = inputState.copy(
133
- isFocused = focusState.isFocused,
134
- hasBeenBlurred = inputState.hasBeenBlurred || wasFocused
135
- )
136
-
137
- if (focusState.isFocused) {
138
- onFocus()
139
- } else if (inputState.hasBeenBlurred) {
140
- onBlur()
141
- }
142
- },
143
- onValueChange = onChangeText,
144
- decorationBox = { innerTextField ->
145
- // Input container
146
- Box(
147
- modifier = Modifier
148
- .fillMaxWidth()
149
- .border(
150
- if(inputState.isFocused) 1.5.dp else 1.dp,
151
- getBorderColor(inputState.isFocused, error),
152
- RoundedCornerShape(size.values.borderRadius)
153
- ),
154
- contentAlignment = Alignment.CenterStart
155
- ) {
156
- Row(
157
- modifier = Modifier.padding(horizontal = Spacing.M),
158
- verticalAlignment = Alignment.CenterVertically
159
- ) {
160
- // Leading icon
161
- Image(
162
- source = "https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png",
163
- modifier = Modifier.size(24.dp).padding(end = Spacing.XS),
164
- options = Options(
165
- contentScale = ContentScale.Fit,
166
- alignment = Alignment.Center
167
- )
168
- )
169
- ScaleSizeScope(disableScale = true) {
170
- Text(
171
- "+84",
172
- color = textColor,
173
- style = textStyle,
174
- )
175
- }
176
-
177
- // Divider
178
- Box(modifier = Modifier.padding(horizontal = Spacing.M)) {
179
- Box(
180
- modifier = Modifier.width(1.dp)
181
- .height(size.values.dividerHeight)
182
- .background(Colors.black_04)
183
- )
184
- }
185
-
186
-
187
- Box(Modifier.weight(1f)) {
188
- if (text.value.isEmpty()) {
189
- ScaleSizeScope(disableScale = true) {
190
- Text(
191
- text = placeholder,
192
- style = placeholderStyle,
193
- color = placeholderColor,
194
- modifier = Modifier.align(Alignment.CenterStart)
195
- )
196
- }
197
- }
198
- innerTextField()
199
- }
200
-
201
- // Clear button
202
- if (inputState.isFocused && text.value.isNotEmpty()) {
203
- Row {
204
- Icon(
205
- source = "24_navigation_close_circle_full",
206
- size = 16.dp,
207
- color = theme.colors.text.hint,
208
- modifier = Modifier.clickable(
209
- onClick = { text.value = "" },
210
- interactionSource = remember { MutableInteractionSource() },
211
- indication = null
212
- )
213
- .padding(horizontal = Spacing.S)
214
- )
215
- }
216
- }
217
-
218
- // Right icon (password toggle or custom icon)
219
- RenderRightIcon(loading, icon, iconTintColor, onRightIconPressed)
220
- }
221
- }
222
- },
223
- )
224
- // Error/hint display
225
- ErrorView(error, errorSpacing, hintText)
226
- }
227
- }