reactjs-virtual-keyboard 1.0.2 → 2.0.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.
package/dist/index.d.ts CHANGED
@@ -8,22 +8,44 @@ export declare const BackspaceIcon: FC<IconProps>;
8
8
 
9
9
  export declare const CapsLockIcon: FC<IconProps>;
10
10
 
11
+ export declare interface ContinuousPressConfig {
12
+ /** Delay before continuous press starts (ms) */
13
+ initialDelay?: number;
14
+ /** Interval between repeated presses (ms) */
15
+ interval?: number;
16
+ }
17
+
11
18
  export declare interface ContinuousPressOptions {
12
19
  initialDelay?: number;
13
20
  interval?: number;
14
21
  shouldPreventDefault?: boolean;
15
22
  }
16
23
 
24
+ /**
25
+ * Creates a caret manager for manipulating text in input elements.
26
+ * This is a pure utility that doesn't use React hooks.
27
+ *
28
+ * @param getInputRef - Function that returns the current input element ref
29
+ * @returns Object with insertText and backspace functions
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * const inputRef = useRef<HTMLInputElement>(null);
34
+ * const { insertText, backspace } = createCaretManager(() => inputRef.current);
35
+ * ```
36
+ */
37
+ export declare function createCaretManager(getInputRef: () => InputElement | null): UseCaretManagerReturn;
38
+
17
39
  export declare const DEFAULT_THEME: {
18
- backgroundColor: string;
19
- keyColor: string;
20
- keyTextColor: string;
21
- keyActiveColor: string;
22
- keyHoverColor: string;
23
- activeStateColor: string;
24
- keyBorderRadius: string;
25
- keyFontSize: string;
26
- keyHeight: string;
40
+ readonly backgroundColor: "#1a1a1a";
41
+ readonly keyColor: "#444444";
42
+ readonly keyTextColor: "#ffffff";
43
+ readonly keyActiveColor: "#666666";
44
+ readonly keyHoverColor: "#555555";
45
+ readonly activeStateColor: "#4a90e2";
46
+ readonly keyBorderRadius: "0.5vw";
47
+ readonly keyFontSize: "32px";
48
+ readonly keyHeight: "100%";
27
49
  };
28
50
 
29
51
  export declare const EnterIcon: FC<IconProps>;
@@ -129,7 +151,12 @@ export declare interface KeyboardLayoutProps {
129
151
  onSpace: () => void;
130
152
  onCapsToggle: () => void;
131
153
  onLayoutToggle: () => void;
132
- inputType: HTMLInputTypeAttribute;
154
+ inputType?: HTMLInputTypeAttribute;
155
+ customLayouts?: {
156
+ letters?: string[][];
157
+ symbols?: string[][];
158
+ numbers?: string[][];
159
+ };
133
160
  }
134
161
 
135
162
  export declare const KeyboardRow: FC<KeyboardRowProps>;
@@ -141,12 +168,12 @@ export declare interface KeyboardRowProps {
141
168
 
142
169
  export declare type LayoutType = 'letters' | 'symbols' | 'numbers';
143
170
 
144
- export declare const NUMBERS_LAYOUT: string[][];
171
+ export declare const NUMBERS_LAYOUT: readonly [readonly ["7", "8", "9", "#"], readonly ["4", "5", "6", "-"], readonly ["1", "2", "3"], readonly [",", "0", "."]];
145
172
 
146
173
  export declare const NumbersLayout: FC<NumbersLayoutProps>;
147
174
 
148
175
  export declare interface NumbersLayoutProps {
149
- currentLayoutData: string[][];
176
+ currentLayoutData: ReadonlyArray<ReadonlyArray<string>> | string[][];
150
177
  onBackspace: () => void;
151
178
  onEnter: () => void;
152
179
  onKeyClick: (key: string) => void;
@@ -159,13 +186,20 @@ export declare interface NumbersLayoutProps {
159
186
  */
160
187
  export declare const onEnterClickUtil: (focusedInputRef: FocusedInputRef) => void;
161
188
 
162
- export declare const QWERTY_LAYOUT: string[][];
189
+ export declare const QWERTY_LAYOUT: readonly [readonly ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"], readonly ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"], readonly ["a", "s", "d", "f", "g", "h", "j", "k", "l"], readonly ["z", "x", "c", "v", "b", "n", "m"]];
163
190
 
164
191
  /**
165
192
  * Reset scroll position by removing transforms from shifted elements
166
193
  */
167
194
  export declare function resetScrollPosition(): void;
168
195
 
196
+ export declare interface ScrollConfig {
197
+ /** Enable automatic scrolling when keyboard appears */
198
+ enabled?: boolean;
199
+ /** Additional offset padding (px) */
200
+ offset?: number;
201
+ }
202
+
169
203
  /**
170
204
  * Utility functions to handle layout shifting when virtual keyboard appears
171
205
  */
@@ -182,6 +216,27 @@ export declare const setInputValueAndDispatchEvents: (input: InputElement, value
182
216
  skipValueAssignment?: boolean;
183
217
  }) => void;
184
218
 
219
+ /**
220
+ * Sets up hardware keyboard event listeners to sync with virtual keyboard.
221
+ * This is a pure utility that returns a cleanup function.
222
+ *
223
+ * @param handlers - Handlers for keyboard events
224
+ * @returns Cleanup function to remove event listeners
225
+ *
226
+ * @example
227
+ * ```tsx
228
+ * useEffect(() => {
229
+ * if (!isInputFocused) return;
230
+ * return setupHardwareKeyboard({
231
+ * onBackspace: handleBackspace,
232
+ * onEnter: handleEnter,
233
+ * // ...
234
+ * });
235
+ * }, [isInputFocused, handleBackspace, handleEnter]);
236
+ * ```
237
+ */
238
+ export declare function setupHardwareKeyboard(handlers: Omit<HardwareKeyboardHandlers, 'isInputFocused'>): () => void;
239
+
185
240
  export declare const SpacebarIcon: FC<IconProps>;
186
241
 
187
242
  export declare const SpecialKey: FC<SpecialKeyProps>;
@@ -196,13 +251,13 @@ export declare interface SpecialKeyProps {
196
251
  enableContinuousPress?: boolean;
197
252
  }
198
253
 
199
- export declare const SYMBOLS_LAYOUT: string[][];
254
+ export declare const SYMBOLS_LAYOUT: readonly [readonly ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"], readonly ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")"], readonly ["-", "_", "=", "+", "[", "]", "{", "}", "\\", "|"], readonly [";", ":", "\"", "'", ",", ".", "<", ">", "/", "?"]];
200
255
 
