Skip to content

Commit c544c45

Browse files
committed
Add touch-hitbox utility (#523)
Also replace touch and notouch by pointer-coarse and pointer-fine
1 parent ee3af4d commit c544c45

13 files changed

+43
-27
lines changed

app/components/blocks/shopify-description-block.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function ShopifyDescriptionBlock(props: ShopifyDescriptionBlockProps) {
1414

1515
return (
1616
<div
17-
className="[&_a]:text-primary touch:[&_a]:active:underline notouch:[&_a]:hover:underline [&_a]:underline-offset-4"
17+
className="[&_a]:text-primary [&_a]:underline-offset-4 pointer-coarse:[&_a]:active:underline pointer-fine:[&_a]:hover:underline"
1818
dangerouslySetInnerHTML={{
1919
__html: product.descriptionHtml,
2020
}}

app/components/collection/sort-filter-layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function SortFilter({
7070
return (
7171
<>
7272
{/* Desktop layout */}
73-
<div className="touch:hidden hidden w-full lg:flex lg:items-center lg:justify-between">
73+
<div className="hidden w-full lg:flex lg:items-center lg:justify-between pointer-coarse:hidden">
7474
<div className="flex items-center gap-2">
7575
<IconButton onClick={() => setIsOpen(!isOpen)}>
7676
<span className="sr-only">
@@ -108,7 +108,7 @@ export function SortFilter({
108108
<div className="mt-6">
109109
<div
110110
className={cn([
111-
'touch:hidden hidden lg:block',
111+
'hidden lg:block pointer-coarse:hidden',
112112
'transition-all duration-200',
113113
isOpen
114114
? 'sticky top-[calc(var(--desktopHeaderHeight)_+_1rem)] opacity-100 md:w-[240px] md:min-w-[240px] md:pr-8'

app/components/collection/sort-mobile-drawer.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function MobileDrawer({
3939
const {pending} = useOptimisticNavigationData<boolean>('clear-all-filters');
4040

4141
return (
42-
<div className="touch:block lg:hidden">
42+
<div className="lg:hidden pointer-coarse:block">
4343
<Drawer onOpenChange={setOpen} open={open}>
4444
<DrawerTrigger asChild>
4545
<SortMobileTrigger />

app/components/collection/sort-mobile-trigger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const SortMobileTrigger = React.forwardRef<
1414
return (
1515
<IconButton
1616
ref={ref}
17-
className="touch:block w-auto flex-nowrap gap-2 px-2 lg:hidden"
17+
className="w-auto flex-nowrap gap-2 px-2 lg:hidden pointer-coarse:flex"
1818
{...props}
1919
>
2020
<IconFilters />

app/components/layout/cart-drawer-wrapper.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {CartReturn} from '@shopify/hydrogen';
22

33
import {Await, Link} from 'react-router';
44
import {CartForm} from '@shopify/hydrogen';
5-
import {cx} from 'class-variance-authority';
65
import {Suspense, useCallback, useEffect, useMemo, useState} from 'react';
76

87
import {useCartFetchers} from '~/hooks/use-cart-fetchers';
@@ -73,16 +72,16 @@ function Badge(props: {cart?: CartReturn | null; count: number}) {
7372

7473
const BadgeCounter = useMemo(
7574
() => (
76-
<span className="relative">
75+
<span className={cn('relative', count > 0 && 'mr-4')}>
7776
<span className="sr-only">{themeContent?.cart?.heading}</span>
7877
<IconBag className="size-6" />
7978
{count > 0 && (
8079
<div
81-
className={cx([
80+
className={cn([
8281
'absolute top-[-4px] right-[-12px] flex items-center justify-center',
8382
'bg-foreground text-background transition-colors',
8483
'group-active:bg-accent-foreground group-active:text-accent',
85-
'notouch:group-hover:bg-accent-foreground notouch:group-hover:text-accent',
84+
'pointer-fine:group-hover:bg-accent-foreground pointer-fine:group-hover:text-accent',
8685
'aspect-square h-auto min-w-[1.35rem] rounded-full p-1',
8786
'text-center text-[.7rem] leading-[0] subpixel-antialiased',
8887
])}

app/components/layout/header-logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function Logo(props: {
1717

1818
if (!logo?._ref) {
1919
return (
20-
<div className="font-heading notouch:group-hover:text-accent-foreground flex h-11 items-center justify-center text-2xl">
20+
<div className="font-heading pointer-fine:group-hover:text-accent-foreground flex h-11 items-center justify-center text-2xl">
2121
{siteName}
2222
</div>
2323
);

app/components/navigation/desktop-navigation.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export function DesktopNavigation(props: {data?: NavigationProps}) {
2525
);
2626

2727
return (
28-
<NavigationMenu className="touch:hidden hidden lg:block" id="header-nav">
28+
<NavigationMenu
29+
className="hidden lg:block pointer-coarse:hidden"
30+
id="header-nav"
31+
>
2932
<CssVars
3033
dropdownWidth={dropdownWidth}
3134
viewportPosition={viewportPosition}

app/components/navigation/mobile-navigation-trigger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const MobileNavigationTrigger = React.forwardRef<
1010
return (
1111
<IconButton
1212
ref={ref}
13-
className="touch:block -mr-2 lg:mr-0 lg:hidden"
13+
className="-mr-2 lg:mr-0 lg:hidden pointer-coarse:block"
1414
{...props}
1515
>
1616
<span className="sr-only">Menu</span>

app/components/navigation/mobile-navigation.client.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {ScrollArea} from '../ui/scroll-area';
1919
import {MobileNavigationTrigger} from './mobile-navigation-trigger';
2020

2121
const mobileMenuLinkClass = cn(
22-
'flex rounded-xs px-4 py-2 items-center gap-2 w-full transition-colors notouch:hover:bg-accent notouch:hover:text-accent-foreground touch:active:bg-accent touch:active:text-accent-foreground',
22+
'flex rounded-xs px-4 py-2 items-center gap-2 w-full transition-colors pointer-fine:hover:bg-accent pointer-fine:hover:text-accent-foreground pointer-coarse:active:bg-accent pointer-coarse:active:text-accent-foreground',
2323
);
2424

2525
export function MobileNavigation(props: {data?: NavigationProps}) {
@@ -31,7 +31,7 @@ export function MobileNavigation(props: {data?: NavigationProps}) {
3131

3232
// Todo => Add <Navlink /> support
3333
return (
34-
<div className="touch:block lg:hidden">
34+
<div className="lg:hidden pointer-coarse:block">
3535
<Drawer
3636
direction={device === 'desktop' ? 'right' : 'bottom'}
3737
onOpenChange={setOpen}

app/components/product/media-gallery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function ThumbnailCarousel({
191191
{media.__typename === 'MediaImage' && media.image && (
192192
<button
193193
className={cn(
194-
'border-primary/0 notouch:hover:border-primary/100 overflow-hidden rounded-(--media-border-corner-radius) border-2 transition-opacity',
194+
'border-primary/0 pointer-fine:hover:border-primary/100 overflow-hidden rounded-(--media-border-corner-radius) border-2 transition-opacity',
195195
'ring-offset-background focus-visible:ring-ring transition focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden',
196196
media.id === selectedImage.id && 'border-primary/100',
197197
)}

0 commit comments

Comments
 (0)