Skip to content
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

Unify expand button enlarge clickable area #678

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 18 additions & 71 deletions src/components/FeaturePanel/PublicTransport/route/Stops.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Link from 'next/link';
import { Feature } from '../../../../services/types';
import { StationItem, StationsList } from './helpers';
import { IconButton, Typography } from '@mui/material';
import { Button, Typography } from '@mui/material';
import { t } from '../../../../services/intl';
import { getUrlOsmId } from '../../../../services/helpers';
import TurnLeftIcon from '@mui/icons-material/TurnLeft';
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
import ExpandMoreIcon from '@mui/icons-material/ChevronRight';

type ShowMoreLessButtonProps = {
type: 'collapse' | 'expand';
Expand All @@ -17,72 +18,23 @@ const ShowMoreLessButton = ({
onClick,
stopCount,
}: ShowMoreLessButtonProps) => (
<Typography variant="body2" color="textSecondary">
<IconButton aria-label={type} onClick={onClick}>
<TurnLeftIcon
style={{
transform:
type === 'collapse' ? 'rotate(90deg) scaleY(-1)' : 'rotate(-90deg)',
}}
/>
</IconButton>
{type === 'collapse'
? t('publictransport.visible_stops', {
amount: stopCount - 2,
})
: t('publictransport.hidden_stops', {
amount: stopCount - 2,
})}
<Typography color="textSecondary">
<Button
color="inherit"
aria-label={type}
onClick={onClick}
endIcon={type === 'collapse' ? <ExpandLessIcon /> : <ExpandMoreIcon />}
>
{t(
type === 'collapse'
? 'publictransport.visible_stops'
: 'publictransport.hidden_stops',
{ amount: stopCount - 2 },
)}
</Button>
</Typography>
);

const StationInner = ({
stop,
stopCount,
onExpand,
onCollapse,
}: {
stop: Feature | 'collapse' | 'expand';
stopCount: number;
onExpand: () => void;
onCollapse: () => void;
}) => {
if (stop === 'expand') {
return (
<Typography variant="body2" color="textSecondary">
<IconButton
aria-label="expand"
onClick={() => {
onExpand();
}}
>
<TurnLeftIcon style={{ transform: 'rotate(-90deg)' }} />
</IconButton>
{t('publictransport.hidden_stops', {
amount: stopCount - 2,
})}
</Typography>
);
}
if (stop === 'collapse') {
return (
<Typography variant="body2" color="textSecondary">
<IconButton
aria-label="expand"
onClick={() => {
onCollapse();
}}
></IconButton>
{t('publictransport.visible_stops', {
amount: stopCount - 2,
})}
</Typography>
);
}

return <Link href={getUrlOsmId(stop.osmMeta)}>{stop.tags.name}</Link>;
};

type Props = {
stops: Feature[];
stopCount: number;
Expand All @@ -97,12 +49,7 @@ export const Stops = ({ stops, stopCount, onExpand, onCollapse }: Props) => {
{stops.map((stop, i) => (
<>
<StationItem isFirst={i === 0} isLast={i === stops.length - 1}>
<StationInner
stop={stop}
stopCount={stopCount}
onExpand={onExpand}
onCollapse={onCollapse}
/>
<Link href={getUrlOsmId(stop.osmMeta)}>{stop.tags.name}</Link>
</StationItem>
{i === 0 && (
<StationItem showCircle={false}>
Expand Down
Loading