@dt-dds/react-text-field 1.0.0-beta.49
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/CHANGELOG.md +536 -0
- package/LICENSE.md +21 -0
- package/README.md +85 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +451 -0
- package/dist/index.mjs +413 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BaseProps, Theme } from '@dt-dds/react-core';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode, ComponentPropsWithoutRef, RefObject } from 'react';
|
|
5
|
+
import * as _emotion_styled from '@emotion/styled';
|
|
6
|
+
import * as _emotion_react from '@emotion/react';
|
|
7
|
+
|
|
8
|
+
type TextFieldVariant = 'outlined' | 'bottom-line';
|
|
9
|
+
type TextFieldBackgroundFill = 'default' | 'contrast' | 'light';
|
|
10
|
+
|
|
11
|
+
interface ExtraComponent {
|
|
12
|
+
onClick?: (text: string) => void;
|
|
13
|
+
component: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
interface TextFieldProps extends ComponentPropsWithoutRef<'input'>, BaseProps {
|
|
16
|
+
label: string;
|
|
17
|
+
isFloatingLabel?: boolean;
|
|
18
|
+
extraPrefix?: ExtraComponent;
|
|
19
|
+
extraSuffix?: ExtraComponent;
|
|
20
|
+
hasError?: boolean;
|
|
21
|
+
requiredMessage?: string;
|
|
22
|
+
initialValue?: string;
|
|
23
|
+
inputRef?: RefObject<HTMLInputElement>;
|
|
24
|
+
message?: string;
|
|
25
|
+
variant?: TextFieldVariant;
|
|
26
|
+
backgroundFill?: TextFieldBackgroundFill;
|
|
27
|
+
onResetInput?: () => void;
|
|
28
|
+
}
|
|
29
|
+
declare const TextField: ({ hasError, extraPrefix, extraSuffix, label, isFloatingLabel, name, id, required, requiredMessage, style, children, initialValue, inputRef, message: messageProp, type, variant, backgroundFill, disabled, onChange, onResetInput, ...rest }: TextFieldProps) => react_jsx_runtime.JSX.Element;
|
|
30
|
+
|
|
31
|
+
interface InputFieldStyledProps {
|
|
32
|
+
isFloatingLabel: boolean;
|
|
33
|
+
isSearchType: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface InputWrapperStyledProps {
|
|
36
|
+
isFloatingLabel: boolean;
|
|
37
|
+
variant: TextFieldVariant;
|
|
38
|
+
backgroundFill: TextFieldBackgroundFill;
|
|
39
|
+
hasError: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare const TextFieldStyled: _emotion_styled.StyledComponent<{
|
|
42
|
+
theme?: _emotion_react.Theme | undefined;
|
|
43
|
+
as?: react.ElementType<any, keyof react.JSX.IntrinsicElements> | undefined;
|
|
44
|
+
} & {
|
|
45
|
+
isFloatingLabel?: boolean | undefined;
|
|
46
|
+
hasPrefix?: boolean | undefined;
|
|
47
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
48
|
+
declare const InputFieldStyled: _emotion_styled.StyledComponent<{
|
|
49
|
+
theme?: _emotion_react.Theme | undefined;
|
|
50
|
+
as?: react.ElementType<any, keyof react.JSX.IntrinsicElements> | undefined;
|
|
51
|
+
} & InputFieldStyledProps, react.DetailedHTMLProps<react.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, {}>;
|
|
52
|
+
declare const InputExtraPrefixStyled: _emotion_styled.StyledComponent<{
|
|
53
|
+
theme?: _emotion_react.Theme | undefined;
|
|
54
|
+
as?: react.ElementType<any, keyof react.JSX.IntrinsicElements> | undefined;
|
|
55
|
+
} & {
|
|
56
|
+
isClickable?: boolean | undefined;
|
|
57
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
58
|
+
declare const InputExtraSuffixStyled: _emotion_styled.StyledComponent<{
|
|
59
|
+
theme?: _emotion_react.Theme | undefined;
|
|
60
|
+
as?: react.ElementType<any, keyof react.JSX.IntrinsicElements> | undefined;
|
|
61
|
+
} & {
|
|
62
|
+
isClickable?: boolean | undefined;
|
|
63
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
64
|
+
declare const TextFieldMessageStyled: _emotion_styled.StyledComponent<{
|
|
65
|
+
theme?: _emotion_react.Theme | undefined;
|
|
66
|
+
as?: react.ElementType<any, keyof react.JSX.IntrinsicElements> | undefined;
|
|
67
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
68
|
+
declare const ResetInputIconStyled: _emotion_styled.StyledComponent<{
|
|
69
|
+
theme?: _emotion_react.Theme | undefined;
|
|
70
|
+
as?: react.ElementType<any, keyof react.JSX.IntrinsicElements> | undefined;
|
|
71
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
72
|
+
declare const InputWrapperStyled: _emotion_styled.StyledComponent<{
|
|
73
|
+
theme?: _emotion_react.Theme | undefined;
|
|
74
|
+
as?: react.ElementType<any, keyof react.JSX.IntrinsicElements> | undefined;
|
|
75
|
+
} & InputWrapperStyledProps, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
76
|
+
|
|
77
|
+
declare module '@emotion/react' {
|
|
78
|
+
interface Theme extends Theme {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { ExtraComponent, InputExtraPrefixStyled, InputExtraSuffixStyled, InputFieldStyled, InputFieldStyledProps, InputWrapperStyled, InputWrapperStyledProps, ResetInputIconStyled, TextField, TextFieldMessageStyled, TextFieldProps, TextFieldStyled };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
|
|
59
|
+
// index.ts
|
|
60
|
+
var text_field_exports = {};
|
|
61
|
+
__export(text_field_exports, {
|
|
62
|
+
InputExtraPrefixStyled: () => InputExtraPrefixStyled,
|
|
63
|
+
InputExtraSuffixStyled: () => InputExtraSuffixStyled,
|
|
64
|
+
InputFieldStyled: () => InputFieldStyled,
|
|
65
|
+
InputWrapperStyled: () => InputWrapperStyled,
|
|
66
|
+
ResetInputIconStyled: () => ResetInputIconStyled,
|
|
67
|
+
TextField: () => TextField,
|
|
68
|
+
TextFieldMessageStyled: () => TextFieldMessageStyled,
|
|
69
|
+
TextFieldStyled: () => TextFieldStyled
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(text_field_exports);
|
|
72
|
+
|
|
73
|
+
// src/TextField.tsx
|
|
74
|
+
var import_react_icon = require("@dt-dds/react-icon");
|
|
75
|
+
var import_react_icon_button = require("@dt-dds/react-icon-button");
|
|
76
|
+
var import_react_label_field = require("@dt-dds/react-label-field");
|
|
77
|
+
var import_react_typography = require("@dt-dds/react-typography");
|
|
78
|
+
var import_react = require("react");
|
|
79
|
+
|
|
80
|
+
// src/TextField.styled.ts
|
|
81
|
+
var import_styled = __toESM(require("@emotion/styled"));
|
|
82
|
+
|
|
83
|
+
// src/constants/helpers.ts
|
|
84
|
+
var getThemedBackgroundFill = (backgroundFill, theme) => ({
|
|
85
|
+
default: theme.palette.surface.default,
|
|
86
|
+
contrast: theme.palette.surface.contrast,
|
|
87
|
+
light: theme.palette.surface.light
|
|
88
|
+
})[backgroundFill] || theme.palette.surface.default;
|
|
89
|
+
|
|
90
|
+
// src/TextField.styled.ts
|
|
91
|
+
var TextFieldStyled = import_styled.default.div`
|
|
92
|
+
${({ theme, isFloatingLabel = true, hasPrefix = false }) => `
|
|
93
|
+
display: flex;
|
|
94
|
+
flex-direction: column;
|
|
95
|
+
gap: ${theme.spacing["5xs"]};
|
|
96
|
+
width: 100%;
|
|
97
|
+
position: relative;
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
${hasPrefix ? `
|
|
101
|
+
label {
|
|
102
|
+
left: 0;
|
|
103
|
+
padding-left: ${isFloatingLabel ? theme.spacing.l : ""};
|
|
104
|
+
}
|
|
105
|
+
` : ""}
|
|
106
|
+
|
|
107
|
+
i {
|
|
108
|
+
color: ${theme.palette.content.medium};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
:has(input[disabled]) {
|
|
112
|
+
i, label > span {
|
|
113
|
+
color: ${theme.palette.content.light};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
:has(input[readonly]:not(input[disabled])) {
|
|
118
|
+
label, label > span {
|
|
119
|
+
color: ${isFloatingLabel ? theme.palette.content.medium : theme.palette.content.default};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
`}
|
|
123
|
+
|
|
124
|
+
input[type="search"]::-webkit-search-decoration,
|
|
125
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
126
|
+
input[type="search"]::-webkit-search-results-button,
|
|
127
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
128
|
+
display: none;
|
|
129
|
+
}
|
|
130
|
+
`;
|
|
131
|
+
var InputFieldStyled = import_styled.default.input`
|
|
132
|
+
${({ theme, isFloatingLabel, isSearchType }) => `
|
|
133
|
+
${theme.fontStyles.body2}
|
|
134
|
+
border: 0;
|
|
135
|
+
outline: 0;
|
|
136
|
+
width: 100%;
|
|
137
|
+
background-color: inherit;
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
input:-webkit-autofill,
|
|
142
|
+
input:-webkit-autofill:hover,
|
|
143
|
+
input:-webkit-autofill:focus,
|
|
144
|
+
input:-webkit-autofill:active {
|
|
145
|
+
transition: background-color 5000s ease-in-out 0s;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
&::placeholder {
|
|
149
|
+
color: ${isFloatingLabel ? "transparent" : theme.palette.content.medium};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
padding: ${isFloatingLabel && !isSearchType ? `${theme.spacing.xs} 0 ${theme.spacing["4xs"]} 0` : ""};
|
|
153
|
+
|
|
154
|
+
`}
|
|
155
|
+
`;
|
|
156
|
+
var InputExtraPrefixStyled = import_styled.default.div`
|
|
157
|
+
${({ theme, onClick }) => {
|
|
158
|
+
const isClickable = !!onClick;
|
|
159
|
+
return `
|
|
160
|
+
display: flex;
|
|
161
|
+
cursor: ${isClickable ? "pointer" : "default"};
|
|
162
|
+
|
|
163
|
+
${isClickable && `
|
|
164
|
+
&:hover > i {
|
|
165
|
+
color: ${theme.palette.content.dark};
|
|
166
|
+
}
|
|
167
|
+
`}
|
|
168
|
+
|
|
169
|
+
`;
|
|
170
|
+
}}
|
|
171
|
+
`;
|
|
172
|
+
var InputExtraSuffixStyled = import_styled.default.div`
|
|
173
|
+
${({ theme, onClick }) => {
|
|
174
|
+
const isClickable = !!onClick;
|
|
175
|
+
return `
|
|
176
|
+
display: flex;
|
|
177
|
+
cursor: ${isClickable ? "pointer" : "default"};
|
|
178
|
+
|
|
179
|
+
${isClickable && `
|
|
180
|
+
&:hover > i {
|
|
181
|
+
color: ${theme.palette.content.dark};
|
|
182
|
+
}
|
|
183
|
+
`}
|
|
184
|
+
`;
|
|
185
|
+
}}
|
|
186
|
+
`;
|
|
187
|
+
var TextFieldMessageStyled = import_styled.default.div`
|
|
188
|
+
padding-left: ${({ theme }) => theme.spacing["2xs"]};
|
|
189
|
+
`;
|
|
190
|
+
var ResetInputIconStyled = import_styled.default.div`
|
|
191
|
+
${({ theme }) => `
|
|
192
|
+
cursor: pointer;
|
|
193
|
+
display: flex;
|
|
194
|
+
|
|
195
|
+
:hover > i {
|
|
196
|
+
color: ${theme.palette.content.dark}
|
|
197
|
+
}
|
|
198
|
+
`}
|
|
199
|
+
`;
|
|
200
|
+
var InputWrapperStyled = import_styled.default.div`
|
|
201
|
+
${({ theme, isFloatingLabel, variant, backgroundFill, hasError }) => {
|
|
202
|
+
const borderColor = hasError ? theme.palette.error.default : theme.palette.border.medium;
|
|
203
|
+
const borderFocusColor = hasError ? theme.palette.error.default : theme.palette.border.dark;
|
|
204
|
+
return `
|
|
205
|
+
display:flex;
|
|
206
|
+
flex-direction: row;
|
|
207
|
+
align-items: center;
|
|
208
|
+
min-width: 198px;
|
|
209
|
+
width: 100%;
|
|
210
|
+
height: 54px;
|
|
211
|
+
color: ${theme.palette.content.default};
|
|
212
|
+
gap: ${theme.spacing["4xs"]};
|
|
213
|
+
background-color: ${getThemedBackgroundFill(backgroundFill, theme)};
|
|
214
|
+
|
|
215
|
+
padding-inline: ${theme.spacing["3xs"]};
|
|
216
|
+
|
|
217
|
+
${variant === "outlined" ? `border-radius: ${theme.shape.formField};
|
|
218
|
+
border: 1px solid ${borderColor};
|
|
219
|
+
&:focus-within, &:hover { { border: 1px solid ${borderFocusColor}};
|
|
220
|
+
` : `border-radius: ${theme.shape.formField} ${theme.shape.formField} 0 0;
|
|
221
|
+
border-bottom: 1px solid ${borderColor};
|
|
222
|
+
&:focus-within, &:hover { { border-bottom: 1px solid ${borderFocusColor}};
|
|
223
|
+
`};
|
|
224
|
+
|
|
225
|
+
&:has(input[readonly]:not([disabled])) {
|
|
226
|
+
background-color: ${theme.palette.surface.default};
|
|
227
|
+
color: ${theme.palette.content.medium};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
&:has(input[disabled]), &:has(input[disabled]) > * {
|
|
231
|
+
color: ${theme.palette.content.light};
|
|
232
|
+
background-color: ${theme.palette.surface.light};
|
|
233
|
+
border-color: ${theme.palette.border.default};
|
|
234
|
+
cursor: not-allowed;
|
|
235
|
+
|
|
236
|
+
input::placeholder {
|
|
237
|
+
color: ${isFloatingLabel ? "transparent" : theme.palette.content.light};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
`;
|
|
241
|
+
}}
|
|
242
|
+
`;
|
|
243
|
+
|
|
244
|
+
// src/TextField.tsx
|
|
245
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
246
|
+
var TextField = (_a) => {
|
|
247
|
+
var _b = _a, {
|
|
248
|
+
hasError = false,
|
|
249
|
+
extraPrefix,
|
|
250
|
+
extraSuffix,
|
|
251
|
+
label,
|
|
252
|
+
isFloatingLabel = true,
|
|
253
|
+
name,
|
|
254
|
+
id,
|
|
255
|
+
required,
|
|
256
|
+
requiredMessage,
|
|
257
|
+
style,
|
|
258
|
+
children,
|
|
259
|
+
initialValue,
|
|
260
|
+
inputRef,
|
|
261
|
+
message: messageProp = "",
|
|
262
|
+
type = "text",
|
|
263
|
+
variant = "outlined",
|
|
264
|
+
backgroundFill = "default",
|
|
265
|
+
disabled = false,
|
|
266
|
+
onChange = () => null,
|
|
267
|
+
onResetInput = () => null
|
|
268
|
+
} = _b, rest = __objRest(_b, [
|
|
269
|
+
"hasError",
|
|
270
|
+
"extraPrefix",
|
|
271
|
+
"extraSuffix",
|
|
272
|
+
"label",
|
|
273
|
+
"isFloatingLabel",
|
|
274
|
+
"name",
|
|
275
|
+
"id",
|
|
276
|
+
"required",
|
|
277
|
+
"requiredMessage",
|
|
278
|
+
"style",
|
|
279
|
+
"children",
|
|
280
|
+
"initialValue",
|
|
281
|
+
"inputRef",
|
|
282
|
+
"message",
|
|
283
|
+
"type",
|
|
284
|
+
"variant",
|
|
285
|
+
"backgroundFill",
|
|
286
|
+
"disabled",
|
|
287
|
+
"onChange",
|
|
288
|
+
"onResetInput"
|
|
289
|
+
]);
|
|
290
|
+
const [activeInput, setActiveInput] = (0, import_react.useState)(false);
|
|
291
|
+
const [inputValue, setInputValue] = (0, import_react.useState)("");
|
|
292
|
+
const [hasRequiredError, setHasRequiredError] = (0, import_react.useState)(false);
|
|
293
|
+
const textFieldId = id != null ? id : label.replaceAll(" ", "-").toLowerCase();
|
|
294
|
+
(0, import_react.useEffect)(() => {
|
|
295
|
+
if (!!initialValue) {
|
|
296
|
+
setInputValue(initialValue);
|
|
297
|
+
setHasRequiredError(false);
|
|
298
|
+
} else {
|
|
299
|
+
setInputValue("");
|
|
300
|
+
}
|
|
301
|
+
}, [initialValue]);
|
|
302
|
+
const handleChange = (event) => {
|
|
303
|
+
setInputValue(event.target.value);
|
|
304
|
+
setHasRequiredError(false);
|
|
305
|
+
if (onChange) {
|
|
306
|
+
onChange(event);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const onFocus = (event) => {
|
|
310
|
+
if (!rest.readOnly) {
|
|
311
|
+
setActiveInput(true);
|
|
312
|
+
}
|
|
313
|
+
if (rest.onFocus) {
|
|
314
|
+
rest.onFocus(event);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
const onBlur = (event) => {
|
|
318
|
+
const isEmptyOrOnlySpaces = event.currentTarget.value.trim().length === 0;
|
|
319
|
+
if (isEmptyOrOnlySpaces) {
|
|
320
|
+
setActiveInput(false);
|
|
321
|
+
if (required && requiredMessage) {
|
|
322
|
+
setHasRequiredError(true);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (rest.onBlur) {
|
|
326
|
+
rest.onBlur(event);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const handleResetInput = () => {
|
|
330
|
+
setInputValue("");
|
|
331
|
+
setActiveInput(false);
|
|
332
|
+
onResetInput();
|
|
333
|
+
};
|
|
334
|
+
const handleResetIconEnter = (event) => event.code === "Enter" && handleResetInput();
|
|
335
|
+
const handleExtraPreffixEnter = (event) => event.code === "Enter" && (extraPrefix == null ? void 0 : extraPrefix.onClick) && extraPrefix.onClick(inputValue);
|
|
336
|
+
const handleExtraSuffixEnter = (event) => event.code === "Enter" && (extraSuffix == null ? void 0 : extraSuffix.onClick) && extraSuffix.onClick(inputValue);
|
|
337
|
+
const messageColor = disabled ? "content.light" : "content.medium";
|
|
338
|
+
const showError = hasError || hasRequiredError;
|
|
339
|
+
const message = hasRequiredError ? requiredMessage != null ? requiredMessage : messageProp : messageProp;
|
|
340
|
+
const isActiveInput = activeInput || !!inputValue.trim();
|
|
341
|
+
const isSearchType = type === "search";
|
|
342
|
+
const extraPreffixOnClick = (extraPrefix == null ? void 0 : extraPrefix.onClick) ? extraPrefix.onClick : null;
|
|
343
|
+
const extraSuffixOnClick = (extraSuffix == null ? void 0 : extraSuffix.onClick) ? extraSuffix.onClick : null;
|
|
344
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
345
|
+
TextFieldStyled,
|
|
346
|
+
{
|
|
347
|
+
hasPrefix: !!extraPrefix,
|
|
348
|
+
isFloatingLabel,
|
|
349
|
+
style,
|
|
350
|
+
children: [
|
|
351
|
+
!isActiveInput || !isFloatingLabel || !isSearchType ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
352
|
+
import_react_label_field.LabelField,
|
|
353
|
+
{
|
|
354
|
+
hasError: showError,
|
|
355
|
+
htmlFor: textFieldId,
|
|
356
|
+
isActive: isActiveInput || type === "date",
|
|
357
|
+
isDisabled: disabled,
|
|
358
|
+
isFloating: isFloatingLabel,
|
|
359
|
+
isRequired: required,
|
|
360
|
+
children: label
|
|
361
|
+
}
|
|
362
|
+
) : null,
|
|
363
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
364
|
+
InputWrapperStyled,
|
|
365
|
+
{
|
|
366
|
+
backgroundFill,
|
|
367
|
+
"data-testid": "input-wrapper",
|
|
368
|
+
hasError: showError,
|
|
369
|
+
isFloatingLabel,
|
|
370
|
+
variant,
|
|
371
|
+
children: [
|
|
372
|
+
(extraPrefix == null ? void 0 : extraPrefix.component) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
373
|
+
InputExtraPrefixStyled,
|
|
374
|
+
__spreadProps(__spreadValues({
|
|
375
|
+
"data-testid": "extra-preffix"
|
|
376
|
+
}, !!extraPreffixOnClick && {
|
|
377
|
+
tabIndex: 0,
|
|
378
|
+
onClick: () => extraPreffixOnClick(inputValue),
|
|
379
|
+
onKeyDown: handleExtraPreffixEnter
|
|
380
|
+
}), {
|
|
381
|
+
children: extraPrefix.component
|
|
382
|
+
})
|
|
383
|
+
) : null,
|
|
384
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
385
|
+
InputFieldStyled,
|
|
386
|
+
__spreadProps(__spreadValues({
|
|
387
|
+
"data-error": showError,
|
|
388
|
+
"data-testid": "input-field",
|
|
389
|
+
disabled,
|
|
390
|
+
id: textFieldId,
|
|
391
|
+
isFloatingLabel,
|
|
392
|
+
isSearchType,
|
|
393
|
+
name: name != null ? name : textFieldId,
|
|
394
|
+
ref: inputRef,
|
|
395
|
+
type,
|
|
396
|
+
value: inputValue
|
|
397
|
+
}, rest), {
|
|
398
|
+
onBlur,
|
|
399
|
+
onChange: handleChange,
|
|
400
|
+
onFocus
|
|
401
|
+
})
|
|
402
|
+
),
|
|
403
|
+
isSearchType && !!inputValue ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
404
|
+
ResetInputIconStyled,
|
|
405
|
+
{
|
|
406
|
+
"data-testid": "reset-icon",
|
|
407
|
+
onKeyDown: handleResetIconEnter,
|
|
408
|
+
tabIndex: 0,
|
|
409
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon_button.IconButton, { onClick: handleResetInput, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon.Icon, { code: "close_small" }) })
|
|
410
|
+
}
|
|
411
|
+
) : null,
|
|
412
|
+
(extraSuffix == null ? void 0 : extraSuffix.component) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
413
|
+
InputExtraSuffixStyled,
|
|
414
|
+
__spreadProps(__spreadValues({
|
|
415
|
+
"data-testid": "extra-suffix"
|
|
416
|
+
}, !!extraSuffixOnClick && {
|
|
417
|
+
tabIndex: 0,
|
|
418
|
+
onClick: () => extraSuffixOnClick(inputValue),
|
|
419
|
+
onKeyDown: handleExtraSuffixEnter
|
|
420
|
+
}), {
|
|
421
|
+
children: extraSuffix.component
|
|
422
|
+
})
|
|
423
|
+
) : null
|
|
424
|
+
]
|
|
425
|
+
}
|
|
426
|
+
),
|
|
427
|
+
message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextFieldMessageStyled, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
428
|
+
import_react_typography.Typography,
|
|
429
|
+
{
|
|
430
|
+
color: showError ? "error.default" : messageColor,
|
|
431
|
+
element: "span",
|
|
432
|
+
fontStyles: "body3",
|
|
433
|
+
children: message
|
|
434
|
+
}
|
|
435
|
+
) }) : null,
|
|
436
|
+
children
|
|
437
|
+
]
|
|
438
|
+
}
|
|
439
|
+
);
|
|
440
|
+
};
|
|
441
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
442
|
+
0 && (module.exports = {
|
|
443
|
+
InputExtraPrefixStyled,
|
|
444
|
+
InputExtraSuffixStyled,
|
|
445
|
+
InputFieldStyled,
|
|
446
|
+
InputWrapperStyled,
|
|
447
|
+
ResetInputIconStyled,
|
|
448
|
+
TextField,
|
|
449
|
+
TextFieldMessageStyled,
|
|
450
|
+
TextFieldStyled
|
|
451
|
+
});
|