Skip to content

Commit

Permalink
[sc] auto lock touchscreens
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Jun 6, 2024
1 parent 5a52d33 commit 09816c5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/star-chart/web/src/components/project/TouchTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from '@a-type/ui/components/button';
import { CanvasOverlayContent } from '../canvas/CanvasOverlay.jsx';
import { useIsTouch } from '@biscuits/client';
import { Icon } from '@a-type/ui/components/icon';
import { useEffect } from 'react';

export interface TouchToolsProps {
className?: string;
Expand All @@ -17,6 +18,12 @@ export function TouchTools({ className }: TouchToolsProps) {
const boxSelect = useBoxSelectEnabled();

const isTouchscreen = useIsTouch();
// auto-lock on touch devices.
useEffect(() => {
if (isTouchscreen) {
canvas.tools.dragLocked = true;
}
}, [canvas, isTouchscreen]);

return (
<CanvasOverlayContent
Expand All @@ -32,7 +39,7 @@ export function TouchTools({ className }: TouchToolsProps) {
aria-pressed={dragLocked}
className={clsx(
'flex-col gap-0 rounded-md px-1 py-0',
dragLocked && 'bg-primary-light text-primary-dark',
dragLocked && 'bg-primary-wash text-primary-dark',
)}
>
<span>
Expand All @@ -48,7 +55,7 @@ export function TouchTools({ className }: TouchToolsProps) {
aria-pressed={boxSelect}
className={clsx(
'flex-col gap-0 rounded-md px-1 py-0',
boxSelect && 'bg-primary-light text-primary-dark',
boxSelect && 'bg-primary-wash text-primary-dark',
)}
>
<span>
Expand Down

0 comments on commit 09816c5

Please sign in to comment.