@cleartrip/ct-design-field 4.0.0 → 5.1.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 (134) hide show
  1. package/README.md +87 -0
  2. package/dist/Field.d.ts +4 -4
  3. package/dist/Field.d.ts.map +1 -1
  4. package/dist/FieldAction/index.d.ts +0 -1
  5. package/dist/FieldAction/index.d.ts.map +1 -1
  6. package/dist/FieldAction/type.d.ts +1 -1
  7. package/dist/FieldAction/type.d.ts.map +1 -1
  8. package/dist/FieldIcon/index.d.ts +0 -1
  9. package/dist/FieldIcon/index.d.ts.map +1 -1
  10. package/dist/FieldIcon/type.d.ts +4 -2
  11. package/dist/FieldIcon/type.d.ts.map +1 -1
  12. package/dist/Input.d.ts +8 -0
  13. package/dist/Input.d.ts.map +1 -0
  14. package/dist/Input.native.d.ts +7 -0
  15. package/dist/Input.native.d.ts.map +1 -0
  16. package/dist/InputField.d.ts +4 -0
  17. package/dist/InputField.d.ts.map +1 -0
  18. package/dist/Label.d.ts +6 -0
  19. package/dist/Label.d.ts.map +1 -0
  20. package/dist/Label.native.d.ts +6 -0
  21. package/dist/Label.native.d.ts.map +1 -0
  22. package/dist/TextArea.d.ts +7 -0
  23. package/dist/TextArea.d.ts.map +1 -0
  24. package/dist/TextAreaInput.d.ts +7 -0
  25. package/dist/TextAreaInput.d.ts.map +1 -0
  26. package/dist/TextAreaInput.native.d.ts +3 -0
  27. package/dist/TextAreaInput.native.d.ts.map +1 -0
  28. package/dist/constants.d.ts +10 -0
  29. package/dist/constants.d.ts.map +1 -0
  30. package/dist/ct-design-field.browser.cjs.js +11 -1
  31. package/dist/ct-design-field.browser.cjs.js.map +1 -1
  32. package/dist/ct-design-field.browser.esm.js +11 -1
  33. package/dist/ct-design-field.browser.esm.js.map +1 -1
  34. package/dist/ct-design-field.cjs.js +1003 -396
  35. package/dist/ct-design-field.cjs.js.map +1 -1
  36. package/dist/ct-design-field.esm.js +997 -387
  37. package/dist/ct-design-field.esm.js.map +1 -1
  38. package/dist/ct-design-field.umd.js +2721 -537
  39. package/dist/ct-design-field.umd.js.map +1 -1
  40. package/dist/index.d.ts +6 -9
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/style.d.ts +146 -38
  43. package/dist/style.d.ts.map +1 -1
  44. package/dist/type.d.ts +114 -25
  45. package/dist/type.d.ts.map +1 -1
  46. package/dist/variants/Card/index.d.ts +13 -0
  47. package/dist/variants/Card/index.d.ts.map +1 -0
  48. package/dist/variants/Card/index.native.d.ts +13 -0
  49. package/dist/variants/Card/index.native.d.ts.map +1 -0
  50. package/dist/variants/Card/type.d.ts +5 -0
  51. package/dist/variants/Card/type.d.ts.map +1 -0
  52. package/dist/variants/OTP/index.d.ts +4 -0
  53. package/dist/variants/OTP/index.d.ts.map +1 -0
  54. package/dist/variants/OTP/type.d.ts +25 -0
  55. package/dist/variants/OTP/type.d.ts.map +1 -0
  56. package/dist/variants/Phone/Prefix/index.d.ts +4 -0
  57. package/dist/variants/Phone/Prefix/index.d.ts.map +1 -0
  58. package/dist/variants/Phone/Prefix/type.d.ts.map +1 -0
  59. package/dist/variants/Phone/index.d.ts +5 -0
  60. package/dist/variants/Phone/index.d.ts.map +1 -0
  61. package/dist/variants/Phone/index.native.d.ts +5 -0
  62. package/dist/variants/Phone/index.native.d.ts.map +1 -0
  63. package/dist/variants/Phone/type.d.ts +7 -0
  64. package/dist/variants/Phone/type.d.ts.map +1 -0
  65. package/package.json +33 -19
  66. package/src/Field.tsx +201 -0
  67. package/src/FieldAction/index.tsx +47 -0
  68. package/src/FieldAction/type.ts +15 -0
  69. package/src/FieldIcon/index.tsx +48 -0
  70. package/src/FieldIcon/type.ts +52 -0
  71. package/src/Input.native.tsx +284 -0
  72. package/src/Input.tsx +242 -0
  73. package/src/InputField.tsx +22 -0
  74. package/src/Label.native.tsx +83 -0
  75. package/src/Label.tsx +91 -0
  76. package/src/TextArea.tsx +14 -0
  77. package/src/TextAreaInput.native.tsx +4 -0
  78. package/src/TextAreaInput.tsx +243 -0
  79. package/src/constants.ts +10 -0
  80. package/src/index.ts +8 -0
  81. package/src/style.ts +353 -0
  82. package/src/type.ts +243 -0
  83. package/src/variants/Card/index.native.tsx +46 -0
  84. package/src/variants/Card/index.tsx +89 -0
  85. package/src/variants/Card/type.ts +5 -0
  86. package/src/variants/OTP/index.tsx +343 -0
  87. package/src/variants/OTP/type.ts +34 -0
  88. package/src/variants/Phone/Prefix/index.tsx +87 -0
  89. package/src/variants/Phone/Prefix/type.ts +24 -0
  90. package/src/variants/Phone/index.native.tsx +84 -0
  91. package/src/variants/Phone/index.tsx +79 -0
  92. package/src/variants/Phone/type.ts +13 -0
  93. package/dist/CardField/CardField.d.ts +0 -6
  94. package/dist/CardField/CardField.d.ts.map +0 -1
  95. package/dist/CardField/index.d.ts +0 -3
  96. package/dist/CardField/index.d.ts.map +0 -1
  97. package/dist/CardField/type.d.ts +0 -16
  98. package/dist/CardField/type.d.ts.map +0 -1
  99. package/dist/OTPField/OTPField.d.ts +0 -6
  100. package/dist/OTPField/OTPField.d.ts.map +0 -1
  101. package/dist/OTPField/SingleOTPInput.d.ts +0 -6
  102. package/dist/OTPField/SingleOTPInput.d.ts.map +0 -1
  103. package/dist/OTPField/index.d.ts +0 -3
  104. package/dist/OTPField/index.d.ts.map +0 -1
  105. package/dist/OTPField/type.d.ts +0 -23
  106. package/dist/OTPField/type.d.ts.map +0 -1
  107. package/dist/PhoneField/PhoneField.d.ts +0 -6
  108. package/dist/PhoneField/PhoneField.d.ts.map +0 -1
  109. package/dist/PhoneField/index.d.ts +0 -3
  110. package/dist/PhoneField/index.d.ts.map +0 -1
  111. package/dist/PhoneField/type.d.ts +0 -11
  112. package/dist/PhoneField/type.d.ts.map +0 -1
  113. package/dist/PhoneFieldPrefix/index.d.ts +0 -5
  114. package/dist/PhoneFieldPrefix/index.d.ts.map +0 -1
  115. package/dist/PhoneFieldPrefix/type.d.ts.map +0 -1
  116. package/dist/StyledField/StyledField.d.ts +0 -7
  117. package/dist/StyledField/StyledField.d.ts.map +0 -1
  118. package/dist/StyledField/index.d.ts +0 -2
  119. package/dist/StyledField/index.d.ts.map +0 -1
  120. package/dist/StyledField/type.d.ts +0 -12
  121. package/dist/StyledField/type.d.ts.map +0 -1
  122. package/dist/StyledFieldContainer/StyledFieldContainer.d.ts +0 -7
  123. package/dist/StyledFieldContainer/StyledFieldContainer.d.ts.map +0 -1
  124. package/dist/StyledFieldContainer/index.d.ts +0 -2
  125. package/dist/StyledFieldContainer/index.d.ts.map +0 -1
  126. package/dist/StyledFieldContainer/type.d.ts +0 -8
  127. package/dist/StyledFieldContainer/type.d.ts.map +0 -1
  128. package/dist/StyledFieldPlaceholder/StyledFieldPlaceholder.d.ts +0 -7
  129. package/dist/StyledFieldPlaceholder/StyledFieldPlaceholder.d.ts.map +0 -1
  130. package/dist/StyledFieldPlaceholder/index.d.ts +0 -2
  131. package/dist/StyledFieldPlaceholder/index.d.ts.map +0 -1
  132. package/dist/StyledFieldPlaceholder/type.d.ts +0 -7
  133. package/dist/StyledFieldPlaceholder/type.d.ts.map +0 -1
  134. /package/dist/{PhoneFieldPrefix → variants/Phone/Prefix}/type.d.ts +0 -0
