Library created for implements super power in input.
npm i @sajermann/react-input
import { Input, ISajermannReactInput } from '@sajermann/ui-react';
label?: string; Note: Override in label attribute input;
labelProps?: React.DetailedHTMLProps<LabelHTMLAttributes, HTMLLabelElement>;
containerProps?: React.DetailedHTMLProps<React.HTMLAttributes, HTMLDivElement>;
onChange?: (e: React.ChangeEvent) => void;
onBeforeChange?: { Â Â Â Â removeNumber?: boolean; Â Â Â Â removeLetterUpper?: boolean; Â Â Â Â removeLetterLow?: boolean; Â Â Â Â removeSpecialCharacter?: boolean; Â Â Â Â regexForReplace?: RegExp; Â Â Â Â fn?: (e: React.ChangeEvent) => React.ChangeEvent; };
applyMask?: TCurrency | TCnpj | TCpf | TCep;
debounce?: number;
<Input
placeholder="Simple Label"
id="Simple Label"
label="Simple Label"
/><Input
placeholder="Label Props"
labelProps={{
children: 'Test',
style: { color: 'red' },
}}
id="Label Props"
/><Input
placeholder="Container Props"
id="Container Props"
label="Container Props"
containerProps={{
style: {
display: 'flex',
flexDirection: 'column',
border: '1px solid',
width: 300,
},
}}
/><Input
placeholder="On Change"
onChange={e => console.log(e.target.value)}
/><Input
placeholder="Remove Number"
onBeforeChange={{ removeNumber: true }}
/><Input
placeholder="Remove Upper Case"
onBeforeChange={{ removeUpperCase: true }}
/><Input
placeholder="Remove Lower Case"
onBeforeChange={{ removeLowerCase: true }}
/><Input
placeholder="Remove Special Character"
onBeforeChange={{ removeSpecialCharacter: true }}
/><Input
placeholder="Remove numbers from 1 to 5"
onBeforeChange={{ regexForReplace: /[1-5]/g }}
/><Input
placeholder="Function Before Change"
onChange={e => console.log(e.target.value)}
onBeforeChange={{
fn: e => {
const temp = { ...e };
temp.target.value = addMessage(temp.target.value); // Any Custom Function
return temp;
},
}}
/><Input
placeholder="Apply Mask - Currency"
onBeforeChange={{
applyMask: {
currency: {
decimalPlace: 2,
},
},
}}
/><Input
placeholder="Apply Mask - Cnpj"
onBeforeChange={{
applyMask: {
cnpj: true,
},
}}
/><Input
placeholder="Apply Mask - Cpf"
onBeforeChange={{
applyMask: {
cpf: true,
},
}}
/><Input
placeholder="Apply Mask - Cep"
onBeforeChange={{
applyMask: {
cep: true,
},
}}
/><Input
placeholder="Debounce 2 seconds"
onChange={e => console.log(e.target.value)}
debounce={2000}
/><Input
placeholder="Controlled"
onChange={e => setControlledValue(e.target.value)}
value={controlledValue}
/>
Controlled Value: {controlledValue}const ref = useRef<HTMLInputElement>(null);
<Input ref={ref} placeholder="Ref - Focus" />
<button
type="button"
style={{ width: 173 }}
onClick={() => ref.current?.focus()}
>
Focus
</button><Input
placeholder="Errors"
containerProps={{
style: {
display: 'flex',
flexDirection: 'column',
width: 173,
},
}}
errorContainerProps={{
style: {
display: 'flex',
flexDirection: 'column',
color: 'red',
fontSize: 14,
},
}}
errors={['Required', 'Invalid email adress']}
/><Input
placeholder="Render Top"
renderTop={<div>Element In Top</div>}
/><Input
placeholder="Custom Error"
renderBottom={
<div
style={{
position: 'absolute',
top: 2,
right: 10,
color: 'black',
cursor: 'pointer',
}}
title="Invalid email adress"
>
i
</div>
}
/>