Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uncontrolled form to the nextjs example #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
);
}
Loading