-
Notifications
You must be signed in to change notification settings - Fork 0
feat: travel card TPW #751
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
Open
strandlie
wants to merge
30
commits into
main
Choose a base branch
from
strandlie/travel-card-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
bc93421
feat: travel-card foundation
strandlie 0c7ea43
feat: render refreshed trip pattern and fetch price on hover
strandlie e7f9538
style: remove code comments
strandlie 73adf37
feat: add TintedMonoIcon
strandlie e85ade2
feat: add transport pill notification badge
strandlie c2a9b6c
feat: redesign travel card
strandlie c9d4302
refactor: replace travel-card magic numbers with design tokens
strandlie e7ba113
refactor: extract shared TransportNotificationBadge component
strandlie 689ca11
feat: completely hide overflowing legs in trip pattern
strandlie e0a54ac
fix: drop removed shouldFetchPrice prop
strandlie 99da356
refactor: drop vestigial shouldFetch prop on Price
strandlie 1c52e14
fix: gate trip refresh polling to visible cards
strandlie d545bf8
style: apply prettier formatting
strandlie 32e8f6e
chore: drop unused getBookingStatus import
strandlie 591c9b7
feat: add line pill and inline walk icon in trip details
strandlie 7641dc6
feat: show walking distance in walk sections
strandlie e4c182f
refactor: reuse humanizeDistance for total walk distance
strandlie 2285c30
fix: show original times on walk-first trips from initial load
strandlie 220ab4a
refactor: rename situations module to notifications
strandlie 429b84c
refactor: extract getMostCriticalStatusColor into notifications
strandlie 1e7db04
refactor: use IntersectionObserver for trip-pattern overflow
strandlie c797294
refactor: Refactored overflow from IntersectionObserver to ResizeObse…
strandlie 2011767
refactor: Changed from notifications to situations-and-notices
strandlie 73e7dfa
fix: Fixed a typo bug
strandlie 4523fb9
refactor: Renamed StatusColorName to Statuses, equaling the app
strandlie 5571d76
refactor: Implemented OverflowContainer like the app
strandlie bdd6f95
fix: Keyboard focus order in expanded trip pattern
strandlie d8b732e
style: fixed tripPattern gap
strandlie cad59a6
fix: Fixed button, map size and correct icon
strandlie 30c3bad
fix: use TintedMonoIcon for See more button
strandlie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .counterBox { | ||
| background-color: token('color.background.neutral.2.background'); | ||
| border-radius: token('border.radius.circle'); | ||
| padding: token('spacing.small') token('spacing.medium'); | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { type ReactNode } from 'react'; | ||
| import { Typo } from '@atb/components/typography'; | ||
| import { and } from '@atb/utils/css'; | ||
| import style from './counter-box.module.css'; | ||
|
|
||
| export type CounterBoxProps = { | ||
| count: number; | ||
| notification?: ReactNode; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export function CounterBox({ | ||
| count, | ||
| notification, | ||
| className, | ||
| }: CounterBoxProps) { | ||
| if (count < 1) return null; | ||
| return ( | ||
| <> | ||
| <div className={and(style.counterBox, className)}> | ||
| <Typo.span textType="body__m__strong">+{count}</Typo.span> | ||
| </div> | ||
| {notification} | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| export * from './color-icon'; | ||
| export * from './image'; | ||
| export * from './mono-icon'; | ||
| export * from './tinted-mono-icon'; | ||
| export * from './checkbox-icon'; | ||
| export type * from './generated-icons'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { CSSProperties } from 'react'; | ||
| import { MonoIcons, icons } from './generated-icons'; | ||
| import { SizeProps, useSize } from './utils'; | ||
|
|
||
| export type TintedMonoIconProps = { | ||
| icon: MonoIcons; | ||
| size?: SizeProps; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export function TintedMonoIcon({ | ||
| icon, | ||
| size = 'normal', | ||
| className, | ||
| }: TintedMonoIconProps) { | ||
| const wh = useSize(size); | ||
| const maskUrl = `/assets/${icons['mono'][icon].relative.replace( | ||
| 'mono/', | ||
| 'mono/dark/', | ||
| )}`; | ||
|
|
||
| const maskStyle: CSSProperties = { | ||
| display: 'inline-block', | ||
| width: wh, | ||
| height: wh, | ||
| backgroundColor: 'currentColor', | ||
| WebkitMaskImage: `url("${maskUrl}")`, | ||
| maskImage: `url("${maskUrl}")`, | ||
| WebkitMaskRepeat: 'no-repeat', | ||
| maskRepeat: 'no-repeat', | ||
| WebkitMaskPosition: 'center', | ||
| maskPosition: 'center', | ||
| WebkitMaskSize: 'contain', | ||
| maskSize: 'contain', | ||
| }; | ||
|
|
||
| return <span aria-hidden="true" className={className} style={maskStyle} />; | ||
| } | ||
|
|
||
| export default TintedMonoIcon; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/components/overflow-container/__tests__/overflow-container.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { cleanup, render } from '@testing-library/react'; | ||
| import { afterEach, describe, expect, it } from 'vitest'; | ||
| import { OverflowContainer } from '../'; | ||
|
|
||
| afterEach(function () { | ||
| cleanup(); | ||
| }); | ||
|
|
||
| function renderContainer(labels: string[]) { | ||
| return render( | ||
| <OverflowContainer overflow={(hiddenCount) => <span>+{hiddenCount}</span>}> | ||
| {labels.map((label) => ( | ||
| <span key={label}>{label}</span> | ||
| ))} | ||
| </OverflowContainer>, | ||
| ); | ||
| } | ||
|
|
||
| describe('overflow container', function () { | ||
| it('renders all children without marking any as overflowing', () => { | ||
| const output = renderContainer(['a', 'b', 'c']); | ||
|
|
||
| expect(output.getByText('a')).toBeInTheDocument(); | ||
| expect(output.getByText('b')).toBeInTheDocument(); | ||
| expect(output.getByText('c')).toBeInTheDocument(); | ||
| expect( | ||
| output.container.querySelectorAll('[data-overflowing]'), | ||
| ).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('renders the worst-case overflow indicator only inside the hidden probe', () => { | ||
| const output = renderContainer(['a', 'b', 'c']); | ||
|
|
||
| const worstCase = output.getByText('+3'); | ||
| expect(worstCase.parentElement).toHaveAttribute('aria-hidden', 'true'); | ||
| }); | ||
|
|
||
| it('renders no probe when there are no children', () => { | ||
| const output = renderContainer([]); | ||
|
|
||
| expect(output.container.querySelector('[aria-hidden="true"]')).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { Children, isValidElement, type ReactNode } from 'react'; | ||
| import { and } from '@atb/utils/css'; | ||
| import { useOverflowingChildren } from './use-overflowing-children'; | ||
| import style from './overflow-container.module.css'; | ||
|
|
||
| export type OverflowContainerProps = { | ||
| children: ReactNode[]; | ||
| overflow: (hiddenCount: number) => ReactNode; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export function OverflowContainer({ | ||
| children, | ||
| overflow, | ||
| className, | ||
| }: OverflowContainerProps) { | ||
| const items = Children.toArray(children); | ||
| const keys = items.map((child, i) => | ||
| isValidElement(child) && child.key != null ? child.key : `__idx_${i}`, | ||
| ); | ||
|
|
||
| const { | ||
| rootRef, | ||
| overflowProbeRef, | ||
| visibleCount, | ||
| overflowIndicatorPositionLeft, | ||
| } = useOverflowingChildren(keys.join('|')); | ||
|
|
||
| const hasOverflow = visibleCount < items.length; | ||
| const hiddenCount = hasOverflow ? items.length - visibleCount : 0; | ||
|
|
||
| return ( | ||
| <div className={and(style.container, className)}> | ||
| <div className={style.row} ref={rootRef}> | ||
| {items.map((child, i) => ( | ||
| <div | ||
| key={keys[i]} | ||
| className={style.item} | ||
| data-overflowing={ | ||
| hasOverflow && i >= visibleCount ? 'true' : undefined | ||
| } | ||
| > | ||
| {child} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| {hasOverflow && ( | ||
| <div | ||
| className={style.indicator} | ||
| style={{ left: overflowIndicatorPositionLeft }} | ||
| > | ||
| {overflow(hiddenCount)} | ||
| </div> | ||
| )} | ||
| {items.length > 0 && ( | ||
| <div className={style.probe} aria-hidden="true" ref={overflowProbeRef}> | ||
| {overflow(items.length)} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/components/overflow-container/overflow-container.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| .container { | ||
| position: relative; | ||
| min-width: 0; | ||
| } | ||
|
|
||
| .row { | ||
| display: flex; | ||
| flex-wrap: nowrap; | ||
| align-items: center; | ||
| gap: var(--overflow-container-gap, 0); | ||
| min-width: 0; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .item { | ||
| display: flex; | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .item[data-overflowing='true'] { | ||
| visibility: hidden; | ||
| } | ||
|
|
||
| .indicator { | ||
| position: absolute; | ||
| top: 50%; | ||
| transform: translateY(-50%); | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .probe { | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| width: max-content; | ||
| display: flex; | ||
| align-items: center; | ||
| visibility: hidden; | ||
| pointer-events: none; | ||
| } |
71 changes: 71 additions & 0 deletions
71
src/components/overflow-container/use-overflowing-children.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { useRef, useState } from 'react'; | ||
| import { useIsomorphicLayoutEffect } from '@atb/utils/use-isomorphic-layout-effect'; | ||
|
|
||
| type OverflowState = { | ||
| visibleCount: number; | ||
|
|
||
| // To determine how many elements fit before overflow, we need to lay out all | ||
| // elements and measure (with some hidden if they don't fit). | ||
| // But that means that if we need an overflow indicator, another element | ||
| // already has its position in the flex flow | ||
| // | ||
| // Therefore, we absolutely position the overflow indicator at this position: | ||
| overflowIndicatorPositionLeft: number; | ||
| }; | ||
|
|
||
| export function useOverflowingChildren(depKey: string) { | ||
| const rootRef = useRef<HTMLDivElement | null>(null); | ||
| const overflowProbeRef = useRef<HTMLDivElement | null>(null); | ||
| const [state, setState] = useState<OverflowState>({ | ||
| visibleCount: Number.POSITIVE_INFINITY, | ||
| overflowIndicatorPositionLeft: 0, | ||
| }); | ||
|
|
||
| useIsomorphicLayoutEffect(() => { | ||
| const root = rootRef.current; | ||
| const overflowIndicatorProbe = overflowProbeRef.current; | ||
| if ( | ||
| !root || | ||
| !overflowIndicatorProbe || | ||
| typeof ResizeObserver === 'undefined' | ||
| ) | ||
| return; | ||
|
|
||
| const measure = () => { | ||
| const rootRect = root.getBoundingClientRect(); | ||
| if (rootRect.width === 0) return; | ||
| const rects = Array.from(root.children, (child) => | ||
| child.getBoundingClientRect(), | ||
| ); | ||
| const lastRect = rects[rects.length - 1]; | ||
| let visibleCount = rects.length; | ||
| let overflowIndicatorPositionLeft = 0; | ||
| if (lastRect && lastRect.right > rootRect.right) { | ||
| const gap = parseFloat(getComputedStyle(root).columnGap) || 0; | ||
| const limit = rootRect.right - overflowIndicatorProbe.offsetWidth - gap; | ||
| visibleCount = 0; | ||
| for (const rect of rects) { | ||
| if (rect.right > limit) break; | ||
| visibleCount++; | ||
| overflowIndicatorPositionLeft = rect.right - rootRect.left + gap; | ||
| } | ||
| } | ||
| setState((previous) => | ||
| previous.visibleCount === visibleCount && | ||
| previous.overflowIndicatorPositionLeft === overflowIndicatorPositionLeft | ||
| ? previous | ||
| : { visibleCount, overflowIndicatorPositionLeft }, | ||
| ); | ||
| }; | ||
|
|
||
| const observer = new ResizeObserver(measure); | ||
| observer.observe(root); | ||
| observer.observe(overflowIndicatorProbe); | ||
| Array.from(root.children).forEach((child) => observer.observe(child)); | ||
| measure(); | ||
|
|
||
| return () => observer.disconnect(); | ||
| }, [depKey]); | ||
|
|
||
| return { rootRef, overflowProbeRef, ...state }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.