mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
refactor form input fields
This commit is contained in:
committed by
Thomas Ruoff
parent
0ed66962ba
commit
b92ff0e3d8
@@ -1,6 +1,6 @@
|
||||
import React, { useContext } from 'react'
|
||||
import { WizardContext } from './context/wizardStore'
|
||||
import Required from './required'
|
||||
import Input from './input'
|
||||
|
||||
export default function Contact() {
|
||||
const { state, onChangeEvent } = useContext(WizardContext)
|
||||
@@ -9,77 +9,42 @@ export default function Contact() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
Name <Required />
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
value={name}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
className="input-text"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
E-Mail <Required />
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
name="email"
|
||||
value={email}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
className="input-text"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
Straße <Required />
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="street"
|
||||
value={street}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
className="input-text"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
PLZ <Required />
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="zip"
|
||||
value={zip}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
className="input-text"
|
||||
/>
|
||||
<label className="flabel">
|
||||
Stadt <Required />
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="city"
|
||||
value={city}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
className="input-text"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Input
|
||||
label="Name"
|
||||
required
|
||||
name="name"
|
||||
value={name}
|
||||
onChange={onChangeEvent}
|
||||
/>
|
||||
<Input
|
||||
label="E-Mail"
|
||||
type="email"
|
||||
name="email"
|
||||
value={email}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Straße"
|
||||
name="street"
|
||||
value={street}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="PLZ"
|
||||
name="zip"
|
||||
value={zip}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Stadt"
|
||||
name="city"
|
||||
value={city}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import useSWR from 'swr'
|
||||
import { getNextBigger, getNextSmaller } from '../../helpers/array'
|
||||
import { dateFormatBackend } from '../../helpers/date'
|
||||
import { WizardContext } from './context/wizardStore'
|
||||
import Required from './required'
|
||||
import InputWrapper from './inputWrapper'
|
||||
|
||||
const fetcher = (path: string) => fetch(path).then((r) => r.json())
|
||||
|
||||
@@ -70,65 +70,60 @@ export default function DateSelect() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
Datum <Required />
|
||||
</label>
|
||||
<DayPickerInput
|
||||
ref={fromRef}
|
||||
inputProps={{ className: 'input-text', required: true }}
|
||||
value={from}
|
||||
placeholder="Von"
|
||||
formatDate={MomentLocaleUtils.formatDate}
|
||||
parseDate={MomentLocaleUtils.parseDate}
|
||||
dayPickerProps={{
|
||||
locale: 'de',
|
||||
localeUtils: MomentLocaleUtils,
|
||||
className: 'datepicker',
|
||||
disabledDays,
|
||||
modifiers,
|
||||
numberOfMonths: 1,
|
||||
}}
|
||||
onDayChange={(from) => setRange({ ...range, from })}
|
||||
/>
|
||||
{' - '}
|
||||
<DayPickerInput
|
||||
ref={toRef}
|
||||
inputProps={{
|
||||
className: 'input-text',
|
||||
disabled: !from,
|
||||
required: true,
|
||||
}}
|
||||
value={to}
|
||||
placeholder="Bis"
|
||||
formatDate={MomentLocaleUtils.formatDate}
|
||||
parseDate={MomentLocaleUtils.parseDate}
|
||||
dayPickerProps={{
|
||||
locale: 'de',
|
||||
localeUtils: MomentLocaleUtils,
|
||||
className: 'datepicker',
|
||||
selectedDays: [from, { from, to }],
|
||||
disabledDays,
|
||||
modifiers,
|
||||
numberOfMonths: 1,
|
||||
month: from,
|
||||
fromMonth: from,
|
||||
}}
|
||||
onDayChange={(to) => setRange({ ...range, to })}
|
||||
/>
|
||||
<button
|
||||
onClick={() => setRange({ from: undefined, to: undefined })}
|
||||
className="ibtn"
|
||||
>
|
||||
<svg className="w-full" viewBox="0 0 352 512">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
|
||||
></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<InputWrapper label="Datum" required>
|
||||
<DayPickerInput
|
||||
ref={fromRef}
|
||||
inputProps={{ className: 'input-text', required: true }}
|
||||
value={from}
|
||||
placeholder="Von"
|
||||
formatDate={MomentLocaleUtils.formatDate}
|
||||
parseDate={MomentLocaleUtils.parseDate}
|
||||
dayPickerProps={{
|
||||
locale: 'de',
|
||||
localeUtils: MomentLocaleUtils,
|
||||
className: 'datepicker',
|
||||
disabledDays,
|
||||
modifiers,
|
||||
numberOfMonths: 1,
|
||||
}}
|
||||
onDayChange={(from) => setRange({ ...range, from })}
|
||||
/>
|
||||
{' - '}
|
||||
<DayPickerInput
|
||||
ref={toRef}
|
||||
inputProps={{
|
||||
className: 'input-text',
|
||||
disabled: !from,
|
||||
required: true,
|
||||
}}
|
||||
value={to}
|
||||
placeholder="Bis"
|
||||
formatDate={MomentLocaleUtils.formatDate}
|
||||
parseDate={MomentLocaleUtils.parseDate}
|
||||
dayPickerProps={{
|
||||
locale: 'de',
|
||||
localeUtils: MomentLocaleUtils,
|
||||
className: 'datepicker',
|
||||
selectedDays: [from, { from, to }],
|
||||
disabledDays,
|
||||
modifiers,
|
||||
numberOfMonths: 1,
|
||||
month: from,
|
||||
fromMonth: from,
|
||||
}}
|
||||
onDayChange={(to) => setRange({ ...range, to })}
|
||||
/>
|
||||
<button
|
||||
onClick={() => setRange({ from: undefined, to: undefined })}
|
||||
className="ibtn"
|
||||
>
|
||||
<svg className="w-full" viewBox="0 0 352 512">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
|
||||
></path>
|
||||
</svg>
|
||||
</button>
|
||||
</InputWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
17
components/wizard/input.tsx
Normal file
17
components/wizard/input.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import React from 'react'
|
||||
|
||||
import InputWrapper from './inputWrapper'
|
||||
|
||||
interface InputProps extends React.InputHTMLAttributes<T> {
|
||||
label: string
|
||||
}
|
||||
|
||||
export default function Input(props: InputProps) {
|
||||
const { label, required, type = 'text', ...rest } = props
|
||||
|
||||
return (
|
||||
<InputWrapper label="label" required={required}>
|
||||
<input type={type} required={required} className="input-text" {...rest} />
|
||||
</InputWrapper>
|
||||
)
|
||||
}
|
||||
23
components/wizard/inputWrapper.tsx
Normal file
23
components/wizard/inputWrapper.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react'
|
||||
import Required from './required'
|
||||
|
||||
export default function Input(props: {
|
||||
label: string
|
||||
required: boolean
|
||||
children: React.ReactChildren
|
||||
}) {
|
||||
const { label, required, children } = props
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
{label} {required && <Required />}
|
||||
</label>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,59 +1,29 @@
|
||||
import React, { useContext } from 'react'
|
||||
import { WizardContext } from './context/wizardStore'
|
||||
import Required from './required'
|
||||
import Input from './input'
|
||||
|
||||
export default function Contact() {
|
||||
const { state, onChangeEvent } = useContext(WizardContext)
|
||||
|
||||
const { formDataChanged } = state
|
||||
const { purpose, destination, org } = state.formData
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
Zweck der Fahrt <Required />
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="purpose"
|
||||
value={purpose}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
className={`input-text ${
|
||||
formDataChanged.includes('purpose') && 'input-changed'
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">
|
||||
Ziel der Fahrt <Required />
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="destination"
|
||||
value={destination}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
className="input-text"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="fsw">
|
||||
<div className="fs">
|
||||
<label className="flabel">Verein</label>
|
||||
<input
|
||||
type="text"
|
||||
name="org"
|
||||
value={org}
|
||||
onChange={onChangeEvent}
|
||||
className="input-text"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Input
|
||||
label="Zweck der Fahrt"
|
||||
name="purpose"
|
||||
value={purpose}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Ziel der Fahrt"
|
||||
name="destination"
|
||||
value={destination}
|
||||
onChange={onChangeEvent}
|
||||
required
|
||||
/>
|
||||
<Input label="Verein" name="org" value={org} onChange={onChangeEvent} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user