-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add uncontrolled form to the nextjs example
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
nextjs-app-v14/src/app/integrations/uncontrolled-form/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import UncontrolledForm from './uncontrolled-form'; | ||
import { type Metadata } from 'next'; | ||
|
||
export const metadata: Metadata = { | ||
title: 'Uncontrolled Form', | ||
} | ||
|
||
export default function UncontrolledFormPage() { | ||
return <UncontrolledForm/>; | ||
} |
56 changes: 56 additions & 0 deletions
56
nextjs-app-v14/src/app/integrations/uncontrolled-form/uncontrolled-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import NavigationLayout from '@/app/layout/navigation'; | ||
import { PieButton } from '@justeattakeaway/pie-webc/react/button.js'; | ||
import { PieTextInput } from '@justeattakeaway/pie-text-input/dist/index.js'; | ||
import { createComponent } from '@lit/react'; | ||
|
||
|
||
import '@/styles/form.scss'; | ||
|
||
const ReactPieTextInput = createComponent({ | ||
tagName: 'pie-text-input', | ||
elementClass: PieTextInput, | ||
react: React, | ||
events: { | ||
onchange: 'change', | ||
}, | ||
}); | ||
|
||
export default function UnControlledForm() { | ||
|
||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
const formData = new FormData(e.currentTarget); | ||
console.log(formData.get('first-name')) | ||
console.log(formData.get('last-name')) | ||
}; | ||
|
||
return ( | ||
<NavigationLayout title="Uncontrolled Form Test Page"> | ||
<form className="form" id="testForm" onSubmit={handleSubmit}> | ||
|
||
{/* importing the element directly */} | ||
<pie-text-input | ||
placeholder="First name" | ||
name="first-name"> | ||
</pie-text-input> | ||
|
||
<hr /> | ||
|
||
{/* importing the React element */} | ||
<ReactPieTextInput | ||
placeholder='Last Name' | ||
name="last-name"> | ||
</ReactPieTextInput> | ||
|
||
|
||
<div className='form-btns'> | ||
<PieButton className="form-btn" data-test-id="reset-btn" variant="secondary" type="reset">Reset</PieButton> | ||
<PieButton className="form-btn" data-test-id="submit-btn" type="submit">Submit</PieButton> | ||
</div> | ||
</form> | ||
</NavigationLayout> | ||
); | ||
} |