Skip to content

Commit db1b133

Browse files
authored
replaced radio buttons by selects in SelectFilter (#24)
* replaced radio buttons by selects in SelectFilter * fix: review
1 parent a647417 commit db1b133

File tree

7 files changed

+52
-32
lines changed

7 files changed

+52
-32
lines changed

src/components/UI/Input.module.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
@import '@/variables';
22

3-
43
.inputWrapper {
54
display: flex;
65
border-radius: 10px;
76
border: 3px solid #D3D3D3;
8-
background-color: #F0F0F2;
7+
background-color: $light-gray;
98

109
input {
11-
background-color: #F0F0F2;
12-
color: #444C5F;
10+
background-color: $light-gray;
11+
color: $ung-light-grey;
1312
border-radius: 7px;
1413
padding: 10px 15px;
1514
border: none;
@@ -36,7 +35,7 @@
3635
}
3736

3837
svg {
39-
color: #F0F0F2;
38+
color: $light-gray;
4039
}
4140
}
4241
}

src/components/UI/Select.module.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@import '@/variables';
2+
3+
.select {
4+
width: 100%;
5+
background-color: $light-gray;
6+
border: 3px solid #D3D3D3;
7+
border-radius: 10px;
8+
padding: 0.2rem 0.5rem;
9+
}

src/components/UI/Select.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import styles from './Select.module.scss';
2+
3+
export default function Select<Choices extends string = string>({
4+
options,
5+
value,
6+
onSelect,
7+
className = '',
8+
}: {
9+
options: Array<{ id: Choices; name: string }>;
10+
value: string;
11+
onSelect: (item: Choices) => void;
12+
className?: string;
13+
}) {
14+
return (
15+
<select
16+
value={value}
17+
onChange={(event) => onSelect(event.currentTarget.value as Choices)}
18+
className={`${styles.select} ${className}`}>
19+
{options.map((option) => (
20+
<option key={option.id} value={option.id}>
21+
{option.name}
22+
</option>
23+
))}
24+
</select>
25+
);
26+
}

src/components/filteredSearch/FilteredSearch.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
.filter {
1111
margin: 2rem 0;
12-
overflow-y: scroll;
12+
//overflow-y: scroll;
1313
}
1414
}

src/components/filteredSearch/InputFilter.module.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
.input {
1010
display: flex;
1111
border-radius: 10px;
12-
width: max-content;
1312
}
1413
}

src/components/filteredSearch/SelectFilter.module.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,4 @@
55
color: $ung-light-grey;
66
margin-bottom: 0.75rem;
77
}
8-
9-
.option {
10-
display: block;
11-
line-height: 1.5rem;
12-
13-
input {
14-
margin-right: 0.5rem;
15-
}
16-
}
178
}

src/components/filteredSearch/SelectFilter.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import styles from './SelectFilter.module.scss';
22
import { FC, useEffect, useRef, useState } from 'react';
33
import { NotParameteredTranslationKey, useAppTranslation } from '@/lib/i18n';
44
import { BaseFilterProps } from '@/components/filteredSearch/FilteredSearch';
5+
import Select from '@/components/UI/Select';
56

67
export function SelectFilter<Choices extends string>({
78
onUpdate,
@@ -27,22 +28,17 @@ export function SelectFilter<Choices extends string>({
2728
return (
2829
<div className={styles.filter}>
2930
<h3 className={styles.title}>{t(title)}</h3>
30-
<label key={'all'} className={styles.option}>
31-
<input type={'radio'} name={title} value={'all'} onChange={() => setValue('all')} checked={value === 'all'} />
32-
{t('common:filter.all')}
33-
</label>
34-
{choices.map((choice) => (
35-
<label key={choice} className={styles.option}>
36-
<input
37-
type={'radio'}
38-
name={title}
39-
value={choice}
40-
onChange={() => setValue(choice)}
41-
checked={value === choice}
42-
/>
43-
{humanReadableMapping ? t(humanReadableMapping[choice]) : choice}
44-
</label>
45-
))}
31+
<Select<Choices | 'all'>
32+
options={[
33+
{ id: 'all', name: t('common:filter.all') },
34+
...choices.map((choice) => ({
35+
id: choice,
36+
name: humanReadableMapping ? t(humanReadableMapping[choice]) : choice,
37+
})),
38+
]}
39+
onSelect={setValue}
40+
value={value}
41+
/>
4642
</div>
4743
);
4844
}

0 commit comments

Comments
 (0)