201
256
  export declare const TextLayout: FC<TextLayoutProps>;
202
257
 
203
258
  export declare interface TextLayoutProps {
204
- inputType: HTMLInputTypeAttribute;
205
- currentLayoutData: string[][];
259
+ inputType?: HTMLInputTypeAttribute;
260
+ currentLayoutData: ReadonlyArray<ReadonlyArray<string>> | string[][];
206
261
  onBackspace: () => void;
207
262
  onEnter: () => void;
208
263
  onSpace: () => void;
@@ -213,11 +268,6 @@ export declare interface TextLayoutProps {
213
268
  currentLayout: LayoutType;
214
269
  }
215
270
 
216
- /**
217
- * Hook to manage caret position and text insertion/deletion in input elements
218
- */
219
- export declare function useCaretManager(focusedInputRef: RefObject<InputElement | null>): UseCaretManagerReturn;
220
-
221
271
  export declare interface UseCaretManagerReturn {
222
272
  insertText: (text: string) => void;
223
273
  backspace: () => void;
@@ -234,12 +284,6 @@ export declare function useContinuousPress(onPress: () => void, { initialDelay,
234
284
  onTouchEnd: (e: React.TouchEvent) => void;
235
285
  };
236
286
 
237
- /**
238
- * Hook to keep virtual keyboard in sync with hardware keyboard events
239
- * (e.g., when pressing caps lock on hardware keyboard, virtual keyboard should reflect it)
240
- */
241
- export declare function useHardwareKeyboard({ isInputFocused, onBackspace, onEnter, onSpace, onCapsToggle, onKeyClick, }: HardwareKeyboardHandlers): void;
242
-
243
287
  /**
244
288
  * Hook to handle keyboard scrolling for input elements.
245
289
  * Automatically shifts content up when the virtual keyboard would cover the input.
@@ -314,6 +358,43 @@ export declare interface VirtualKeyboardProps {
314
358
  validate?: (value: string) => boolean;
315
359
  /** Theme configuration */
316
360
  theme?: VirtualKeyboardTheme;
361
+ /** Custom keyboard layouts (overrides default layouts) */
362
+ customLayouts?: {
363
+ letters?: string[][];
364
+ symbols?: string[][];
365
+ numbers?: string[][];
366
+ };
367
+ /** Continuous press configuration for backspace */
368
+ continuousPressConfig?: ContinuousPressConfig;
369
+ /** Scroll behavior configuration */
370
+ scrollConfig?: ScrollConfig;
371
+ /** Enable/disable hardware keyboard synchronization */
372
+ syncWithHardwareKeyboard?: boolean;
373
+ /** Custom key labels (e.g., { 'enter': 'Submit', 'space': 'Space Bar' }) */
374
+ keyLabels?: Record<string, string>;
375
+ /** Keys to hide from the keyboard */
376
+ hiddenKeys?: string[];
377
+ /** Keys to disable (grayed out and non-clickable) */
378
+ disabledKeys?: string[];
379
+ /** Custom render function for individual keys */
380
+ renderKey?: (key: string, defaultRender: ReactNode) => ReactNode;
381
+ /** Custom render function for special keys */
382
+ renderSpecialKey?: (type: string, defaultRender: ReactNode) => ReactNode;
383
+ /** Multi-language keyboard layouts */
384
+ languages?: {
385
+ [languageCode: string]: {
386
+ letters?: string[][];
387
+ symbols?: string[][];
388
+ numbers?: string[][];
389
+ label?: string;
390
+ };
391
+ };
392
+ /** Currently selected language code */
393
+ currentLanguage?: string;
394
+ /** Callback when language changes */
395
+ onLanguageChange?: (languageCode: string) => void;
396
+ /** Show language switcher button */
397
+ showLanguageSwitcher?: boolean;
317
398
  }
318
399
 
319
400
  export declare interface VirtualKeyboardTheme {