Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@chakra-ui/pin-input
Advanced tools
A React component optimized for entering sequences of digits
@chakra-ui/pin-input is a component library for creating PIN input fields in React applications. It provides a set of components that make it easy to build PIN input forms with various customization options, such as managing focus, handling input values, and styling.
Basic PIN Input
This code demonstrates a basic PIN input with four fields. The `PinInput` component wraps around `PinInputField` components to create a PIN input form.
```jsx
import { PinInput, PinInputField } from '@chakra-ui/pin-input';
function BasicPinInput() {
return (
<PinInput>
<PinInputField />
<PinInputField />
<PinInputField />
<PinInputField />
</PinInput>
);
}
```
Controlled PIN Input
This code demonstrates a controlled PIN input where the value is managed by the component's state. The `value` and `onChange` props are used to control the input.
```jsx
import { useState } from 'react';
import { PinInput, PinInputField } from '@chakra-ui/pin-input';
function ControlledPinInput() {
const [value, setValue] = useState('');
return (
<PinInput value={value} onChange={setValue}>
<PinInputField />
<PinInputField />
<PinInputField />
<PinInputField />
</PinInput>
);
}
```
Custom Length PIN Input
This code demonstrates a PIN input with a custom length of six fields. The `length` prop is used to specify the number of input fields.
```jsx
import { PinInput, PinInputField } from '@chakra-ui/pin-input';
function CustomLengthPinInput() {
return (
<PinInput size="lg" length={6}>
<PinInputField />
<PinInputField />
<PinInputField />
<PinInputField />
<PinInputField />
<PinInputField />
</PinInput>
);
}
```
Masked PIN Input
This code demonstrates a masked PIN input where the input values are hidden. The `type` prop is set to `password` to mask the input.
```jsx
import { PinInput, PinInputField } from '@chakra-ui/pin-input';
function MaskedPinInput() {
return (
<PinInput type="password">
<PinInputField />
<PinInputField />
<PinInputField />
<PinInputField />
</PinInput>
);
}
```
react-pin-input is a React component for creating PIN input fields. It offers similar functionality to @chakra-ui/pin-input, including customizable length, focus management, and styling options. However, it may not integrate as seamlessly with the Chakra UI ecosystem.
react-code-input is another React component for creating code or PIN input fields. It provides a variety of customization options, such as different input types and styles. Compared to @chakra-ui/pin-input, it offers more flexibility in terms of input types but may require additional styling to match Chakra UI's design system.
react-otp-input is a React component specifically designed for OTP (One Time Password) inputs. It supports features like auto-focus, customizable length, and input masking. While it offers similar functionality to @chakra-ui/pin-input, it is more focused on OTP use cases and may not provide the same level of integration with Chakra UI.
The PinInupt component is optimized for entering sequences of digits. The most common application is for entering single-use security codes. It is optimized for entering digits quickly.
yarn add @chakra-ui/pin-input
or
npm i @chakra-ui/pin-input
import {
PinInput,
PinInputField,
usePinInput,
usePinInputField,
} from "@chakra-ui/switch"
Chakra UI exports two primary components, PinInput
and PinInputField
to
compose a PinInput component. Chakra UI also provides hooks to can create a
custom PinInput component.
<PinInput defaultValue="234">
<PinInputField />
<PinInputField />
<PinInputField />
</PinInput>
function PinInputHookExample() {
const context = usePinInput({ autoFocus: true })
const input1 = usePinInputField({ context })
const input2 = usePinInputField({ context })
const input3 = usePinInputField({ context })
const input4 = usePinInputField({ context })
return (
<div>
<input style={style} {...input1} />
<input style={style} {...input2} />
<input style={style} {...input3} />
<input style={style} {...input4} />
</div>
)
}
<PinInput size="lg" defaultValue="234">
<PinInputField />
<PinInputField />
<PinInputField />
</PinInput>
function ControlledPinInput() {
const [value, setValue] = React.useState("")
const handleChange = (value: string) => {
setValue(value)
}
const handleComplete = (value: string) => {
console.log(value)
}
return (
<PinInput value={value} onChange={handleChange} onComplete={handleComplete}>
<PinInputField />
<PinInputField />
<PinInputField />
</PinInput>
)
}
FAQs
A React component optimized for entering sequences of digits
The npm package @chakra-ui/pin-input receives a total of 374,163 weekly downloads. As such, @chakra-ui/pin-input popularity was classified as popular.
We found that @chakra-ui/pin-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.