Skip to content

Commit

Permalink
Remove touch handlers, allow card switch from top
Browse files Browse the repository at this point in the history
  • Loading branch information
joonassandell committed Sep 14, 2024
1 parent 1663410 commit d1e4523
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
8 changes: 1 addition & 7 deletions app/dynamic-pay-button/DynamicPayButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Content } from './components/Content';
import { createContext, useContext, useEffect, useRef, useState } from 'react';
import {
type DynamicBuyButtonContextProps,
type DynamicBuyButtonProps,
type TabContentProps,
TABS,
} from './';
Expand All @@ -27,10 +26,7 @@ import { TabsList } from './components/TabsList';
*
* @author Joonas Sandell <[email protected]>
*/
export const DynamicPayButton = ({
onCardTouchEnd,
onCardTouchStart,
}: DynamicBuyButtonProps) => {
export const DynamicPayButton = () => {
const [ccv, setCcv] = useState<string>('');
const [icon, setIcon] = useState(<CreditCard />);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -112,8 +108,6 @@ export const DynamicPayButton = ({
handleOpen,
inputRef,
loading,
onCardTouchEnd,
onCardTouchStart,
open,
overflow,
selectedTab,
Expand Down
15 changes: 7 additions & 8 deletions app/dynamic-pay-button/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const Card = ({
variant = 'visa',
...props
}: CardProps) => {
const { onCardTouchEnd, onCardTouchStart, overflow, setOverflow } =
useDynamicPayButton();
const { overflow, setOverflow } = useDynamicPayButton();
const [flip, setFlip] = useState(false);
const x = useMotionValue(0);
const scale = useTransform(x, [-150, 0, 150], [0.8, 1, 0.8]);
Expand All @@ -33,10 +32,12 @@ export const Card = ({

const handleDragEndOffset: DragHandlers['onDragEnd'] = (e, info) => {
if (front) {
if (info.offset.x < -100) {
onDragEndOffset && onDragEndOffset(e, info);
}
if (info.offset.x > 100 || info.offset.y > 50) {
if (
info.offset.x < -100 ||
info.offset.x > 100 ||
info.offset.y < -50 ||
info.offset.y > 50
) {
onDragEndOffset && onDragEndOffset(e, info);
}
}
Expand All @@ -57,8 +58,6 @@ export const Card = ({
initial={false}
onDragEnd={handleDragEndOffset}
onDragStart={() => !overflow && setOverflow(true)}
onTouchEnd={e => onCardTouchEnd && onCardTouchEnd(e)}
onTouchStart={e => onCardTouchStart && onCardTouchStart(e)}
style={{
perspective: 1000,
rotate,
Expand Down
8 changes: 1 addition & 7 deletions app/dynamic-pay-button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import {
type PropsWithChildren,
type RefObject,
type SetStateAction,
type TouchEventHandler,
} from 'react';
import { type DragHandlers, type HTMLMotionProps } from 'framer-motion';
import { type TabsContentProps } from '@radix-ui/react-tabs';

export interface DynamicBuyButtonProps {
onCardTouchEnd?: TouchEventHandler<HTMLDivElement>;
onCardTouchStart?: TouchEventHandler<HTMLDivElement>;
}

export interface DynamicBuyButtonContextProps extends DynamicBuyButtonProps {
export interface DynamicBuyButtonContextProps {
ccv: string;
handleOpen: () => void;
inputRef: RefObject<HTMLInputElement>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@joonassandell/ui-lab",
"description": "User interface laboratory by Joonas Sandell",
"version": "0.1.10",
"version": "0.1.11",
"type": "module",
"author": {
"name": "Joonas Sandell",
Expand Down

0 comments on commit d1e4523

Please sign in to comment.