react-scan-engine
v0.1.3
Published
Tiny React wrapper for scan-engine with react-scannable-like Scanner/Scannable components.
Downloads
8
Readme
react-scan-engine
Tiny React wrapper around scan-engine with a familiar react-scannable style API.
Install
npm install react-scan-engine scan-engineQuick start
import React from 'react';
import { Scanner, Scannable } from 'react-scan-engine';
export function Example() {
return (
<Scanner active>
<Scannable><button onClick={() => alert('A')}>A</button></Scannable>
<Scannable><button onClick={() => alert('B')}>B</button></Scannable>
<Scannable><button onClick={() => alert('C')}>C</button></Scannable>
</Scanner>
);
}Compatibility notes
Scanner+Scannablepattern is compatible with thereact-scannablestyle.activeis supported.- Default keyboard mapping:
Enter/Space->selectArrowRight/ArrowDown->stepBackspace->resetEscape->cancel
- Focused items get
scan-focusanddata-scan-focused="true". - Selected items briefly get
data-scan-selected="true".
Why use this wrapper
You can keep React ergonomics while using the richer scan engine features from scan-engine:
- row/column, linear, snake, quadrant, elimination
- continuous, probability, cause/effect, color-code modes
- overscan, loop controls, configurable timing
Pass engine options through config:
<Scanner
active={isActive}
columns={4}
config={{
scanPattern: 'row-column',
scanTechnique: 'block',
scanInputMode: 'auto',
scanRate: 900
}}
/>API
Scanner
Props:
active?: booleancolumns?: numberconfig?: PartialScanConfigonSelect?: (index: number, element: HTMLElement | null) => voidkeyMap?: Partial<Record<string, SwitchAction>>- plus normal
divprops
Scannable
Props:
children: ReactElement(single child)className?: string(merged onto child)
