@dxos/react-input 0.8.3-staging.0fa589b → 0.8.4-main.03d5cd7b56

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/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@dxos/react-input",
3
- "version": "0.8.3-staging.0fa589b",
3
+ "version": "0.8.4-main.03d5cd7b56",
4
4
  "description": "Input primitive components for React.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
- "sideEffects": true,
13
+ "sideEffects": false,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
17
+ "source": "./src/index.ts",
13
18
  "types": "./dist/types/src/index.d.ts",
14
19
  "browser": "./dist/lib/browser/index.mjs",
15
20
  "node": "./dist/lib/node-esm/index.mjs"
@@ -21,25 +26,22 @@
21
26
  "src"
22
27
  ],
23
28
  "dependencies": {
24
- "@preact-signals/safe-react": "^0.9.0",
25
29
  "@radix-ui/react-compose-refs": "1.1.1",
26
30
  "@radix-ui/react-context": "1.1.1",
27
31
  "@radix-ui/react-primitive": "2.0.2",
28
32
  "@radix-ui/react-slot": "1.1.2",
29
33
  "@radix-ui/react-use-controllable-state": "1.1.0",
30
- "lodash.omit": "^4.5.0",
31
- "rci": "^0.1.0",
32
- "@dxos/react-hooks": "0.8.3-staging.0fa589b"
34
+ "@dxos/react-hooks": "0.8.4-main.03d5cd7b56"
33
35
  },
34
36
  "devDependencies": {
35
- "@types/react": "~18.2.0",
36
- "@types/react-dom": "~18.2.0",
37
- "react": "~18.2.0",
38
- "react-dom": "~18.2.0"
37
+ "@types/react": "~19.2.7",
38
+ "@types/react-dom": "~19.2.3",
39
+ "react": "~19.2.3",
40
+ "react-dom": "~19.2.3"
39
41
  },
40
42
  "peerDependencies": {
41
- "react": "~18.2.0",
42
- "react-dom": "~18.2.0"
43
+ "react": "~19.2.3",
44
+ "react-dom": "~19.2.3"
43
45
  },
