@sytechui/input 2.4.33
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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/chunk-6SGLJYRO.mjs +442 -0
- package/dist/chunk-PPYXCOZH.mjs +105 -0
- package/dist/chunk-ZTVVBFTB.mjs +102 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +667 -0
- package/dist/index.mjs +15 -0
- package/dist/input.d.mts +11 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +553 -0
- package/dist/input.mjs +8 -0
- package/dist/textarea.d.mts +44 -0
- package/dist/textarea.d.ts +44 -0
- package/dist/textarea.js +560 -0
- package/dist/textarea.mjs +8 -0
- package/dist/use-input.d.mts +105 -0
- package/dist/use-input.d.ts +105 -0
- package/dist/use-input.js +458 -0
- package/dist/use-input.mjs +7 -0
- package/package.json +65 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { Ref } from 'react';
|
|
3
|
+
import * as _sytechui_system from '@sytechui/system';
|
|
4
|
+
import { HTMLHeroUIProps, PropGetter } from '@sytechui/system';
|
|
5
|
+
import { InputVariantProps, SlotsToClasses, InputSlots } from '@sytechui/theme';
|
|
6
|
+
import { AriaTextFieldProps } from '@react-types/textfield';
|
|
7
|
+
|
|
8
|
+
interface Props<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement> extends Omit<HTMLHeroUIProps<"input">, keyof InputVariantProps> {
|
|
9
|
+
/**
|
|
10
|
+
* Ref to the DOM node.
|
|
11
|
+
*/
|
|
12
|
+
ref?: Ref<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Ref to the container DOM node.
|
|
15
|
+
*/
|
|
16
|
+
baseRef?: Ref<HTMLDivElement>;
|
|
17
|
+
/**
|
|
18
|
+
* Ref to the input wrapper DOM node.
|
|
19
|
+
* This is the element that wraps the input label and the innerWrapper when the labelPlacement="inside"
|
|
20
|
+
* and the input has start/end content.
|
|
21
|
+
*/
|
|
22
|
+
wrapperRef?: Ref<HTMLDivElement>;
|
|
23
|
+
/**
|
|
24
|
+
* Ref to the input inner wrapper DOM node.
|
|
25
|
+
* This is the element that wraps the input and the start/end content when passed.
|
|
26
|
+
*/
|
|
27
|
+
innerWrapperRef?: Ref<HTMLDivElement>;
|
|
28
|
+
/**
|
|
29
|
+
* Element to be rendered in the left side of the input.
|
|
30
|
+
*/
|
|
31
|
+
startContent?: React.ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* Element to be rendered in the right side of the input.
|
|
34
|
+
* if you pass this prop and the `onClear` prop, the passed element
|
|
35
|
+
* will have the clear button props and it will be rendered instead of the
|
|
36
|
+
* default clear button.
|
|
37
|
+
*/
|
|
38
|
+
endContent?: React.ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* Classname or List of classes to change the classNames of the element.
|
|
41
|
+
* if `className` is passed, it will be added to the base slot.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* <Input classNames={{
|
|
46
|
+
* base:"base-classes",
|
|
47
|
+
* label: "label-classes",
|
|
48
|
+
* mainWrapper: "main-wrapper-classes",
|
|
49
|
+
* inputWrapper: "input-wrapper-classes",
|
|
50
|
+
* innerWrapper: "inner-wrapper-classes",
|
|
51
|
+
* input: "input-classes",
|
|
52
|
+
* clearButton: "clear-button-classes",
|
|
53
|
+
* helperWrapper: "helper-wrapper-classes",
|
|
54
|
+
* description: "description-classes",
|
|
55
|
+
* errorMessage: "error-message-classes",
|
|
56
|
+
* }} />
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
classNames?: SlotsToClasses<InputSlots>;
|
|
60
|
+
/**
|
|
61
|
+
* Callback fired when the value is cleared.
|
|
62
|
+
* if you pass this prop, the clear button will be shown.
|
|
63
|
+
*/
|
|
64
|
+
onClear?: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* React aria onChange event.
|
|
67
|
+
*/
|
|
68
|
+
onValueChange?: (value: string) => void;
|
|
69
|
+
}
|
|
70
|
+
type UseInputProps<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement> = Props<T> & Omit<AriaTextFieldProps, "onChange"> & InputVariantProps;
|
|
71
|
+
declare function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement>(originalProps: UseInputProps<T>): {
|
|
72
|
+
Component: _sytechui_system.As<any>;
|
|
73
|
+
classNames: SlotsToClasses<"description" | "base" | "label" | "errorMessage" | "input" | "helperWrapper" | "mainWrapper" | "inputWrapper" | "innerWrapper" | "clearButton"> | undefined;
|
|
74
|
+
domRef: react.RefObject<T>;
|
|
75
|
+
label: react.ReactNode;
|
|
76
|
+
description: react.ReactNode;
|
|
77
|
+
startContent: react.ReactNode;
|
|
78
|
+
endContent: react.ReactNode;
|
|
79
|
+
labelPlacement: "inside" | "outside" | "outside-left" | "outside-top";
|
|
80
|
+
isClearable: boolean | undefined;
|
|
81
|
+
hasHelper: boolean;
|
|
82
|
+
hasStartContent: boolean;
|
|
83
|
+
isLabelOutside: boolean;
|
|
84
|
+
isOutsideLeft: boolean;
|
|
85
|
+
isOutsideTop: boolean;
|
|
86
|
+
isLabelOutsideAsPlaceholder: boolean;
|
|
87
|
+
shouldLabelBeOutside: boolean;
|
|
88
|
+
shouldLabelBeInside: boolean;
|
|
89
|
+
hasPlaceholder: boolean;
|
|
90
|
+
isInvalid: boolean;
|
|
91
|
+
errorMessage: react.ReactNode;
|
|
92
|
+
getBaseProps: PropGetter;
|
|
93
|
+
getLabelProps: PropGetter;
|
|
94
|
+
getInputProps: PropGetter;
|
|
95
|
+
getMainWrapperProps: PropGetter;
|
|
96
|
+
getInputWrapperProps: PropGetter;
|
|
97
|
+
getInnerWrapperProps: PropGetter;
|
|
98
|
+
getHelperWrapperProps: PropGetter;
|
|
99
|
+
getDescriptionProps: PropGetter;
|
|
100
|
+
getErrorMessageProps: PropGetter;
|
|
101
|
+
getClearButtonProps: PropGetter;
|
|
102
|
+
};
|
|
103
|
+
type UseInputReturn = ReturnType<typeof useInput>;
|
|
104
|
+
|
|
105
|
+
export { type Props, type UseInputProps, type UseInputReturn, useInput };
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/use-input.ts
|
|
22
|
+
var use_input_exports = {};
|
|
23
|
+
__export(use_input_exports, {
|
|
24
|
+
useInput: () => useInput
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(use_input_exports);
|
|
27
|
+
var import_system = require("@sytechui/system");
|
|
28
|
+
var import_use_safe_layout_effect = require("@sytechui/use-safe-layout-effect");
|
|
29
|
+
var import_focus = require("@react-aria/focus");
|
|
30
|
+
var import_theme = require("@sytechui/theme");
|
|
31
|
+
var import_react_utils = require("@sytechui/react-utils");
|
|
32
|
+
var import_interactions = require("@react-aria/interactions");
|
|
33
|
+
var import_shared_utils = require("@sytechui/shared-utils");
|
|
34
|
+
var import_utils = require("@react-stately/utils");
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_textfield = require("@react-aria/textfield");
|
|
37
|
+
var import_form = require("@sytechui/form");
|
|
38
|
+
function useInput(originalProps) {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
40
|
+
const globalContext = (0, import_system.useProviderContext)();
|
|
41
|
+
const { validationBehavior: formValidationBehavior } = (0, import_form.useSlottedContext)(import_form.FormContext) || {};
|
|
42
|
+
const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.input.variantKeys);
|
|
43
|
+
const {
|
|
44
|
+
ref,
|
|
45
|
+
as,
|
|
46
|
+
type,
|
|
47
|
+
label,
|
|
48
|
+
baseRef,
|
|
49
|
+
wrapperRef,
|
|
50
|
+
description,
|
|
51
|
+
className,
|
|
52
|
+
classNames,
|
|
53
|
+
autoFocus,
|
|
54
|
+
startContent,
|
|
55
|
+
endContent,
|
|
56
|
+
onClear,
|
|
57
|
+
onChange,
|
|
58
|
+
validationState,
|
|
59
|
+
validationBehavior = (_a = formValidationBehavior != null ? formValidationBehavior : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _a : "native",
|
|
60
|
+
innerWrapperRef: innerWrapperRefProp,
|
|
61
|
+
onValueChange = () => {
|
|
62
|
+
},
|
|
63
|
+
...otherProps
|
|
64
|
+
} = props;
|
|
65
|
+
const handleValueChange = (0, import_react.useCallback)(
|
|
66
|
+
(value) => {
|
|
67
|
+
onValueChange(value != null ? value : "");
|
|
68
|
+
},
|
|
69
|
+
[onValueChange]
|
|
70
|
+
);
|
|
71
|
+
const [isFocusWithin, setFocusWithin] = (0, import_react.useState)(false);
|
|
72
|
+
const Component = as || "div";
|
|
73
|
+
const disableAnimation = (_c = (_b = originalProps.disableAnimation) != null ? _b : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _c : false;
|
|
74
|
+
const domRef = (0, import_react_utils.useDOMRef)(ref);
|
|
75
|
+
const baseDomRef = (0, import_react_utils.useDOMRef)(baseRef);
|
|
76
|
+
const inputWrapperRef = (0, import_react_utils.useDOMRef)(wrapperRef);
|
|
77
|
+
const innerWrapperRef = (0, import_react_utils.useDOMRef)(innerWrapperRefProp);
|
|
78
|
+
const [inputValue, setInputValue] = (0, import_utils.useControlledState)(
|
|
79
|
+
props.value,
|
|
80
|
+
(_d = props.defaultValue) != null ? _d : "",
|
|
81
|
+
handleValueChange
|
|
82
|
+
);
|
|
83
|
+
const isFileTypeInput = type === "file";
|
|
84
|
+
const hasUploadedFiles = ((_g = (_f = (_e = domRef == null ? void 0 : domRef.current) == null ? void 0 : _e.files) == null ? void 0 : _f.length) != null ? _g : 0) > 0;
|
|
85
|
+
const isFilledByDefault = ["date", "time", "month", "week", "range"].includes(type);
|
|
86
|
+
const isFilled = !(0, import_shared_utils.isEmpty)(inputValue) || isFilledByDefault || hasUploadedFiles;
|
|
87
|
+
const isFilledWithin = isFilled || isFocusWithin;
|
|
88
|
+
const isHiddenType = type === "hidden";
|
|
89
|
+
const isMultiline = originalProps.isMultiline;
|
|
90
|
+
const baseStyles = (0, import_theme.cn)(classNames == null ? void 0 : classNames.base, className, isFilled ? "is-filled" : "");
|
|
91
|
+
const handleClear = (0, import_react.useCallback)(() => {
|
|
92
|
+
var _a2;
|
|
93
|
+
if (isFileTypeInput) {
|
|
94
|
+
domRef.current.value = "";
|
|
95
|
+
} else {
|
|
96
|
+
setInputValue("");
|
|
97
|
+
}
|
|
98
|
+
onClear == null ? void 0 : onClear();
|
|
99
|
+
(_a2 = domRef.current) == null ? void 0 : _a2.focus();
|
|
100
|
+
}, [setInputValue, onClear, isFileTypeInput]);
|
|
101
|
+
(0, import_use_safe_layout_effect.useSafeLayoutEffect)(() => {
|
|
102
|
+
if (!domRef.current) return;
|
|
103
|
+
setInputValue(domRef.current.value);
|
|
104
|
+
}, [domRef.current]);
|
|
105
|
+
const {
|
|
106
|
+
labelProps,
|
|
107
|
+
inputProps,
|
|
108
|
+
isInvalid: isAriaInvalid,
|
|
109
|
+
validationErrors,
|
|
110
|
+
validationDetails,
|
|
111
|
+
descriptionProps,
|
|
112
|
+
errorMessageProps
|
|
113
|
+
} = (0, import_textfield.useTextField)(
|
|
114
|
+
{
|
|
115
|
+
...originalProps,
|
|
116
|
+
validationBehavior,
|
|
117
|
+
autoCapitalize: originalProps.autoCapitalize,
|
|
118
|
+
value: inputValue,
|
|
119
|
+
"aria-label": originalProps.label ? originalProps["aria-label"] : (0, import_shared_utils.safeAriaLabel)(originalProps["aria-label"], originalProps.placeholder),
|
|
120
|
+
inputElementType: isMultiline ? "textarea" : "input",
|
|
121
|
+
onChange: setInputValue
|
|
122
|
+
},
|
|
123
|
+
domRef
|
|
124
|
+
);
|
|
125
|
+
if (isFileTypeInput) {
|
|
126
|
+
delete inputProps.value;
|
|
127
|
+
delete inputProps.onChange;
|
|
128
|
+
}
|
|
129
|
+
const { isFocusVisible, isFocused, focusProps } = (0, import_focus.useFocusRing)({
|
|
130
|
+
autoFocus,
|
|
131
|
+
isTextInput: true
|
|
132
|
+
});
|
|
133
|
+
const { isHovered, hoverProps } = (0, import_interactions.useHover)({ isDisabled: !!(originalProps == null ? void 0 : originalProps.isDisabled) });
|
|
134
|
+
const { isHovered: isLabelHovered, hoverProps: labelHoverProps } = (0, import_interactions.useHover)({
|
|
135
|
+
isDisabled: !!(originalProps == null ? void 0 : originalProps.isDisabled)
|
|
136
|
+
});
|
|
137
|
+
const { focusProps: clearFocusProps, isFocusVisible: isClearButtonFocusVisible } = (0, import_focus.useFocusRing)();
|
|
138
|
+
const { focusWithinProps } = (0, import_interactions.useFocusWithin)({
|
|
139
|
+
onFocusWithinChange: setFocusWithin
|
|
140
|
+
});
|
|
141
|
+
const { pressProps: clearPressProps } = (0, import_interactions.usePress)({
|
|
142
|
+
isDisabled: !!(originalProps == null ? void 0 : originalProps.isDisabled) || !!(originalProps == null ? void 0 : originalProps.isReadOnly),
|
|
143
|
+
onPress: handleClear
|
|
144
|
+
});
|
|
145
|
+
const isInvalid = validationState === "invalid" || isAriaInvalid;
|
|
146
|
+
const labelPlacement = (0, import_system.useLabelPlacement)({
|
|
147
|
+
labelPlacement: originalProps.labelPlacement,
|
|
148
|
+
label
|
|
149
|
+
});
|
|
150
|
+
const errorMessage = typeof props.errorMessage === "function" ? props.errorMessage({ isInvalid, validationErrors, validationDetails }) : props.errorMessage || (validationErrors == null ? void 0 : validationErrors.join(" "));
|
|
151
|
+
const isClearable = !!onClear || originalProps.isClearable;
|
|
152
|
+
const hasElements = !!label || !!description || !!errorMessage;
|
|
153
|
+
const hasPlaceholder = !!props.placeholder;
|
|
154
|
+
const hasLabel = !!label;
|
|
155
|
+
const hasHelper = !!description || !!errorMessage;
|
|
156
|
+
const isOutsideLeft = labelPlacement === "outside-left";
|
|
157
|
+
const isOutsideTop = labelPlacement === "outside-top";
|
|
158
|
+
const shouldLabelBeOutside = (
|
|
159
|
+
// label is outside only when some placeholder is there
|
|
160
|
+
labelPlacement === "outside" || // label is outside regardless of placeholder
|
|
161
|
+
isOutsideLeft || isOutsideTop
|
|
162
|
+
);
|
|
163
|
+
const shouldLabelBeInside = labelPlacement === "inside";
|
|
164
|
+
const isPlaceholderShown = domRef.current ? (!domRef.current.value || domRef.current.value === "" || !inputValue || inputValue === "") && hasPlaceholder : false;
|
|
165
|
+
const hasStartContent = !!startContent;
|
|
166
|
+
const isLabelOutside = shouldLabelBeOutside ? isOutsideLeft || isOutsideTop || hasPlaceholder || labelPlacement === "outside" && hasStartContent : false;
|
|
167
|
+
const isLabelOutsideAsPlaceholder = labelPlacement === "outside" && !hasPlaceholder && !hasStartContent;
|
|
168
|
+
const slots = (0, import_react.useMemo)(
|
|
169
|
+
() => (0, import_theme.input)({
|
|
170
|
+
...variantProps,
|
|
171
|
+
isInvalid,
|
|
172
|
+
labelPlacement,
|
|
173
|
+
isClearable,
|
|
174
|
+
disableAnimation
|
|
175
|
+
}),
|
|
176
|
+
[
|
|
177
|
+
(0, import_shared_utils.objectToDeps)(variantProps),
|
|
178
|
+
isInvalid,
|
|
179
|
+
labelPlacement,
|
|
180
|
+
isClearable,
|
|
181
|
+
hasStartContent,
|
|
182
|
+
disableAnimation
|
|
183
|
+
]
|
|
184
|
+
);
|
|
185
|
+
const getBaseProps = (0, import_react.useCallback)(
|
|
186
|
+
(props2 = {}) => {
|
|
187
|
+
return {
|
|
188
|
+
ref: baseDomRef,
|
|
189
|
+
className: slots.base({ class: baseStyles }),
|
|
190
|
+
"data-slot": "base",
|
|
191
|
+
"data-filled": (0, import_shared_utils.dataAttr)(
|
|
192
|
+
isFilled || hasPlaceholder || hasStartContent || isPlaceholderShown || isFileTypeInput
|
|
193
|
+
),
|
|
194
|
+
"data-filled-within": (0, import_shared_utils.dataAttr)(
|
|
195
|
+
isFilledWithin || hasPlaceholder || hasStartContent || isPlaceholderShown || isFileTypeInput
|
|
196
|
+
),
|
|
197
|
+
"data-focus-within": (0, import_shared_utils.dataAttr)(isFocusWithin),
|
|
198
|
+
"data-focus-visible": (0, import_shared_utils.dataAttr)(isFocusVisible),
|
|
199
|
+
"data-readonly": (0, import_shared_utils.dataAttr)(originalProps.isReadOnly),
|
|
200
|
+
"data-focus": (0, import_shared_utils.dataAttr)(isFocused),
|
|
201
|
+
"data-hover": (0, import_shared_utils.dataAttr)(isHovered || isLabelHovered),
|
|
202
|
+
"data-required": (0, import_shared_utils.dataAttr)(originalProps.isRequired),
|
|
203
|
+
"data-invalid": (0, import_shared_utils.dataAttr)(isInvalid),
|
|
204
|
+
"data-disabled": (0, import_shared_utils.dataAttr)(originalProps.isDisabled),
|
|
205
|
+
"data-has-elements": (0, import_shared_utils.dataAttr)(hasElements),
|
|
206
|
+
"data-has-helper": (0, import_shared_utils.dataAttr)(hasHelper),
|
|
207
|
+
"data-has-label": (0, import_shared_utils.dataAttr)(hasLabel),
|
|
208
|
+
"data-has-value": (0, import_shared_utils.dataAttr)(!isPlaceholderShown),
|
|
209
|
+
"data-hidden": (0, import_shared_utils.dataAttr)(isHiddenType),
|
|
210
|
+
...focusWithinProps,
|
|
211
|
+
...props2
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
[
|
|
215
|
+
slots,
|
|
216
|
+
baseStyles,
|
|
217
|
+
isFilled,
|
|
218
|
+
isFocused,
|
|
219
|
+
isHovered,
|
|
220
|
+
isLabelHovered,
|
|
221
|
+
isInvalid,
|
|
222
|
+
hasHelper,
|
|
223
|
+
hasLabel,
|
|
224
|
+
hasElements,
|
|
225
|
+
isPlaceholderShown,
|
|
226
|
+
hasStartContent,
|
|
227
|
+
isFocusWithin,
|
|
228
|
+
isFocusVisible,
|
|
229
|
+
isFilledWithin,
|
|
230
|
+
hasPlaceholder,
|
|
231
|
+
focusWithinProps,
|
|
232
|
+
isHiddenType,
|
|
233
|
+
originalProps.isReadOnly,
|
|
234
|
+
originalProps.isRequired,
|
|
235
|
+
originalProps.isDisabled
|
|
236
|
+
]
|
|
237
|
+
);
|
|
238
|
+
const getLabelProps = (0, import_react.useCallback)(
|
|
239
|
+
(props2 = {}) => {
|
|
240
|
+
return {
|
|
241
|
+
"data-slot": "label",
|
|
242
|
+
className: slots.label({ class: classNames == null ? void 0 : classNames.label }),
|
|
243
|
+
...(0, import_shared_utils.mergeProps)(labelProps, labelHoverProps, props2)
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
[slots, isLabelHovered, labelProps, classNames == null ? void 0 : classNames.label]
|
|
247
|
+
);
|
|
248
|
+
const handleKeyDown = (0, import_react.useCallback)(
|
|
249
|
+
(e) => {
|
|
250
|
+
if (e.key === "Escape" && inputValue && (isClearable || onClear) && !originalProps.isReadOnly) {
|
|
251
|
+
setInputValue("");
|
|
252
|
+
onClear == null ? void 0 : onClear();
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
[inputValue, setInputValue, onClear, isClearable, originalProps.isReadOnly]
|
|
256
|
+
);
|
|
257
|
+
const getInputProps = (0, import_react.useCallback)(
|
|
258
|
+
(props2 = {}) => {
|
|
259
|
+
return {
|
|
260
|
+
"data-slot": "input",
|
|
261
|
+
"data-filled": (0, import_shared_utils.dataAttr)(isFilled),
|
|
262
|
+
"data-filled-within": (0, import_shared_utils.dataAttr)(isFilledWithin),
|
|
263
|
+
"data-has-start-content": (0, import_shared_utils.dataAttr)(hasStartContent),
|
|
264
|
+
"data-has-end-content": (0, import_shared_utils.dataAttr)(!!endContent),
|
|
265
|
+
"data-type": type,
|
|
266
|
+
className: slots.input({
|
|
267
|
+
class: (0, import_theme.cn)(
|
|
268
|
+
classNames == null ? void 0 : classNames.input,
|
|
269
|
+
isFilled ? "is-filled" : "",
|
|
270
|
+
isMultiline ? "pe-0" : "",
|
|
271
|
+
type === "password" ? "[&::-ms-reveal]:hidden" : ""
|
|
272
|
+
)
|
|
273
|
+
}),
|
|
274
|
+
...(0, import_shared_utils.mergeProps)(
|
|
275
|
+
focusProps,
|
|
276
|
+
inputProps,
|
|
277
|
+
(0, import_react_utils.filterDOMProps)(otherProps, {
|
|
278
|
+
enabled: true,
|
|
279
|
+
labelable: true,
|
|
280
|
+
omitEventNames: new Set(Object.keys(inputProps))
|
|
281
|
+
}),
|
|
282
|
+
props2
|
|
283
|
+
),
|
|
284
|
+
"aria-readonly": (0, import_shared_utils.dataAttr)(originalProps.isReadOnly),
|
|
285
|
+
onChange: (0, import_shared_utils.chain)(inputProps.onChange, onChange),
|
|
286
|
+
onKeyDown: (0, import_shared_utils.chain)(inputProps.onKeyDown, props2.onKeyDown, handleKeyDown),
|
|
287
|
+
ref: domRef
|
|
288
|
+
};
|
|
289
|
+
},
|
|
290
|
+
[
|
|
291
|
+
slots,
|
|
292
|
+
inputValue,
|
|
293
|
+
focusProps,
|
|
294
|
+
inputProps,
|
|
295
|
+
otherProps,
|
|
296
|
+
isFilled,
|
|
297
|
+
isFilledWithin,
|
|
298
|
+
hasStartContent,
|
|
299
|
+
endContent,
|
|
300
|
+
classNames == null ? void 0 : classNames.input,
|
|
301
|
+
originalProps.isReadOnly,
|
|
302
|
+
originalProps.isRequired,
|
|
303
|
+
onChange,
|
|
304
|
+
handleKeyDown
|
|
305
|
+
]
|
|
306
|
+
);
|
|
307
|
+
const getInputWrapperProps = (0, import_react.useCallback)(
|
|
308
|
+
(props2 = {}) => {
|
|
309
|
+
return {
|
|
310
|
+
ref: inputWrapperRef,
|
|
311
|
+
"data-slot": "input-wrapper",
|
|
312
|
+
"data-hover": (0, import_shared_utils.dataAttr)(isHovered || isLabelHovered),
|
|
313
|
+
"data-focus-visible": (0, import_shared_utils.dataAttr)(isFocusVisible),
|
|
314
|
+
"data-focus": (0, import_shared_utils.dataAttr)(isFocused),
|
|
315
|
+
className: slots.inputWrapper({
|
|
316
|
+
class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.inputWrapper, isFilled ? "is-filled" : "")
|
|
317
|
+
}),
|
|
318
|
+
...(0, import_shared_utils.mergeProps)(props2, hoverProps),
|
|
319
|
+
onClick: (e) => {
|
|
320
|
+
if (domRef.current && e.currentTarget === e.target) {
|
|
321
|
+
domRef.current.focus();
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
style: {
|
|
325
|
+
cursor: "text",
|
|
326
|
+
...props2.style
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
[
|
|
331
|
+
slots,
|
|
332
|
+
isHovered,
|
|
333
|
+
isLabelHovered,
|
|
334
|
+
isFocusVisible,
|
|
335
|
+
isFocused,
|
|
336
|
+
inputValue,
|
|
337
|
+
classNames == null ? void 0 : classNames.inputWrapper
|
|
338
|
+
]
|
|
339
|
+
);
|
|
340
|
+
const getInnerWrapperProps = (0, import_react.useCallback)(
|
|
341
|
+
(props2 = {}) => {
|
|
342
|
+
return {
|
|
343
|
+
...props2,
|
|
344
|
+
ref: innerWrapperRef,
|
|
345
|
+
"data-slot": "inner-wrapper",
|
|
346
|
+
onClick: (e) => {
|
|
347
|
+
if (domRef.current && e.currentTarget === e.target) {
|
|
348
|
+
domRef.current.focus();
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
className: slots.innerWrapper({
|
|
352
|
+
class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.innerWrapper, props2 == null ? void 0 : props2.className)
|
|
353
|
+
})
|
|
354
|
+
};
|
|
355
|
+
},
|
|
356
|
+
[slots, classNames == null ? void 0 : classNames.innerWrapper]
|
|
357
|
+
);
|
|
358
|
+
const getMainWrapperProps = (0, import_react.useCallback)(
|
|
359
|
+
(props2 = {}) => {
|
|
360
|
+
return {
|
|
361
|
+
...props2,
|
|
362
|
+
"data-slot": "main-wrapper",
|
|
363
|
+
className: slots.mainWrapper({
|
|
364
|
+
class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.mainWrapper, props2 == null ? void 0 : props2.className)
|
|
365
|
+
})
|
|
366
|
+
};
|
|
367
|
+
},
|
|
368
|
+
[slots, classNames == null ? void 0 : classNames.mainWrapper]
|
|
369
|
+
);
|
|
370
|
+
const getHelperWrapperProps = (0, import_react.useCallback)(
|
|
371
|
+
(props2 = {}) => {
|
|
372
|
+
return {
|
|
373
|
+
...props2,
|
|
374
|
+
"data-slot": "helper-wrapper",
|
|
375
|
+
className: slots.helperWrapper({
|
|
376
|
+
class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.helperWrapper, props2 == null ? void 0 : props2.className)
|
|
377
|
+
})
|
|
378
|
+
};
|
|
379
|
+
},
|
|
380
|
+
[slots, classNames == null ? void 0 : classNames.helperWrapper]
|
|
381
|
+
);
|
|
382
|
+
const getDescriptionProps = (0, import_react.useCallback)(
|
|
383
|
+
(props2 = {}) => {
|
|
384
|
+
return {
|
|
385
|
+
...props2,
|
|
386
|
+
...descriptionProps,
|
|
387
|
+
"data-slot": "description",
|
|
388
|
+
className: slots.description({ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.description, props2 == null ? void 0 : props2.className) })
|
|
389
|
+
};
|
|
390
|
+
},
|
|
391
|
+
[slots, classNames == null ? void 0 : classNames.description]
|
|
392
|
+
);
|
|
393
|
+
const getErrorMessageProps = (0, import_react.useCallback)(
|
|
394
|
+
(props2 = {}) => {
|
|
395
|
+
return {
|
|
396
|
+
...props2,
|
|
397
|
+
...errorMessageProps,
|
|
398
|
+
"data-slot": "error-message",
|
|
399
|
+
className: slots.errorMessage({ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.errorMessage, props2 == null ? void 0 : props2.className) })
|
|
400
|
+
};
|
|
401
|
+
},
|
|
402
|
+
[slots, errorMessageProps, classNames == null ? void 0 : classNames.errorMessage]
|
|
403
|
+
);
|
|
404
|
+
const getClearButtonProps = (0, import_react.useCallback)(
|
|
405
|
+
(props2 = {}) => {
|
|
406
|
+
return {
|
|
407
|
+
...props2,
|
|
408
|
+
type: "button",
|
|
409
|
+
tabIndex: -1,
|
|
410
|
+
disabled: originalProps.isDisabled,
|
|
411
|
+
"aria-label": "clear input",
|
|
412
|
+
"data-slot": "clear-button",
|
|
413
|
+
"data-focus-visible": (0, import_shared_utils.dataAttr)(isClearButtonFocusVisible),
|
|
414
|
+
className: slots.clearButton({
|
|
415
|
+
class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.clearButton, props2 == null ? void 0 : props2.className)
|
|
416
|
+
}),
|
|
417
|
+
...(0, import_shared_utils.mergeProps)(clearPressProps, clearFocusProps)
|
|
418
|
+
};
|
|
419
|
+
},
|
|
420
|
+
[slots, isClearButtonFocusVisible, clearPressProps, clearFocusProps, classNames == null ? void 0 : classNames.clearButton]
|
|
421
|
+
);
|
|
422
|
+
return {
|
|
423
|
+
Component,
|
|
424
|
+
classNames,
|
|
425
|
+
domRef,
|
|
426
|
+
label,
|
|
427
|
+
description,
|
|
428
|
+
startContent,
|
|
429
|
+
endContent,
|
|
430
|
+
labelPlacement,
|
|
431
|
+
isClearable,
|
|
432
|
+
hasHelper,
|
|
433
|
+
hasStartContent,
|
|
434
|
+
isLabelOutside,
|
|
435
|
+
isOutsideLeft,
|
|
436
|
+
isOutsideTop,
|
|
437
|
+
isLabelOutsideAsPlaceholder,
|
|
438
|
+
shouldLabelBeOutside,
|
|
439
|
+
shouldLabelBeInside,
|
|
440
|
+
hasPlaceholder,
|
|
441
|
+
isInvalid,
|
|
442
|
+
errorMessage,
|
|
443
|
+
getBaseProps,
|
|
444
|
+
getLabelProps,
|
|
445
|
+
getInputProps,
|
|
446
|
+
getMainWrapperProps,
|
|
447
|
+
getInputWrapperProps,
|
|
448
|
+
getInnerWrapperProps,
|
|
449
|
+
getHelperWrapperProps,
|
|
450
|
+
getDescriptionProps,
|
|
451
|
+
getErrorMessageProps,
|
|
452
|
+
getClearButtonProps
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
456
|
+
0 && (module.exports = {
|
|
457
|
+
useInput
|
|
458
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sytechui/input",
|
|
3
|
+
"version": "2.4.33",
|
|
4
|
+
"description": "The input component is designed for capturing user input within a text field.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"input"
|
|
7
|
+
],
|
|
8
|
+
"author": "HeroUI <support@heroui.com>",
|
|
9
|
+
"homepage": "https://heroui.com",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/heroui-inc/heroui.git",
|
|
22
|
+
"directory": "packages/components/input"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/heroui-inc/heroui/issues"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18 || >=19.0.0-rc.0",
|
|
29
|
+
"react-dom": ">=18 || >=19.0.0-rc.0",
|
|
30
|
+
"@sytechui/theme": ">=2.4.24",
|
|
31
|
+
"@sytechui/system": ">=2.4.18"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@react-aria/focus": "3.21.5",
|
|
35
|
+
"@react-aria/interactions": "3.27.1",
|
|
36
|
+
"@react-aria/textfield": "3.18.5",
|
|
37
|
+
"@react-stately/utils": "3.11.0",
|
|
38
|
+
"@react-types/shared": "3.33.1",
|
|
39
|
+
"@react-types/textfield": "3.12.8",
|
|
40
|
+
"react-textarea-autosize": "^8.5.3",
|
|
41
|
+
"@sytechui/react-utils": "2.1.14",
|
|
42
|
+
"@sytechui/form": "2.1.32",
|
|
43
|
+
"@sytechui/shared-utils": "2.1.12",
|
|
44
|
+
"@sytechui/shared-icons": "2.1.10",
|
|
45
|
+
"@sytechui/use-safe-layout-effect": "2.1.8"
|
|
46
|
+
},
|
|
47
|
+
"clean-package": "../../../clean-package.config.json",
|
|
48
|
+
"module": "dist/index.mjs",
|
|
49
|
+
"types": "dist/index.d.ts",
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"import": "./dist/index.mjs",
|
|
54
|
+
"require": "./dist/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./package.json": "./package.json"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsup src --dts",
|
|
60
|
+
"build:fast": "tsup src",
|
|
61
|
+
"dev": "pnpm build:fast --watch",
|
|
62
|
+
"clean": "rimraf dist .turbo",
|
|
63
|
+
"typecheck": "tsc --noEmit"
|
|
64
|
+
}
|
|
65
|
+
}
|