@cleartrip/ct-design-field 5.6.0 → 5.7.0-SNAPSHOT-native-main.2
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/dist/Field.d.ts.map +1 -1
- package/dist/Field.native.d.ts +6 -0
- package/dist/Field.native.d.ts.map +1 -0
- package/dist/Input.d.ts.map +1 -1
- package/dist/Label.d.ts.map +1 -1
- package/dist/TextAreaInput.d.ts.map +1 -1
- package/dist/ct-design-field.browser.cjs.js +3 -3
- package/dist/ct-design-field.browser.cjs.js.map +1 -1
- package/dist/ct-design-field.browser.esm.js +3 -3
- package/dist/ct-design-field.browser.esm.js.map +1 -1
- package/dist/ct-design-field.cjs.js +79 -94
- package/dist/ct-design-field.cjs.js.map +1 -1
- package/dist/ct-design-field.esm.js +79 -94
- package/dist/ct-design-field.esm.js.map +1 -1
- package/dist/ct-design-field.umd.js +82 -97
- package/dist/ct-design-field.umd.js.map +1 -1
- package/dist/style.d.ts +0 -10
- package/dist/style.d.ts.map +1 -1
- package/dist/variants/Phone/index.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/Field.native.tsx +204 -0
- package/src/Field.tsx +19 -4
- package/src/Input.tsx +36 -39
- package/src/Label.tsx +30 -13
- package/src/TextAreaInput.tsx +27 -27
- package/src/style.ts +7 -3
- package/src/variants/Phone/Prefix/index.tsx +7 -7
- package/src/variants/Phone/index.tsx +6 -19
package/dist/style.d.ts
CHANGED
|
@@ -18,10 +18,6 @@ export declare const getFieldContainerBorderStyle: ({ theme, hasError, focus, di
|
|
|
18
18
|
borderStyle: string;
|
|
19
19
|
borderColor: string;
|
|
20
20
|
borderWidth: 1.5;
|
|
21
|
-
} | {
|
|
22
|
-
borderStyle: string;
|
|
23
|
-
borderColor: string;
|
|
24
|
-
borderWidth: 1;
|
|
25
21
|
};
|
|
26
22
|
export declare const getFieldSpacingAndHeight: ({ isLabeledPlaceholder, theme, variant, focus, value, disabledPlaceHolder, customSpacingTop, }: Omit<IFieldContainerStylesParams, "hasError">) => {
|
|
27
23
|
height: 40;
|
|
@@ -40,12 +36,6 @@ export declare const getFieldContainerStyles: ({ hasError, theme, focus, disable
|
|
|
40
36
|
borderStyle: string;
|
|
41
37
|
borderColor: string;
|
|
42
38
|
borderWidth: 1.5;
|
|
43
|
-
} | {
|
|
44
|
-
backgroundColor: string;
|
|
45
|
-
height: 40 | 56;
|
|
46
|
-
borderStyle: string;
|
|
47
|
-
borderColor: string;
|
|
48
|
-
borderWidth: 1;
|
|
49
39
|
};
|
|
50
40
|
export declare const getFieldPlaceholderStyles: ({ isFocused, variant, fieldType, }: {
|
|
51
41
|
theme: Theme;
|
package/dist/style.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Field/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAqB,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3F,UAAU,2BAA2B;IACnC,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,eAAO,MAAM,4BAA4B,GAAI,uCAK1C,IAAI,CAAC,2BAA2B,EAAE,SAAS,GAAG,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Field/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAqB,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3F,UAAU,2BAA2B;IACnC,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,eAAO,MAAM,4BAA4B,GAAI,uCAK1C,IAAI,CAAC,2BAA2B,EAAE,SAAS,GAAG,OAAO,CAAC;;;;CAYxD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,gGAQtC,IAAI,CAAC,2BAA2B,EAAE,UAAU,CAAC;;;;;;;;;;CAyC/C,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,yEAQrC,2BAA2B;;;;;;CAuB7B,CAAC;AAGF,eAAO,MAAM,yBAAyB,GAAI,oCAIvC;IACD,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;IAC3B,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;;;;;;;;;;;CAcA,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,iHAU5B;IACD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;IAC3B,IAAI,EAAE,GAAG,SAAS,EAAE,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;;;;;;;;;;;;;;CAkBA,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,OAAO,KAAK,EAAE,SAAS,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuKhF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/components/Field/src/variants/Phone/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAoB,SAAS,EAAE,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/components/Field/src/variants/Phone/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAoB,SAAS,EAAE,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAoBrC,QAAA,MAAM,UAAU,mGAuCf,CAAC;AAGF,eAAe,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleartrip/ct-design-field",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0-SNAPSHOT-native-main.2",
|
|
4
4
|
"description": "Field Component",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "./dist/ct-design-field.cjs.js",
|
|
@@ -26,23 +26,23 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@emotion/react": "^11.14.0",
|
|
28
28
|
"@emotion/styled": "^11.14.0",
|
|
29
|
-
"@cleartrip/ct-design-theme": "5.
|
|
30
|
-
"@cleartrip/ct-design-typography": "5.
|
|
31
|
-
"@cleartrip/ct-design-container": "5.
|
|
32
|
-
"@cleartrip/ct-design-
|
|
33
|
-
"@cleartrip/ct-design-
|
|
34
|
-
"@cleartrip/ct-design-outside-click-handler": "5.
|
|
35
|
-
"@cleartrip/ct-design-common-utils": "5.
|
|
36
|
-
"@cleartrip/ct-design-
|
|
37
|
-
"@cleartrip/ct-design-
|
|
38
|
-
"@cleartrip/ct-design-card": "5.
|
|
39
|
-
"@cleartrip/ct-design-
|
|
40
|
-
"@cleartrip/ct-design-style-manager": "5.
|
|
41
|
-
"@cleartrip/ct-design-use-merge-refs": "5.
|
|
29
|
+
"@cleartrip/ct-design-theme": "5.7.0-SNAPSHOT-native-main.2",
|
|
30
|
+
"@cleartrip/ct-design-typography": "5.7.0-SNAPSHOT-native-main.2",
|
|
31
|
+
"@cleartrip/ct-design-container": "5.7.0-SNAPSHOT-native-main.2",
|
|
32
|
+
"@cleartrip/ct-design-types": "5.7.0-SNAPSHOT-native-main.2",
|
|
33
|
+
"@cleartrip/ct-design-box": "5.7.0-SNAPSHOT-native-main.2",
|
|
34
|
+
"@cleartrip/ct-design-outside-click-handler": "5.7.0-SNAPSHOT-native-main.2",
|
|
35
|
+
"@cleartrip/ct-design-common-utils": "5.7.0-SNAPSHOT-native-main.2",
|
|
36
|
+
"@cleartrip/ct-design-common-constants": "5.7.0-SNAPSHOT-native-main.1",
|
|
37
|
+
"@cleartrip/ct-design-divider": "5.7.0-SNAPSHOT-native-main.2",
|
|
38
|
+
"@cleartrip/ct-design-card": "5.7.0-SNAPSHOT-native-main.2",
|
|
39
|
+
"@cleartrip/ct-design-dotted-loader": "5.7.0-SNAPSHOT-native-main.2",
|
|
40
|
+
"@cleartrip/ct-design-style-manager": "5.7.0-SNAPSHOT-native-main.2",
|
|
41
|
+
"@cleartrip/ct-design-use-merge-refs": "5.7.0-SNAPSHOT-native-main.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@emotion/babel-plugin": "^11.12.0",
|
|
45
|
-
"@cleartrip/ct-design-icons": "
|
|
45
|
+
"@cleartrip/ct-design-icons": "41.0.0-SNAPSHOT-native-main.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": ">=16.8.0",
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { cloneElement, forwardRef, isValidElement, useState } from 'react';
|
|
2
|
+
import { IFieldProps, IFieldRef } from './type';
|
|
3
|
+
import { Box } from '@cleartrip/ct-design-box';
|
|
4
|
+
import { makeStyles, useStyles } from '@cleartrip/ct-design-style-manager';
|
|
5
|
+
import { Container } from '@cleartrip/ct-design-container';
|
|
6
|
+
import { Typography } from '@cleartrip/ct-design-typography';
|
|
7
|
+
import InputFieldCore from './Input';
|
|
8
|
+
import FieldLabelWrapper from './Label';
|
|
9
|
+
import { getFieldContainerStyles } from './style';
|
|
10
|
+
import TextArea from './TextAreaInput';
|
|
11
|
+
|
|
12
|
+
const staticStyles = makeStyles((theme) => {
|
|
13
|
+
return {
|
|
14
|
+
fieldWrapper: {
|
|
15
|
+
flex: 1,
|
|
16
|
+
flexShrink: 1,
|
|
17
|
+
display: 'flex',
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
justifyContent: 'center',
|
|
20
|
+
position: 'relative',
|
|
21
|
+
height: '100%',
|
|
22
|
+
},
|
|
23
|
+
promptBox: {
|
|
24
|
+
paddingLeft: theme.spacing[4],
|
|
25
|
+
paddingRight: theme.spacing[4],
|
|
26
|
+
display: 'flex',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
},
|
|
29
|
+
promptIcon: {
|
|
30
|
+
height: theme.size[4],
|
|
31
|
+
width: theme.size[4],
|
|
32
|
+
paddingRight: theme.spacing[1],
|
|
33
|
+
display: 'flex',
|
|
34
|
+
justifyContent: 'center',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
},
|
|
37
|
+
flexNoShrink: {
|
|
38
|
+
flexShrink: 0,
|
|
39
|
+
},
|
|
40
|
+
fieldContainer: {
|
|
41
|
+
position: 'relative',
|
|
42
|
+
display: 'flex',
|
|
43
|
+
alignItems: 'center',
|
|
44
|
+
justifyContent: 'center',
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
borderStyle: theme?.border.style.solid,
|
|
47
|
+
borderRadius: theme?.border.radius[8],
|
|
48
|
+
boxSizing: 'border-box',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const Field = forwardRef<IFieldRef, IFieldProps & { numberOfLines?: number }>(
|
|
54
|
+
(
|
|
55
|
+
{
|
|
56
|
+
prefix,
|
|
57
|
+
onBlur,
|
|
58
|
+
onFocus,
|
|
59
|
+
onChange,
|
|
60
|
+
onKeyDown,
|
|
61
|
+
onPressIn,
|
|
62
|
+
onSelect,
|
|
63
|
+
value,
|
|
64
|
+
autoCapitalize,
|
|
65
|
+
autoFocus = false,
|
|
66
|
+
disabled,
|
|
67
|
+
inputMode,
|
|
68
|
+
placeholder,
|
|
69
|
+
prefixGap: _prefixGap,
|
|
70
|
+
prompt,
|
|
71
|
+
readOnly,
|
|
72
|
+
placeholderType = 'default',
|
|
73
|
+
suffix,
|
|
74
|
+
suffixGap: _suffixGap,
|
|
75
|
+
type,
|
|
76
|
+
variant,
|
|
77
|
+
styleConfig = {},
|
|
78
|
+
fieldTypographyVariant,
|
|
79
|
+
id,
|
|
80
|
+
maxLength,
|
|
81
|
+
numberOfLines,
|
|
82
|
+
showSoftInputOnFocus,
|
|
83
|
+
customSpacingTop,
|
|
84
|
+
cursorColor,
|
|
85
|
+
},
|
|
86
|
+
ref,
|
|
87
|
+
) => {
|
|
88
|
+
const [focus, setFocus] = useState<boolean>(autoFocus);
|
|
89
|
+
const _isFocused = focus || value.length > 0;
|
|
90
|
+
|
|
91
|
+
const { promptStyles } = styleConfig || {};
|
|
92
|
+
const { Icon: promptIcon, message: promptMessage, hasError = false } = prompt || {};
|
|
93
|
+
const fieldContainerStyles = useStyles(
|
|
94
|
+
(theme) => ({
|
|
95
|
+
root: getFieldContainerStyles({
|
|
96
|
+
variant: variant ?? 'md',
|
|
97
|
+
theme,
|
|
98
|
+
hasError,
|
|
99
|
+
focus,
|
|
100
|
+
value,
|
|
101
|
+
disabled,
|
|
102
|
+
}),
|
|
103
|
+
}),
|
|
104
|
+
[variant, hasError, focus, value, disabled, styleConfig],
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const InputField = numberOfLines && numberOfLines > 1 ? TextArea : InputFieldCore;
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Box boxSize='micro' styleConfig={styleConfig}>
|
|
111
|
+
<Container
|
|
112
|
+
styleConfig={{
|
|
113
|
+
root: [fieldContainerStyles.root, staticStyles.fieldContainer, ...(styleConfig.fieldContainer || [])],
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
{isValidElement(prefix) && (
|
|
117
|
+
<Container styleConfig={{ root: [staticStyles.flexNoShrink] }}>{cloneElement(prefix, { focus })}</Container>
|
|
118
|
+
)}
|
|
119
|
+
<Container styleConfig={{ root: [staticStyles.fieldWrapper, ...(styleConfig.field || [])] }}>
|
|
120
|
+
<FieldLabelWrapper
|
|
121
|
+
id={id}
|
|
122
|
+
variant={variant}
|
|
123
|
+
type={type}
|
|
124
|
+
value={value}
|
|
125
|
+
focus={_isFocused}
|
|
126
|
+
placeholder={placeholder}
|
|
127
|
+
placeholderType={placeholderType}
|
|
128
|
+
disabled={disabled}
|
|
129
|
+
styleConfig={styleConfig}
|
|
130
|
+
prefix={prefix}
|
|
131
|
+
/>
|
|
132
|
+
<InputField
|
|
133
|
+
id={id}
|
|
134
|
+
ref={ref}
|
|
135
|
+
value={value}
|
|
136
|
+
disabled={disabled}
|
|
137
|
+
placeholder={placeholder}
|
|
138
|
+
placeholderType={placeholderType}
|
|
139
|
+
autoFocus={autoFocus}
|
|
140
|
+
readOnly={readOnly}
|
|
141
|
+
type={type}
|
|
142
|
+
inputMode={inputMode}
|
|
143
|
+
autoCapitalize={autoCapitalize}
|
|
144
|
+
fieldTypographyVariant={fieldTypographyVariant}
|
|
145
|
+
styleConfig={styleConfig}
|
|
146
|
+
focus={_isFocused}
|
|
147
|
+
prefix={prefix}
|
|
148
|
+
cursorColor={cursorColor}
|
|
149
|
+
onChange={onChange}
|
|
150
|
+
onSelect={onSelect}
|
|
151
|
+
onPressIn={onPressIn}
|
|
152
|
+
onFocus={(e) => {
|
|
153
|
+
setFocus(true);
|
|
154
|
+
onFocus?.(e);
|
|
155
|
+
}}
|
|
156
|
+
onBlur={(e) => {
|
|
157
|
+
setFocus(false);
|
|
158
|
+
onBlur?.(e);
|
|
159
|
+
}}
|
|
160
|
+
onKeyDown={onKeyDown}
|
|
161
|
+
maxLength={maxLength}
|
|
162
|
+
numberOfLines={numberOfLines}
|
|
163
|
+
showSoftInputOnFocus={showSoftInputOnFocus}
|
|
164
|
+
customSpacingTop={customSpacingTop}
|
|
165
|
+
/>
|
|
166
|
+
</Container>
|
|
167
|
+
{isValidElement(suffix) && (
|
|
168
|
+
<Container styleConfig={{ root: [staticStyles.flexNoShrink] }}>{cloneElement(suffix, { focus })}</Container>
|
|
169
|
+
)}
|
|
170
|
+
</Container>
|
|
171
|
+
{(promptIcon || promptMessage) && (
|
|
172
|
+
<Box
|
|
173
|
+
boxSize='pico'
|
|
174
|
+
horizontal={true}
|
|
175
|
+
styleConfig={{
|
|
176
|
+
root: [staticStyles.promptBox, ...(promptStyles?.promptBox || [])],
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
{promptIcon && (
|
|
180
|
+
<Container
|
|
181
|
+
styleConfig={{ root: [staticStyles.promptIcon, ...(promptStyles?.promptIconContainer || [])] }}
|
|
182
|
+
>
|
|
183
|
+
{promptIcon}
|
|
184
|
+
</Container>
|
|
185
|
+
)}
|
|
186
|
+
{promptMessage && (
|
|
187
|
+
<Typography
|
|
188
|
+
variant='B3'
|
|
189
|
+
color={hasError ? 'warning' : 'success'}
|
|
190
|
+
styleConfig={promptStyles?.promptMessageTypography}
|
|
191
|
+
>
|
|
192
|
+
{promptMessage}
|
|
193
|
+
</Typography>
|
|
194
|
+
)}
|
|
195
|
+
</Box>
|
|
196
|
+
)}
|
|
197
|
+
</Box>
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
Field.displayName = 'Field';
|
|
203
|
+
|
|
204
|
+
export default Field;
|
package/src/Field.tsx
CHANGED
|
@@ -15,10 +15,11 @@ const staticStyles = makeStyles((theme) => {
|
|
|
15
15
|
flex: 1,
|
|
16
16
|
flexShrink: 1,
|
|
17
17
|
display: 'flex',
|
|
18
|
-
alignItems: '
|
|
18
|
+
alignItems: 'stretch',
|
|
19
19
|
justifyContent: 'center',
|
|
20
20
|
position: 'relative',
|
|
21
21
|
height: '100%',
|
|
22
|
+
minHeight: 0,
|
|
22
23
|
},
|
|
23
24
|
promptBox: {
|
|
24
25
|
paddingLeft: theme.spacing[4],
|
|
@@ -34,7 +35,18 @@ const staticStyles = makeStyles((theme) => {
|
|
|
34
35
|
justifyContent: 'center',
|
|
35
36
|
alignItems: 'center',
|
|
36
37
|
},
|
|
37
|
-
|
|
38
|
+
prefixSlot: {
|
|
39
|
+
display: 'flex',
|
|
40
|
+
flexDirection: 'row',
|
|
41
|
+
alignItems: 'stretch',
|
|
42
|
+
alignSelf: 'stretch',
|
|
43
|
+
flexShrink: 0,
|
|
44
|
+
},
|
|
45
|
+
suffixSlot: {
|
|
46
|
+
display: 'flex',
|
|
47
|
+
flexDirection: 'row',
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
alignSelf: 'stretch',
|
|
38
50
|
flexShrink: 0,
|
|
39
51
|
},
|
|
40
52
|
fieldContainer: {
|
|
@@ -81,6 +93,7 @@ const Field = forwardRef<IFieldRef, IFieldProps & { numberOfLines?: number }>(
|
|
|
81
93
|
numberOfLines,
|
|
82
94
|
showSoftInputOnFocus,
|
|
83
95
|
customSpacingTop,
|
|
96
|
+
cursorColor,
|
|
84
97
|
},
|
|
85
98
|
ref,
|
|
86
99
|
) => {
|
|
@@ -113,7 +126,7 @@ const Field = forwardRef<IFieldRef, IFieldProps & { numberOfLines?: number }>(
|
|
|
113
126
|
}}
|
|
114
127
|
>
|
|
115
128
|
{isValidElement(prefix) && (
|
|
116
|
-
<Container styleConfig={{ root: [staticStyles.
|
|
129
|
+
<Container styleConfig={{ root: [staticStyles.prefixSlot] }}>{cloneElement(prefix, { focus })}</Container>
|
|
117
130
|
)}
|
|
118
131
|
<Container styleConfig={{ root: [staticStyles.fieldWrapper, ...(styleConfig.field || [])] }}>
|
|
119
132
|
<FieldLabelWrapper
|
|
@@ -143,6 +156,8 @@ const Field = forwardRef<IFieldRef, IFieldProps & { numberOfLines?: number }>(
|
|
|
143
156
|
fieldTypographyVariant={fieldTypographyVariant}
|
|
144
157
|
styleConfig={styleConfig}
|
|
145
158
|
focus={_isFocused}
|
|
159
|
+
prefix={prefix}
|
|
160
|
+
cursorColor={cursorColor}
|
|
146
161
|
onChange={onChange}
|
|
147
162
|
onSelect={onSelect}
|
|
148
163
|
onPressIn={onPressIn}
|
|
@@ -162,7 +177,7 @@ const Field = forwardRef<IFieldRef, IFieldProps & { numberOfLines?: number }>(
|
|
|
162
177
|
/>
|
|
163
178
|
</Container>
|
|
164
179
|
{isValidElement(suffix) && (
|
|
165
|
-
<Container styleConfig={{ root: [staticStyles.
|
|
180
|
+
<Container styleConfig={{ root: [staticStyles.suffixSlot] }}>{cloneElement(suffix, { focus })}</Container>
|
|
166
181
|
)}
|
|
167
182
|
</Container>
|
|
168
183
|
{(promptIcon || promptMessage) && (
|
package/src/Input.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import React, { forwardRef, isValidElement, useCallback, useImperativeHandle, us
|
|
|
2
2
|
import { makeStyles, useStyles } from '@cleartrip/ct-design-style-manager';
|
|
3
3
|
import { css } from '@emotion/css';
|
|
4
4
|
import { useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
5
|
+
import { useTheme } from '@cleartrip/ct-design-theme';
|
|
5
6
|
import { IFieldRef, IFieldProps } from './type';
|
|
6
7
|
import { getFieldStyles, getTypographyVariant } from './style';
|
|
7
8
|
|
|
@@ -11,18 +12,13 @@ const styles = css`
|
|
|
11
12
|
outline: none;
|
|
12
13
|
}
|
|
13
14
|
`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
fontWeight: theme.typography.weight.medium,
|
|
22
|
-
lineHeight: theme.typography.lineHeight[24],
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
});
|
|
15
|
+
|
|
16
|
+
const staticStyles = makeStyles(() => ({
|
|
17
|
+
root: {
|
|
18
|
+
border: 'none',
|
|
19
|
+
outline: 'none',
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
26
22
|
|
|
27
23
|
const InputFieldCore = forwardRef<IFieldRef, IFieldProps & { focus: boolean; numberOfLines?: number }>(
|
|
28
24
|
(
|
|
@@ -44,25 +40,21 @@ const InputFieldCore = forwardRef<IFieldRef, IFieldProps & { focus: boolean; num
|
|
|
44
40
|
autoCapitalize,
|
|
45
41
|
fieldTypographyVariant,
|
|
46
42
|
variant,
|
|
47
|
-
prefix,
|
|
48
43
|
focus,
|
|
49
44
|
placeholderType,
|
|
45
|
+
prefix,
|
|
46
|
+
cursorColor,
|
|
50
47
|
id,
|
|
51
48
|
maxLength,
|
|
52
49
|
},
|
|
53
50
|
forwardedRef,
|
|
54
51
|
) => {
|
|
52
|
+
const theme = useTheme();
|
|
55
53
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
56
|
-
const { field = [] } = styleConfig ?? {};
|
|
54
|
+
const { field = [], root = [] } = styleConfig ?? {};
|
|
57
55
|
const isPrefixComponent = isValidElement(prefix);
|
|
58
56
|
const disabledPlaceHolder = !placeholder?.length;
|
|
59
|
-
|
|
60
|
-
const dynamicStyles = useStyles(
|
|
61
|
-
(theme) => ({
|
|
62
|
-
root: getTypographyVariant(theme, fieldTypographyVariant ?? 'HM2'),
|
|
63
|
-
}),
|
|
64
|
-
[fieldTypographyVariant],
|
|
65
|
-
);
|
|
57
|
+
const inputPlaceholder = placeholderType === 'labeled' && focus ? '' : placeholder;
|
|
66
58
|
|
|
67
59
|
const fieldStyles = useStyles(
|
|
68
60
|
(theme) => {
|
|
@@ -83,9 +75,16 @@ const InputFieldCore = forwardRef<IFieldRef, IFieldProps & { focus: boolean; num
|
|
|
83
75
|
[disabled, variant, focus, value, type, isPrefixComponent, disabledPlaceHolder],
|
|
84
76
|
);
|
|
85
77
|
|
|
78
|
+
const typographyStyles = useStyles(
|
|
79
|
+
(theme) => ({
|
|
80
|
+
root: fieldTypographyVariant ? getTypographyVariant(theme, fieldTypographyVariant) : {},
|
|
81
|
+
}),
|
|
82
|
+
[fieldTypographyVariant],
|
|
83
|
+
);
|
|
84
|
+
|
|
86
85
|
const mergedStyles = useWebMergeStyles(
|
|
87
|
-
[staticStyles.root,
|
|
88
|
-
[fieldStyles.root,
|
|
86
|
+
[staticStyles.root, styles, fieldStyles.root, typographyStyles.root, ...root, ...field],
|
|
87
|
+
[fieldStyles.root, typographyStyles.root, root, field],
|
|
89
88
|
);
|
|
90
89
|
|
|
91
90
|
useImperativeHandle(
|
|
@@ -116,6 +115,7 @@ const InputFieldCore = forwardRef<IFieldRef, IFieldProps & { focus: boolean; num
|
|
|
116
115
|
inputRef.current?.setSelectionRange(start, end);
|
|
117
116
|
},
|
|
118
117
|
},
|
|
118
|
+
preventDefault: () => event.preventDefault(),
|
|
119
119
|
});
|
|
120
120
|
},
|
|
121
121
|
[onChange],
|
|
@@ -209,21 +209,6 @@ const InputFieldCore = forwardRef<IFieldRef, IFieldProps & { focus: boolean; num
|
|
|
209
209
|
[onPressIn],
|
|
210
210
|
);
|
|
211
211
|
|
|
212
|
-
const webProps = {
|
|
213
|
-
onChange: handleOnChange,
|
|
214
|
-
onFocus: handleOnFocus,
|
|
215
|
-
onBlur: handleOnBlur,
|
|
216
|
-
onKeyDown: handleOnKeyDown,
|
|
217
|
-
onSelect: handleOnSelect,
|
|
218
|
-
onMouseDown: handleOnPressIn,
|
|
219
|
-
placeholder,
|
|
220
|
-
autoFocus,
|
|
221
|
-
readOnly,
|
|
222
|
-
type,
|
|
223
|
-
inputMode,
|
|
224
|
-
autoCapitalize,
|
|
225
|
-
};
|
|
226
|
-
|
|
227
212
|
return (
|
|
228
213
|
<input
|
|
229
214
|
maxLength={maxLength}
|
|
@@ -231,8 +216,20 @@ const InputFieldCore = forwardRef<IFieldRef, IFieldProps & { focus: boolean; num
|
|
|
231
216
|
ref={inputRef}
|
|
232
217
|
value={value}
|
|
233
218
|
disabled={disabled}
|
|
219
|
+
readOnly={readOnly}
|
|
234
220
|
className={mergedStyles}
|
|
235
|
-
{
|
|
221
|
+
style={{ caretColor: cursorColor || theme.color.text.primary }}
|
|
222
|
+
onChange={handleOnChange}
|
|
223
|
+
onFocus={handleOnFocus}
|
|
224
|
+
onBlur={handleOnBlur}
|
|
225
|
+
onKeyDown={handleOnKeyDown}
|
|
226
|
+
onSelect={handleOnSelect}
|
|
227
|
+
onMouseDown={handleOnPressIn}
|
|
228
|
+
placeholder={inputPlaceholder}
|
|
229
|
+
autoFocus={autoFocus}
|
|
230
|
+
type={type}
|
|
231
|
+
inputMode={inputMode}
|
|
232
|
+
autoCapitalize={autoCapitalize}
|
|
236
233
|
/>
|
|
237
234
|
);
|
|
238
235
|
},
|
package/src/Label.tsx
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
|
+
import { isValidElement } from 'react';
|
|
1
2
|
import { makeStyles, useStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
2
3
|
import { IFieldProps } from './type';
|
|
3
4
|
import { FieldType, FieldVariant } from './constants';
|
|
4
5
|
import { getFieldPlaceholderStyles } from './style';
|
|
5
|
-
import { Container } from '@cleartrip/ct-design-container';
|
|
6
6
|
import { Typography } from '@cleartrip/ct-design-typography';
|
|
7
|
-
import { isValidElement } from 'react';
|
|
8
7
|
|
|
9
8
|
const staticStyles = makeStyles((theme) => {
|
|
10
9
|
return {
|
|
11
10
|
root: {
|
|
12
11
|
position: 'absolute',
|
|
13
12
|
paddingLeft: theme.spacing[4],
|
|
13
|
+
paddingRight: theme.spacing[4],
|
|
14
14
|
width: '100%',
|
|
15
15
|
height: '100%',
|
|
16
16
|
display: 'flex',
|
|
17
|
-
transform: [{ translateY: 0 }],
|
|
18
17
|
top: 16,
|
|
18
|
+
pointerEvents: 'none',
|
|
19
|
+
boxSizing: 'border-box',
|
|
20
|
+
},
|
|
21
|
+
rootSM: {
|
|
22
|
+
top: 8,
|
|
19
23
|
},
|
|
20
24
|
};
|
|
21
25
|
});
|
|
22
26
|
|
|
27
|
+
/** Web label overlay — behavior matches `Label.native.tsx`. */
|
|
23
28
|
const FieldLabelWrapper: React.FC<
|
|
24
|
-
Omit<IFieldProps, 'onChange' | 'onSelect' | 'onPressIn' | 'onKeyDown' | 'onFocus' | 'onBlur'> & {
|
|
29
|
+
Omit<IFieldProps, 'onChange' | 'onSelect' | 'onPressIn' | 'onKeyDown' | 'onFocus' | 'onBlur'> & {
|
|
30
|
+
focus: boolean;
|
|
31
|
+
}
|
|
25
32
|
> = ({
|
|
26
33
|
variant,
|
|
27
34
|
type,
|
|
@@ -39,6 +46,7 @@ const FieldLabelWrapper: React.FC<
|
|
|
39
46
|
|
|
40
47
|
const shiftPlaceholder = placeholderType === 'floating';
|
|
41
48
|
const isPrefixComponent = isValidElement(prefix);
|
|
49
|
+
const fieldType = type ?? FieldType.TEXT;
|
|
42
50
|
|
|
43
51
|
const baseStyles = useStyles(
|
|
44
52
|
(theme) => ({
|
|
@@ -47,37 +55,46 @@ const FieldLabelWrapper: React.FC<
|
|
|
47
55
|
isFocused: focus,
|
|
48
56
|
disabled,
|
|
49
57
|
variant: variant ?? 'md',
|
|
50
|
-
fieldType
|
|
58
|
+
fieldType,
|
|
51
59
|
isPrefixComponent,
|
|
52
60
|
shiftPlaceholder,
|
|
53
61
|
}),
|
|
54
62
|
}),
|
|
55
63
|
[focus, disabled, variant, type, isPrefixComponent, shiftPlaceholder],
|
|
56
64
|
);
|
|
57
|
-
|
|
58
65
|
const labelStyles = useWebMergeStyles(
|
|
59
|
-
[
|
|
60
|
-
|
|
66
|
+
[
|
|
67
|
+
staticStyles.root,
|
|
68
|
+
variant === FieldVariant.SM ? staticStyles.rootSM : undefined,
|
|
69
|
+
baseStyles.root,
|
|
70
|
+
...placeholderLabel,
|
|
71
|
+
],
|
|
72
|
+
[variant, baseStyles.root, placeholderLabel],
|
|
61
73
|
);
|
|
62
74
|
|
|
63
75
|
if (placeholderType === 'default' || !focus) {
|
|
64
76
|
return null;
|
|
65
77
|
}
|
|
78
|
+
|
|
66
79
|
if (variant === FieldVariant.SM) {
|
|
67
|
-
if (value.length)
|
|
80
|
+
if (value.length) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
68
83
|
|
|
69
84
|
return (
|
|
70
|
-
<
|
|
85
|
+
<label className={labelStyles} htmlFor={id}>
|
|
71
86
|
<Typography variant='B2' color='tertiary' styleConfig={placeholderTypography}>
|
|
72
87
|
{placeholder}
|
|
73
88
|
</Typography>
|
|
74
|
-
</
|
|
89
|
+
</label>
|
|
75
90
|
);
|
|
76
91
|
}
|
|
77
92
|
|
|
78
|
-
if (
|
|
93
|
+
if (fieldType === FieldType.PHONE && value.length) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
79
96
|
|
|
80
|
-
const typographyVariant =
|
|
97
|
+
const typographyVariant = fieldType === FieldType.PHONE ? 'B1' : focus ? 'B3' : 'B1';
|
|
81
98
|
|
|
82
99
|
return (
|
|
83
100
|
<label className={labelStyles} htmlFor={id}>
|