-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wire in "prompt" and "prompt parts"; use react-hook form in React com…
…ponents.
- Loading branch information
1 parent
4b316a0
commit 2d753c2
Showing
19 changed files
with
426 additions
and
139 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
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
52 changes: 0 additions & 52 deletions
52
apps/spotlight/src/components/react/form-builder/index.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 |
---|---|---|
@@ -1,52 +0,0 @@ | ||
import React from 'react'; | ||
|
||
import { SuggestedForm } from '@atj/documents/src/suggestions'; | ||
|
||
export const FormBuilder = ({ fields }: { fields: SuggestedForm }) => { | ||
return ( | ||
<div> | ||
{fields.map((field, index) => { | ||
return <FieldBuilder key={index} field={field} />; | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
const FieldBuilder = ({ field }: { field: SuggestedForm[number] }) => { | ||
const fieldId = `field-${field.id}`; | ||
return ( | ||
<div className="grid-row grid-gap"> | ||
<div className="grid-col"> | ||
<label className="usa-label"> | ||
Input type | ||
<select className="usa-select" name={`input-type-${fieldId}`}> | ||
<option value={'input'}>Input</option> | ||
<option value={'textarea'}>Textarea</option> | ||
</select> | ||
</label> | ||
</div> | ||
<div className="grid-col"> | ||
<label className="usa-label"> | ||
Field label | ||
<input | ||
className="usa-input" | ||
type="text" | ||
name={`description-${fieldId}`} | ||
defaultValue={field.label} | ||
></input> | ||
</label> | ||
</div> | ||
<div className="grid-col"> | ||
<label className="usa-label"> | ||
Default value | ||
<input | ||
className="usa-input" | ||
type="text" | ||
name={`default-value-${fieldId}`} | ||
defaultValue={field.value} | ||
></input> | ||
</label> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
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
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
17 changes: 16 additions & 1 deletion
17
...ight/src/components/react/form/fields.tsx → .../react/form/prompts/additional-fields.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
11 changes: 11 additions & 0 deletions
11
apps/spotlight/src/components/react/form/prompts/form-summary.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,11 @@ | ||
import React from 'react'; | ||
|
||
import { FormSummaryPrompt } from '@atj/forms'; | ||
|
||
export const FormSummary = ({ prompt }: { prompt: FormSummaryPrompt }) => { | ||
return ( | ||
<legend className="usa-legend usa-legend--large"> | ||
{prompt.title} - {prompt.description} | ||
</legend> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
apps/spotlight/src/components/react/form/prompts/index.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,16 @@ | ||
import React from 'react'; | ||
|
||
import { type PromptPart } from '@atj/forms'; | ||
import { FormSummary } from './form-summary'; | ||
import { TextInput } from './text-input'; | ||
|
||
export const PromptSegment = ({ promptPart }: { promptPart: PromptPart }) => { | ||
if (promptPart.type === 'form-summary') { | ||
return <FormSummary prompt={promptPart} />; | ||
} else if (promptPart.type === 'text') { | ||
return <TextInput prompt={promptPart} />; | ||
} else { | ||
const _exhaustiveCheck: never = promptPart; | ||
return <></>; | ||
} | ||
}; |
30 changes: 30 additions & 0 deletions
30
apps/spotlight/src/components/react/form/prompts/text-input.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,30 @@ | ||
import React from 'react'; | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
import { type TextInputPrompt } from '@atj/forms'; | ||
|
||
export const TextInput = ({ prompt }: { prompt: TextInputPrompt }) => { | ||
const { register } = useFormContext(); | ||
return ( | ||
<div className="usa-form-group" key={prompt.id}> | ||
<label className="usa-label" htmlFor={prompt.id}> | ||
{prompt.label} | ||
{prompt.required && ( | ||
<> | ||
{' '} | ||
<abbr title="required" className="usa-hint usa-hint--required"> | ||
* | ||
</abbr> | ||
</> | ||
)} | ||
</label> | ||
<input | ||
className="usa-input" | ||
defaultValue={prompt.value} | ||
{...register(prompt.id, { | ||
required: prompt.required, | ||
})} | ||
/> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.