mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
fix: GL maps read the stored copy again while offline, and a switch that is on keeps a visible knob in the dark scheme
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { fireEvent, render, screen } from '../../../tests/helpers/render';
|
||||
import MToggle from './MToggle';
|
||||
|
||||
vi.mock('../../native/haptics', () => ({ selectionHaptic: vi.fn() }));
|
||||
|
||||
describe('MToggle', () => {
|
||||
it('FE-MOB-TOGGLE-001: on, the knob takes the track ink so it stays visible on the near-white dark track', () => {
|
||||
const onChange = vi.fn();
|
||||
const { rerender } = render(<MToggle checked onChange={onChange} ariaLabel="Offline" />);
|
||||
const knob = screen.getByRole('switch').firstElementChild as HTMLElement;
|
||||
expect(knob.className).toContain('bg-[color:var(--m-actfg)]');
|
||||
expect(knob.className).not.toContain('--m-knob');
|
||||
|
||||
rerender(<MToggle checked={false} onChange={onChange} ariaLabel="Offline" />);
|
||||
expect((screen.getByRole('switch').firstElementChild as HTMLElement).className).toContain(
|
||||
'bg-[color:var(--m-knob)]'
|
||||
);
|
||||
fireEvent.click(screen.getByRole('switch'));
|
||||
expect(onChange).toHaveBeenCalledWith(true);
|
||||
});
|
||||
});
|
||||
@@ -7,7 +7,11 @@ interface MToggleProps {
|
||||
className?: string
|
||||
}
|
||||
|
||||
/** iOS-style switch: --m-act track when on, --m-trackoff when off, 18px knob. */
|
||||
/**
|
||||
* iOS-style switch: --m-act track when on, --m-trackoff when off, 18px knob. The knob on
|
||||
* takes the track's ink (--m-actfg): in the dark scheme the track is near white, and a
|
||||
* white knob on it left the whole switch one white pill.
|
||||
*/
|
||||
export default function MToggle({ checked, onChange, ariaLabel, disabled = false, className = '' }: MToggleProps) {
|
||||
return (
|
||||
<button
|
||||
@@ -27,8 +31,10 @@ export default function MToggle({ checked, onChange, ariaLabel, disabled = false
|
||||
} ${className}`}
|
||||
>
|
||||
<span
|
||||
className={`block h-[18px] w-[18px] rounded-full bg-[color:var(--m-knob)] transition-transform duration-[180ms] ${
|
||||
checked ? 'translate-x-[18px] rtl:-translate-x-[18px]' : 'translate-x-0'
|
||||
className={`block h-[18px] w-[18px] rounded-full transition-transform duration-[180ms] ${
|
||||
checked
|
||||
? 'translate-x-[18px] bg-[color:var(--m-actfg)] rtl:-translate-x-[18px]'
|
||||
: 'translate-x-0 bg-[color:var(--m-knob)]'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user