|
| 1 | +import { useKeyFilter } from '@primereact/hooks'; |
| 2 | +import { InputText } from 'primereact/inputtext'; |
| 3 | +import { Label } from 'primereact/label'; |
| 4 | +import * as React from 'react'; |
| 5 | + |
| 6 | +export default function PatternDemo() { |
| 7 | + const { onKeyPress: onIntegerKeyPress } = useKeyFilter({ pattern: 'int' }); |
| 8 | + const { onKeyPress: onNumberKeyPress } = useKeyFilter({ pattern: 'num' }); |
| 9 | + const { onKeyPress: onMoneyKeyPress } = useKeyFilter({ pattern: 'money' }); |
| 10 | + const { onKeyPress: onHexKeyPress } = useKeyFilter({ pattern: 'hex' }); |
| 11 | + const { onKeyPress: onAlphaKeyPress } = useKeyFilter({ pattern: 'alpha' }); |
| 12 | + const { onKeyPress: onAlphanumKeyPress } = useKeyFilter({ pattern: 'alphanum' }); |
| 13 | + |
| 14 | + const [integer, setInteger] = React.useState(''); |
| 15 | + const [number, setNumber] = React.useState(''); |
| 16 | + const [money, setMoney] = React.useState(''); |
| 17 | + const [hex, setHex] = React.useState(''); |
| 18 | + const [alphabetic, setAlphabetic] = React.useState(''); |
| 19 | + const [alphanumeric, setAlphanumeric] = React.useState(''); |
| 20 | + |
| 21 | + return ( |
| 22 | + <div className="card"> |
| 23 | + <div className="flex flex-wrap gap-3 mb-4"> |
| 24 | + <div className="flex-auto"> |
| 25 | + <Label htmlFor="integer" className="font-bold block mb-2"> |
| 26 | + Integer |
| 27 | + </Label> |
| 28 | + <InputText id="integer" value={integer} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setInteger(e.target.value)} onKeyPress={onIntegerKeyPress} className="w-full" /> |
| 29 | + </div> |
| 30 | + <div className="flex-auto"> |
| 31 | + <Label htmlFor="number" className="font-bold block mb-2"> |
| 32 | + Number |
| 33 | + </Label> |
| 34 | + <InputText id="number" value={number} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNumber(e.target.value)} onKeyPress={onNumberKeyPress} className="w-full" /> |
| 35 | + </div> |
| 36 | + <div className="flex-auto"> |
| 37 | + <Label htmlFor="money" className="font-bold block mb-2"> |
| 38 | + Money |
| 39 | + </Label> |
| 40 | + <InputText id="money" value={money} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setMoney(e.target.value)} onKeyPress={onMoneyKeyPress} className="w-full" /> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + <div className="flex flex-wrap gap-3"> |
| 44 | + <div className="flex-auto"> |
| 45 | + <Label htmlFor="hex" className="font-bold block mb-2"> |
| 46 | + Hex |
| 47 | + </Label> |
| 48 | + <InputText id="hex" value={hex} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setHex(e.target.value)} onKeyPress={onHexKeyPress} className="w-full" /> |
| 49 | + </div> |
| 50 | + <div className="flex-auto"> |
| 51 | + <Label htmlFor="alphabetic" className="font-bold block mb-2"> |
| 52 | + Alphabetic |
| 53 | + </Label> |
| 54 | + <InputText id="alphabetic" value={alphabetic} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setAlphabetic(e.target.value)} onKeyPress={onAlphaKeyPress} className="w-full" /> |
| 55 | + </div> |
| 56 | + <div className="flex-auto"> |
| 57 | + <Label htmlFor="alphanumeric" className="font-bold block mb-2"> |
| 58 | + Alphanumeric |
| 59 | + </Label> |
| 60 | + <InputText id="alphanumeric" value={alphanumeric} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setAlphanumeric(e.target.value)} onKeyPress={onAlphanumKeyPress} className="w-full" /> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + ); |
| 65 | +} |
0 commit comments