Skip to content

Commit

Permalink
Merge branch 'variants'
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasKn committed Feb 9, 2024
2 parents c456b35 + 3adf18c commit bf9c585
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/components/product/VariantSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type {
ProductOption,
ProductVariant,
} from '@shopify/hydrogen/storefront-api-types';
import type {ProductOption} from '@shopify/hydrogen/storefront-api-types';
import type {ProductVariantFragmentFragment} from 'storefrontapi.generated';
import type {PartialDeep} from 'type-fest';
import type {PartialObjectDeep} from 'type-fest/source/partial-deep';

Expand Down Expand Up @@ -33,7 +31,7 @@ export function VariantSelector(props: {
| undefined
)[]
| undefined;
variants?: Array<PartialDeep<ProductVariant>>;
variants?: Array<PartialDeep<ProductVariantFragmentFragment>>;
}) {
const selectedVariant = useSelectedVariant({variants: props.variants});

Expand Down Expand Up @@ -102,12 +100,13 @@ export function VariantSelector(props: {
return options?.map((option) => (
<div key={option.name}>
<div>{option.name}</div>
<Pills option={option} />
<Pills handle={selectedVariant?.product?.handle} option={option} />
</div>
));
}

function Pills(props: {
handle: string | undefined;
option: {
name: string | undefined;
value: string | undefined;
Expand All @@ -116,11 +115,13 @@ function Pills(props: {
}) {
const navigate = useNavigate();
const layoutId = useRef(
props.option.name +
props.handle! +
props.option.name +
'-' +
Math.random().toString(36).substring(2, 15) +
Math.random().toString(36).substring(2, 15),
);

const optimisticId = `${props.option.name}-selected-variant`;
const {optimisticData, pending} =
useOptimisticNavigationData<string>(optimisticId);
Expand Down Expand Up @@ -188,7 +189,7 @@ function Pills(props: {
)}
<m.span
className={cn([
'notouch:hover:text-accent-foreground inline-flex h-8 items-center justify-center whitespace-nowrap px-3 py-1.5 transition-colors',
'inline-flex h-8 items-center justify-center whitespace-nowrap px-3 py-1.5 transition-colors notouch:hover:text-accent-foreground',
isActive && 'text-accent-foreground',
])}
tabIndex={-1}
Expand Down

0 comments on commit bf9c585

Please sign in to comment.