Skip to content

Commit 7fa63c7

Browse files
committed
Touch up IconsTd of StopRow
* Reorder code sesctions to match each other. * Remove unneeded layers of divs. * Improve acessibility: - Mark icons as images. - Hide placeholder icons. * Touch up icon/label "generation" code.
1 parent c1aead9 commit 7fa63c7

File tree

1 file changed

+87
-96
lines changed
  • ui/src/components/stop-registry/components/StopTableRow/components

1 file changed

+87
-96
lines changed

ui/src/components/stop-registry/components/StopTableRow/components/IconsTd.tsx

Lines changed: 87 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -10,116 +10,107 @@ import {
1010
mapStopRegistryShelterElectricityEnumToUiName,
1111
mapStopRegistryShelterTypeEnumToUiName,
1212
} from '../../../../../i18n/uiNameMappings';
13-
import { Column, Row } from '../../../../../layoutComponents';
1413
import { StopRowTdProps } from '../types';
1514

16-
type EquipmentIconProps = {
17-
readonly className: string;
18-
readonly ariaLabel: string;
15+
const placeholderIcon = 'icon-placeholder-dot text-light-grey';
16+
17+
type EquipmentIconDetails = {
18+
readonly icon: string;
19+
readonly label: string;
1920
};
2021

21-
const EquipmentIcon: FC<EquipmentIconProps> = ({ className, ariaLabel }) => (
22-
<i
23-
className={`${className} py-3 text-4xl`}
24-
aria-label={ariaLabel}
25-
title={ariaLabel}
26-
/>
27-
);
22+
type Details = EquipmentIconDetails | false | undefined | null | '';
2823

29-
const PLACEHOLDER_ICON_CLASS = 'icon-placeholder-dot text-light-grey';
24+
type EquipmentIconProps = {
25+
readonly className?: string;
26+
readonly details: Details;
27+
};
3028

31-
const ELECTRICITY_ICON_MAP: Record<
32-
StopRegistryShelterElectricity,
33-
string | null
34-
> = {
35-
[StopRegistryShelterElectricity.Light]: 'icon-time-limited-power',
36-
[StopRegistryShelterElectricity.ContinuousPlanned]: 'icon-no-power',
37-
[StopRegistryShelterElectricity.ContinuousUnderConstruction]: 'icon-no-power',
38-
[StopRegistryShelterElectricity.TemporarilyOff]: 'icon-no-power',
39-
[StopRegistryShelterElectricity.None]: 'icon-no-power',
40-
[StopRegistryShelterElectricity.Continuous]: 'icon-power',
29+
const EquipmentIcon: FC<EquipmentIconProps> = ({ className = '', details }) => {
30+
if (!details) {
31+
return (
32+
<i
33+
aria-hidden
34+
className={`${className} ${placeholderIcon} py-3 text-4xl`}
35+
/>
36+
);
37+
}
38+
39+
return (
40+
<i
41+
role="img"
42+
className={`${className} ${details.icon} py-3 text-4xl`}
43+
aria-label={details.label}
44+
title={details.label}
45+
/>
46+
);
4147
};
4248

49+
function getElectricityIcon(electricity: string) {
50+
switch (electricity) {
51+
case StopRegistryShelterElectricity.Light:
52+
return 'icon-time-limited-power';
53+
54+
case StopRegistryShelterElectricity.ContinuousPlanned:
55+
case StopRegistryShelterElectricity.ContinuousUnderConstruction:
56+
case StopRegistryShelterElectricity.TemporarilyOff:
57+
case StopRegistryShelterElectricity.None:
58+
return 'icon-no-power';
59+
60+
case StopRegistryShelterElectricity.Continuous:
61+
default:
62+
return 'icon-power';
63+
}
64+
}
65+
4366
export const IconsTd: FC<StopRowTdProps> = ({ className, stop }) => {
4467
const { t } = useTranslation();
4568

46-
const shelterIcon = stop.shelter
47-
? {
48-
className:
49-
stop.shelter.toLowerCase() ===
50-
StopRegistryShelterType.Post.toLowerCase()
51-
? 'icon-post'
52-
: 'icon-shelter',
53-
ariaLabel: mapStopRegistryShelterTypeEnumToUiName(
54-
t,
55-
stop.shelter as StopRegistryShelterType,
56-
),
57-
}
58-
: { className: PLACEHOLDER_ICON_CLASS, ariaLabel: '' };
59-
60-
const electricityIcon = stop.electricity
61-
? {
62-
className:
63-
ELECTRICITY_ICON_MAP[
64-
stop.electricity as StopRegistryShelterElectricity
65-
] ?? 'icon-power',
66-
ariaLabel: mapStopRegistryShelterElectricityEnumToUiName(
67-
t,
68-
stop.electricity as StopRegistryShelterElectricity,
69-
),
70-
}
71-
: { className: PLACEHOLDER_ICON_CLASS, ariaLabel: '' };
72-
73-
const accessibilityIcon =
74-
stop.accessibility === StopRegistryAccessibilityLevel.FullyAccessible
75-
? {
76-
className: 'icon-accessible',
77-
ariaLabel: mapStopAccessibilityLevelToUiName(
78-
t,
79-
stop.accessibility as StopRegistryAccessibilityLevel,
80-
),
81-
}
82-
: { className: PLACEHOLDER_ICON_CLASS, ariaLabel: '' };
83-
84-
const replaceRailSignIcon = stop.replacesRailSign
85-
? {
86-
className:
87-
'icon-replacement-line-grey border-r border-r-background pr-2',
88-
ariaLabel: t('stopDetails.signs.replacesRailSign'),
89-
}
90-
: {
91-
className: `${PLACEHOLDER_ICON_CLASS} border-r border-r-background pr-2`,
92-
ariaLabel: '',
93-
};
69+
const replaceRailSignIcon: Details = stop.replacesRailSign && {
70+
icon: 'icon-replacement-line-grey',
71+
label: t('stopDetails.signs.replacesRailSign'),
72+
};
73+
74+
const electricityIcon: Details = stop.electricity && {
75+
icon: getElectricityIcon(stop.electricity),
76+
label: mapStopRegistryShelterElectricityEnumToUiName(
77+
t,
78+
stop.electricity as StopRegistryShelterElectricity,
79+
),
80+
};
81+
82+
const shelterIcon: Details = stop.shelter && {
83+
icon:
84+
stop.shelter.toLowerCase() === StopRegistryShelterType.Post
85+
? 'icon-post'
86+
: 'icon-shelter',
87+
label: mapStopRegistryShelterTypeEnumToUiName(
88+
t,
89+
stop.shelter as StopRegistryShelterType,
90+
),
91+
};
92+
93+
const accessibilityIcon: Details = stop.accessibility ===
94+
StopRegistryAccessibilityLevel.FullyAccessible && {
95+
icon: 'icon-accessible',
96+
label: mapStopAccessibilityLevelToUiName(
97+
t,
98+
stop.accessibility as StopRegistryAccessibilityLevel,
99+
),
100+
};
94101

95102
return (
96103
<td className={className}>
97-
<Row>
98-
<Column>
99-
<EquipmentIcon
100-
className={replaceRailSignIcon.className}
101-
ariaLabel={replaceRailSignIcon.ariaLabel}
102-
/>
103-
</Column>
104-
<Column>
105-
<EquipmentIcon
106-
className={electricityIcon.className}
107-
ariaLabel={electricityIcon.ariaLabel}
108-
/>
109-
</Column>
110-
<Column>
111-
<EquipmentIcon
112-
className={shelterIcon.className}
113-
ariaLabel={shelterIcon.ariaLabel}
114-
/>
115-
</Column>
116-
<Column>
117-
<EquipmentIcon
118-
className={accessibilityIcon.className}
119-
ariaLabel={accessibilityIcon.ariaLabel}
120-
/>
121-
</Column>
122-
</Row>
104+
<EquipmentIcon
105+
className="border-r border-r-background pr-2"
106+
details={replaceRailSignIcon}
107+
/>
108+
109+
<EquipmentIcon details={electricityIcon} />
110+
111+
<EquipmentIcon details={shelterIcon} />
112+
113+
<EquipmentIcon details={accessibilityIcon} />
123114
</td>
124115
);
125116
};

0 commit comments

Comments
 (0)