mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
import {Button, Form, Input} from "@nextui-org/react";
|
|
|
|
export default function App() {
|
|
const [submitted, setSubmitted] = React.useState(null);
|
|
|
|
const onSubmit = (e) => {
|
|
e.preventDefault();
|
|
const data = Object.fromEntries(new FormData(e.currentTarget));
|
|
|
|
setSubmitted(data);
|
|
};
|
|
|
|
return (
|
|
<Form className="w-full max-w-xs" validationBehavior="native" onSubmit={onSubmit}>
|
|
<Input
|
|
isRequired
|
|
label="Username"
|
|
labelPlacement="outside"
|
|
name="username"
|
|
placeholder="Enter your username"
|
|
type="text"
|
|
validate={(value) => {
|
|
if (value.length < 3) {
|
|
return "Username must be at least 3 characters long";
|
|
}
|
|
|
|
return value === "admin" ? "Nice try!" : null;
|
|
}}
|
|
/>
|
|
<Button color="primary" type="submit">
|
|
Submit
|
|
</Button>
|
|
{submitted && (
|
|
<div className="text-small text-default-500">
|
|
You submitted: <code>{JSON.stringify(submitted)}</code>
|
|
</div>
|
|
)}
|
|
</Form>
|
|
);
|
|
}
|