-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLandingPageSearchForm.tsx
More file actions
133 lines (130 loc) · 4.1 KB
/
Copy pathLandingPageSearchForm.tsx
File metadata and controls
133 lines (130 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {
isPageType,
SecondaryLink,
usePageContext,
} from '@city-of-helsinki/react-helsinki-headless-cms';
import {
DateSelector,
MobileDateSelector,
useLocale,
useHomeTranslation,
useAppEventsTranslation,
AdvancedSearchTextInput,
} from '@events-helsinki/components';
import classnames from 'classnames';
import { Button, ButtonVariant, IconSearch } from 'hds-react';
import { ROUTES } from '../../../constants';
import routerHelper from '../../../domain/app/routerHelper';
import styles from './landingPageSearchForm.module.scss';
export type LandingPageSearchFormProps = Readonly<{
className?: string;
dateTypes: string[];
start: Date | null;
end: Date | null;
isCustomDate: boolean;
textSearchInput: string;
setStart: (value: Date | null) => void;
setEnd: (value: Date | null) => void;
setTextSearchInput: (value: string) => void;
handleChangeDateTypes: (value: string[]) => void;
toggleIsCustomDate: () => void;
handleSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
}>;
export default function LandingPageSearchForm({
className,
dateTypes,
start,
setStart,
end,
setEnd,
isCustomDate,
textSearchInput,
setTextSearchInput,
handleChangeDateTypes,
toggleIsCustomDate,
handleSubmit,
}: LandingPageSearchFormProps) {
const { t } = useHomeTranslation();
const { t: tAppEvents } = useAppEventsTranslation();
const locale = useLocale();
const { page } = usePageContext();
const heroTitle =
isPageType(page) && page?.hero?.title?.trim() !== ''
? page?.hero?.title?.trim()
: tAppEvents('appEvents:home.search.title');
const heroDescription =
isPageType(page) && page?.hero?.description?.trim() !== ''
? page?.hero?.description?.trim()
: undefined;
return (
<form
className={classnames(className, styles.landingPageSearch)}
onSubmit={handleSubmit}
>
<h1
id="heroTitle"
className={classnames({ [styles.withDescription]: !!heroDescription })}
>
{heroTitle}
</h1>
{!!heroDescription && <p id="heroDescription">{heroDescription}</p>}
<div className={styles.searchRow}>
<div className={styles.textSearchWrapper}>
<AdvancedSearchTextInput
id="search"
name="search"
placeholder={t('home:search.placeholder')}
value={textSearchInput}
onChange={(event) => setTextSearchInput(event.target.value)}
clearButton={false} // HH-456 the clear button not working properly when value handled programmatically.
/>
</div>
<div className={styles.dateAndButtonWrapper}>
<div className={styles.dateSelectorWrapper}>
<div className={styles.desktopDateSelector}>
<DateSelector
dateTypes={dateTypes}
endDate={end}
isCustomDate={isCustomDate}
name="date"
onChangeDateTypes={handleChangeDateTypes}
onChangeEndDate={setEnd}
onChangeStartDate={setStart}
startDate={start}
toggleIsCustomDate={toggleIsCustomDate}
/>
</div>
<MobileDateSelector
dateTypes={dateTypes}
endDate={end}
name={'mobile_date'}
onChangeDateTypes={handleChangeDateTypes}
onChangeEndDate={setEnd}
onChangeStartDate={setStart}
startDate={start}
/>
</div>
<div className={styles.buttonWrapper}>
<Button
fullWidth={true}
iconStart={<IconSearch aria-hidden />}
variant={ButtonVariant.Success}
type="submit"
>
{t('home:search.buttonSearch')}
</Button>
</div>
</div>
</div>
<div className={styles.linkRow}>
<SecondaryLink
variant="arrowRight"
className={styles.link}
href={routerHelper.getI18nPath(ROUTES.SEARCH, locale)}
>
{t('home:search.linkAdvancedSearch')}
</SecondaryLink>
</div>
</form>
);
}