@lynx-js/lynx-ui-input-otp 0.0.0-oidc-bootstrap.0 → 3.136.0

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.
@@ -0,0 +1,397 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import type { ForwardedRef, ReactElement, ReactNode } from '@lynx-js/react'
6
+
7
+ import type { ComponentBasicProps } from '@lynx-js/lynx-ui-common'
8
+
9
+ /**
10
+ * Positive number of slots managed by InputOTP.
11
+ * @zh InputOTP 管理的输入槽数量,必须为正整数。
12
+ */
13
+ export type InputOTPLength = number
14
+
15
+ /**
16
+ * Character set accepted by InputOTP.
17
+ * @zh InputOTP 接受的字符集。
18
+ */
19
+ export type InputOTPInputType =
20
+ | 'alphabetic'
21
+ | 'numeric'
22
+ | 'alphanumeric'
23
+
24
+ /**
25
+ * State exposed to an InputOTP render function.
26
+ * @zh 暴露给 InputOTP 渲染函数的状态。
27
+ */
28
+ export interface InputOTPRenderProps {
29
+ /**
30
+ * The normalized OTP or PIN value.
31
+ * @zh 规范化后的 OTP 或 PIN 值。
32
+ */
33
+ value: string
34
+
35
+ /**
36
+ * The configured field length.
37
+ * @zh 配置的输入长度。
38
+ */
39
+ length: InputOTPLength
40
+
41
+ /**
42
+ * The configured input character set.
43
+ * @zh 配置的输入字符集。
44
+ */
45
+ inputType: InputOTPInputType
46
+
47
+ /**
48
+ * Whether the hidden native input is focused.
49
+ * @zh 隐藏的原生输入框是否聚焦。
50
+ */
51
+ focused: boolean
52
+
53
+ /**
54
+ * Whether every slot is filled.
55
+ * @zh 是否所有输入槽均已填充。
56
+ */
57
+ complete: boolean
58
+
59
+ /**
60
+ * Whether input is disabled.
61
+ * @zh 输入是否已禁用。
62
+ */
63
+ disabled: boolean
64
+
65
+ /**
66
+ * Whether the field is invalid.
67
+ * @zh 输入是否处于无效状态。
68
+ */
69
+ invalid: boolean
70
+ }
71
+
72
+ /**
73
+ * State exposed to an InputOTPSlot render function.
74
+ * @zh 暴露给 InputOTPSlot 渲染函数的状态。
75
+ */
76
+ export interface InputOTPSlotRenderProps {
77
+ /**
78
+ * Zero-based slot index.
79
+ * @zh 从零开始的输入槽索引。
80
+ */
81
+ index: number
82
+
83
+ /**
84
+ * Character displayed by this slot.
85
+ * @zh 当前输入槽展示的字符。
86
+ */
87
+ char?: string
88
+
89
+ /**
90
+ * Whether this is the focused slot that contains the visual caret.
91
+ * @zh 当前输入槽是否为包含可视光标的聚焦槽。
92
+ */
93
+ focused: boolean
94
+
95
+ /**
96
+ * Whether this slot contains a character.
97
+ * @zh 当前输入槽是否已经包含字符。
98
+ */
99
+ filled: boolean
100
+
101
+ /**
102
+ * Whether every slot in the field is filled.
103
+ * @zh 当前输入框中的所有输入槽是否均已填充。
104
+ */
105
+ complete: boolean
106
+
107
+ /**
108
+ * Whether input is disabled.
109
+ * @zh 输入是否已禁用。
110
+ */
111
+ disabled: boolean
112
+
113
+ /**
114
+ * Whether the field is invalid.
115
+ * @zh 输入是否处于无效状态。
116
+ */
117
+ invalid: boolean
118
+ }
119
+
120
+ /**
121
+ * UI variants injected by InputOTP for state-based styling.
122
+ * @zh InputOTP 注入的 UI variants,可用于按状态定制样式。
123
+ */
124
+ export interface InputOTPUIVariants {
125
+ /**
126
+ * Applied to the root while the hidden input is focused.
127
+ * @zh 隐藏输入框聚焦时应用于根节点。
128
+ */
129
+ 'ui-focused'?: boolean
130
+
131
+ /**
132
+ * Applied to the root when every slot is filled.
133
+ * @zh 所有输入槽均已填充时应用于根节点。
134
+ */
135
+ 'ui-complete'?: boolean
136
+
137
+ /**
138
+ * Applied to the root while input is disabled.
139
+ * @zh 禁用输入时应用于根节点。
140
+ */
141
+ 'ui-disabled'?: boolean
142
+
143
+ /**
144
+ * Applied to the root while the value is invalid.
145
+ * @zh 输入值无效时应用于根节点。
146
+ */
147
+ 'ui-invalid'?: boolean
148
+ }
149
+
150
+ /**
151
+ * UI variants injected by InputOTPSlot for state-based styling.
152
+ * @zh InputOTPSlot 注入的 UI variants,可用于按状态定制样式。
153
+ */
154
+ export interface InputOTPSlotUIVariants {
155
+ /**
156
+ * Applied to the slot that contains the visual caret.
157
+ * @zh 应用于包含可视光标的输入槽。
158
+ */
159
+ 'ui-focused'?: boolean
160
+
161
+ /**
162
+ * Applied to slots that contain a character.
163
+ * @zh 应用于已经包含字符的输入槽。
164
+ */
165
+ 'ui-filled'?: boolean
166
+
167
+ /**
168
+ * Applied to every slot when the field is complete.
169
+ * @zh 输入完成时应用于每个输入槽。
170
+ */
171
+ 'ui-complete'?: boolean
172
+
173
+ /**
174
+ * Applied to the slot while input is disabled.
175
+ * @zh 禁用输入时应用于输入槽。
176
+ */
177
+ 'ui-disabled'?: boolean
178
+
179
+ /**
180
+ * Applied to the slot while the value is invalid.
181
+ * @zh 输入值无效时应用于输入槽。
182
+ */
183
+ 'ui-invalid'?: boolean
184
+ }
185
+
186
+ /**
187
+ * Imperative methods exposed by InputOTP.
188
+ * @zh InputOTP 暴露的命令式方法。
189
+ */
190
+ export interface InputOTPRef {
191
+ /**
192
+ * Focus the hidden native input and show the configured keyboard.
193
+ * @zh 聚焦隐藏的原生输入框并唤起配置的键盘。
194
+ * @Android
195
+ * @iOS
196
+ * @Harmony
197
+ */
198
+ focus: () => Promise<void>
199
+
200
+ /**
201
+ * Blur the hidden native input and dismiss the keyboard.
202
+ * @zh 让隐藏的原生输入框失焦并收起键盘。
203
+ * @Android
204
+ * @iOS
205
+ * @Harmony
206
+ */
207
+ blur: () => Promise<void>
208
+
209
+ /**
210
+ * Replace the current uncontrolled value. In controlled mode, this requests
211
+ * the next value through onChange and the value prop remains authoritative.
212
+ * Unsupported characters are discarded.
213
+ * @zh 替换当前非受控值。在受控模式下,该方法通过 onChange 请求新值,
214
+ * value 属性仍是唯一数据源。不支持的字符会被丢弃。
215
+ * @Android
216
+ * @iOS
217
+ * @Harmony
218
+ */
219
+ setValue: (value: string) => Promise<void>
220
+
221
+ /**
222
+ * Clear the current uncontrolled value. In controlled mode, update the
223
+ * value prop from the onChange callback.
224
+ * @zh 清空当前非受控值。在受控模式下,请通过 onChange 回调更新 value 属性。
225
+ * @Android
226
+ * @iOS
227
+ * @Harmony
228
+ */
229
+ clear: () => Promise<void>
230
+
231
+ /**
232
+ * Return the currently displayed value.
233
+ * @zh 返回当前展示的值。
234
+ * @Android
235
+ * @iOS
236
+ * @Harmony
237
+ */
238
+ getValue: () => string
239
+ }
240
+
241
+ /**
242
+ * Props for InputOTP.
243
+ * @zh InputOTP 属性。
244
+ */
245
+ export interface InputOTPProps extends ComponentBasicProps {
246
+ ref?: ForwardedRef<InputOTPRef>
247
+
248
+ /**
249
+ * Positive number of OTP or PIN characters. Invalid values fall back to 6.
250
+ * @defaultValue 6
251
+ * @zh OTP 或 PIN 字符数,必须为正整数。无效值会回退为 6。
252
+ * @Android
253
+ * @iOS
254
+ * @Harmony
255
+ */
256
+ length?: InputOTPLength
257
+
258
+ /**
259
+ * Character set accepted by the hidden native input.
260
+ * @defaultValue "numeric"
261
+ * @zh 隐藏的原生输入框接受的字符集。
262
+ * @Android
263
+ * @iOS
264
+ * @Harmony
265
+ */
266
+ inputType?: InputOTPInputType
267
+
268
+ /**
269
+ * Controlled value. Characters outside inputType are discarded.
270
+ * @zh 受控值;不符合 inputType 的字符会被丢弃。
271
+ * @Android
272
+ * @iOS
273
+ * @Harmony
274
+ */
275
+ value?: string
276
+
277
+ /**
278
+ * Initial value in uncontrolled mode.
279
+ * @zh 非受控模式下的初始值。
280
+ * @Android
281
+ * @iOS
282
+ * @Harmony
283
+ */
284
+ defaultValue?: string
285
+
286
+ /**
287
+ * Focus the hidden input after mounting.
288
+ * @defaultValue false
289
+ * @zh 挂载后自动聚焦隐藏输入框。
290
+ * @Android
291
+ * @iOS
292
+ * @Harmony
293
+ */
294
+ autoFocus?: boolean
295
+
296
+ /**
297
+ * Disable keyboard input and focus.
298
+ * @defaultValue false
299
+ * @zh 禁用键盘输入和聚焦。
300
+ * @Android
301
+ * @iOS
302
+ * @Harmony
303
+ */
304
+ disabled?: boolean
305
+
306
+ /**
307
+ * Expose the invalid state to render props and the ui-invalid variant.
308
+ * @defaultValue false
309
+ * @zh 通过渲染属性和 ui-invalid variant 暴露无效状态。
310
+ * @Android
311
+ * @iOS
312
+ * @Harmony
313
+ */
314
+ invalid?: boolean
315
+
316
+ /**
317
+ * InputOTPSlot children, or a render function receiving the field state.
318
+ * InputOTP does not create slots automatically.
319
+ * @zh InputOTPSlot 子节点,或接收输入状态的渲染函数。InputOTP
320
+ * 不会自动创建输入槽。
321
+ * @docTypeFallback ReactNode | ((state: InputOTPRenderProps) => ReactNode)
322
+ * @Android
323
+ * @iOS
324
+ * @Harmony
325
+ */
326
+ children?:
327
+ | ReactNode
328
+ | ((state: InputOTPRenderProps) => ReactNode)
329
+
330
+ /**
331
+ * Called after the normalized value changes.
332
+ * @zh 规范化后的值变化时触发。
333
+ * @Android
334
+ * @iOS
335
+ * @Harmony
336
+ */
337
+ onChange?: (value: string) => void
338
+
339
+ /**
340
+ * Called when the value transitions from incomplete to complete.
341
+ * @zh 输入值从未完成变为完整时触发。
342
+ * @Android
343
+ * @iOS
344
+ * @Harmony
345
+ */
346
+ onComplete?: (value: string) => void
347
+
348
+ /**
349
+ * Called when the hidden input gains focus.
350
+ * @zh 隐藏输入框聚焦时触发。
351
+ * @Android
352
+ * @iOS
353
+ * @Harmony
354
+ */
355
+ onFocus?: () => void
356
+
357
+ /**
358
+ * Called when the hidden input loses focus.
359
+ * @zh 隐藏输入框失焦时触发。
360
+ * @Android
361
+ * @iOS
362
+ * @Harmony
363
+ */
364
+ onBlur?: () => void
365
+ }
366
+
367
+ /**
368
+ * Props for an individual InputOTP visual slot.
369
+ * @zh 单个 InputOTP 可视输入槽的属性。
370
+ */
371
+ export interface InputOTPSlotProps extends ComponentBasicProps {
372
+ /**
373
+ * Zero-based index used to read the corresponding InputOTP character.
374
+ * @zh 从零开始的索引,用于读取 InputOTP 中对应的字符。
375
+ * @Android
376
+ * @iOS
377
+ * @Harmony
378
+ */
379
+ index: number
380
+
381
+ /**
382
+ * Custom slot content. A render function receives the slot state.
383
+ * When omitted, InputOTPSlot renders its character and visual caret.
384
+ * @zh 自定义输入槽内容。渲染函数会接收输入槽状态。省略时,
385
+ * InputOTPSlot 会渲染默认字符和可视光标。
386
+ * @docTypeFallback ReactNode | ((state: InputOTPSlotRenderProps) => ReactNode)
387
+ * @Android
388
+ * @iOS
389
+ * @Harmony
390
+ */
391
+ children?:
392
+ | ReactNode
393
+ | ((state: InputOTPSlotRenderProps) => ReactNode)
394
+ }
395
+
396
+ export type InputOTP = (props: InputOTPProps) => ReactElement
397
+ export type InputOTPSlot = (props: InputOTPSlotProps) => ReactElement
@@ -0,0 +1,5 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ export type * from './index.docs'
package/src/utils.ts ADDED
@@ -0,0 +1,29 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import type { InputOTPInputType, InputOTPLength } from './types'
6
+
7
+ const inputPatterns: Record<InputOTPInputType, RegExp> = {
8
+ alphabetic: /[^a-z]/gi,
9
+ numeric: /\D/g,
10
+ alphanumeric: /[^a-z0-9]/gi,
11
+ }
12
+
13
+ export const nativeInputFilters: Record<InputOTPInputType, string> = {
14
+ alphabetic: '[A-Za-z]',
15
+ numeric: '[0-9]',
16
+ alphanumeric: '[A-Za-z0-9]',
17
+ }
18
+
19
+ export function normalizeInputOTPLength(length: number): InputOTPLength {
20
+ return Number.isInteger(length) && length > 0 ? length : 6
21
+ }
22
+
23
+ export function normalizeOTPValue(
24
+ value: string,
25
+ length: InputOTPLength,
26
+ inputType: InputOTPInputType = 'numeric',
27
+ ): string {
28
+ return value.replace(inputPatterns[inputType], '').slice(0, length)
29
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tools/configs/tsconfig.docs.json",
3
+ "include": [
4
+ "src",
5
+ "dist/types/index.docs.d.ts"
6
+ ]
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tools/configs/tsconfig.lib.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ },
6
+ "include": [
7
+ "src",
8
+ ],
9
+ }