Skip to content

Commit

Permalink
Add uncontrolled form to the nextjs example
Browse files Browse the repository at this point in the history
  • Loading branch information
raoufswe committed Jan 17, 2025
1 parent 9ce51ad commit 43a9d63
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions nextjs-app-v14/src/app/components/home-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function HomePage() {
<h2>Demo Integrations</h2>
<ul>
<li><PieLink onClick={() => router.push('/integrations/form')} tag="button">Form Demo</PieLink></li>
<li><PieLink onClick={() => router.push('/integrations/uncontrolled-form')} tag="button">Uncontrolled Form Demo</PieLink></li>
</ul>
<h2>Component Pages</h2>
<ul>
Expand Down
10 changes: 10 additions & 0 deletions nextjs-app-v14/src/app/integrations/uncontrolled-form/page.tsx
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/>;
}
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>
);
}

0 comments on commit 43a9d63

Please sign in to comment.