44
46
  "publishConfig": {
45
47
  "access": "public"
package/src/InputMeta.tsx CHANGED
@@ -13,11 +13,11 @@ type LabelProps = ComponentPropsWithRef<typeof Primitive.label> & { asChild?: bo
13
13
  const Label = forwardRef<HTMLLabelElement, LabelProps>(
14
14
  ({ __inputScope, asChild, children, ...props }: InputScopedProps<LabelProps>, forwardedRef) => {
15
15
  const { id } = useInputContext(INPUT_NAME, __inputScope);
16
- const Root = asChild ? Slot : Primitive.label;
16
+ const Comp = asChild ? Slot : Primitive.label;
17
17
  return (
18
- <Root {...props} htmlFor={id} ref={forwardedRef}>
18
+ <Comp {...props} htmlFor={id} ref={forwardedRef}>
19
19
  {children}
20
- </Root>
20
+ </Comp>
21
21
  );
22
22
  },
23
23
  );
@@ -27,11 +27,11 @@ type DescriptionProps = Omit<ComponentPropsWithRef<typeof Primitive.span>, 'id'>
27
27
  const Description = forwardRef<HTMLSpanElement, DescriptionProps>(
28
28
  ({ __inputScope, asChild, children, ...props }: InputScopedProps<DescriptionProps>, forwardedRef) => {
29
29
  const { descriptionId, validationValence } = useInputContext(INPUT_NAME, __inputScope);
30
- const Root = asChild ? Slot : Primitive.span;
30
+ const Comp = asChild ? Slot : Primitive.span;
31
31
  return (
32
- <Root {...props} {...(validationValence === 'error' && { id: descriptionId })} ref={forwardedRef}>
32
+ <Comp {...props} {...(validationValence === 'error' && { id: descriptionId })} ref={forwardedRef}>
33
33
  {children}
34
- </Root>
34
+ </Comp>
35
35
  );
36
36
  },
37
37
  );
@@ -41,11 +41,11 @@ type ErrorMessageProps = Omit<ComponentPropsWithRef<typeof Primitive.span>, 'id'
41
41
  const ErrorMessage = forwardRef<HTMLSpanElement, ErrorMessageProps>(
42
42
  ({ __inputScope, asChild, children, ...props }: InputScopedProps<ErrorMessageProps>, forwardedRef) => {
43
43
  const { errorMessageId } = useInputContext(INPUT_NAME, __inputScope);
44
- const Root = asChild ? Slot : Primitive.span;
44
+ const Comp = asChild ? Slot : Primitive.span;
45
45
  return (
46
- <Root {...props} id={errorMessageId} ref={forwardedRef}>
46
+ <Comp {...props} id={errorMessageId} ref={forwardedRef}>
47
47
  {children}
48
- </Root>
48
+ </Comp>
49
49
  );
50
50
  },
51
51
  );
@@ -59,11 +59,11 @@ const Validation = forwardRef<HTMLSpanElement, ValidationProps>(
59
59
  if (validationValence === 'error') {
60
60
  return <ErrorMessage {...props} ref={forwardedRef} />;
61
61
  } else {
62
- const Root = asChild ? Slot : Primitive.span;
62
+ const Comp = asChild ? Slot : Primitive.span;
63
63
  return (
64
- <Root {...otherProps} ref={forwardedRef}>
64
+ <Comp {...otherProps} ref={forwardedRef}>
65
65
  {children}
66
- </Root>
66
+ </Comp>
67
67
  );
68
68
  }
69
69
  },
@@ -74,11 +74,11 @@ type DescriptionAndValidationProps = ComponentPropsWithRef<typeof Primitive.p> &
74
74
  const DescriptionAndValidation = forwardRef<HTMLParagraphElement, DescriptionAndValidationProps>(
75
75
  ({ __inputScope, asChild, children, ...props }: InputScopedProps<DescriptionAndValidationProps>, forwardedRef) => {
76
76
  const { descriptionId, validationValence } = useInputContext(INPUT_NAME, __inputScope);
77
- const Root = asChild ? Slot : Primitive.p;
77
+ const Comp = asChild ? Slot : Primitive.p;
78
78
  return (
79
- <Root {...props} {...(validationValence !== 'error' && { id: descriptionId })} ref={forwardedRef}>
79
+ <Comp {...props} {...(validationValence !== 'error' && { id: descriptionId })} ref={forwardedRef}>
80
80
  {children}
81
- </Root>
81
+ </Comp>
82
82
  );
83
83
  },
84
84
  );
package/src/PinInput.tsx CHANGED
@@ -2,75 +2,206 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { CodeInput, getSegmentCssWidth } from 'rci';
6
- import React, { type ComponentProps, type ComponentPropsWithRef, forwardRef, useCallback } from 'react';
5
+ import React, {
6
+ type ChangeEvent,
7
+ type ClipboardEvent,
8
+ type ComponentPropsWithRef,
9
+ type KeyboardEvent,
10
+ forwardRef,
11
+ useCallback,
12
+ useEffect,
13
+ useMemo,
14
+ useState,
15
+ } from 'react';
7
16
 
8
17
  import { useForwardedRef, useIsFocused } from '@dxos/react-hooks';
9
18
 
10
- import { INPUT_NAME, type InputScopedProps, useInputContext, type Valence } from './Root';
19
+ import { INPUT_NAME, type InputScopedProps, useInputContext } from './Root';
11
20
 
12
- type PinInputProps = Omit<
13
- ComponentPropsWithRef<typeof CodeInput>,
14
- 'id' | 'className' | 'inputRef' | 'renderSegment'
15
- > & {
16
- inputClassName?: string;
17
- segmentClassName?: (styleProps: { focused: boolean; validationValence: Valence }) => string;
18
- segmentPadding?: string;
19
- segmentHeight?: string;
21
+ type PinInputProps = Omit<ComponentPropsWithRef<'input'>, 'type' | 'maxLength'> & {
22
+ /** Class name applied to each segment div. */
23
+ segmentClassName?: string;
24
+ /** Number of code segments. */
25
+ length?: number;
20
26
  };
21
27
 
22
28
  const PinInput = forwardRef<HTMLInputElement, PinInputProps>(
23
29
  (
24
30
  {
25
31
  __inputScope,
32
+ className,
33
+ disabled,
26
34
  segmentClassName,
27
- inputClassName,
28
- segmentPadding = '8px',
29
- segmentHeight = '100%',
35
+ length = 6,
36
+ pattern,
37
+ value: controlledValue,
38
+ onChange,
39
+ onPaste,
30
40
  ...props
31
41
  }: InputScopedProps<PinInputProps>,
32
42
  forwardedRef,
33
43
  ) => {
34
44
  const { id, validationValence, descriptionId, errorMessageId } = useInputContext(INPUT_NAME, __inputScope);
35
- const width = getSegmentCssWidth(segmentPadding);
36
45
  const inputRef = useForwardedRef(forwardedRef);
37
46
  const inputFocused = useIsFocused(inputRef);
47
+ const [internalValue, setInternalValue] = useState('');
48
+ const [cursorPosition, setCursorPosition] = useState(0);
38
49
 
39
- const renderSegment = useCallback<ComponentProps<typeof CodeInput>['renderSegment']>(
40
- ({ state, index }) => (
41
- <div
42
- key={index}
43
- className={segmentClassName?.({
44
- focused: !!(inputFocused && state),
45
- validationValence,
46
- })}
47
- data-state={state}
48
- style={{ width, height: segmentHeight }}
49
- />
50
- ),
51
- [segmentClassName, inputFocused, validationValence],
50
+ const value = controlledValue != null ? String(controlledValue) : internalValue;
51
+
52
+ // Derive a per-character filter from the `pattern` prop (e.g., `\\d*` → test each char against `\\d`).
53
+ const charPattern = useMemo(() => {
54
+ if (!pattern) {
55
+ return undefined;
56
+ }
57
+ try {
58
+ // Strip quantifiers (*, +, {n}) to get the base character class.
59
+ const base = pattern.replace(/[*+?]$|\{\d+,?\d*\}$/g, '');
60
+ return new RegExp(`^${base}$`);
61
+ } catch {
62
+ return undefined;
63
+ }
64
+ }, [pattern]);
65
+
66
+ /** Filter a string to only characters matching the pattern. */
67
+ const filterValue = useCallback(
68
+ (input: string) => {
69
+ if (!charPattern) {
70
+ return input;
71
+ }
72
+ return input
73
+ .split('')
74
+ .filter((char) => charPattern.test(char))
75
+ .join('');
76
+ },
77
+ [charPattern],
78
+ );
79
+
80
+ // Sync cursor position from the hidden input's selection.
81
+ const syncCursor = useCallback(() => {
82
+ const pos = inputRef.current?.selectionStart ?? value.length;
83
+ setCursorPosition(Math.min(pos, value.length));
84
+ }, [inputRef, value.length]);
85
+
86
+ // Keep cursor in sync after value changes.
87
+ useEffect(() => {
88
+ setCursorPosition((prev) => Math.min(prev, value.length));
89
+ }, [value.length]);
90
+
91
+ const handleChange = useCallback(
92
+ (event: ChangeEvent<HTMLInputElement>) => {
93
+ const newValue = filterValue(event.target.value).slice(0, length);
94
+ if (controlledValue == null) {
95
+ setInternalValue(newValue);
96
+ }
97
+ setCursorPosition(event.target.selectionStart ?? newValue.length);
98
+ onChange?.(event);
99
+ },
100
+ [length, controlledValue, onChange, filterValue],
52
101
  );
53
102
 
103
+ const handlePaste = useCallback(
104
+ (event: ClipboardEvent<HTMLInputElement>) => {
105
+ onPaste?.(event);
106
+ if (event.defaultPrevented) {
107
+ return;
108
+ }
109
+ event.preventDefault();
110
+ const pasted = filterValue(event.clipboardData.getData('text/plain')).slice(0, length);
111
+ const input = inputRef.current;
112
+ if (!input) {
113
+ return;
114
+ }
115
+ // Use native setter to trigger React's synthetic onChange.
116
+ const nativeInputValueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
117
+ nativeInputValueSetter?.call(input, pasted);
118
+ input.dispatchEvent(new Event('input', { bubbles: true }));
119
+ },
120
+ [length, inputRef, onPaste, filterValue],
121
+ );
122
+
123
+ const handleKeyDown = useCallback(
124
+ (event: KeyboardEvent<HTMLInputElement>) => {
125
+ if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
126
+ // Let the native input handle cursor movement, then sync.
127
+ requestAnimationFrame(syncCursor);
128
+ } else if (event.key === 'Backspace' && value.length === 0) {
129
+ event.preventDefault();
130
+ } else if (event.key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey) {
131
+ // Reject characters that don't match the allow pattern.
132
+ if (charPattern && !charPattern.test(event.key)) {
133
+ event.preventDefault();
134
+ props.onKeyDown?.(event);
135
+ return;
136
+ }
137
+ // Overwrite mode: replace character at cursor position instead of inserting.
138
+ const input = inputRef.current;
139
+ const pos = input?.selectionStart ?? value.length;
140
+ if (pos < value.length && input) {
141
+ event.preventDefault();
142
+ const newValue = value.slice(0, pos) + event.key + value.slice(pos + 1);
143
+ const newPos = Math.min(pos + 1, length);
144
+ // Update state and cursor synchronously to avoid flicker.
145
+ if (controlledValue == null) {
146
+ setInternalValue(newValue);
147
+ }
148
+ setCursorPosition(newPos);
149
+ // Sync the native input to match.
150
+ const nativeInputValueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
151
+ nativeInputValueSetter?.call(input, newValue);
152
+ input.setSelectionRange(newPos, newPos);
153
+ // Notify consumer via onChange with a synthetic-like event.
154
+ onChange?.({ target: input, currentTarget: input } as ChangeEvent<HTMLInputElement>);
155
+ }
156
+ }
157
+ props.onKeyDown?.(event);
158
+ },
159
+ [value, length, props.onKeyDown, syncCursor, inputRef, charPattern, controlledValue, onChange],
160
+ );
161
+
162
+ const handleSelect = useCallback(() => {
163
+ syncCursor();
164
+ }, [syncCursor]);
165
+
166
+ const activeIndex = Math.min(cursorPosition, value.length < length ? value.length : length - 1);
167
+
54
168
  return (
55
- <CodeInput
56
- {...{
57
- padding: '8px',
58
- spacing: '8px',
59
- fontFamily: '',
60
- spellCheck: false,
61
- length: 6,
62
- ...props,
63
- id,
64
- 'aria-describedby': descriptionId,
65
- ...(validationValence === 'error' && {
169
+ <div className={`relative inline-flex items-center gap-2 ${className ?? ''}`}>
170
+ <input
171
+ ref={inputRef}
172
+ id={id}
173
+ type='text'
174
+ value={value}
175
+ onChange={handleChange}
176
+ onPaste={handlePaste}
177
+ onKeyDown={handleKeyDown}
178
+ onSelect={handleSelect}
179
+ maxLength={length}
180
+ disabled={disabled}
181
+ spellCheck={false}
182
+ aria-describedby={descriptionId}
183
+ {...(validationValence === 'error' && {
66
184
  'aria-invalid': 'true' as const,
67
185
  'aria-errormessage': errorMessageId,
68
- }),
69
- inputRef,
70
- renderSegment,
71
- className: inputClassName,
72
- }}
73
- />
186
+ })}
187
+ {...props}
188
+ pattern={pattern}
189
+ className='dx-fullscreen opacity-0'
190
+ style={{
191
+ caretColor: 'transparent',
192
+ ...props.style,
193
+ }}
194
+ />
195
+ {Array.from({ length }, (_, index) => {
196
+ const char = value[index] || '\u00A0';
197
+ const isCursor = !!(inputFocused && index === activeIndex);
198
+ return (
199
+ <div key={index} className={segmentClassName} {...(isCursor && { 'data-focused': '' })} aria-hidden='true'>
200
+ {char}
201
+ </div>
202
+ );
203
+ })}
204
+ </div>
74
205
  );
75
206
  },
76
207
  );
package/src/Root.tsx CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { createContextScope, type Scope } from '@radix-ui/react-context';
5
+ import { type Scope, createContextScope } from '@radix-ui/react-context';
6
6
  import React, { type PropsWithChildren } from 'react';
7
7
 
8
8
  import { useId } from '@dxos/react-hooks';
@@ -51,6 +51,6 @@ const InputRoot = ({
51
51
 
52
52
  InputRoot.displayName = INPUT_NAME;
53
53
 
54
- export { InputRoot, InputRoot as Root, createInputScope, useInputContext, INPUT_NAME };
54
+ export { InputRoot, createInputScope, useInputContext, INPUT_NAME };
55
55
 
56
56
  export type { Valence, InputRootProps, InputScopedProps };
@@ -1,261 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var node_exports = {};
30
- __export(node_exports, {
31
- Description: () => Description,
32
- DescriptionAndValidation: () => DescriptionAndValidation,
33
- ErrorMessage: () => ErrorMessage,
34
- INPUT_NAME: () => INPUT_NAME,
35
- InputRoot: () => InputRoot,
36
- Label: () => Label,
37
- PinInput: () => PinInput,
38
- Root: () => InputRoot,
39
- TextArea: () => TextArea,
40
- TextInput: () => TextInput,
41
- Validation: () => Validation,
42
- createInputScope: () => createInputScope,
43
- useInputContext: () => useInputContext
44
- });
45
- module.exports = __toCommonJS(node_exports);
46
- var import_tracking = require("@preact-signals/safe-react/tracking");
47
- var import_react_primitive = require("@radix-ui/react-primitive");
48
- var import_react_slot = require("@radix-ui/react-slot");
49
- var import_react = __toESM(require("react"));
50
- var import_tracking2 = require("@preact-signals/safe-react/tracking");
51
- var import_react_context = require("@radix-ui/react-context");
52
- var import_react2 = __toESM(require("react"));
53
- var import_react_hooks = require("@dxos/react-hooks");
54
- var import_tracking3 = require("@preact-signals/safe-react/tracking");
55
- var import_rci = require("rci");
56
- var import_react3 = __toESM(require("react"));
57
- var import_react_hooks2 = require("@dxos/react-hooks");
58
- var import_tracking4 = require("@preact-signals/safe-react/tracking");
59
- var import_react_primitive2 = require("@radix-ui/react-primitive");
60
- var import_react4 = __toESM(require("react"));
61
- var import_tracking5 = require("@preact-signals/safe-react/tracking");
62
- var import_react5 = __toESM(require("react"));
63
- var INPUT_NAME = "Input";
64
- var [createInputContext, createInputScope] = (0, import_react_context.createContextScope)(INPUT_NAME, []);
65
- var [InputProvider, useInputContext] = createInputContext(INPUT_NAME);
66
- var InputRoot = ({ __inputScope, id: propsId, descriptionId: propsDescriptionId, errorMessageId: propsErrorMessageId, validationValence = "neutral", children }) => {
67
- var _effect = (0, import_tracking2.useSignals)();
68
- try {
69
- const id = (0, import_react_hooks.useId)("input", propsId);
70
- const descriptionId = (0, import_react_hooks.useId)("input__description", propsDescriptionId);
71
- const errorMessageId = (0, import_react_hooks.useId)("input__error-message", propsErrorMessageId);
72
- return /* @__PURE__ */ import_react2.default.createElement(InputProvider, {
73
- id,
74
- descriptionId,
75
- errorMessageId,
76
- validationValence,
77
- scope: __inputScope
78
- }, children);
79
- } finally {
80
- _effect.f();
81
- }
82
- };
83
- InputRoot.displayName = INPUT_NAME;
84
- var Label = /* @__PURE__ */ (0, import_react.forwardRef)(({ __inputScope, asChild, children, ...props }, forwardedRef) => {
85
- var _effect = (0, import_tracking.useSignals)();
86
- try {
87
- const { id } = useInputContext(INPUT_NAME, __inputScope);
88
- const Root = asChild ? import_react_slot.Slot : import_react_primitive.Primitive.label;
89
- return /* @__PURE__ */ import_react.default.createElement(Root, {
90
- ...props,
91
- htmlFor: id,
92
- ref: forwardedRef
93
- }, children);
94
- } finally {
95
- _effect.f();
96
- }
97
- });
98
- var Description = /* @__PURE__ */ (0, import_react.forwardRef)(({ __inputScope, asChild, children, ...props }, forwardedRef) => {
99
- var _effect = (0, import_tracking.useSignals)();
100
- try {
101
- const { descriptionId, validationValence } = useInputContext(INPUT_NAME, __inputScope);
102
- const Root = asChild ? import_react_slot.Slot : import_react_primitive.Primitive.span;
103
- return /* @__PURE__ */ import_react.default.createElement(Root, {
104
- ...props,
105
- ...validationValence === "error" && {
106
- id: descriptionId
107
- },
108
- ref: forwardedRef
109
- }, children);
110
- } finally {
111
- _effect.f();
112
- }
113
- });
114
- var ErrorMessage = /* @__PURE__ */ (0, import_react.forwardRef)(({ __inputScope, asChild, children, ...props }, forwardedRef) => {
115
- var _effect = (0, import_tracking.useSignals)();
116
- try {
117
- const { errorMessageId } = useInputContext(INPUT_NAME, __inputScope);
118
- const Root = asChild ? import_react_slot.Slot : import_react_primitive.Primitive.span;
119
- return /* @__PURE__ */ import_react.default.createElement(Root, {
120
- ...props,
121
- id: errorMessageId,
122
- ref: forwardedRef
123
- }, children);
124
- } finally {
125
- _effect.f();
126
- }
127
- });
128
- var Validation = /* @__PURE__ */ (0, import_react.forwardRef)((props, forwardedRef) => {
129
- var _effect = (0, import_tracking.useSignals)();
130
- try {
131
- const { __inputScope, asChild, children, ...otherProps } = props;
132
- const { validationValence } = useInputContext(INPUT_NAME, __inputScope);
133
- if (validationValence === "error") {
134
- return /* @__PURE__ */ import_react.default.createElement(ErrorMessage, {
135
- ...props,
136
- ref: forwardedRef
137
- });
138
- } else {
139
- const Root = asChild ? import_react_slot.Slot : import_react_primitive.Primitive.span;
140
- return /* @__PURE__ */ import_react.default.createElement(Root, {
141
- ...otherProps,
142
- ref: forwardedRef
143
- }, children);
144
- }
145
- } finally {
146
- _effect.f();
147
- }
148
- });
149
- var DescriptionAndValidation = /* @__PURE__ */ (0, import_react.forwardRef)(({ __inputScope, asChild, children, ...props }, forwardedRef) => {
150
- var _effect = (0, import_tracking.useSignals)();
151
- try {
152
- const { descriptionId, validationValence } = useInputContext(INPUT_NAME, __inputScope);
153
- const Root = asChild ? import_react_slot.Slot : import_react_primitive.Primitive.p;
154
- return /* @__PURE__ */ import_react.default.createElement(Root, {
155
- ...props,
156
- ...validationValence !== "error" && {
157
- id: descriptionId
158
- },
159
- ref: forwardedRef
160
- }, children);
161
- } finally {
162
- _effect.f();
163
- }
164
- });
165
- var PinInput = /* @__PURE__ */ (0, import_react3.forwardRef)(({ __inputScope, segmentClassName, inputClassName, segmentPadding = "8px", segmentHeight = "100%", ...props }, forwardedRef) => {
166
- var _effect = (0, import_tracking3.useSignals)();
167
- try {
168
- const { id, validationValence, descriptionId, errorMessageId } = useInputContext(INPUT_NAME, __inputScope);
169
- const width = (0, import_rci.getSegmentCssWidth)(segmentPadding);
170
- const inputRef = (0, import_react_hooks2.useForwardedRef)(forwardedRef);
171
- const inputFocused = (0, import_react_hooks2.useIsFocused)(inputRef);
172
- const renderSegment = (0, import_react3.useCallback)(({ state, index }) => /* @__PURE__ */ import_react3.default.createElement("div", {
173
- key: index,
174
- className: segmentClassName?.({
175
- focused: !!(inputFocused && state),
176
- validationValence
177
- }),
178
- "data-state": state,
179
- style: {
180
- width,
181
- height: segmentHeight
182
- }
183
- }), [
184
- segmentClassName,
185
- inputFocused,
186
- validationValence
187
- ]);
188
- return /* @__PURE__ */ import_react3.default.createElement(import_rci.CodeInput, {
189
- padding: "8px",
190
- spacing: "8px",
191
- fontFamily: "",
192
- spellCheck: false,
193
- length: 6,
194
- ...props,
195
- id,
196
- "aria-describedby": descriptionId,
197
- ...validationValence === "error" && {
198
- "aria-invalid": "true",
199
- "aria-errormessage": errorMessageId
200
- },
201
- inputRef,
202
- renderSegment,
203
- className: inputClassName
204
- });
205
- } finally {
206
- _effect.f();
207
- }
208
- });
209
- var TextInput = /* @__PURE__ */ (0, import_react4.forwardRef)(({ __inputScope, ...props }, forwardedRef) => {
210
- var _effect = (0, import_tracking4.useSignals)();
211
- try {
212
- const { id, validationValence, descriptionId, errorMessageId } = useInputContext(INPUT_NAME, __inputScope);
213
- return /* @__PURE__ */ import_react4.default.createElement(import_react_primitive2.Primitive.input, {
214
- ...props,
215
- id,
216
- "aria-describedby": descriptionId,
217
- ...validationValence === "error" && {
218
- "aria-invalid": "true",
219
- "aria-errormessage": errorMessageId
220
- },
221
- ref: forwardedRef
222
- });
223
- } finally {
224
- _effect.f();
225
- }
226
- });
227
- var TextArea = /* @__PURE__ */ (0, import_react5.forwardRef)(({ __inputScope, ...props }, forwardedRef) => {
228
- var _effect = (0, import_tracking5.useSignals)();
229
- try {
230
- const { id, validationValence, descriptionId, errorMessageId } = useInputContext(INPUT_NAME, __inputScope);
231
- return /* @__PURE__ */ import_react5.default.createElement("textarea", {
232
- ...props,
233
- id,
234
- "aria-describedby": descriptionId,
235
- ...validationValence === "error" && {
236
- "aria-invalid": "true",
237
- "aria-errormessage": errorMessageId
238
- },
239
- ref: forwardedRef
240
- });
241
- } finally {
242
- _effect.f();
243
- }
244
- });
245
- // Annotate the CommonJS export names for ESM import in node:
246
- 0 && (module.exports = {
247
- Description,
248
- DescriptionAndValidation,
249
- ErrorMessage,
250
- INPUT_NAME,
251
- InputRoot,
252
- Label,
253
- PinInput,
254
- Root,
255
- TextArea,
256
- TextInput,
257
- Validation,
258
- createInputScope,
259
- useInputContext
260
- });
261
- //# sourceMappingURL=index.cjs.map