Skip to content

Commit

Permalink
formSummary-defaultValue (#162)
Browse files Browse the repository at this point in the history
* ensure formSummary inputs have defaultValue

* remove build artifacts

* remove build artifacts
  • Loading branch information
jimmoffet authored Jun 6, 2024
1 parent acce251 commit a8ff905
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ node_modules/
NOTES.md
tsconfig.tsbuildinfo
*storybook.log
packages/form-service
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { type FormSummaryProps, type PatternId } from '@atj/forms';
import { type FormSummaryProps } from '@atj/forms';
import { type Pattern } from '@atj/forms/src/pattern';

import FormSummary from '../../../Form/components/FormSummary';
import { PatternEditComponent } from '../types';
Expand All @@ -17,7 +18,7 @@ const FormSummaryEdit: PatternEditComponent<FormSummaryProps> = ({
{focus ? (
<PatternEditForm
pattern={focus.pattern}
editComponent={<EditComponent patternId={focus.pattern.id} />}
editComponent={<EditComponent pattern={focus.pattern} />}
></PatternEditForm>
) : (
<FormSummary {...previewProps} />
Expand All @@ -26,26 +27,30 @@ const FormSummaryEdit: PatternEditComponent<FormSummaryProps> = ({
);
};

const EditComponent = ({ patternId }: { patternId: PatternId }) => {
const EditComponent = ({ pattern }: { pattern: Pattern }) => {
const patternId = pattern.id;
const { register } = usePatternEditFormContext(patternId);

return (
<div className="grid-row grid-gap-1">
<div className="desktop:grid-col-4 mobile:grid-col-12">
<div className="desktop:grid-col-6 mobile:grid-col-12">
<label className="usa-label">
Title
<input
className="usa-input bg-primary-lighter text-bold"
{...register('title')}
defaultValue={pattern.data.title}
type="text"
></input>
</label>
</div>
<div className="desktop:grid-col-2 mobile:grid-col-12">
<div className="desktop:grid-col-6 mobile:grid-col-12">
<label className="usa-label">
Description
<textarea
className="usa-textarea bg-primary-lighter text-bold"
{...register('description')}
defaultValue={pattern.data.description}
></textarea>
</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const PageEdit: PatternEditComponent<PageProps> = props => {
{props.focus ? (
<PatternEditForm
pattern={props.focus.pattern}
editComponent={<PageEditComopnent pattern={props.focus.pattern} />}
editComponent={<PageEditComponent pattern={props.focus.pattern} />}
></PatternEditForm>
) : (
<div
Expand Down Expand Up @@ -50,7 +50,7 @@ export const PageEdit: PatternEditComponent<PageProps> = props => {
);
};

const PageEditComopnent = ({ pattern }: { pattern: PagePattern }) => {
const PageEditComponent = ({ pattern }: { pattern: PagePattern }) => {
const { fieldId, getFieldState, register } =
usePatternEditFormContext<PagePattern>(pattern.id);
const title = getFieldState('title');
Expand Down

0 comments on commit a8ff905

Please sign in to comment.