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