-
Notifications
You must be signed in to change notification settings - Fork 9
Add basic form fields #4961
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
Open
juliawegmayr
wants to merge
13
commits into
feature/contact-form
Choose a base branch
from
add-form-fields
base: feature/contact-form
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+176
−1
Open
Add basic form fields #4961
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
aa0c072
add basic CheckboxField
juliawegmayr 45da3e0
add basic InputField
juliawegmayr 412c209
add basic SelectField
juliawegmayr 760294e
add fields to ContactForm as used in the screendesign
juliawegmayr fb4c256
fix labels
juliawegmayr 8eed041
remove local states
juliawegmayr 393a2ed
use real react imports
juliawegmayr 2cacba4
use ReactNode for helperText
juliawegmayr b2eae8c
use ReactNode for label and helperText in SelectField
juliawegmayr 84e660e
use FormattedMessage for default placeholder in SelectField
juliawegmayr cff9a81
rename FormattedMessage id for optional in SelectField
juliawegmayr d7ce682
split up InputField in TextField and TextareaField
juliawegmayr bd1efd9
remove explicit return type definitions
juliawegmayr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,10 +1,71 @@ | ||
| "use client"; | ||
| import { type PropsWithData, withPreview } from "@comet/site-nextjs"; | ||
| import { type ContactFormBlockData } from "@src/blocks.generated"; | ||
| import { FormattedMessage, useIntl } from "react-intl"; | ||
|
|
||
| import { Button } from "../components/Button"; | ||
| import { CheckboxField } from "../components/form/CheckboxField"; | ||
| import { SelectField } from "../components/form/SelectField"; | ||
| import { TextareaField } from "../components/form/TextareaField"; | ||
| import { TextField } from "../components/form/TextField"; | ||
|
|
||
| const subjectOptions = [ | ||
| { value: "Option 1", label: "Option 1" }, | ||
| { value: "Option 2", label: "Option 2" }, | ||
| { value: "Option 3", label: "Option 3" }, | ||
| ]; | ||
|
|
||
| export const ContactFormBlock = withPreview( | ||
| ({ data }: PropsWithData<ContactFormBlockData>) => { | ||
| return <>Contact Form</>; | ||
| const intl = useIntl(); | ||
| return ( | ||
| <> | ||
| <TextField | ||
| label={intl.formatMessage({ id: "contactForm.name.label", defaultMessage: "Name" })} | ||
| placeholder={intl.formatMessage({ id: "contactForm.name.placeholder", defaultMessage: "First and last name" })} | ||
| required | ||
| /> | ||
| <TextField | ||
| label={intl.formatMessage({ id: "contactForm.company.label", defaultMessage: "Company" })} | ||
| placeholder={intl.formatMessage({ id: "contactForm.company.placeholder", defaultMessage: "Company name" })} | ||
| /> | ||
| <TextField | ||
| label={intl.formatMessage({ id: "contactForm.email.label", defaultMessage: "Email" })} | ||
| placeholder={intl.formatMessage({ id: "contactForm.email.placeholder", defaultMessage: "Your email address" })} | ||
| required | ||
| /> | ||
| <TextField | ||
| label={intl.formatMessage({ id: "contactForm.phoneNumber.label", defaultMessage: "Phone Number" })} | ||
| placeholder={intl.formatMessage({ id: "contactForm.phoneNumber.placeholder", defaultMessage: "0043123456789" })} | ||
| helperText={intl.formatMessage({ | ||
| id: "contactForm.phoneNumber.helperText", | ||
| defaultMessage: "Please enter without special characters and spaces", | ||
| })} | ||
| /> | ||
| <SelectField | ||
| label={intl.formatMessage({ id: "contactForm.subject.label", defaultMessage: "Subject" })} | ||
| required | ||
| placeholder={intl.formatMessage({ id: "contactForm.subject.placeholder", defaultMessage: "Please select" })} | ||
| options={subjectOptions} | ||
| /> | ||
| <TextareaField | ||
| label={intl.formatMessage({ id: "contactForm.message.label", defaultMessage: "Message" })} | ||
| placeholder={intl.formatMessage({ id: "contactForm.message.placeholder", defaultMessage: "Your message" })} | ||
| required | ||
| /> | ||
| <CheckboxField | ||
| label={intl.formatMessage({ | ||
| id: "contactForm.privacyConsent.label", | ||
| defaultMessage: | ||
| "I agree that my information from the contact form will be collected and processed to answer my inquiry. Note: You can revoke your consent at any time by email to [email protected]. For more information, please see our privacy policy.", | ||
| })} | ||
| required | ||
| /> | ||
| <Button type="submit" variant="contained"> | ||
| <FormattedMessage id="contactForm.submitButton.label" defaultMessage="Submit" /> | ||
| </Button> | ||
| </> | ||
| ); | ||
| }, | ||
| { label: "Contact Form" }, | ||
| ); |
This file contains hidden or 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,17 @@ | ||
| import { type ReactNode } from "react"; | ||
|
|
||
| interface CheckboxFieldProps { | ||
| label: ReactNode; | ||
| helperText?: ReactNode; | ||
| required?: boolean; | ||
| } | ||
|
|
||
| export function CheckboxField({ label, helperText }: CheckboxFieldProps) { | ||
| return ( | ||
| <div> | ||
| <input type="checkbox" /> | ||
| <label>{label}</label> | ||
| {helperText && <div>{helperText}</div>} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,45 @@ | ||
| import { SvgUse } from "@src/common/helpers/SvgUse"; | ||
| import { type ReactNode } from "react"; | ||
| import { FormattedMessage } from "react-intl"; | ||
|
|
||
| interface SelectFieldProps { | ||
| label: ReactNode; | ||
| required?: boolean; | ||
| helperText?: ReactNode; | ||
| options: Array<{ value: string; label: string }>; | ||
| placeholder?: ReactNode; | ||
| } | ||
|
|
||
| export function SelectField({ | ||
| label, | ||
| required = false, | ||
| helperText, | ||
| options, | ||
| placeholder = <FormattedMessage id="selectField.placeholder" defaultMessage="Select an option" />, | ||
| }: SelectFieldProps): React.ReactElement { | ||
| return ( | ||
| <div> | ||
| <label> | ||
| {label} | ||
| {!required && ( | ||
| <span> | ||
| <FormattedMessage id="selectField.optional" defaultMessage="(optional)" /> | ||
| </span> | ||
| )} | ||
| </label> | ||
| <div> | ||
| <button type="button"> | ||
| <span>{placeholder}</span> | ||
| <SvgUse href="/assets/icons/chevron-down.svg#root" width={16} height={16} /> | ||
| </button> | ||
|
|
||
| <div> | ||
| {options.map((option) => ( | ||
| <div key={option.value}>{option.label}</div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| {helperText && <div>{helperText}</div>} | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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,26 @@ | ||
| import { type ReactNode } from "react"; | ||
| import { FormattedMessage } from "react-intl"; | ||
|
|
||
| interface InputProps { | ||
| label: ReactNode; | ||
| required?: boolean; | ||
| placeholder?: string; | ||
| helperText?: ReactNode; | ||
| } | ||
|
|
||
| export function TextField({ label, required = false, placeholder, helperText }: InputProps): React.ReactElement { | ||
| return ( | ||
| <div> | ||
| <label> | ||
| {label} | ||
| {!required && ( | ||
| <span> | ||
| <FormattedMessage id="inputField.optional" defaultMessage="(optional)" /> | ||
| </span> | ||
| )} | ||
| </label> | ||
| <input required={required} placeholder={placeholder} /> | ||
| {helperText && <div>{helperText}</div>} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,26 @@ | ||
| import { type ReactNode } from "react"; | ||
| import { FormattedMessage } from "react-intl"; | ||
|
|
||
| interface InputProps { | ||
| label: ReactNode; | ||
| required?: boolean; | ||
| placeholder?: string; | ||
| helperText?: ReactNode; | ||
| } | ||
|
|
||
| export function TextareaField({ label, required = false, placeholder, helperText }: InputProps): React.ReactElement { | ||
| return ( | ||
| <div> | ||
| <label> | ||
| {label} | ||
| {!required && ( | ||
| <span> | ||
| <FormattedMessage id="inputField.optional" defaultMessage="(optional)" /> | ||
| </span> | ||
| )} | ||
| </label> | ||
| <textarea required={required} placeholder={placeholder} /> | ||
| {helperText && <div>{helperText}</div>} | ||
| </div> | ||
| ); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use ReactNode for the label.