@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Next UI Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @sytechui/input
2
+
3
+ Input is a component that allows users to enter text. It can be used to get user inputs in forms, search fields, and more.
4
+
5
+ This package contains the Input component and the TextArea component.
6
+
7
+ Please refer to the [documentation](https://heroui.com/docs/components/input) for more information.
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ yarn add @sytechui/input
13
+ # or
14
+ npm i @sytechui/input
15
+ ```
16
+
17
+ ## Contribution
18
+
19
+ Yes please! See the
20
+ [contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
21
+ for details.
22
+
23
+ ## License
24
+
25
+ This project is licensed under the terms of the
26
+ [MIT license](https://github.com/heroui-inc/heroui/blob/master/LICENSE).
@@ -0,0 +1,442 @@
1
+ "use client";
2
+
3
+ // src/use-input.ts
4
+ import { mapPropsVariants, useProviderContext, useLabelPlacement } from "@sytechui/system";
5
+ import { useSafeLayoutEffect } from "@sytechui/use-safe-layout-effect";
6
+ import { useFocusRing } from "@react-aria/focus";
7
+ import { input, cn } from "@sytechui/theme";
8
+ import { useDOMRef, filterDOMProps } from "@sytechui/react-utils";
9
+ import { useFocusWithin, useHover, usePress } from "@react-aria/interactions";
10
+ import {
11
+ dataAttr,
12
+ isEmpty,
13
+ objectToDeps,
14
+ safeAriaLabel,
15
+ chain,
16
+ mergeProps
17
+ } from "@sytechui/shared-utils";
18
+ import { useControlledState } from "@react-stately/utils";
19
+ import { useMemo, useCallback, useState } from "react";
20
+ import { useTextField } from "@react-aria/textfield";
21
+ import { FormContext, useSlottedContext } from "@sytechui/form";
22
+ function useInput(originalProps) {
23
+ var _a, _b, _c, _d, _e, _f, _g;
24
+ const globalContext = useProviderContext();
25
+ const { validationBehavior: formValidationBehavior } = useSlottedContext(FormContext) || {};
26
+ const [props, variantProps] = mapPropsVariants(originalProps, input.variantKeys);
27
+ const {
28
+ ref,
29
+ as,
30
+ type,
31
+ label,
32
+ baseRef,
33
+ wrapperRef,
34
+ description,
35
+ className,
36
+ classNames,
37
+ autoFocus,
38
+ startContent,
39
+ endContent,
40
+ onClear,
41
+ onChange,
42
+ validationState,
43
+ validationBehavior = (_a = formValidationBehavior != null ? formValidationBehavior : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _a : "native",
44
+ innerWrapperRef: innerWrapperRefProp,
45
+ onValueChange = () => {
46
+ },
47
+ ...otherProps
48
+ } = props;
49
+ const handleValueChange = useCallback(
50
+ (value) => {
51
+ onValueChange(value != null ? value : "");
52
+ },
53
+ [onValueChange]
54
+ );
55
+ const [isFocusWithin, setFocusWithin] = useState(false);
56
+ const Component = as || "div";
57
+ const disableAnimation = (_c = (_b = originalProps.disableAnimation) != null ? _b : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _c : false;
58
+ const domRef = useDOMRef(ref);
59
+ const baseDomRef = useDOMRef(baseRef);
60
+ const inputWrapperRef = useDOMRef(wrapperRef);
61
+ const innerWrapperRef = useDOMRef(innerWrapperRefProp);
62
+ const [inputValue, setInputValue] = useControlledState(
63
+ props.value,
64
+ (_d = props.defaultValue) != null ? _d : "",
65
+ handleValueChange
66
+ );
67
+ const isFileTypeInput = type === "file";
68
+ 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;
69
+ const isFilledByDefault = ["date", "time", "month", "week", "range"].includes(type);
70
+ const isFilled = !isEmpty(inputValue) || isFilledByDefault || hasUploadedFiles;
71
+ const isFilledWithin = isFilled || isFocusWithin;
72
+ const isHiddenType = type === "hidden";
73
+ const isMultiline = originalProps.isMultiline;
74
+ const baseStyles = cn(classNames == null ? void 0 : classNames.base, className, isFilled ? "is-filled" : "");
75
+ const handleClear = useCallback(() => {
76
+ var _a2;
77
+ if (isFileTypeInput) {
78
+ domRef.current.value = "";
79
+ } else {
80
+ setInputValue("");
81
+ }
82
+ onClear == null ? void 0 : onClear();
83
+ (_a2 = domRef.current) == null ? void 0 : _a2.focus();
84
+ }, [setInputValue, onClear, isFileTypeInput]);
85
+ useSafeLayoutEffect(() => {
86
+ if (!domRef.current) return;
87
+ setInputValue(domRef.current.value);
88
+ }, [domRef.current]);
89
+ const {
90
+ labelProps,
91
+ inputProps,
92
+ isInvalid: isAriaInvalid,
93
+ validationErrors,
94
+ validationDetails,
95
+ descriptionProps,
96
+ errorMessageProps
97
+ } = useTextField(
98
+ {
99
+ ...originalProps,
100
+ validationBehavior,
101
+ autoCapitalize: originalProps.autoCapitalize,
102
+ value: inputValue,
103
+ "aria-label": originalProps.label ? originalProps["aria-label"] : safeAriaLabel(originalProps["aria-label"], originalProps.placeholder),
104
+ inputElementType: isMultiline ? "textarea" : "input",
105
+ onChange: setInputValue
106
+ },
107
+ domRef
108
+ );
109
+ if (isFileTypeInput) {
110
+ delete inputProps.value;
111
+ delete inputProps.onChange;
112
+ }
113
+ const { isFocusVisible, isFocused, focusProps } = useFocusRing({
114
+ autoFocus,
115
+ isTextInput: true
116
+ });
117
+ const { isHovered, hoverProps } = useHover({ isDisabled: !!(originalProps == null ? void 0 : originalProps.isDisabled) });
118
+ const { isHovered: isLabelHovered, hoverProps: labelHoverProps } = useHover({
119
+ isDisabled: !!(originalProps == null ? void 0 : originalProps.isDisabled)
120
+ });
121
+ const { focusProps: clearFocusProps, isFocusVisible: isClearButtonFocusVisible } = useFocusRing();
122
+ const { focusWithinProps } = useFocusWithin({
123
+ onFocusWithinChange: setFocusWithin
124
+ });
125
+ const { pressProps: clearPressProps } = usePress({
126
+ isDisabled: !!(originalProps == null ? void 0 : originalProps.isDisabled) || !!(originalProps == null ? void 0 : originalProps.isReadOnly),
127
+ onPress: handleClear
128
+ });
129
+ const isInvalid = validationState === "invalid" || isAriaInvalid;
130
+ const labelPlacement = useLabelPlacement({
131
+ labelPlacement: originalProps.labelPlacement,
132
+ label
133
+ });
134
+ const errorMessage = typeof props.errorMessage === "function" ? props.errorMessage({ isInvalid, validationErrors, validationDetails }) : props.errorMessage || (validationErrors == null ? void 0 : validationErrors.join(" "));
135
+ const isClearable = !!onClear || originalProps.isClearable;
136
+ const hasElements = !!label || !!description || !!errorMessage;
137
+ const hasPlaceholder = !!props.placeholder;
138
+ const hasLabel = !!label;
139
+ const hasHelper = !!description || !!errorMessage;
140
+ const isOutsideLeft = labelPlacement === "outside-left";
141
+ const isOutsideTop = labelPlacement === "outside-top";
142
+ const shouldLabelBeOutside = (
143
+ // label is outside only when some placeholder is there
144
+ labelPlacement === "outside" || // label is outside regardless of placeholder
145
+ isOutsideLeft || isOutsideTop
146
+ );
147
+ const shouldLabelBeInside = labelPlacement === "inside";
148
+ const isPlaceholderShown = domRef.current ? (!domRef.current.value || domRef.current.value === "" || !inputValue || inputValue === "") && hasPlaceholder : false;
149
+ const hasStartContent = !!startContent;
150
+ const isLabelOutside = shouldLabelBeOutside ? isOutsideLeft || isOutsideTop || hasPlaceholder || labelPlacement === "outside" && hasStartContent : false;
151
+ const isLabelOutsideAsPlaceholder = labelPlacement === "outside" && !hasPlaceholder && !hasStartContent;
152
+ const slots = useMemo(
153
+ () => input({
154
+ ...variantProps,
155
+ isInvalid,
156
+ labelPlacement,
157
+ isClearable,
158
+ disableAnimation
159
+ }),
160
+ [
161
+ objectToDeps(variantProps),
162
+ isInvalid,
163
+ labelPlacement,
164
+ isClearable,
165
+ hasStartContent,
166
+ disableAnimation
167
+ ]
168
+ );
169
+ const getBaseProps = useCallback(
170
+ (props2 = {}) => {
171
+ return {
172
+ ref: baseDomRef,
173
+ className: slots.base({ class: baseStyles }),
174
+ "data-slot": "base",
175
+ "data-filled": dataAttr(
176
+ isFilled || hasPlaceholder || hasStartContent || isPlaceholderShown || isFileTypeInput
177
+ ),
178
+ "data-filled-within": dataAttr(
179
+ isFilledWithin || hasPlaceholder || hasStartContent || isPlaceholderShown || isFileTypeInput
180
+ ),
181
+ "data-focus-within": dataAttr(isFocusWithin),
182
+ "data-focus-visible": dataAttr(isFocusVisible),
183
+ "data-readonly": dataAttr(originalProps.isReadOnly),
184
+ "data-focus": dataAttr(isFocused),
185
+ "data-hover": dataAttr(isHovered || isLabelHovered),
186
+ "data-required": dataAttr(originalProps.isRequired),
187
+ "data-invalid": dataAttr(isInvalid),
188
+ "data-disabled": dataAttr(originalProps.isDisabled),
189
+ "data-has-elements": dataAttr(hasElements),
190
+ "data-has-helper": dataAttr(hasHelper),
191
+ "data-has-label": dataAttr(hasLabel),
192
+ "data-has-value": dataAttr(!isPlaceholderShown),
193
+ "data-hidden": dataAttr(isHiddenType),
194
+ ...focusWithinProps,
195
+ ...props2
196
+ };
197
+ },
198
+ [
199
+ slots,
200
+ baseStyles,
201
+ isFilled,
202
+ isFocused,
203
+ isHovered,
204
+ isLabelHovered,
205
+ isInvalid,
206
+ hasHelper,
207
+ hasLabel,
208
+ hasElements,
209
+ isPlaceholderShown,
210
+ hasStartContent,
211
+ isFocusWithin,
212
+ isFocusVisible,
213
+ isFilledWithin,
214
+ hasPlaceholder,
215
+ focusWithinProps,
216
+ isHiddenType,
217
+ originalProps.isReadOnly,
218
+ originalProps.isRequired,
219
+ originalProps.isDisabled
220
+ ]
221
+ );
222
+ const getLabelProps = useCallback(
223
+ (props2 = {}) => {
224
+ return {
225
+ "data-slot": "label",
226
+ className: slots.label({ class: classNames == null ? void 0 : classNames.label }),
227
+ ...mergeProps(labelProps, labelHoverProps, props2)
228
+ };
229
+ },
230
+ [slots, isLabelHovered, labelProps, classNames == null ? void 0 : classNames.label]
231
+ );
232
+ const handleKeyDown = useCallback(
233
+ (e) => {
234
+ if (e.key === "Escape" && inputValue && (isClearable || onClear) && !originalProps.isReadOnly) {
235
+ setInputValue("");
236
+ onClear == null ? void 0 : onClear();
237
+ }
238
+ },
239
+ [inputValue, setInputValue, onClear, isClearable, originalProps.isReadOnly]
240
+ );
241
+ const getInputProps = useCallback(
242
+ (props2 = {}) => {
243
+ return {
244
+ "data-slot": "input",
245
+ "data-filled": dataAttr(isFilled),
246
+ "data-filled-within": dataAttr(isFilledWithin),
247
+ "data-has-start-content": dataAttr(hasStartContent),
248
+ "data-has-end-content": dataAttr(!!endContent),
249
+ "data-type": type,
250
+ className: slots.input({
251
+ class: cn(
252
+ classNames == null ? void 0 : classNames.input,
253
+ isFilled ? "is-filled" : "",
254
+ isMultiline ? "pe-0" : "",
255
+ type === "password" ? "[&::-ms-reveal]:hidden" : ""
256
+ )
257
+ }),
258
+ ...mergeProps(
259
+ focusProps,
260
+ inputProps,
261
+ filterDOMProps(otherProps, {
262
+ enabled: true,
263
+ labelable: true,
264
+ omitEventNames: new Set(Object.keys(inputProps))
265
+ }),
266
+ props2
267
+ ),
268
+ "aria-readonly": dataAttr(originalProps.isReadOnly),
269
+ onChange: chain(inputProps.onChange, onChange),
270
+ onKeyDown: chain(inputProps.onKeyDown, props2.onKeyDown, handleKeyDown),
271
+ ref: domRef
272
+ };
273
+ },
274
+ [
275
+ slots,
276
+ inputValue,
277
+ focusProps,
278
+ inputProps,
279
+ otherProps,
280
+ isFilled,
281
+ isFilledWithin,
282
+ hasStartContent,
283
+ endContent,
284
+ classNames == null ? void 0 : classNames.input,
285
+ originalProps.isReadOnly,
286
+ originalProps.isRequired,
287
+ onChange,
288
+ handleKeyDown
289
+ ]
290
+ );
291
+ const getInputWrapperProps = useCallback(
292
+ (props2 = {}) => {
293
+ return {
294
+ ref: inputWrapperRef,
295
+ "data-slot": "input-wrapper",
296
+ "data-hover": dataAttr(isHovered || isLabelHovered),
297
+ "data-focus-visible": dataAttr(isFocusVisible),
298
+ "data-focus": dataAttr(isFocused),
299
+ className: slots.inputWrapper({
300
+ class: cn(classNames == null ? void 0 : classNames.inputWrapper, isFilled ? "is-filled" : "")
301
+ }),
302
+ ...mergeProps(props2, hoverProps),
303
+ onClick: (e) => {
304
+ if (domRef.current && e.currentTarget === e.target) {
305
+ domRef.current.focus();
306
+ }
307
+ },
308
+ style: {
309
+ cursor: "text",
310
+ ...props2.style
311
+ }
312
+ };
313
+ },
314
+ [
315
+ slots,
316
+ isHovered,
317
+ isLabelHovered,
318
+ isFocusVisible,
319
+ isFocused,
320
+ inputValue,
321
+ classNames == null ? void 0 : classNames.inputWrapper
322
+ ]
323
+ );
324
+ const getInnerWrapperProps = useCallback(
325
+ (props2 = {}) => {
326
+ return {
327
+ ...props2,
328
+ ref: innerWrapperRef,
329
+ "data-slot": "inner-wrapper",
330
+ onClick: (e) => {
331
+ if (domRef.current && e.currentTarget === e.target) {
332
+ domRef.current.focus();
333
+ }
334
+ },
335
+ className: slots.innerWrapper({
336
+ class: cn(classNames == null ? void 0 : classNames.innerWrapper, props2 == null ? void 0 : props2.className)
337
+ })
338
+ };
339
+ },
340
+ [slots, classNames == null ? void 0 : classNames.innerWrapper]
341
+ );
342
+ const getMainWrapperProps = useCallback(
343
+ (props2 = {}) => {
344
+ return {
345
+ ...props2,
346
+ "data-slot": "main-wrapper",
347
+ className: slots.mainWrapper({
348
+ class: cn(classNames == null ? void 0 : classNames.mainWrapper, props2 == null ? void 0 : props2.className)
349
+ })
350
+ };
351
+ },
352
+ [slots, classNames == null ? void 0 : classNames.mainWrapper]
353
+ );
354
+ const getHelperWrapperProps = useCallback(
355
+ (props2 = {}) => {
356
+ return {
357
+ ...props2,
358
+ "data-slot": "helper-wrapper",
359
+ className: slots.helperWrapper({
360
+ class: cn(classNames == null ? void 0 : classNames.helperWrapper, props2 == null ? void 0 : props2.className)
361
+ })
362
+ };
363
+ },
364
+ [slots, classNames == null ? void 0 : classNames.helperWrapper]
365
+ );
366
+ const getDescriptionProps = useCallback(
367
+ (props2 = {}) => {
368
+ return {
369
+ ...props2,
370
+ ...descriptionProps,
371
+ "data-slot": "description",
372
+ className: slots.description({ class: cn(classNames == null ? void 0 : classNames.description, props2 == null ? void 0 : props2.className) })
373
+ };
374
+ },
375
+ [slots, classNames == null ? void 0 : classNames.description]
376
+ );
377
+ const getErrorMessageProps = useCallback(
378
+ (props2 = {}) => {
379
+ return {
380
+ ...props2,
381
+ ...errorMessageProps,
382
+ "data-slot": "error-message",
383
+ className: slots.errorMessage({ class: cn(classNames == null ? void 0 : classNames.errorMessage, props2 == null ? void 0 : props2.className) })
384
+ };
385
+ },
386
+ [slots, errorMessageProps, classNames == null ? void 0 : classNames.errorMessage]
387
+ );
388
+ const getClearButtonProps = useCallback(
389
+ (props2 = {}) => {
390
+ return {
391
+ ...props2,
392
+ type: "button",
393
+ tabIndex: -1,
394
+ disabled: originalProps.isDisabled,
395
+ "aria-label": "clear input",
396
+ "data-slot": "clear-button",
397
+ "data-focus-visible": dataAttr(isClearButtonFocusVisible),
398
+ className: slots.clearButton({
399
+ class: cn(classNames == null ? void 0 : classNames.clearButton, props2 == null ? void 0 : props2.className)
400
+ }),
401
+ ...mergeProps(clearPressProps, clearFocusProps)
402
+ };
403
+ },
404
+ [slots, isClearButtonFocusVisible, clearPressProps, clearFocusProps, classNames == null ? void 0 : classNames.clearButton]
405
+ );
406
+ return {
407
+ Component,
408
+ classNames,
409
+ domRef,
410
+ label,
411
+ description,
412
+ startContent,
413
+ endContent,
414
+ labelPlacement,
415
+ isClearable,
416
+ hasHelper,
417
+ hasStartContent,
418
+ isLabelOutside,
419
+ isOutsideLeft,
420
+ isOutsideTop,
421
+ isLabelOutsideAsPlaceholder,
422
+ shouldLabelBeOutside,
423
+ shouldLabelBeInside,
424
+ hasPlaceholder,
425
+ isInvalid,
426
+ errorMessage,
427
+ getBaseProps,
428
+ getLabelProps,
429
+ getInputProps,
430
+ getMainWrapperProps,
431
+ getInputWrapperProps,
432
+ getInnerWrapperProps,
433
+ getHelperWrapperProps,
434
+ getDescriptionProps,
435
+ getErrorMessageProps,
436
+ getClearButtonProps
437
+ };
438
+ }
439
+
440
+ export {
441
+ useInput
442
+ };
@@ -0,0 +1,105 @@
1
+ "use client";
2
+ import {
3
+ useInput
4
+ } from "./chunk-6SGLJYRO.mjs";
5
+
6
+ // src/input.tsx
7
+ import { CloseFilledIcon } from "@sytechui/shared-icons";
8
+ import { useMemo } from "react";
9
+ import { forwardRef } from "@sytechui/system";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
+ var Input = forwardRef((props, ref) => {
12
+ const {
13
+ Component,
14
+ label,
15
+ description,
16
+ isClearable,
17
+ startContent,
18
+ endContent,
19
+ labelPlacement,
20
+ hasHelper,
21
+ isOutsideLeft,
22
+ isOutsideTop,
23
+ shouldLabelBeOutside,
24
+ errorMessage,
25
+ isInvalid,
26
+ getBaseProps,
27
+ getLabelProps,
28
+ getInputProps,
29
+ getInnerWrapperProps,
30
+ getInputWrapperProps,
31
+ getMainWrapperProps,
32
+ getHelperWrapperProps,
33
+ getDescriptionProps,
34
+ getErrorMessageProps,
35
+ getClearButtonProps
36
+ } = useInput({ ...props, ref });
37
+ const labelContent = label ? /* @__PURE__ */ jsx("label", { ...getLabelProps(), children: label }) : null;
38
+ const end = useMemo(() => {
39
+ if (isClearable) {
40
+ return /* @__PURE__ */ jsx("button", { ...getClearButtonProps(), children: endContent || /* @__PURE__ */ jsx(CloseFilledIcon, {}) });
41
+ }
42
+ return endContent;
43
+ }, [isClearable, getClearButtonProps]);
44
+ const helperWrapper = useMemo(() => {
45
+ const shouldShowError = isInvalid && errorMessage;
46
+ const hasContent = shouldShowError || description;
47
+ if (!hasHelper || !hasContent) return null;
48
+ return /* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: shouldShowError ? /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: errorMessage }) : /* @__PURE__ */ jsx("div", { ...getDescriptionProps(), children: description }) });
49
+ }, [
50
+ hasHelper,
51
+ isInvalid,
52
+ errorMessage,
53
+ description,
54
+ getHelperWrapperProps,
55
+ getErrorMessageProps,
56
+ getDescriptionProps
57
+ ]);
58
+ const innerWrapper = useMemo(() => {
59
+ return /* @__PURE__ */ jsxs("div", { ...getInnerWrapperProps(), children: [
60
+ startContent,
61
+ /* @__PURE__ */ jsx("input", { ...getInputProps() }),
62
+ end
63
+ ] });
64
+ }, [startContent, end, getInputProps, getInnerWrapperProps]);
65
+ const mainWrapper = useMemo(() => {
66
+ if (shouldLabelBeOutside) {
67
+ return /* @__PURE__ */ jsxs("div", { ...getMainWrapperProps(), children: [
68
+ /* @__PURE__ */ jsxs("div", { ...getInputWrapperProps(), children: [
69
+ !isOutsideLeft && !isOutsideTop ? labelContent : null,
70
+ innerWrapper
71
+ ] }),
72
+ helperWrapper
73
+ ] });
74
+ }
75
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
76
+ /* @__PURE__ */ jsxs("div", { ...getInputWrapperProps(), children: [
77
+ labelContent,
78
+ innerWrapper
79
+ ] }),
80
+ helperWrapper
81
+ ] });
82
+ }, [
83
+ labelPlacement,
84
+ helperWrapper,
85
+ shouldLabelBeOutside,
86
+ labelContent,
87
+ innerWrapper,
88
+ errorMessage,
89
+ description,
90
+ getMainWrapperProps,
91
+ getInputWrapperProps,
92
+ getErrorMessageProps,
93
+ getDescriptionProps
94
+ ]);
95
+ return /* @__PURE__ */ jsxs(Component, { ...getBaseProps(), children: [
96
+ isOutsideLeft || isOutsideTop ? labelContent : null,
97
+ mainWrapper
98
+ ] });
99
+ });
100
+ Input.displayName = "HeroUI.Input";
101
+ var input_default = Input;
102
+
103
+ export {
104
+ input_default
105
+ };
@@ -0,0 +1,102 @@
1
+ "use client";
2
+ import {
3
+ useInput
4
+ } from "./chunk-6SGLJYRO.mjs";
5
+
6
+ // src/textarea.tsx
7
+ import { dataAttr, mergeProps } from "@sytechui/shared-utils";
8
+ import { forwardRef } from "@sytechui/system";
9
+ import { useMemo, useState } from "react";
10
+ import TextareaAutosize from "react-textarea-autosize";
11
+ import { CloseFilledIcon } from "@sytechui/shared-icons";
12
+ import { jsx, jsxs } from "react/jsx-runtime";
13
+ var Textarea = forwardRef(
14
+ ({
15
+ style,
16
+ minRows = 3,
17
+ maxRows = 8,
18
+ cacheMeasurements = false,
19
+ disableAutosize = false,
20
+ onHeightChange,
21
+ ...otherProps
22
+ }, ref) => {
23
+ const {
24
+ Component,
25
+ label,
26
+ description,
27
+ startContent,
28
+ endContent,
29
+ hasHelper,
30
+ shouldLabelBeOutside,
31
+ shouldLabelBeInside,
32
+ isInvalid,
33
+ errorMessage,
34
+ getBaseProps,
35
+ getLabelProps,
36
+ getInputProps,
37
+ getInnerWrapperProps,
38
+ getInputWrapperProps,
39
+ getHelperWrapperProps,
40
+ getDescriptionProps,
41
+ getErrorMessageProps,
42
+ isClearable,
43
+ getClearButtonProps
44
+ } = useInput({ ...otherProps, ref, isMultiline: true });
45
+ const [hasMultipleRows, setIsHasMultipleRows] = useState(minRows > 1);
46
+ const [isLimitReached, setIsLimitReached] = useState(false);
47
+ const labelContent = label ? /* @__PURE__ */ jsx("label", { ...getLabelProps(), children: label }) : null;
48
+ const inputProps = getInputProps();
49
+ const handleHeightChange = (height, meta) => {
50
+ if (minRows === 1) {
51
+ setIsHasMultipleRows(height >= meta.rowHeight * 2);
52
+ }
53
+ if (maxRows > minRows) {
54
+ const limitReached = height >= maxRows * meta.rowHeight;
55
+ setIsLimitReached(limitReached);
56
+ }
57
+ onHeightChange == null ? void 0 : onHeightChange(height, meta);
58
+ };
59
+ const content = disableAutosize ? /* @__PURE__ */ jsx("textarea", { ...inputProps, style: mergeProps(inputProps.style, style != null ? style : {}) }) : /* @__PURE__ */ jsx(
60
+ TextareaAutosize,
61
+ {
62
+ ...inputProps,
63
+ cacheMeasurements,
64
+ "data-hide-scroll": dataAttr(!isLimitReached),
65
+ maxRows,
66
+ minRows,
67
+ style: mergeProps(inputProps.style, style != null ? style : {}),
68
+ onHeightChange: handleHeightChange
69
+ }
70
+ );
71
+ const clearButtonContent = useMemo(() => {
72
+ return isClearable ? /* @__PURE__ */ jsx("button", { ...getClearButtonProps(), children: /* @__PURE__ */ jsx(CloseFilledIcon, {}) }) : null;
73
+ }, [isClearable, getClearButtonProps]);
74
+ const innerWrapper = useMemo(() => {
75
+ if (startContent || endContent) {
76
+ return /* @__PURE__ */ jsxs("div", { ...getInnerWrapperProps(), children: [
77
+ startContent,
78
+ content,
79
+ endContent
80
+ ] });
81
+ }
82
+ return /* @__PURE__ */ jsx("div", { ...getInnerWrapperProps(), children: content });
83
+ }, [startContent, inputProps, endContent, getInnerWrapperProps]);
84
+ const shouldShowError = isInvalid && errorMessage;
85
+ const hasHelperContent = shouldShowError || description;
86
+ return /* @__PURE__ */ jsxs(Component, { ...getBaseProps(), children: [
87
+ shouldLabelBeOutside ? labelContent : null,
88
+ /* @__PURE__ */ jsxs("div", { ...getInputWrapperProps(), "data-has-multiple-rows": dataAttr(hasMultipleRows), children: [
89
+ shouldLabelBeInside ? labelContent : null,
90
+ innerWrapper,
91
+ clearButtonContent
92
+ ] }),
93
+ hasHelper && hasHelperContent ? /* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: shouldShowError ? /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: errorMessage }) : /* @__PURE__ */ jsx("div", { ...getDescriptionProps(), children: description }) }) : null
94
+ ] });
95
+ }
96
+ );
97
+ Textarea.displayName = "HeroUI.Textarea";
98
+ var textarea_default = Textarea;
99
+
100
+ export {
101
+ textarea_default
102
+ };