@cleartrip/ct-design-field 4.0.0-TEST.3 → 5.0.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
@@ -1,32 +1,17 @@
1
- import { __assign, __rest, __spreadArray } from 'tslib';
2
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
- import { forwardRef, useState, isValidElement, cloneElement, useRef, useEffect, useCallback } from 'react';
4
- import { useTheme } from '@cleartrip/ct-design-theme';
5
- import { Typography, TypographyColor, getTypographyStyles, TypographyVariant } from '@cleartrip/ct-design-typography';
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { forwardRef, useRef, isValidElement, useImperativeHandle, useCallback, useState, cloneElement, useEffect } from 'react';
6
3
  import { Box } from '@cleartrip/ct-design-box';
4
+ import { makeStyles, useStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
7
5
  import { Container } from '@cleartrip/ct-design-container';
8
- import styled, { useTheme as useTheme$1 } from 'styled-components';
9
- import { ONLY_NUMERIC, KEYBOARD_KEY_CODE } from '@cleartrip/ct-design-common-constants';
10
- import { addSpaceAtInterval, removeNonNumerals, removeSpace } from '@cleartrip/ct-design-common-utils';
6
+ import { TypographyVariant, Typography, TypographyColor } from '@cleartrip/ct-design-typography';
7
+ import { css } from '@emotion/css';
8
+ import { __rest } from 'tslib';
11
9
  import { Divider } from '@cleartrip/ct-design-divider';
12
- import { DownChevron, CheckCircle } from '@cleartrip/ct-design-icons';
10
+ import { ONLY_NUMERIC } from '@cleartrip/ct-design-common-constants';
11
+ import { useTheme } from '@cleartrip/ct-design-theme';
12
+ import { isIOS } from '@cleartrip/ct-design-common-utils';
13
+ import useMergeRefs from '@cleartrip/ct-design-use-merge-refs';
13
14
  import { DottedLoader } from '@cleartrip/ct-design-dotted-loader';
14
- import { Card, CardBorderDirection, CardShadowVariant } from '@cleartrip/ct-design-card';
15
-
16
- var StyledFieldContainer = styled.div(function (_a) {
17
- var borderColor = _a.borderColor, borderWidth = _a.borderWidth, theme = _a.theme, backgroundColor = _a.backgroundColor, cursor = _a.cursor, css = _a.css;
18
- return (__assign({ borderColor: borderColor, borderWidth: borderWidth, borderStyle: theme.border.style.solid, borderRadius: theme.border.radius[8], backgroundColor: backgroundColor, cursor: "".concat(cursor, " !important"), boxSizing: 'border-box', position: 'relative', display: 'flex', alignItems: 'center' }, css));
19
- });
20
-
21
- var StyledFieldPlaceholder = styled.label(function (_a) {
22
- var position = _a.position, marginLeft = _a.marginLeft, top = _a.top, _b = _a.css, css = _b === void 0 ? {} : _b;
23
- return (__assign({ position: position || 'absolute', display: 'flex', alignItems: 'center', transition: 'position 1s ease-in-out', marginLeft: marginLeft, top: top, pointerEvents: 'none' }, css));
24
- });
25
-
26
- var StyledField = styled.input(function (_a) {
27
- var theme = _a.theme, cursor = _a.cursor, color = _a.color, backgroundColor = _a.backgroundColor, height = _a.height, paddingTop = _a.paddingTop, paddingBottom = _a.paddingBottom, paddingLeft = _a.paddingLeft, marginLeft = _a.marginLeft, paddingRight = _a.paddingRight, _b = _a.css, css = _b === void 0 ? {} : _b;
28
- return (__assign({ width: '100%', border: 'none', outline: 'none', backgroundColor: backgroundColor, cursor: cursor, color: color, height: height, paddingTop: paddingTop, paddingBottom: paddingBottom, paddingRight: paddingRight, paddingLeft: paddingLeft, marginLeft: marginLeft, fontSize: theme.typography.size[16], fontWeight: theme.typography.weight.medium, lineHeight: theme.typography.lineHeight[24] }, css));
29
- });
30
15
 
31
16
  var FieldVariant;
32
17
  (function (FieldVariant) {
@@ -40,167 +25,966 @@ var FieldType;
40
25
  FieldType["PHONE"] = "phone";
41
26
  })(FieldType || (FieldType = {}));
42
27
 
43
- var getFieldContainerBorderStyle = function (_a) {
44
- var theme = _a.theme, hasError = _a.hasError, focus = _a.focus, disabled = _a.disabled;
28
+ const getFieldContainerBorderStyle = ({ theme, hasError, focus, disabled, }) => {
45
29
  if (hasError) {
46
- return {
47
- borderColor: theme.color.border.warning,
48
- borderWidth: theme.border.width.md,
49
- };
30
+ return { borderStyle: 'solid', borderColor: theme.color.border.warning, borderWidth: theme.border.width.md };
50
31
  }
51
32
  if (focus && !disabled) {
52
- return {
53
- borderColor: theme.color.border.primary,
54
- borderWidth: theme.border.width.md,
55
- };
33
+ return { borderStyle: 'solid', borderColor: theme.color.border.primary, borderWidth: theme.border.width.md };
56
34
  }
57
- return {
58
- borderColor: theme.color.border.disabledDark,
59
- borderWidth: theme.border.width.sm,
60
- };
35
+ return { borderStyle: 'solid', borderColor: theme.color.border.disabledDark, borderWidth: theme.border.width.sm };
61
36
  };
62
- var getFieldSpacingAndHeight = function (_a) {
63
- var _b, _c;
64
- var theme = _a.theme, variant = _a.variant, focus = _a.focus, value = _a.value, isPrefixComponent = _a.isPrefixComponent, disabledPlaceHolder = _a.disabledPlaceHolder;
65
- var isFieldNotEmpty = focus || value.length > 0;
66
- var valueWithPlaceholder = isFieldNotEmpty && !disabledPlaceHolder;
67
- var leftMargin = isPrefixComponent ? (_b = theme === null || theme === void 0 ? void 0 : theme.spacing) === null || _b === void 0 ? void 0 : _b[13] : (_c = theme === null || theme === void 0 ? void 0 : theme.spacing) === null || _c === void 0 ? void 0 : _c[4];
68
- var commonStyles = {
69
- paddingLeft: leftMargin,
37
+ const getFieldSpacingAndHeight = ({ isLabeledPlaceholder, theme, variant, focus, value, disabledPlaceHolder, customSpacingTop = 4, }) => {
38
+ const isFieldNotEmpty = focus || value.length > 0;
39
+ const valueWithPlaceholder = isFieldNotEmpty && !disabledPlaceHolder;
40
+ const commonStyles = {
70
41
  paddingRight: theme.spacing[4],
42
+ paddingLeft: theme.spacing[4],
71
43
  };
72
44
  switch (variant) {
73
45
  case FieldVariant.SM: {
74
- return __assign(__assign({}, commonStyles), { height: theme.size[10] });
46
+ return Object.assign(Object.assign({}, commonStyles), { height: theme.size[10] });
75
47
  }
76
48
  case FieldVariant.MD: {
77
- return __assign(__assign({}, commonStyles), { height: theme.size[14], paddingTop: valueWithPlaceholder ? theme.spacing[6] : theme.spacing[4], paddingBottom: valueWithPlaceholder ? theme.spacing[2] : theme.spacing[4] });
49
+ return Object.assign(Object.assign({}, commonStyles), { height: theme.size[14], paddingTop: (isLabeledPlaceholder && focus) || (isLabeledPlaceholder && value.length > 0)
50
+ ? 24
51
+ : valueWithPlaceholder
52
+ ? theme.spacing[customSpacingTop]
53
+ : theme.spacing[4], paddingBottom: valueWithPlaceholder ? theme.spacing[2] : theme.spacing[4] });
78
54
  }
79
55
  default: {
80
- return __assign(__assign({}, commonStyles), { height: theme.size[14], paddingTop: valueWithPlaceholder ? theme.spacing[6] : theme.spacing[4], paddingBottom: valueWithPlaceholder ? theme.spacing[2] : theme.spacing[4] });
56
+ return Object.assign(Object.assign({}, commonStyles), { height: theme.size[14], paddingTop: valueWithPlaceholder ? theme.spacing[6] : theme.spacing[4], paddingBottom: valueWithPlaceholder ? theme.spacing[2] : theme.spacing[4] });
81
57
  }
82
58
  }
83
59
  };
84
- var getFieldContainerStyles = function (_a) {
85
- var hasError = _a.hasError, theme = _a.theme, focus = _a.focus, disabled = _a.disabled;
86
- var fieldContainerBorderStyle = getFieldContainerBorderStyle({
87
- theme: theme,
88
- hasError: hasError,
89
- focus: focus,
90
- disabled: disabled,
60
+ const getFieldContainerStyles = ({ hasError, theme, focus, disabled, variant, value, customSpacingTop, }) => {
61
+ const fieldContainerBorderStyle = getFieldContainerBorderStyle({
62
+ theme,
63
+ hasError,
64
+ focus,
65
+ disabled,
91
66
  });
92
- return __assign(__assign({}, fieldContainerBorderStyle), { backgroundColor: disabled ? theme.color.background.disabled : theme.color.background.neutral, cursor: disabled ? 'not-allowed' : 'auto' });
67
+ const { height } = getFieldSpacingAndHeight({
68
+ theme,
69
+ variant,
70
+ focus,
71
+ value,
72
+ customSpacingTop,
73
+ });
74
+ return Object.assign(Object.assign({}, fieldContainerBorderStyle), { backgroundColor: disabled ? theme.color.background.disabled : theme.color.background.neutral, height });
93
75
  };
94
- var getFieldPlaceholderStyles = function (_a) {
95
- var _b, _c;
96
- var theme = _a.theme, isFocused = _a.isFocused; _a.disabled; var variant = _a.variant, fieldType = _a.fieldType, _d = _a.isPrefixComponent, isPrefixComponent = _d === void 0 ? false : _d;
97
- var leftMargin = isPrefixComponent ? (_b = theme === null || theme === void 0 ? void 0 : theme.spacing) === null || _b === void 0 ? void 0 : _b[13] : (_c = theme === null || theme === void 0 ? void 0 : theme.spacing) === null || _c === void 0 ? void 0 : _c[4];
98
- var fieldPlaceholderStyles = {
99
- position: 'absolute',
100
- marginLeft: leftMargin,
101
- };
102
- if (variant === FieldVariant.SM || fieldType === FieldType.PHONE) {
103
- return fieldPlaceholderStyles;
76
+ const getFieldPlaceholderStyles = ({ isFocused, variant, fieldType, }) => {
77
+ if (variant === FieldVariant.SM) {
78
+ return { top: 8 };
79
+ }
80
+ if (fieldType === FieldType.PHONE) {
81
+ return {};
104
82
  }
105
83
  if (isFocused) {
106
- fieldPlaceholderStyles = __assign(__assign({}, fieldPlaceholderStyles), { top: theme === null || theme === void 0 ? void 0 : theme.spacing[2] });
84
+ return { transform: [{ translateY: -12 }] };
107
85
  }
108
- return fieldPlaceholderStyles;
86
+ return {};
109
87
  };
110
- var getFieldStyles = function (_a) {
111
- var disabled = _a.disabled, theme = _a.theme, variant = _a.variant, focus = _a.focus, value = _a.value, type = _a.type, _b = _a.isPrefixComponent, isPrefixComponent = _b === void 0 ? false : _b, disabledPlaceHolder = _a.disabledPlaceHolder;
112
- var fieldSpacingAndHeight = getFieldSpacingAndHeight({
113
- theme: theme,
114
- variant: variant,
115
- focus: focus,
116
- value: value,
117
- type: type,
118
- isPrefixComponent: isPrefixComponent,
119
- disabledPlaceHolder: disabledPlaceHolder,
88
+ const getFieldStyles = ({ isLabeledPlaceholder, disabled, theme, variant, focus, value, type, isPrefixComponent = false, disabledPlaceHolder, }) => {
89
+ const fieldSpacingAndHeight = getFieldSpacingAndHeight({
90
+ isLabeledPlaceholder,
91
+ theme,
92
+ variant,
93
+ focus,
94
+ value,
95
+ type,
96
+ isPrefixComponent,
97
+ disabledPlaceHolder,
98
+ customSpacingTop: 2,
120
99
  });
121
- return __assign(__assign({}, fieldSpacingAndHeight), { cursor: disabled ? 'not-allowed' : 'auto', color: disabled ? theme.color.text.disabled : theme.color.text.primary, backgroundColor: disabled ? theme.color.background.disabled : 'transparent' });
100
+ return Object.assign(Object.assign({}, fieldSpacingAndHeight), { backgroundColor: 'transparent', color: disabled ? theme.color.text.disabled : theme.color.text.primary });
122
101
  };
123
-
124
- var Field = forwardRef(function (_a, forwardedRef) {
125
- var _b = _a.value, value = _b === void 0 ? '' : _b, _c = _a.placeholder, placeholder = _c === void 0 ? '' : _c, onChange = _a.onChange, prefix = _a.prefix, suffix = _a.suffix, _d = _a.variant, variant = _d === void 0 ? FieldVariant.MD : _d, _e = _a.type, type = _e === void 0 ? FieldType.TEXT : _e, prompt = _a.prompt, _f = _a.disabled, disabled = _f === void 0 ? false : _f; _a.prefixGap; _a.suffixGap; var css = _a.css, id = _a.id, autoFocus = _a.autoFocus, rootCss = _a.rootCss, _g = _a.styleConfig, styleConfig = _g === void 0 ? {} : _g, onFocus = _a.onFocus, onBlur = _a.onBlur, rest = __rest(_a, ["value", "placeholder", "onChange", "prefix", "suffix", "variant", "type", "prompt", "disabled", "prefixGap", "suffixGap", "css", "id", "autoFocus", "rootCss", "styleConfig", "onFocus", "onBlur"]);
126
- var theme = useTheme();
127
- var rootBox = styleConfig.rootBox, fieldContainer = styleConfig.fieldContainer, placeholderLabel = styleConfig.placeholderLabel, placeholderTypography = styleConfig.placeholderTypography, field = styleConfig.field, promptBox = styleConfig.promptBox, promptIconContainer = styleConfig.promptIconContainer, promptMessageTypography = styleConfig.promptMessageTypography;
128
- var _h = useState(autoFocus || false), focus = _h[0], setFocus = _h[1];
129
- var _j = prompt || {}, _k = _j.hasError, hasError = _k === void 0 ? false : _k, promptIcon = _j.Icon, promptMessage = _j.message;
130
- var isFocused = focus || value.length > 0;
131
- var isPrefixComponent = isValidElement(prefix);
132
- var disabledPlaceHolder = !(placeholder === null || placeholder === void 0 ? void 0 : placeholder.length);
133
- var fieldContainerStyles = getFieldContainerStyles({
134
- variant: variant,
135
- theme: theme,
136
- hasError: hasError,
137
- focus: focus,
138
- value: value,
139
- disabled: disabled,
140
- });
141
- var fieldPlaceholderStyles = getFieldPlaceholderStyles({
142
- isFocused: isFocused,
143
- theme: theme,
144
- disabled: disabled,
145
- variant: variant,
146
- fieldType: type,
147
- isPrefixComponent: isPrefixComponent,
148
- });
149
- var fieldStyles = getFieldStyles({
150
- disabled: disabled,
151
- theme: theme,
152
- variant: variant,
153
- focus: focus,
154
- value: value,
155
- type: type,
156
- isPrefixComponent: isPrefixComponent,
157
- disabledPlaceHolder: disabledPlaceHolder,
158
- });
159
- var onFieldChange = function (e) {
160
- var value = e.target.value;
161
- var isValidValue = true;
162
- switch (type) {
163
- case FieldType.NUMBER: {
164
- if (value && !ONLY_NUMERIC.test(value)) {
165
- isValidValue = false;
166
- }
167
- break;
168
- }
102
+ const getTypographyVariant = (theme, variant) => {
103
+ switch (variant) {
104
+ case TypographyVariant.HD1: {
105
+ return {
106
+ fontSize: theme.typography.size[48],
107
+ fontWeight: theme.typography.weight.semibold,
108
+ lineHeight: theme.typography.lineHeight[56],
109
+ };
110
+ }
111
+ case TypographyVariant.HD2: {
112
+ return {
113
+ fontSize: theme.typography.size[40],
114
+ fontWeight: theme.typography.weight.semibold,
115
+ lineHeight: theme.typography.lineHeight[48],
116
+ };
117
+ }
118
+ case TypographyVariant.HD3: {
119
+ return {
120
+ fontSize: theme.typography.size[32],
121
+ fontWeight: theme.typography.weight.semibold,
122
+ lineHeight: theme.typography.lineHeight[40],
123
+ };
124
+ }
125
+ case TypographyVariant.HM1: {
126
+ return {
127
+ fontSize: theme.typography.size[24],
128
+ fontWeight: theme.typography.weight.semibold,
129
+ lineHeight: theme.typography.lineHeight[32],
130
+ };
131
+ }
132
+ case TypographyVariant.HM2: {
133
+ return {
134
+ fontSize: theme.typography.size[20],
135
+ fontWeight: theme.typography.weight.semibold,
136
+ lineHeight: theme.typography.lineHeight[28],
137
+ };
169
138
  }
170
- if (isValidValue) {
171
- onChange(e);
139
+ case TypographyVariant.HM3: {
140
+ return {
141
+ fontSize: theme.typography.size[16],
142
+ fontWeight: theme.typography.weight.semibold,
143
+ lineHeight: theme.typography.lineHeight[24],
144
+ };
172
145
  }
146
+ case TypographyVariant.HM4: {
147
+ return {
148
+ fontSize: theme.typography.size[14],
149
+ fontWeight: theme.typography.weight.semibold,
150
+ lineHeight: theme.typography.lineHeight[20],
151
+ };
152
+ }
153
+ case TypographyVariant.B1: {
154
+ return {
155
+ fontSize: theme.typography.size[16],
156
+ fontWeight: theme.typography.weight.medium,
157
+ lineHeight: theme.typography.lineHeight[24],
158
+ };
159
+ }
160
+ case TypographyVariant.B2: {
161
+ return {
162
+ fontSize: theme.typography.size[14],
163
+ fontWeight: theme.typography.weight.medium,
164
+ lineHeight: theme.typography.lineHeight[20],
165
+ };
166
+ }
167
+ case TypographyVariant.B3: {
168
+ return {
169
+ fontSize: theme.typography.size[12],
170
+ fontWeight: theme.typography.weight.medium,
171
+ lineHeight: theme.typography.lineHeight[16],
172
+ };
173
+ }
174
+ case TypographyVariant.B3CAPS: {
175
+ return {
176
+ fontSize: theme.typography.size[12],
177
+ fontWeight: theme.typography.weight.semibold,
178
+ lineHeight: theme.typography.lineHeight[16],
179
+ letterSpacing: theme.typography.letterSpacing.point4,
180
+ };
181
+ }
182
+ case TypographyVariant.B4: {
183
+ return {
184
+ fontSize: theme.typography.size[10],
185
+ fontWeight: theme.typography.weight.medium,
186
+ lineHeight: theme.typography.lineHeight[14],
187
+ };
188
+ }
189
+ case TypographyVariant.B4CAPS: {
190
+ return {
191
+ fontSize: theme.typography.size[10],
192
+ fontWeight: theme.typography.weight.semibold,
193
+ lineHeight: theme.typography.lineHeight[12],
194
+ letterSpacing: theme.typography.letterSpacing.point4,
195
+ };
196
+ }
197
+ case TypographyVariant.P1: {
198
+ return {
199
+ fontSize: theme.typography.size[16],
200
+ fontWeight: theme.typography.weight.normal,
201
+ lineHeight: theme.typography.lineHeight[22],
202
+ };
203
+ }
204
+ case TypographyVariant.P2: {
205
+ return {
206
+ fontSize: theme.typography.size[14],
207
+ fontWeight: theme.typography.weight.normal,
208
+ lineHeight: theme.typography.lineHeight[20],
209
+ };
210
+ }
211
+ case TypographyVariant.P3: {
212
+ return {
213
+ fontSize: theme.typography.size[12],
214
+ fontWeight: theme.typography.weight.normal,
215
+ lineHeight: theme.typography.lineHeight[16],
216
+ };
217
+ }
218
+ case TypographyVariant.P4: {
219
+ return {
220
+ fontSize: theme.typography.size[12],
221
+ fontWeight: theme.typography.weight.normal,
222
+ lineHeight: theme.typography.lineHeight[16],
223
+ };
224
+ }
225
+ case TypographyVariant.L1: {
226
+ return {
227
+ fontSize: theme.typography.size[16],
228
+ fontWeight: theme.typography.weight.semibold,
229
+ lineHeight: theme.typography.lineHeight[24],
230
+ };
231
+ }
232
+ case TypographyVariant.L2: {
233
+ return {
234
+ fontSize: theme.typography.size[14],
235
+ fontWeight: theme.typography.weight.semibold,
236
+ lineHeight: theme.typography.lineHeight[20],
237
+ };
238
+ }
239
+ case TypographyVariant.L3: {
240
+ return {
241
+ fontSize: theme.typography.size[12],
242
+ fontWeight: theme.typography.weight.semibold,
243
+ lineHeight: theme.typography.lineHeight[16],
244
+ };
245
+ }
246
+ case TypographyVariant.OVERLINE: {
247
+ return {
248
+ fontSize: theme.typography.size[12],
249
+ fontWeight: theme.typography.weight.semibold,
250
+ lineHeight: theme.typography.lineHeight[16],
251
+ };
252
+ }
253
+ case TypographyVariant.TAG: {
254
+ return {
255
+ fontSize: theme.typography.size[10],
256
+ fontWeight: theme.typography.weight.semibold,
257
+ lineHeight: theme.typography.lineHeight[12],
258
+ letterSpacing: theme.typography.letterSpacing.point5,
259
+ };
260
+ }
261
+ default: {
262
+ return {
263
+ fontSize: theme.typography.size[20],
264
+ fontWeight: theme.typography.weight.semibold,
265
+ lineHeight: theme.typography.lineHeight[28],
266
+ };
267
+ }
268
+ }
269
+ };
270
+
271
+ const styles$4 = css `
272
+ outline: none;
273
+ &:focus {
274
+ outline: none;
275
+ }
276
+ `;
277
+ const staticStyles$5 = makeStyles((theme) => {
278
+ return {
279
+ root: {
280
+ width: '100%',
281
+ border: 'none',
282
+ outline: 'none',
283
+ fontSize: theme.typography.size[16],
284
+ fontWeight: theme.typography.weight.medium,
285
+ lineHeight: theme.typography.lineHeight[24],
286
+ },
287
+ };
288
+ });
289
+ const InputFieldCore$1 = forwardRef(({ value, disabled, styleConfig, onChange, onFocus, onBlur, onKeyDown, onSelect, onPressIn, placeholder, autoFocus, readOnly, type, inputMode, autoCapitalize, fieldTypographyVariant, variant, prefix, focus, placeholderType, id, maxLength, }, forwardedRef) => {
290
+ const inputRef = useRef(null);
291
+ const { field = [] } = styleConfig !== null && styleConfig !== void 0 ? styleConfig : {};
292
+ const isPrefixComponent = isValidElement(prefix);
293
+ const disabledPlaceHolder = !(placeholder === null || placeholder === void 0 ? void 0 : placeholder.length);
294
+ const dynamicStyles = useStyles((theme) => ({
295
+ root: getTypographyVariant(theme, fieldTypographyVariant !== null && fieldTypographyVariant !== void 0 ? fieldTypographyVariant : 'HM2'),
296
+ }), [fieldTypographyVariant]);
297
+ const fieldStyles = useStyles((theme) => {
298
+ return {
299
+ root: getFieldStyles({
300
+ isLabeledPlaceholder: placeholderType === 'labeled',
301
+ disabled: disabled !== null && disabled !== void 0 ? disabled : false,
302
+ theme,
303
+ variant: variant !== null && variant !== void 0 ? variant : 'md',
304
+ focus,
305
+ value,
306
+ type: type !== null && type !== void 0 ? type : 'text',
307
+ isPrefixComponent,
308
+ disabledPlaceHolder,
309
+ }),
310
+ };
311
+ }, [disabled, variant, focus, value, type, isPrefixComponent, disabledPlaceHolder]);
312
+ const mergedStyles = useWebMergeStyles([staticStyles$5.root, dynamicStyles.root, styles$4, fieldStyles.root, ...field], [fieldStyles.root, dynamicStyles.root, field]);
313
+ useImperativeHandle(forwardedRef, () => ({
314
+ focus: () => {
315
+ var _a;
316
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
317
+ },
318
+ blur: () => {
319
+ var _a;
320
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
321
+ },
322
+ setSelection: (start, end) => {
323
+ var _a;
324
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
325
+ },
326
+ }), []);
327
+ const handleOnChange = useCallback((event) => {
328
+ const inputValue = event.target.value;
329
+ onChange === null || onChange === void 0 ? void 0 : onChange({
330
+ target: { value: inputValue, selectionStart: event.target.selectionStart || 0 },
331
+ currentTarget: {
332
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
333
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
334
+ setSelection: (start, end) => {
335
+ var _a;
336
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
337
+ },
338
+ },
339
+ });
340
+ }, [onChange]);
341
+ const handleOnFocus = useCallback((event) => {
342
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus({
343
+ target: { value: event.target.value },
344
+ currentTarget: {
345
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
346
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
347
+ setSelection: (start, end) => {
348
+ var _a;
349
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
350
+ },
351
+ },
352
+ preventDefault: () => event.preventDefault(),
353
+ });
354
+ }, [onFocus]);
355
+ const handleOnBlur = useCallback((event) => {
356
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur({
357
+ target: { value: event.target.value },
358
+ currentTarget: {
359
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
360
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
361
+ setSelection: (start, end) => {
362
+ var _a;
363
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
364
+ },
365
+ },
366
+ preventDefault: () => event.preventDefault(),
367
+ });
368
+ }, [onBlur]);
369
+ const handleOnKeyDown = useCallback((event) => {
370
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown({
371
+ target: { value: event.target.value, key: event.key },
372
+ currentTarget: {
373
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
374
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
375
+ setSelection: (start, end) => {
376
+ var _a;
377
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
378
+ },
379
+ },
380
+ preventDefault: () => event.preventDefault(),
381
+ });
382
+ }, [onKeyDown]);
383
+ const handleOnSelect = useCallback((event) => {
384
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect({
385
+ target: {
386
+ value: event.target.value,
387
+ selectionStart: event.target.selectionStart || 0,
388
+ },
389
+ currentTarget: {
390
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
391
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
392
+ setSelection: (start, end) => {
393
+ var _a;
394
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
395
+ },
396
+ },
397
+ preventDefault: () => event.preventDefault(),
398
+ });
399
+ }, [onSelect]);
400
+ const handleOnPressIn = useCallback((event) => {
401
+ var _a;
402
+ onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn({
403
+ target: { value: ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) || '' },
404
+ currentTarget: {
405
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
406
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
407
+ setSelection: (start, end) => {
408
+ var _a;
409
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
410
+ },
411
+ },
412
+ preventDefault: () => event.preventDefault(),
413
+ });
414
+ }, [onPressIn]);
415
+ const webProps = {
416
+ onChange: handleOnChange,
417
+ onFocus: handleOnFocus,
418
+ onBlur: handleOnBlur,
419
+ onKeyDown: handleOnKeyDown,
420
+ onSelect: handleOnSelect,
421
+ onMouseDown: handleOnPressIn,
422
+ placeholder,
423
+ autoFocus,
424
+ readOnly,
425
+ type,
426
+ inputMode,
427
+ autoCapitalize,
173
428
  };
174
- var customOnFocus = function (e) {
175
- setFocus(true);
176
- onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
429
+ return (jsx("input", Object.assign({ maxLength: maxLength, id: id, ref: inputRef, value: value, disabled: disabled, className: mergedStyles }, webProps)));
430
+ });
431
+ InputFieldCore$1.displayName = 'InputFieldCore';
432
+
433
+ const staticStyles$4 = makeStyles((theme) => {
434
+ return {
435
+ root: {
436
+ position: 'absolute',
437
+ paddingLeft: theme.spacing[4],
438
+ width: '100%',
439
+ height: '100%',
440
+ display: 'flex',
441
+ transform: [{ translateY: 0 }],
442
+ top: 16,
443
+ },
177
444
  };
178
- var customOnBlur = function (e) {
179
- setFocus(false);
180
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
445
+ });
446
+ const FieldLabelWrapper = ({ variant, type, value, focus = false, placeholder, placeholderType, disabled = false, styleConfig, prefix, id, }) => {
447
+ const { placeholder: placeholderStyleConfig } = styleConfig !== null && styleConfig !== void 0 ? styleConfig : {};
448
+ const { placeholderLabel = [], placeholderTypography = {} } = placeholderStyleConfig !== null && placeholderStyleConfig !== void 0 ? placeholderStyleConfig : {};
449
+ const shiftPlaceholder = placeholderType === 'floating';
450
+ const isPrefixComponent = isValidElement(prefix);
451
+ const baseStyles = useStyles((theme) => ({
452
+ root: getFieldPlaceholderStyles({
453
+ theme,
454
+ isFocused: focus,
455
+ disabled,
456
+ variant: variant !== null && variant !== void 0 ? variant : 'md',
457
+ fieldType: type !== null && type !== void 0 ? type : 'text',
458
+ isPrefixComponent,
459
+ shiftPlaceholder,
460
+ }),
461
+ }), [focus, disabled, variant, type, isPrefixComponent, shiftPlaceholder]);
462
+ const labelStyles = useWebMergeStyles([baseStyles.root, staticStyles$4.root, ...placeholderLabel], [baseStyles.root, placeholderLabel]);
463
+ if (placeholderType === 'default' || !focus) {
464
+ return null;
465
+ }
466
+ if (variant === FieldVariant.SM) {
467
+ if (value.length)
468
+ return null;
469
+ return (jsx(Container, { styleConfig: { root: [baseStyles.root, staticStyles$4.root, ...placeholderLabel] }, children: jsx(Typography, { variant: 'B2', color: 'tertiary', styleConfig: placeholderTypography, children: placeholder }) }));
470
+ }
471
+ if (type === FieldType.PHONE && value.length)
472
+ return null;
473
+ const typographyVariant = type === FieldType.PHONE ? 'B1' : focus ? 'B3' : 'B1';
474
+ return (jsx("label", { className: labelStyles, htmlFor: id, children: jsx(Typography, { variant: typographyVariant, color: 'tertiary', styleConfig: placeholderTypography, children: placeholder }) }));
475
+ };
476
+
477
+ const styles$3 = css `
478
+ outline: none;
479
+ &:focus {
480
+ outline: none;
481
+ }
482
+ `;
483
+ const staticStyles$3 = makeStyles((theme) => {
484
+ return {
485
+ root: {
486
+ width: '100%',
487
+ border: 'none',
488
+ outline: 'none',
489
+ fontSize: theme.typography.size[16],
490
+ fontWeight: theme.typography.weight.medium,
491
+ lineHeight: theme.typography.lineHeight[24],
492
+ },
181
493
  };
182
- var getFieldPlaceholder = function () {
183
- switch (variant) {
184
- case FieldVariant.SM: {
185
- if (!value.length) {
186
- return (jsx(StyledFieldPlaceholder, __assign({}, fieldPlaceholderStyles, { htmlFor: id, className: placeholderLabel === null || placeholderLabel === void 0 ? void 0 : placeholderLabel.className, css: placeholderLabel === null || placeholderLabel === void 0 ? void 0 : placeholderLabel.css }, { children: jsx(Typography, __assign({ variant: 'B1', color: 'tertiary', styleConfig: placeholderTypography }, { children: placeholder })) })));
187
- }
188
- break;
494
+ });
495
+ const InputFieldCore = forwardRef(({ value, disabled, styleConfig, onChange, onFocus, onBlur, onKeyDown, onSelect, onPressIn, placeholder, autoFocus, readOnly, type, inputMode, autoCapitalize, fieldTypographyVariant, variant, prefix, focus, placeholderType, id, maxLength, }, forwardedRef) => {
496
+ const inputRef = useRef(null);
497
+ const { field = [] } = styleConfig !== null && styleConfig !== void 0 ? styleConfig : {};
498
+ const isPrefixComponent = isValidElement(prefix);
499
+ const disabledPlaceHolder = !(placeholder === null || placeholder === void 0 ? void 0 : placeholder.length);
500
+ const dynamicStyles = useStyles((theme) => ({
501
+ root: getTypographyVariant(theme, fieldTypographyVariant !== null && fieldTypographyVariant !== void 0 ? fieldTypographyVariant : 'HM2'),
502
+ }), [fieldTypographyVariant]);
503
+ const fieldStyles = useStyles((theme) => {
504
+ return {
505
+ root: getFieldStyles({
506
+ isLabeledPlaceholder: placeholderType === 'labeled',
507
+ disabled: disabled !== null && disabled !== void 0 ? disabled : false,
508
+ theme,
509
+ variant: variant !== null && variant !== void 0 ? variant : 'md',
510
+ focus,
511
+ value,
512
+ type: type !== null && type !== void 0 ? type : 'text',
513
+ isPrefixComponent,
514
+ disabledPlaceHolder,
515
+ }),
516
+ };
517
+ }, [disabled, variant, focus, value, type, isPrefixComponent, disabledPlaceHolder]);
518
+ const mergedStyles = useWebMergeStyles([staticStyles$3.root, dynamicStyles.root, styles$3, fieldStyles.root, ...field], [fieldStyles.root, dynamicStyles.root, field]);
519
+ useImperativeHandle(forwardedRef, () => ({
520
+ focus: () => {
521
+ var _a;
522
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
523
+ },
524
+ blur: () => {
525
+ var _a;
526
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
527
+ },
528
+ setSelection: (start, end) => {
529
+ var _a;
530
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
531
+ },
532
+ }), []);
533
+ const handleOnChange = useCallback((event) => {
534
+ const inputValue = event.target.value;
535
+ onChange === null || onChange === void 0 ? void 0 : onChange({
536
+ target: { value: inputValue, selectionStart: event.target.selectionStart || 0 },
537
+ currentTarget: {
538
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
539
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
540
+ setSelection: (start, end) => {
541
+ var _a;
542
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
543
+ },
544
+ },
545
+ });
546
+ }, [onChange]);
547
+ const handleOnFocus = useCallback((event) => {
548
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus({
549
+ target: { value: event.target.value },
550
+ currentTarget: {
551
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
552
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
553
+ setSelection: (start, end) => {
554
+ var _a;
555
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
556
+ },
557
+ },
558
+ preventDefault: () => event.preventDefault(),
559
+ });
560
+ }, [onFocus]);
561
+ const handleOnBlur = useCallback((event) => {
562
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur({
563
+ target: { value: event.target.value },
564
+ currentTarget: {
565
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
566
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
567
+ setSelection: (start, end) => {
568
+ var _a;
569
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
570
+ },
571
+ },
572
+ preventDefault: () => event.preventDefault(),
573
+ });
574
+ }, [onBlur]);
575
+ const handleOnKeyDown = useCallback((event) => {
576
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown({
577
+ target: { value: event.target.value, key: event.key },
578
+ currentTarget: {
579
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
580
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
581
+ setSelection: (start, end) => {
582
+ var _a;
583
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
584
+ },
585
+ },
586
+ preventDefault: () => event.preventDefault(),
587
+ });
588
+ }, [onKeyDown]);
589
+ const handleOnSelect = useCallback((event) => {
590
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect({
591
+ target: {
592
+ value: event.target.value,
593
+ selectionStart: event.target.selectionStart || 0,
594
+ },
595
+ currentTarget: {
596
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
597
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
598
+ setSelection: (start, end) => {
599
+ var _a;
600
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
601
+ },
602
+ },
603
+ preventDefault: () => event.preventDefault(),
604
+ });
605
+ }, [onSelect]);
606
+ const handleOnPressIn = useCallback((event) => {
607
+ var _a;
608
+ onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn({
609
+ target: { value: ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) || '' },
610
+ currentTarget: {
611
+ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
612
+ blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
613
+ setSelection: (start, end) => {
614
+ var _a;
615
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(start, end);
616
+ },
617
+ },
618
+ preventDefault: () => event.preventDefault(),
619
+ });
620
+ }, [onPressIn]);
621
+ const webProps = {
622
+ onChange: handleOnChange,
623
+ onFocus: handleOnFocus,
624
+ onBlur: handleOnBlur,
625
+ onKeyDown: handleOnKeyDown,
626
+ onSelect: handleOnSelect,
627
+ onMouseDown: handleOnPressIn,
628
+ placeholder,
629
+ autoFocus,
630
+ readOnly,
631
+ type,
632
+ inputMode,
633
+ autoCapitalize,
634
+ };
635
+ return (jsx("textarea", Object.assign({ maxLength: maxLength, id: id, ref: inputRef, value: value, disabled: disabled, className: mergedStyles }, webProps)));
636
+ });
637
+ InputFieldCore.displayName = 'TextArea';
638
+
639
+ const staticStyles$2 = makeStyles((theme) => {
640
+ return {
641
+ fieldWrapper: {
642
+ flex: 1,
643
+ flexShrink: 1,
644
+ display: 'flex',
645
+ alignItems: 'center',
646
+ justifyContent: 'center',
647
+ position: 'relative',
648
+ height: '100%',
649
+ },
650
+ promptBox: {
651
+ paddingLeft: theme.spacing[4],
652
+ paddingRight: theme.spacing[4],
653
+ display: 'flex',
654
+ alignItems: 'center',
655
+ },
656
+ promptIcon: {
657
+ height: theme.size[4],
658
+ width: theme.size[4],
659
+ paddingRight: theme.spacing[1],
660
+ display: 'flex',
661
+ justifyContent: 'center',
662
+ alignItems: 'center',
663
+ },
664
+ flexNoShrink: {
665
+ flexShrink: 0,
666
+ },
667
+ fieldContainer: {
668
+ position: 'relative',
669
+ display: 'flex',
670
+ alignItems: 'center',
671
+ justifyContent: 'center',
672
+ flexDirection: 'row',
673
+ borderStyle: theme === null || theme === void 0 ? void 0 : theme.border.style.solid,
674
+ borderRadius: theme === null || theme === void 0 ? void 0 : theme.border.radius[8],
675
+ boxSizing: 'border-box',
676
+ },
677
+ };
678
+ });
679
+ const Field = forwardRef(({ prefix, onBlur, onFocus, onChange, onKeyDown, onPressIn, onSelect, value, autoCapitalize, autoFocus = false, disabled, inputMode, placeholder, prefixGap: _prefixGap, prompt, readOnly, placeholderType = 'default', suffix, suffixGap: _suffixGap, type, variant, styleConfig = {}, fieldTypographyVariant, id, maxLength, numberOfLines, showSoftInputOnFocus, customSpacingTop, }, ref) => {
680
+ const [focus, setFocus] = useState(autoFocus);
681
+ const _isFocused = focus || value.length > 0;
682
+ const { promptStyles } = styleConfig || {};
683
+ const { Icon: promptIcon, message: promptMessage, hasError = false } = prompt || {};
684
+ const fieldContainerStyles = useStyles((theme) => ({
685
+ root: getFieldContainerStyles({
686
+ variant: variant !== null && variant !== void 0 ? variant : 'md',
687
+ theme,
688
+ hasError,
689
+ focus,
690
+ value,
691
+ disabled,
692
+ }),
693
+ }), [variant, hasError, focus, value, disabled, styleConfig]);
694
+ const InputField = numberOfLines && numberOfLines > 1 ? InputFieldCore : InputFieldCore$1;
695
+ return (jsxs(Box, { boxSize: 'micro', styleConfig: styleConfig, children: [jsxs(Container, { styleConfig: {
696
+ root: [fieldContainerStyles.root, staticStyles$2.fieldContainer, ...(styleConfig.fieldContainer || [])],
697
+ }, children: [isValidElement(prefix) && (jsx(Container, { styleConfig: { root: [staticStyles$2.flexNoShrink] }, children: cloneElement(prefix, { focus }) })), jsxs(Container, { styleConfig: { root: [staticStyles$2.fieldWrapper, ...(styleConfig.field || [])] }, children: [jsx(FieldLabelWrapper, { id: id, variant: variant, type: type, value: value, focus: _isFocused, placeholder: placeholder, placeholderType: placeholderType, disabled: disabled, styleConfig: styleConfig, prefix: prefix }), jsx(InputField, { id: id, ref: ref, value: value, disabled: disabled, placeholder: placeholder, placeholderType: placeholderType, autoFocus: autoFocus, readOnly: readOnly, type: type, inputMode: inputMode, autoCapitalize: autoCapitalize, fieldTypographyVariant: fieldTypographyVariant, styleConfig: styleConfig, focus: _isFocused, onChange: onChange, onSelect: onSelect, onPressIn: onPressIn, onFocus: (e) => {
698
+ setFocus(true);
699
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
700
+ }, onBlur: (e) => {
701
+ setFocus(false);
702
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
703
+ }, onKeyDown: onKeyDown, maxLength: maxLength, numberOfLines: numberOfLines, showSoftInputOnFocus: showSoftInputOnFocus, customSpacingTop: customSpacingTop })] }), isValidElement(suffix) && (jsx(Container, { styleConfig: { root: [staticStyles$2.flexNoShrink] }, children: cloneElement(suffix, { focus }) }))] }), (promptIcon || promptMessage) && (jsxs(Box, { boxSize: 'pico', horizontal: true, styleConfig: {
704
+ root: [staticStyles$2.promptBox, ...((promptStyles === null || promptStyles === void 0 ? void 0 : promptStyles.promptBox) || [])],
705
+ }, children: [promptIcon && (jsx(Container, { styleConfig: { root: [staticStyles$2.promptIcon, ...((promptStyles === null || promptStyles === void 0 ? void 0 : promptStyles.promptIconContainer) || [])] }, children: promptIcon })), promptMessage && (jsx(Typography, { variant: 'B3', color: hasError ? 'warning' : 'success', styleConfig: promptStyles === null || promptStyles === void 0 ? void 0 : promptStyles.promptMessageTypography, children: promptMessage }))] }))] }));
706
+ });
707
+ Field.displayName = 'Field';
708
+
709
+ const styles$2 = makeStyles((theme) => {
710
+ return {
711
+ wrapper: {
712
+ alignItems: 'center',
713
+ justifyContent: 'center',
714
+ flexDirection: 'row',
715
+ paddingLeft: 16,
716
+ },
717
+ flagContainer: {
718
+ display: 'flex',
719
+ alignItems: 'center',
720
+ justifyContent: 'center',
721
+ flexDirection: 'row',
722
+ height: theme.size[6],
723
+ width: theme.size[6],
724
+ },
725
+ countryCode: {
726
+ alignSelf: 'flex-start',
727
+ },
728
+ divider: {
729
+ borderRightWidth: 1,
730
+ height: '100%',
731
+ borderRightColor: theme.color.background.disabledDark,
732
+ },
733
+ disabledColor: {
734
+ color: theme.color.text.disabled,
735
+ },
736
+ enabledColor: {
737
+ color: theme.color.text.primary,
738
+ },
739
+ container: {
740
+ flexDirection: 'row',
741
+ alignItems: 'center',
742
+ gap: theme.spacing[2],
743
+ },
744
+ };
745
+ });
746
+ const DownChevronV2 = (_a) => {
747
+ var { color = '#1A1A1A' } = _a, rest = __rest(_a, ["color"]);
748
+ return (jsx("svg", Object.assign({ xmlns: 'http://www.w3.org/2000/svg', width: '12', height: '12', fill: 'none', viewBox: '0 0 12 12' }, rest, { children: jsx("path", { stroke: color, strokeLinecap: 'round', strokeLinejoin: 'round', strokeWidth: '2', d: 'M2 4l4 4 4-4' }) })));
749
+ };
750
+ const PhoneFieldPrefix = ({ countryCode, disabled = false, flagIcon, onDropdownClick, showDropdownIcon, }) => {
751
+ const onClick = () => {
752
+ if (disabled)
753
+ return;
754
+ onDropdownClick === null || onDropdownClick === void 0 ? void 0 : onDropdownClick();
755
+ };
756
+ return (jsxs(Box, { boxSize: 'micro', styleConfig: { root: [styles$2.wrapper] }, onClick: onClick, children: [jsxs(Container, { styleConfig: {
757
+ root: [styles$2.container],
758
+ }, children: [flagIcon && jsx(Container, { styleConfig: { root: [styles$2.flagContainer] }, children: flagIcon }), jsx(Typography, { variant: 'B1', color: disabled ? 'disabled' : 'primary', styleConfig: { root: [styles$2.countryCode] }, children: countryCode }), showDropdownIcon && (jsx(DownChevronV2, { color: disabled ? styles$2.disabledColor.color : styles$2.enabledColor.color }))] }), jsx(Divider, { dividerWidth: 1, dividerLength: 0, orientation: 'vertical', styleConfig: { root: [styles$2.divider] } })] }));
759
+ };
760
+
761
+ const styles$1 = makeStyles((theme) => {
762
+ return {
763
+ fieldConfig: {
764
+ flex: 1,
765
+ paddingTop: 0,
766
+ paddingBottom: 0,
767
+ paddingVertical: 0,
768
+ lineHeight: 18,
769
+ paddingLeft: theme.spacing[4],
770
+ },
771
+ };
772
+ });
773
+ const PhoneField = forwardRef((_a, forwardedRef) => {
774
+ var _b;
775
+ var { flagIcon, countryCode, showDropdownIcon, onDropdownClick, disabled, max, onChange, styleConfig } = _a, rest = __rest(_a, ["flagIcon", "countryCode", "showDropdownIcon", "onDropdownClick", "disabled", "max", "onChange", "styleConfig"]);
776
+ const [prefixWidth, setPrefixWidth] = useState(0);
777
+ const handleChange = (event) => {
778
+ const value = event.target.value;
779
+ const isValidValue = value ? new RegExp(ONLY_NUMERIC).test(value) : true;
780
+ if (value.length <= max && isValidValue) {
781
+ onChange === null || onChange === void 0 ? void 0 : onChange(event);
782
+ }
783
+ };
784
+ const customPlaceHolderStyling = useStyles(() => {
785
+ return {
786
+ placeholderStyles: {
787
+ marginLeft: prefixWidth,
788
+ },
789
+ };
790
+ }, [prefixWidth]);
791
+ return (jsx(Field, Object.assign({}, rest, { type: FieldType.PHONE, ref: forwardedRef, disabled: disabled, onChange: handleChange, prefix: jsx("div", { ref: (ref) => { var _a; return setPrefixWidth((_a = ref === null || ref === void 0 ? void 0 : ref.getBoundingClientRect().width) !== null && _a !== void 0 ? _a : 0); }, children: jsx(PhoneFieldPrefix, { flagIcon: flagIcon, countryCode: countryCode, showDropdownIcon: showDropdownIcon, onDropdownClick: onDropdownClick, disabled: disabled }) }), inputMode: 'numeric', styleConfig: Object.assign({ field: [styles$1.fieldConfig, ...((styleConfig === null || styleConfig === void 0 ? void 0 : styleConfig.field) || [])], placeholder: {
792
+ placeholderLabel: [
793
+ customPlaceHolderStyling.placeholderStyles,
794
+ ...(((_b = styleConfig === null || styleConfig === void 0 ? void 0 : styleConfig.placeholder) === null || _b === void 0 ? void 0 : _b.placeholderLabel) || []),
795
+ ],
796
+ } }, styleConfig) })));
797
+ });
798
+ PhoneField.displayName = 'PhoneField';
799
+
800
+ const styles = makeStyles((theme) => ({
801
+ rootContainer: {
802
+ justifyContent: 'center',
803
+ },
804
+ otpContainer: {
805
+ display: 'flex',
806
+ flexDirection: 'row',
807
+ gap: theme.spacing[3],
808
+ },
809
+ otpBox: {
810
+ width: theme.size[15],
811
+ height: theme.size[15],
812
+ borderRadius: theme === null || theme === void 0 ? void 0 : theme.border.radius[8],
813
+ justifyContent: 'center',
814
+ alignItems: 'center',
815
+ borderStyle: theme.border.style.solid,
816
+ },
817
+ otpInput: {
818
+ width: '100%',
819
+ height: '100%',
820
+ fontSize: theme === null || theme === void 0 ? void 0 : theme.typography.size[20],
821
+ fontWeight: theme === null || theme === void 0 ? void 0 : theme.typography.weight.semibold,
822
+ color: theme.color.text.primary,
823
+ textAlign: 'center',
824
+ },
825
+ errorText: {
826
+ marginVertical: theme === null || theme === void 0 ? void 0 : theme.spacing[2],
827
+ fontSize: theme === null || theme === void 0 ? void 0 : theme.typography.size[14],
828
+ fontWeight: theme === null || theme === void 0 ? void 0 : theme.typography.weight.semibold,
829
+ color: theme === null || theme === void 0 ? void 0 : theme.color.text.warning,
830
+ },
831
+ }));
832
+ const OtpBox = ({ value, focus, inputMode, onChange, onFocus, readOnly, onBlur, onPressIn, onKeyDown, onSelect, maxLength, prompt, styleConfig, }) => {
833
+ const theme = useTheme();
834
+ const ref = useRef(null);
835
+ const { hasError = false } = prompt || {};
836
+ const { otpBox = [], otpRootInput = [] } = styleConfig || {};
837
+ useEffect(() => {
838
+ if (focus && ref.current) {
839
+ ref.current.focus();
840
+ }
841
+ }, [focus]);
842
+ const dynamicStyles = useStyles((theme) => {
843
+ if (hasError) {
844
+ return {
845
+ otpBox: {
846
+ borderColor: theme.color.border.warning,
847
+ borderWidth: theme.border.width.lg,
848
+ },
849
+ };
850
+ }
851
+ return {
852
+ otpBox: {
853
+ borderColor: focus ? theme.color.border.primary : theme.color.border.disabledDark,
854
+ borderWidth: focus ? theme.border.width.lg : theme.border.width.sm,
855
+ },
856
+ };
857
+ }, [hasError, focus]);
858
+ return (jsx(Container, { styleConfig: {
859
+ root: [styles.otpBox, dynamicStyles.otpBox, ...otpBox],
860
+ }, children: jsx(InputFieldCore$1, { id: `otp-box`, disabled: readOnly, ref: ref, value: value, maxLength: maxLength, inputMode: inputMode, onChange: onChange, onBlur: onBlur, onPressIn: onPressIn, onKeyDown: onKeyDown, onSelect: onSelect, autoCapitalize: 'characters', cursorColor: theme.color.text.grapetini900, onFocus: onFocus, focus: focus, styleConfig: { root: [styles.otpInput, ...otpRootInput] } }) }));
861
+ };
862
+ const OtpField = ({ value = '', numberOfBoxes = 4, inputMode = 'numeric', autoFocus = true, refocus = false, onChange, readOnly = false, onComplete, onKeyDown, onSelect, onBlur, onPressIn, onFocus, prompt, styleConfig = {}, }) => {
863
+ const [focusedIndex, setFocusedIndex] = useState(autoFocus ? 0 : -1);
864
+ const { hasError = false, message: errorMessage } = prompt || {};
865
+ const { promptStyles, otpRootContainer = [], otpRootInput = [] } = styleConfig || {};
866
+ const { promptMessageTypography } = promptStyles || {};
867
+ const otpValues = Array(numberOfBoxes)
868
+ .fill('')
869
+ .map((_, index) => {
870
+ const char = value[index];
871
+ return char && char !== ' ' ? char : '';
872
+ });
873
+ useEffect(() => {
874
+ if (autoFocus && !readOnly) {
875
+ setFocusedIndex(0);
876
+ }
877
+ }, [autoFocus, readOnly]);
878
+ useEffect(() => {
879
+ if (refocus) {
880
+ setFocusedIndex(0);
881
+ }
882
+ }, [refocus]);
883
+ const validateInput = useCallback((text) => {
884
+ if (inputMode === 'numeric') {
885
+ return text.replace(/[^0-9]/g, '');
886
+ }
887
+ return text.replace(/[^0-9A-Za-z]/g, '').toUpperCase();
888
+ }, [inputMode]);
889
+ const handleInputChange = useCallback((e, index) => {
890
+ const validatedText = validateInput(e.target.value);
891
+ const otpString = value || '';
892
+ const currentOtpValues = Array(numberOfBoxes)
893
+ .fill('')
894
+ .map((_, idx) => {
895
+ const char = otpString[idx];
896
+ return char && char !== ' ' ? char : '';
897
+ });
898
+ if (validatedText.length > 1) {
899
+ const newValues = [...currentOtpValues];
900
+ for (let i = 0; i < validatedText.length && index + i < numberOfBoxes; i++) {
901
+ newValues[index + i] = validatedText[i];
902
+ }
903
+ const newValue = newValues.join('');
904
+ onChange === null || onChange === void 0 ? void 0 : onChange({
905
+ target: { value: newValue, selectionStart: index },
906
+ currentTarget: e.currentTarget,
907
+ preventDefault: e.preventDefault,
908
+ });
909
+ const nextEmptyIndex = newValues.findIndex((val) => !val);
910
+ if (nextEmptyIndex !== -1) {
911
+ setFocusedIndex(nextEmptyIndex);
189
912
  }
190
- case FieldVariant.MD: {
191
- if (type === FieldType.PHONE && value.length)
192
- return;
193
- return (jsx(StyledFieldPlaceholder, __assign({}, fieldPlaceholderStyles, { htmlFor: id, className: placeholderLabel === null || placeholderLabel === void 0 ? void 0 : placeholderLabel.className, css: placeholderLabel === null || placeholderLabel === void 0 ? void 0 : placeholderLabel.css }, { children: jsx(Typography, __assign({ variant: type === FieldType.PHONE ? 'B1' : isFocused ? 'B3' : 'B1', color: 'tertiary', styleConfig: placeholderTypography }, { children: placeholder })) })));
913
+ else {
914
+ setFocusedIndex(numberOfBoxes - 1);
194
915
  }
195
- default: {
196
- if (type === FieldType.PHONE && value.length)
197
- return;
198
- return (jsx(StyledFieldPlaceholder, __assign({}, fieldPlaceholderStyles, { htmlFor: id, className: placeholderLabel === null || placeholderLabel === void 0 ? void 0 : placeholderLabel.className, css: placeholderLabel === null || placeholderLabel === void 0 ? void 0 : placeholderLabel.css }, { children: jsx(Typography, __assign({ variant: type === FieldType.PHONE ? 'B1' : isFocused ? 'B3' : 'B1', color: 'tertiary', styleConfig: placeholderTypography }, { children: placeholder })) })));
916
+ if (!newValues.includes('')) {
917
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(newValue);
199
918
  }
919
+ return;
200
920
  }
201
- };
202
- return (jsxs(Box, __assign({ boxSize: 'micro', className: rootBox === null || rootBox === void 0 ? void 0 : rootBox.className, css: (rootBox === null || rootBox === void 0 ? void 0 : rootBox.css) || rootCss }, { children: [jsxs(StyledFieldContainer, __assign({}, fieldContainerStyles, { className: fieldContainer === null || fieldContainer === void 0 ? void 0 : fieldContainer.className, css: (fieldContainer === null || fieldContainer === void 0 ? void 0 : fieldContainer.css) || css }, { children: [isValidElement(prefix) && cloneElement(prefix, { focus: focus }), !disabledPlaceHolder && getFieldPlaceholder(), jsx(StyledField, __assign({}, fieldStyles, { id: id, value: value, onChange: onFieldChange, autoComplete: 'off', disabled: disabled, ref: forwardedRef, autoFocus: autoFocus, onFocus: customOnFocus, onBlur: customOnBlur, css: field === null || field === void 0 ? void 0 : field.css, className: field === null || field === void 0 ? void 0 : field.className }, rest)), isValidElement(suffix) && cloneElement(suffix, { focus: focus })] })), (promptIcon || promptMessage) && (jsxs(Box, __assign({ boxSize: 'pico', horizontal: true, css: __assign({ paddingLeft: theme.spacing[4], paddingRight: theme.spacing[4], display: 'flex', alignItems: 'center' }, promptBox === null || promptBox === void 0 ? void 0 : promptBox.css), className: promptBox === null || promptBox === void 0 ? void 0 : promptBox.className }, { children: [promptIcon && (jsx(Container, __assign({ css: __assign({ height: theme.size[4], width: theme.size[4], paddingRight: theme.spacing[1], display: 'flex', justifyContent: 'center', alignItems: 'center' }, promptIconContainer === null || promptIconContainer === void 0 ? void 0 : promptIconContainer.css), className: promptIconContainer === null || promptIconContainer === void 0 ? void 0 : promptIconContainer.className }, { children: promptIcon }))), promptMessage && (jsx(Typography, __assign({ variant: 'B3', color: hasError ? 'warning' : 'success', styleConfig: promptMessageTypography }, { children: promptMessage })))] })))] })));
203
- });
921
+ if (validatedText) {
922
+ const newValues = [...currentOtpValues];
923
+ newValues[index] = validatedText;
924
+ const newValue = newValues.join('');
925
+ onChange === null || onChange === void 0 ? void 0 : onChange({
926
+ target: { value: newValue, selectionStart: index },
927
+ currentTarget: e.currentTarget,
928
+ preventDefault: e.preventDefault,
929
+ });
930
+ if (index < numberOfBoxes - 1) {
931
+ setFocusedIndex(index + 1);
932
+ }
933
+ if (!newValues.includes('')) {
934
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(newValue);
935
+ }
936
+ }
937
+ }, [validateInput, value, numberOfBoxes, onChange, onComplete]);
938
+ const handleKeyPress = useCallback((e, index) => {
939
+ var _a, _b;
940
+ const key = e.target.key;
941
+ if (key === 'Backspace') {
942
+ const otpString = value || '';
943
+ const currentOtpValues = Array(numberOfBoxes)
944
+ .fill('')
945
+ .map((_, idx) => {
946
+ const char = otpString[idx];
947
+ return char && char !== ' ' ? char : '';
948
+ });
949
+ if (currentOtpValues[index]) {
950
+ const newValues = [...currentOtpValues];
951
+ newValues[index] = ' ';
952
+ onChange === null || onChange === void 0 ? void 0 : onChange({
953
+ target: { value: newValues.join(''), selectionStart: index },
954
+ currentTarget: e.currentTarget,
955
+ preventDefault: e.preventDefault,
956
+ });
957
+ }
958
+ else if (index > 0) {
959
+ setFocusedIndex(index - 1);
960
+ }
961
+ }
962
+ else if (key === 'ArrowLeft' && index > 0) {
963
+ (_a = e.preventDefault) === null || _a === void 0 ? void 0 : _a.call(e);
964
+ setFocusedIndex(index - 1);
965
+ }
966
+ else if (key === 'ArrowRight' && index < numberOfBoxes - 1) {
967
+ (_b = e.preventDefault) === null || _b === void 0 ? void 0 : _b.call(e);
968
+ setFocusedIndex(index + 1);
969
+ }
970
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown({
971
+ target: { value, key },
972
+ currentTarget: e.currentTarget,
973
+ preventDefault: e.preventDefault,
974
+ });
975
+ }, [numberOfBoxes, onKeyDown, value, onChange]);
976
+ const handleFocus = useCallback((e, index) => {
977
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus({
978
+ target: { value, index },
979
+ currentTarget: e.currentTarget,
980
+ preventDefault: e.preventDefault,
981
+ });
982
+ setFocusedIndex(index);
983
+ }, [onFocus, value]);
984
+ return (jsxs(Container, { styleConfig: { root: [styles.rootContainer, ...otpRootContainer] }, children: [jsx(Container, { styleConfig: { root: [styles.otpContainer, ...otpRootInput] }, children: Array(numberOfBoxes)
985
+ .fill(null)
986
+ .map((_, index) => (jsx(OtpBox, { value: otpValues[index], focus: focusedIndex === index, prompt: { hasError }, inputMode: inputMode, maxLength: isIOS() ? numberOfBoxes : 1, onFocus: (e) => handleFocus(e, index), onChange: (e) => handleInputChange(e, index), readOnly: readOnly, onPressIn: onPressIn, onKeyDown: (e) => handleKeyPress(e, index), onSelect: onSelect, onBlur: onBlur, styleConfig: styleConfig }, index))) }), hasError && !!errorMessage && (jsx(Typography, { variant: TypographyVariant.P3, color: TypographyColor.WARNING, styleConfig: Object.assign({ root: [styles.errorText] }, promptMessageTypography), children: errorMessage }))] }));
987
+ };
204
988
 
205
989
  var CURSOR_OPERATION;
206
990
  (function (CURSOR_OPERATION) {
@@ -208,24 +992,25 @@ var CURSOR_OPERATION;
208
992
  CURSOR_OPERATION["ADD"] = "ADD";
209
993
  CURSOR_OPERATION["SUBSTRACT"] = "SUBSTRACT";
210
994
  })(CURSOR_OPERATION || (CURSOR_OPERATION = {}));
211
-
212
- var CardField = forwardRef(function (_a, forwardedRef) {
213
- var onChange = _a.onChange, _b = _a.gap, gap = _b === void 0 ? 4 : _b, value = _a.value, rest = __rest(_a, ["onChange", "gap", "value"]);
214
- var cursorRef = useRef({
995
+ const CardField = forwardRef((_a, forwardedRef) => {
996
+ var { onChange, value } = _a, rest = __rest(_a, ["onChange", "value"]);
997
+ const ref = useRef(null);
998
+ const mergedRef = useMergeRefs(forwardedRef, ref);
999
+ const cursorRef = useRef({
215
1000
  cursorPos: 0,
216
1001
  operation: CURSOR_OPERATION.NONE,
217
1002
  });
218
- useEffect(function () {
1003
+ useEffect(() => {
219
1004
  var _a;
220
- (_a = forwardedRef === null || forwardedRef === void 0 ? void 0 : forwardedRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(cursorRef.current.cursorPos, cursorRef.current.cursorPos);
1005
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.setSelection(cursorRef.current.cursorPos, cursorRef.current.cursorPos);
221
1006
  cursorRef.current = {
222
1007
  cursorPos: cursorRef.current.cursorPos,
223
1008
  operation: CURSOR_OPERATION.NONE,
224
1009
  };
225
1010
  }, [value]);
226
- var onFieldChange = function (e) {
227
- onChange(removeNonNumerals(removeSpace(e.target.value)), e);
228
- var selectionStart = e.target.selectionStart || 0;
1011
+ const handleChange = (e) => {
1012
+ onChange === null || onChange === void 0 ? void 0 : onChange(e);
1013
+ let selectionStart = e.target.selectionStart || 0;
229
1014
  switch (cursorRef.current.operation) {
230
1015
  case CURSOR_OPERATION.SUBSTRACT: {
231
1016
  --selectionStart;
@@ -240,243 +1025,68 @@ var CardField = forwardRef(function (_a, forwardedRef) {
240
1025
  cursorPos: selectionStart,
241
1026
  operation: CURSOR_OPERATION.NONE,
242
1027
  };
243
- setTimeout(function () {
244
- var _a;
245
- (_a = forwardedRef === null || forwardedRef === void 0 ? void 0 : forwardedRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(cursorRef.current.cursorPos, cursorRef.current.cursorPos);
246
- }, 0);
247
1028
  };
248
- var onKeyDown = function (e) {
249
- var _a;
250
- var oldValues = removeNonNumerals(removeSpace(e.target.value));
251
- var cursorOpration = {
252
- cursorPos: cursorRef.current.cursorPos,
253
- operation: CURSOR_OPERATION.NONE,
254
- };
255
- switch (e.code) {
256
- case 'Backspace': {
257
- cursorOpration.operation = CURSOR_OPERATION.NONE;
258
- break;
259
- }
260
- case 'Space': {
261
- cursorOpration.operation = CURSOR_OPERATION.SUBSTRACT;
262
- break;
263
- }
264
- default: {
265
- if (oldValues.length % gap === 0) {
266
- cursorOpration.operation = CURSOR_OPERATION.ADD;
267
- }
268
- }
269
- }
270
- cursorRef.current = cursorOpration;
271
- (_a = rest === null || rest === void 0 ? void 0 : rest.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(rest, e);
272
- };
273
- return (jsx(Field, __assign({}, rest, { type: FieldType.TEXT, ref: forwardedRef, onChange: onFieldChange, onKeyDown: onKeyDown, value: addSpaceAtInterval(value, gap) })));
1029
+ return (jsx(Field, Object.assign({ ref: mergedRef, onChange: handleChange }, rest, { type: FieldType.NUMBER, value: value, inputMode: 'numeric' })));
274
1030
  });
1031
+ CardField.displayName = 'CardField';
275
1032
 
276
- var PhoneFieldPrefix = forwardRef(function (_a, forwardedRef) {
277
- var countryCode = _a.countryCode, _b = _a.disabled, disabled = _b === void 0 ? false : _b, flagIcon = _a.flagIcon, onDropdownClick = _a.onDropdownClick, showDropdownIcon = _a.showDropdownIcon;
278
- var theme = useTheme();
279
- var onClick = function () {
280
- if (disabled)
281
- return;
282
- onDropdownClick === null || onDropdownClick === void 0 ? void 0 : onDropdownClick();
283
- };
284
- return (jsxs(Box, __assign({ boxSize: 'micro', horizontal: true, css: {
285
- alignItems: 'center',
286
- justifyContent: 'center',
287
- cursor: disabled ? 'not-allowed' : 'pointer',
288
- paddingLeft: '16px',
289
- }, onClick: onClick, ref: forwardedRef }, { children: [flagIcon && (jsx(Container, __assign({ display: 'flex', alignItems: 'center', justifyContent: 'center', height: theme.size[6], width: theme.size[6] }, { children: flagIcon }))), jsx(Typography, __assign({ css: { minWidth: 'fit-content' }, variant: 'B1', color: disabled ? 'disabled' : 'primary', isClickable: true }, { children: countryCode })), showDropdownIcon && jsx(DownChevron, { color: disabled ? theme.color.text.disabled : theme.color.text.primary }), jsx(Divider, { width: '1px', height: '24px', css: { borderBottom: "24px ".concat(theme.color.background.disabledDark, " solid") } })] })));
1033
+ const InputField = forwardRef((props, forwardedRef) => {
1034
+ if (props.fieldType === 'phone') {
1035
+ return jsx(PhoneField, Object.assign({}, props, { ref: forwardedRef }));
1036
+ }
1037
+ if (props.fieldType === 'otp') {
1038
+ return jsx(OtpField, Object.assign({}, props));
1039
+ }
1040
+ if (props.fieldType === 'card') {
1041
+ return jsx(CardField, Object.assign({}, props, { ref: forwardedRef }));
1042
+ }
1043
+ return jsx(Field, Object.assign({}, props, { ref: forwardedRef }));
290
1044
  });
1045
+ InputField.displayName = 'InputField';
291
1046
 
292
- var PhoneField = forwardRef(function (_a, forwardedRef) {
293
- var max = _a.max, flagIcon = _a.flagIcon, countryCode = _a.countryCode, showDropdownIcon = _a.showDropdownIcon, onChange = _a.onChange, onDropdownClick = _a.onDropdownClick, disabled = _a.disabled, rest = __rest(_a, ["max", "flagIcon", "countryCode", "showDropdownIcon", "onChange", "onDropdownClick", "disabled"]);
294
- var theme = useTheme$1();
295
- var _b = useState(0), prefixWidth = _b[0], setPrefixWidth = _b[1];
296
- var onFieldChange = function (event) {
297
- var value = event.target.value;
298
- var isValidValue = value ? new RegExp(ONLY_NUMERIC).test(value) : true;
299
- if (value.length <= max && isValidValue) {
300
- onChange(event);
301
- }
302
- };
303
- var calculatePrefixWidth = useCallback(function (node) {
304
- var _a;
305
- if (node) {
306
- setPrefixWidth(((_a = node.getBoundingClientRect().width) !== null && _a !== void 0 ? _a : 0) + 16);
307
- }
308
- }, [countryCode, flagIcon]);
309
- var customPlaceHolderStyling = {
310
- marginLeft: prefixWidth,
1047
+ const staticStyles$1 = makeStyles((theme) => {
1048
+ return {
1049
+ root: {
1050
+ display: 'flex',
1051
+ alignItems: 'center',
1052
+ justifyContent: 'center',
1053
+ marginLeft: theme.spacing[4],
1054
+ width: theme.size[6],
1055
+ height: theme.size[6],
1056
+ },
311
1057
  };
312
- return (jsx(Field, __assign({}, rest, { type: FieldType.PHONE, ref: forwardedRef, onChange: onFieldChange, disabled: disabled, prefix: jsx(PhoneFieldPrefix, { flagIcon: flagIcon, countryCode: countryCode, showDropdownIcon: showDropdownIcon, onDropdownClick: onDropdownClick, disabled: disabled, ref: calculatePrefixWidth }), inputMode: 'numeric', styleConfig: {
313
- field: {
314
- css: {
315
- paddingTop: 'unset',
316
- paddingBottom: 'unset',
317
- paddingLeft: theme.spacing[4],
318
- },
319
- },
320
- placeholderLabel: {
321
- css: __assign({}, customPlaceHolderStyling),
322
- },
323
- } })));
324
1058
  });
325
-
326
- var FieldIcon = function (_a) {
327
- var icon = _a.icon, onClick = _a.onClick, focus = _a.focus, focusedIcon = _a.focusedIcon, css = _a.css;
328
- var theme = useTheme();
329
- var iconPrefix = icon;
330
- if (focus && focusedIcon) {
331
- iconPrefix = focusedIcon;
1059
+ const FieldIcon = ({ icon, onClick, focus, focusedIcon, styleConfig }) => {
1060
+ const { root: customRootStyles = [] } = styleConfig || {};
1061
+ if (!isValidElement(icon))
1062
+ return jsx(Fragment, {});
1063
+ let IconPrefix = icon;
1064
+ if (focus && isValidElement(focusedIcon)) {
1065
+ IconPrefix = focusedIcon;
332
1066
  }
333
- var showIconWithoutPointer = !onClick;
334
- var iconStyles = showIconWithoutPointer ? { pointerEvents: 'none' } : { cursor: 'pointer' };
335
- return (jsx(Container, __assign({ height: theme.size[6], width: theme.size[6], display: 'flex', alignItems: 'center', justifyContent: 'center', onClick: onClick, css: __assign(__assign({ position: 'absolute' }, iconStyles), css), marginLeft: theme.spacing[4] }, { children: iconPrefix })));
1067
+ const handleClick = () => {
1068
+ onClick === null || onClick === void 0 ? void 0 : onClick();
1069
+ };
1070
+ return (jsx(Container, { styleConfig: { root: [staticStyles$1.root, ...customRootStyles] }, onClick: handleClick, children: IconPrefix }));
336
1071
  };
337
1072
 
338
- var FieldAction = function (_a) {
339
- var _b = _a.actionsList, actionsList = _b === void 0 ? [] : _b;
340
- return (jsx(Box, __assign({ boxSize: 'tiny', horizontal: true, css: { paddingRight: '16px' } }, { children: actionsList.map(function (actionItem) {
341
- var _a = actionItem || {}, label = _a.label, color = _a.color, onClick = _a.onClick, isDisabled = _a.isDisabled, isLoading = _a.isLoading;
1073
+ const staticStyles = makeStyles((theme) => ({
1074
+ root: {
1075
+ paddingRight: theme.spacing[4],
1076
+ },
1077
+ }));
1078
+ const FieldAction = ({ actionsList = [] }) => {
1079
+ return (jsx(Box, { boxSize: 'tiny', horizontal: true, styleConfig: { root: [staticStyles.root] }, children: actionsList.map((actionItem) => {
1080
+ const { label, color, onClick, isDisabled, isLoading } = actionItem || {};
342
1081
  if (isLoading) {
343
- return jsx(DottedLoader, {});
1082
+ return jsx(DottedLoader, {}, 'fieldAction');
344
1083
  }
345
- return (jsx(Typography, __assign({ variant: 'HM4', color: isDisabled ? TypographyColor.DISABLED : color, onClick: !isDisabled ? onClick : function () { }, isClickable: true, isDisabled: isDisabled }, { children: label })));
346
- }) })));
1084
+ return (jsx(Typography, { variant: 'HM4', color: isDisabled ? TypographyColor.DISABLED : color, onClick: !isDisabled
1085
+ ? onClick
1086
+ : () => {
1087
+ }, isClickable: true, isDisabled: isDisabled, children: label }, 'fieldAction'));
1088
+ }) }));
347
1089
  };
348
1090
 
349
- var SingleOTPField = forwardRef(function (_a, forwardedRef) {
350
- var _b = _a.isLoading, isLoading = _b === void 0 ? false : _b, otpBoxCss = _a.otpBoxCss, rest = __rest(_a, ["isLoading", "otpBoxCss"]);
351
- var theme = useTheme();
352
- var loadingStyles = isLoading
353
- ? {
354
- backgroundColor: 'unset',
355
- }
356
- : {};
357
- var OTP_FIELD_TEXT_STYLING = __assign(__assign({}, getTypographyStyles({ theme: theme, variant: TypographyVariant.HM1 })), { letterSpacing: ' -0.25px', textAlign: 'center', padding: theme.spacing[3] });
358
- return (jsx(Field, __assign({ ref: forwardedRef, disabled: isLoading, styleConfig: {
359
- field: {
360
- css: __assign(__assign(__assign({}, otpBoxCss), OTP_FIELD_TEXT_STYLING), loadingStyles),
361
- },
362
- fieldContainer: {
363
- css: __assign({}, loadingStyles),
364
- },
365
- } }, rest)));
366
- });
367
-
368
- var BoxCount;
369
- (function (BoxCount) {
370
- BoxCount[BoxCount["SM"] = 4] = "SM";
371
- BoxCount[BoxCount["MD"] = 6] = "MD";
372
- })(BoxCount || (BoxCount = {}));
373
-
374
- var _a;
375
- var SPACEBAR = KEYBOARD_KEY_CODE.SPACEBAR, LEFT_ARROW = KEYBOARD_KEY_CODE.LEFT_ARROW, RIGHT_ARROW = KEYBOARD_KEY_CODE.RIGHT_ARROW;
376
- var boxStyling = (_a = {},
377
- _a[BoxCount.MD] = { width: '48px' },
378
- _a[BoxCount.SM] = { width: '56px' },
379
- _a);
380
- var OTPField = forwardRef(function (_a, forwardedRef) {
381
- var _b = _a.boxCount, boxCount = _b === void 0 ? BoxCount.MD : _b, onChanged = _a.onChanged, onSubmit = _a.onSubmit, onResend = _a.onResend, _c = _a.isLoading, isLoading = _c === void 0 ? false : _c, _d = _a.message, message = _d === void 0 ? '' : _d, _e = _a.hasError, hasError = _e === void 0 ? false : _e, _f = _a.showCountDown, showCountDown = _f === void 0 ? true : _f, _g = _a.initialCountDownTime, initialCountDownTime = _g === void 0 ? 30 : _g;
382
- var theme = useTheme();
383
- var otpInputsArr = Array.from(Array(boxCount), function (_, index) { return index; });
384
- var _h = useState(initialCountDownTime), countDown = _h[0], setCountDown = _h[1];
385
- var _j = useState(showCountDown), startCounter = _j[0], setStartCounter = _j[1];
386
- var _k = useState([]), otpValue = _k[0], setOtpValue = _k[1];
387
- var refs = useRef(new Array(boxCount));
388
- var messageIcon = !hasError && message ? jsx(CheckCircle, {}) : null;
389
- useEffect(function () {
390
- var _a;
391
- (_a = refs.current) === null || _a === void 0 ? void 0 : _a[0].focus();
392
- var timerId;
393
- if (showCountDown && startCounter) {
394
- timerId = setInterval(function () {
395
- setCountDown(function (prev) {
396
- var updatedValue = --prev;
397
- if (updatedValue === 0) {
398
- clearInterval(timerId);
399
- setStartCounter(false);
400
- }
401
- return updatedValue;
402
- });
403
- }, 1000);
404
- }
405
- return function () {
406
- timerId && clearInterval(timerId);
407
- };
408
- }, [startCounter]);
409
- useEffect(function () {
410
- var val = otpValue.join('');
411
- if (val.length === boxCount) {
412
- onSubmit(val);
413
- }
414
- }, [otpValue]);
415
- var onFieldChange = function (index) { return function (event) {
416
- var _a, _b, _c, _d;
417
- var value = event.target.value;
418
- if (value.length) {
419
- (_b = (_a = refs.current) === null || _a === void 0 ? void 0 : _a[index + 1]) === null || _b === void 0 ? void 0 : _b.focus();
420
- }
421
- else {
422
- (_d = (_c = refs.current) === null || _c === void 0 ? void 0 : _c[index - 1]) === null || _d === void 0 ? void 0 : _d.focus();
423
- }
424
- var updatedOtp = __spreadArray([], otpValue, true);
425
- updatedOtp[index] = value;
426
- setOtpValue(updatedOtp);
427
- onChanged === null || onChanged === void 0 ? void 0 : onChanged(event, value);
428
- }; };
429
- var onPasteOTP = function (index) { return function (e) {
430
- e.preventDefault();
431
- var paste = e.clipboardData.getData('text').split('').slice(0, otpInputsArr.length);
432
- if (!ONLY_NUMERIC.test(paste.join(''))) {
433
- return;
434
- }
435
- var focusIndex = Math.min(index + paste.length, otpInputsArr.length - 1);
436
- setOtpValue(paste);
437
- refs.current[focusIndex].focus();
438
- }; };
439
- var handleOnKeyDown = function (index) { return function (e) {
440
- var _a, _b;
441
- if (e.keyCode === LEFT_ARROW) {
442
- e.preventDefault();
443
- (_a = refs.current) === null || _a === void 0 ? void 0 : _a[index - 1].focus();
444
- }
445
- else if (e.keyCode === RIGHT_ARROW) {
446
- e.preventDefault();
447
- (_b = refs.current) === null || _b === void 0 ? void 0 : _b[index + 1].focus();
448
- }
449
- else if (e.keyCode === SPACEBAR || e.key === ' ' || e.key === 'Spacebar' || e.key === 'Space') {
450
- e.preventDefault();
451
- }
452
- }; };
453
- var onResendHandler = function () {
454
- onResend === null || onResend === void 0 ? void 0 : onResend();
455
- setStartCounter(true);
456
- setCountDown(initialCountDownTime);
457
- };
458
- return (jsxs(Fragment, { children: [jsxs(Container, __assign({ ref: forwardedRef, position: 'relative', width: 'fit-content' }, { children: [jsx(Box, __assign({ boxSize: 'micro', horizontal: true }, { children: otpInputsArr.map(function (otp, i) {
459
- return (jsx(SingleOTPField, { type: FieldType.NUMBER, ref: function (el) { return (refs.current[i] = el); }, onChange: onFieldChange(i), onKeyDown: handleOnKeyDown(i), onPaste: onPasteOTP(i), value: otpValue === null || otpValue === void 0 ? void 0 : otpValue[i], prompt: { hasError: hasError }, otpBoxCss: __assign({ height: '56px' }, boxStyling[boxCount]), maxLength: 1, isLoading: isLoading }, 'otp_Input_' + otp));
460
- }) })), isLoading && (jsx(Card, __assign({ shadowDirection: CardBorderDirection.BOTTOM, shadowVariant: CardShadowVariant.E3, css: {
461
- position: 'absolute',
462
- height: '34px',
463
- width: '66px',
464
- padding: theme.spacing[3],
465
- borderRadius: theme.spacing[8],
466
- top: '50%',
467
- left: '50%',
468
- transform: 'translate(-50%, -50%)',
469
- } }, { children: jsx(DottedLoader, {}) })))] })), (messageIcon || message) && (jsxs(Box, __assign({ boxSize: 'pico', horizontal: true, css: {
470
- paddingTop: theme.spacing[2],
471
- alignItems: 'center',
472
- } }, { children: [messageIcon && (jsx(Container, __assign({ css: {
473
- height: theme.size[4],
474
- width: theme.size[4],
475
- display: 'flex',
476
- justifyContent: 'center',
477
- alignItems: 'center',
478
- } }, { children: messageIcon }))), message && (jsx(Typography, __assign({ variant: 'B3', color: hasError ? 'warning' : 'success' }, { children: message })))] }))), showCountDown && (jsxs(Typography, __assign({ className: 'mt-3 flex', variant: 'B2' }, { children: ["Haven\u2019t received OTP yet?", jsxs(Typography, __assign({ variant: 'B2', className: 'ml-1', color: countDown ? 'disabled' : 'link', onClick: !countDown ? onResendHandler : undefined, isClickable: !countDown }, { children: [' ', "Resend ", !!countDown && "(".concat(countDown, "s)")] }))] })))] }));
479
- });
480
-
481
- export { BoxCount, CURSOR_OPERATION, CardField, FieldAction, FieldIcon, FieldType, Field as FieldV2, FieldVariant, OTPField, PhoneField, PhoneFieldPrefix };
1091
+ export { FieldAction, FieldIcon, FieldType, FieldVariant, InputField, InputFieldCore as TextArea };
482
1092
  //# sourceMappingURL=ct-design-field.esm.js.map