@@ -0,0 +1,10 @@
1
+ export enum FieldVariant {
2
+ SM = 'sm',
3
+ MD = 'md',
4
+ }
5
+
6
+ export enum FieldType {
7
+ TEXT = 'text',
8
+ NUMBER = 'number',
9
+ PHONE = 'phone',
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { default as InputField } from './InputField';
2
+ export { default as FieldIcon } from './FieldIcon';
3
+ export { default as FieldAction } from './FieldAction';
4
+ export { default as TextArea } from './TextAreaInput';
5
+ export type * from './FieldIcon/type';
6
+ export type * from './type';
7
+ export * from './constants';
8
+ export type * from './FieldAction/type';
package/src/style.ts ADDED
@@ -0,0 +1,353 @@
1
+ import { Theme } from '@cleartrip/ct-design-theme';
2
+ import { FieldType, FieldVariant } from './constants';
3
+ import { TypographyVariant, TypographyVariantType } from '@cleartrip/ct-design-typography';
4
+ interface IFieldContainerStylesParams {
5
+ variant: `${FieldVariant}`;
6
+ theme: Theme;
7
+ hasError: boolean;
8
+ focus: boolean;
9
+ value: string;
10
+ disabled?: boolean;
11
+ isPrefixComponent?: boolean;
12
+ type?: `${FieldType}`;
13
+ disabledPlaceHolder?: boolean;
14
+ customSpacingTop?: number;
15
+ isLabeledPlaceholder?: boolean;
16
+ }
17
+
18
+ export const getFieldContainerBorderStyle = ({
19
+ theme,
20
+ hasError,
21
+ focus,
22
+ disabled,
23
+ }: Omit<IFieldContainerStylesParams, 'variant' | 'value'>) => {
24
+ if (hasError) {
25
+ return { borderStyle: 'solid', borderColor: theme.color.border.warning, borderWidth: theme.border.width.md };
26
+ }
27
+
28
+ if (focus && !disabled) {
29
+ return { borderStyle: 'solid', borderColor: theme.color.border.primary, borderWidth: theme.border.width.md };
30
+ }
31
+
32
+ return { borderStyle: 'solid', borderColor: theme.color.border.disabledDark, borderWidth: theme.border.width.sm };
33
+ };
34
+
35
+ export const getFieldSpacingAndHeight = ({
36
+ isLabeledPlaceholder,
37
+ theme,
38
+ variant,
39
+ focus,
40
+ value,
41
+ disabledPlaceHolder,
42
+ customSpacingTop = 4,
43
+ }: Omit<IFieldContainerStylesParams, 'hasError'>) => {
44
+ const isFieldNotEmpty = focus || value.length > 0;
45
+ const valueWithPlaceholder = isFieldNotEmpty && !disabledPlaceHolder;
46
+ /**
47
+ * By default Prefix component will be absolute position so its width needs to manage by padding in the field.
48
+ * For custom prefix case: user can send the css from props
49
+ */
50
+ const commonStyles = {
51
+ paddingRight: theme.spacing[4],
52
+ paddingLeft: theme.spacing[4],
53
+ };
54
+
55
+ switch (variant) {
56
+ case FieldVariant.SM: {
57
+ return {
58
+ ...commonStyles,
59
+ height: theme.size[10],
60
+ };
61
+ }
62
+ case FieldVariant.MD: {
63
+ return {
64
+ ...commonStyles,
65
+ height: theme.size[14],
66
+ paddingTop:
67
+ (isLabeledPlaceholder && focus) || (isLabeledPlaceholder && value.length > 0)
68
+ ? 24
69
+ : valueWithPlaceholder
70
+ ? theme.spacing[customSpacingTop as keyof typeof theme.spacing]
71
+ : theme.spacing[4],
72
+ paddingBottom: valueWithPlaceholder ? theme.spacing[2] : theme.spacing[4],
73
+ };
74
+ }
75
+ default: {
76
+ return {
77
+ ...commonStyles,
78
+ height: theme.size[14],
79
+ paddingTop: valueWithPlaceholder ? theme.spacing[6] : theme.spacing[4],
80
+ paddingBottom: valueWithPlaceholder ? theme.spacing[2] : theme.spacing[4],
81
+ };
82
+ }
83
+ }
84
+ };
85
+
86
+ export const getFieldContainerStyles = ({
87
+ hasError,
88
+ theme,
89
+ focus,
90
+ disabled,
91
+ variant,
92
+ value,
93
+ customSpacingTop,
94
+ }: IFieldContainerStylesParams) => {
95
+ const fieldContainerBorderStyle = getFieldContainerBorderStyle({
96
+ theme,
97
+ hasError,
98
+ focus,
99
+ disabled,
100
+ });
101
+
102
+ const { height } = getFieldSpacingAndHeight({
103
+ theme,
104
+ variant,
105
+ focus,
106
+ value,
107
+ customSpacingTop,
108
+ });
109
+
110
+ return {
111
+ ...fieldContainerBorderStyle,
112
+
113
+ backgroundColor: disabled ? theme.color.background.disabled : theme.color.background.neutral,
114
+ // cursor: disabled ? 'not-allowed' : 'auto',
115
+ height,
116
+ };
117
+ };
118
+
119
+ export const getFieldPlaceholderStyles = ({
120
+ isFocused,
121
+ variant,
122
+ fieldType,
123
+ }: {
124
+ theme: Theme;
125
+ isFocused: boolean;
126
+ disabled: boolean;
127
+ variant: `${FieldVariant}`;
128
+ fieldType: `${FieldType}`;
129
+ isPrefixComponent?: boolean;
130
+ shiftPlaceholder?: boolean;
131
+ }) => {
132
+ if (variant === FieldVariant.SM) {
133
+ return { top: 8 };
134
+ }
135
+
136
+ if (fieldType === FieldType.PHONE) {
137
+ return {};
138
+ }
139
+ if (isFocused) {
140
+ return { transform: [{ translateY: -12 }] };
141
+ }
142
+
143
+ return {};
144
+ };
145
+
146
+ export const getFieldStyles = ({
147
+ isLabeledPlaceholder,
148
+ disabled,
149
+ theme,
150
+ variant,
151
+ focus,
152
+ value,
153
+ type,
154
+ isPrefixComponent = false,
155
+ disabledPlaceHolder,
156
+ }: {
157
+ isLabeledPlaceholder: boolean;
158
+ disabled: boolean;
159
+ theme: Theme;
160
+ variant: `${FieldVariant}`;
161
+ type: `${FieldType}`;
162
+ value: string;
163
+ focus: boolean;
164
+ isPrefixComponent?: boolean;
165
+ disabledPlaceHolder?: boolean;
166
+ }) => {
167
+ const fieldSpacingAndHeight = getFieldSpacingAndHeight({
168
+ isLabeledPlaceholder,
169
+ theme,
170
+ variant,
171
+ focus,
172
+ value,
173
+ type,
174
+ isPrefixComponent,
175
+ disabledPlaceHolder,
176
+ customSpacingTop: 2,
177
+ });
178
+
179
+ return {
180
+ ...fieldSpacingAndHeight,
181
+ backgroundColor: 'transparent',
182
+ color: disabled ? theme.color.text.disabled : theme.color.text.primary,
183
+ };
184
+ };
185
+
186
+ export const getTypographyVariant = (theme: Theme, variant: TypographyVariantType) => {
187
+ switch (variant) {
188
+ case TypographyVariant.HD1: {
189
+ return {
190
+ fontSize: theme.typography.size[48],
191
+ fontWeight: theme.typography.weight.semibold,
192
+ lineHeight: theme.typography.lineHeight[56],
193
+ };
194
+ }
195
+ case TypographyVariant.HD2: {
196
+ return {
197
+ fontSize: theme.typography.size[40],
198
+ fontWeight: theme.typography.weight.semibold,
199
+ lineHeight: theme.typography.lineHeight[48],
200
+ };
201
+ }
202
+ case TypographyVariant.HD3: {
203
+ return {
204
+ fontSize: theme.typography.size[32],
205
+ fontWeight: theme.typography.weight.semibold,
206
+ lineHeight: theme.typography.lineHeight[40],
207
+ };
208
+ }
209
+ case TypographyVariant.HM1: {
210
+ return {
211
+ fontSize: theme.typography.size[24],
212
+ fontWeight: theme.typography.weight.semibold,
213
+ lineHeight: theme.typography.lineHeight[32],
214
+ };
215
+ }
216
+ case TypographyVariant.HM2: {
217
+ return {
218
+ fontSize: theme.typography.size[20],
219
+ fontWeight: theme.typography.weight.semibold,
220
+ lineHeight: theme.typography.lineHeight[28],
221
+ };
222
+ }
223
+ case TypographyVariant.HM3: {
224
+ return {
225
+ fontSize: theme.typography.size[16],
226
+ fontWeight: theme.typography.weight.semibold,
227
+ lineHeight: theme.typography.lineHeight[24],
228
+ };
229
+ }
230
+ case TypographyVariant.HM4: {
231
+ return {
232
+ fontSize: theme.typography.size[14],
233
+ fontWeight: theme.typography.weight.semibold,
234
+ lineHeight: theme.typography.lineHeight[20],
235
+ };
236
+ }
237
+ case TypographyVariant.B1: {
238
+ return {
239
+ fontSize: theme.typography.size[16],
240
+ fontWeight: theme.typography.weight.medium,
241
+ lineHeight: theme.typography.lineHeight[24],
242
+ };
243
+ }
244
+ case TypographyVariant.B2: {
245
+ return {
246
+ fontSize: theme.typography.size[14],
247
+ fontWeight: theme.typography.weight.medium,
248
+ lineHeight: theme.typography.lineHeight[20],
249
+ };
250
+ }
251
+ case TypographyVariant.B3: {
252
+ return {
253
+ fontSize: theme.typography.size[12],
254
+ fontWeight: theme.typography.weight.medium,
255
+ lineHeight: theme.typography.lineHeight[16],
256
+ };
257
+ }
258
+ case TypographyVariant.B3CAPS: {
259
+ return {
260
+ fontSize: theme.typography.size[12],
261
+ fontWeight: theme.typography.weight.semibold,
262
+ lineHeight: theme.typography.lineHeight[16],
263
+ letterSpacing: theme.typography.letterSpacing.point4,
264
+ };
265
+ }
266
+ case TypographyVariant.B4: {
267
+ return {
268
+ fontSize: theme.typography.size[10],
269
+ fontWeight: theme.typography.weight.medium,
270
+ lineHeight: theme.typography.lineHeight[14],
271
+ };
272
+ }
273
+ case TypographyVariant.B4CAPS: {
274
+ return {
275
+ fontSize: theme.typography.size[10],
276
+ fontWeight: theme.typography.weight.semibold,
277
+ lineHeight: theme.typography.lineHeight[12],
278
+ letterSpacing: theme.typography.letterSpacing.point4,
279
+ };
280
+ }
281
+ case TypographyVariant.P1: {
282
+ return {
283
+ fontSize: theme.typography.size[16],
284
+ fontWeight: theme.typography.weight.normal,
285
+ lineHeight: theme.typography.lineHeight[22],
286
+ };
287
+ }
288
+ case TypographyVariant.P2: {
289
+ return {
290
+ fontSize: theme.typography.size[14],
291
+ fontWeight: theme.typography.weight.normal,
292
+ lineHeight: theme.typography.lineHeight[20],
293
+ };
294
+ }
295
+ case TypographyVariant.P3: {
296
+ return {
297
+ fontSize: theme.typography.size[12],
298
+ fontWeight: theme.typography.weight.normal,
299
+ lineHeight: theme.typography.lineHeight[16],
300
+ };
301
+ }
302
+ case TypographyVariant.P4: {
303
+ return {
304
+ fontSize: theme.typography.size[12],
305
+ fontWeight: theme.typography.weight.normal,
306
+ lineHeight: theme.typography.lineHeight[16],
307
+ };
308
+ }
309
+ case TypographyVariant.L1: {
310
+ return {
311
+ fontSize: theme.typography.size[16],
312
+ fontWeight: theme.typography.weight.semibold,
313
+ lineHeight: theme.typography.lineHeight[24],
314
+ };
315
+ }
316
+ case TypographyVariant.L2: {
317
+ return {
318
+ fontSize: theme.typography.size[14],
319
+ fontWeight: theme.typography.weight.semibold,
320
+ lineHeight: theme.typography.lineHeight[20],
321
+ };
322
+ }
323
+ case TypographyVariant.L3: {
324
+ return {
325
+ fontSize: theme.typography.size[12],
326
+ fontWeight: theme.typography.weight.semibold,
327
+ lineHeight: theme.typography.lineHeight[16],
328
+ };
329
+ }
330
+ case TypographyVariant.OVERLINE: {
331
+ return {
332
+ fontSize: theme.typography.size[12],
333
+ fontWeight: theme.typography.weight.semibold,
334
+ lineHeight: theme.typography.lineHeight[16],
335
+ };
336
+ }
337
+ case TypographyVariant.TAG: {
338
+ return {
339
+ fontSize: theme.typography.size[10],
340
+ fontWeight: theme.typography.weight.semibold,
341
+ lineHeight: theme.typography.lineHeight[12],
342
+ letterSpacing: theme.typography.letterSpacing.point5,
343
+ };
344
+ }
345
+ default: {
346
+ return {
347
+ fontSize: theme.typography.size[20],
348
+ fontWeight: theme.typography.weight.semibold,
349
+ lineHeight: theme.typography.lineHeight[28],
350
+ };
351
+ }
352
+ }
353
+ };
package/src/type.ts ADDED
@@ -0,0 +1,243 @@
1
+ import { ReactElement, ReactNode } from 'react';
2
+ import { Styles } from '@cleartrip/ct-design-types';
3
+ import { TypographyStyleConfigProps, TypographyVariantType } from '@cleartrip/ct-design-typography';
4
+ import { ICardFieldProps } from './variants/Card/type';
5
+ import { IOtpFieldProps } from './variants/OTP/type';
6
+ import { IPhoneField } from './variants/Phone/type';
7
+
8
+ export interface IFieldPrompt {
9
+ message?: string | ReactNode;
10
+ Icon?: ReactNode;
11
+ hasError: boolean;
12
+ }
13
+
14
+ import { FieldVariant, FieldType } from './constants';
15
+
16
+ export interface FieldChangeEvent {
17
+ target: {
18
+ value: string;
19
+ selectionStart: number;
20
+ };
21
+ currentTarget: IFieldRef;
22
+ preventDefault?: () => void;
23
+ }
24
+
25
+ export interface FieldSelectEvent {
26
+ target: {
27
+ value: string;
28
+ selectionStart: number;
29
+ };
30
+ currentTarget: IFieldRef;
31
+ preventDefault?: () => void;
32
+ }
33
+
34
+ export interface FieldFocusEvent {
35
+ target: {
36
+ value: string;
37
+ };
38
+ currentTarget: IFieldRef;
39
+ preventDefault?: () => void;
40
+ }
41
+
42
+ export interface FieldBlurEvent {
43
+ target: {
44
+ value: string;
45
+ };
46
+ currentTarget: IFieldRef;
47
+ preventDefault?: () => void;
48
+ }
49
+
50
+ export interface FieldPressInEvent {
51
+ target: {
52
+ value: string;
53
+ };
54
+ currentTarget: IFieldRef;
55
+ preventDefault?: () => void;
56
+ }
57
+
58
+ export interface FieldKeyDownEvent {
59
+ target: {
60
+ value: string;
61
+ key: string;
62
+ };
63
+ currentTarget: IFieldRef;
64
+ preventDefault?: () => void;
65
+ }
66
+
67
+ export interface IFieldRef {
68
+ focus: () => void;
69
+ blur: () => void;
70
+ setSelection: (start: number, end: number) => void;
71
+ }
72
+
73
+ export interface IFieldProps {
74
+ /**
75
+ * field id
76
+ */
77
+ id?: string;
78
+ /**
79
+ * field placeholder text
80
+ */
81
+ placeholder?: string;
82
+ /**
83
+ * placeholder type
84
+ */
85
+ placeholderType?: 'default' | 'labeled' | 'floating';
86
+ /**
87
+ * field value
88
+ */
89
+ value: string;
90
+ /**
91
+ * field prefix component
92
+ * For eg: <FieldIcon />, <PhoneFieldPrefix /> etc.
93
+ */
94
+ prefix?: ReactElement<{ focus?: boolean }>;
95
+ /**
96
+ * field suffix component
97
+ * For eg: <FieldIcon />, <FieldAction /> etc.
98
+ */
99
+ suffix?: ReactElement<{ focus?: boolean }>;
100
+ /**
101
+ * gap between input field and the prefix component
102
+ */
103
+ prefixGap?: string;
104
+ /**
105
+ * gap between input field and the suffix component
106
+ */
107
+ suffixGap?: string;
108
+ /**
109
+ * this prop is used to render field with different sizes
110
+ * For eg: sm: 40px in height, md: 56px in height
111
+ */
112
+ variant?: `${FieldVariant}`;
113
+ /**
114
+ * Hints at the type of data for virtual keyboard layout.
115
+ * - `none`: No virtual keyboard (for custom input handling)
116
+ * - `text`: Standard text keyboard
117
+ * - `decimal`: Numeric with decimal separator
118
+ * - `numeric`: Numeric keyboard (0-9)
119
+ * - `tel`: Telephone keypad
120
+ * - `search`: Search-optimized keyboard
121
+ * - `email`: Email-optimized keyboard
122
+ * - `url`: URL-optimized keyboard
123
+ */
124
+ inputMode?: 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url';
125
+ /**
126
+ * this prop is used to auto focus the input field
127
+ */
128
+ autoFocus?: boolean;
129
+ /**
130
+ * Controls automatic capitalization behavior.
131
+ * - `none`: No auto-capitalization
132
+ * - `sentences`: Capitalize first letter of sentences
133
+ * - `words`: Capitalize first letter of each word
134
+ * - `characters`: Capitalize all characters
135
+ */
136
+ autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters' | undefined;
137
+
138
+ /**
139
+ * this props is used to determine the input type
140
+ * like text, number etc.
141
+ */
142
+ type?: `${FieldType}`;
143
+ /**
144
+ * this prop is used show error/success message
145
+ */
146
+ prompt?: IFieldPrompt;
147
+ /**
148
+ * change handler for input field
149
+ */
150
+ onChange?: (e: FieldChangeEvent) => void;
151
+ /**
152
+ * select handler for input field
153
+ */
154
+ onSelect?: (e: FieldSelectEvent) => void;
155
+ /**
156
+ * focus handler for input field
157
+ */
158
+ onFocus?: (e: FieldFocusEvent) => void;
159
+ /**
160
+ * blur handler for input field
161
+ */
162
+ onBlur?: (e: FieldBlurEvent) => void;
163
+ /**
164
+ * press in handler for input field
165
+ */
166
+ onPressIn?: (e: FieldPressInEvent) => void;
167
+ /**
168
+ * key down handler for input field
169
+ */
170
+ onKeyDown?: (e: FieldKeyDownEvent) => void;
171
+ /**
172
+ * this prop is used to disable the input field
173
+ */
174
+ disabled?: boolean;
175
+ /**
176
+ * this prop is used to make the input field read only
177
+ */
178
+ readOnly?: boolean;
179
+ /**
180
+ * When false, it will prevent the soft keyboard from showing when the field is focused. The default value is true
181
+ */
182
+ showSoftInputOnFocus?: boolean;
183
+ /**
184
+ * cursor color
185
+ */
186
+ cursorColor?: string;
187
+ /**
188
+ * max length of the input field
189
+ */
190
+ maxLength?: number;
191
+ /**
192
+ * Granular style configuration for all sub-components.
193
+ * Use this to customize the appearance of specific parts of the input field.
194
+ */
195
+ styleConfig?: {
196
+ /** Styles for the outermost container */
197
+ root?: Styles[];
198
+ /** Styles for the container wrapping the input and prefix/suffix */
199
+ fieldContainer?: Styles[];
200
+ /** Styles for the input element itself */
201
+ field?: Styles[];
202
+ /** Styles for the placeholder */
203
+ placeholder?: placeholderStyleConfig;
204
+ /** Styles for the prompt */
205
+ promptStyles?: promptStyleConfig;
206
+ };
207
+ fieldTypographyVariant?: TypographyVariantType;
208
+
209
+ /**
210
+ * The start and end of the text input's selection. Set start and end to
211
+ * the same value to position the cursor.
212
+ */
213
+ selection?: { start: number; end?: number };
214
+ /**
215
+ * this prop is used to show the clear button
216
+ */
217
+ customSpacingTop?: number;
218
+ }
219
+
220
+ interface promptStyleConfig {
221
+ /** Styles for the prompt message container */
222
+ promptBox?: Styles[];
223
+
224
+ /** Styles for the prompt icon container */
225
+ promptIconContainer?: Styles[];
226
+
227
+ /** Typography styles for the prompt message text */
228
+ promptMessageTypography?: TypographyStyleConfigProps;
229
+ }
230
+
231
+ interface placeholderStyleConfig {
232
+ /** Styles for the floating placeholder label container */
233
+ placeholderLabel?: Styles[];
234
+
235
+ /** Typography styles for the placeholder text */
236
+ placeholderTypography?: TypographyStyleConfigProps;
237
+ }
238
+
239
+ export type InputFieldProps =
240
+ | (IPhoneField & { fieldType: 'phone' })
241
+ | (IOtpFieldProps & { fieldType: 'otp' })
242
+ | (ICardFieldProps & { fieldType: 'card' })
243
+ | (IFieldProps & { fieldType?: 'default' });
@@ -0,0 +1,46 @@
1
+ import { forwardRef, useEffect, useRef } from 'react';
2
+
3
+ import { IFieldProps, IFieldRef } from '../../type';
4
+ import { FieldType } from '../../constants';
5
+ import InputField from '../../Field';
6
+ import useMergeRefs from '@cleartrip/ct-design-use-merge-refs';
7
+
8
+ export interface ICursorRef {
9
+ cursorPos: number;
10
+ operation: string;
11
+ }
12
+
13
+ export enum CURSOR_OPERATION {
14
+ NONE = 'NONE',
15
+ ADD = 'ADD',
16
+ SUBSTRACT = 'SUBSTRACT',
17
+ }
18
+
19
+ /**
20
+ * CardField is a wrapper component which is used add a space after a specific character limit
21
+ * For Eg: 1234 5678 9012 3456
22
+ *
23
+ * Use cases
24
+ *
25
+ * 1.) Gift Voucher
26
+ * 2.) Credit/Debit Card
27
+ */
28
+ const CardField = forwardRef<IFieldRef, IFieldProps>(({ onChange, value, ...rest }, forwardedRef) => {
29
+ const ref = useRef<IFieldRef | null>(null);
30
+ const mergedRef = useMergeRefs(forwardedRef, ref);
31
+
32
+ return (
33
+ <InputField
34
+ ref={mergedRef}
35
+ onChange={onChange}
36
+ {...rest}
37
+ type={FieldType.NUMBER}
38
+ value={value}
39
+ inputMode='numeric'
40
+ />
41
+ );
42
+ });
43
+
44
+ CardField.displayName = 'CardField';
45
+
46
+ export default CardField;