Skip to content

Commit

Permalink
Merge pull request #31 from likhith-deriv/lkhith/76932/migrate-swipea…
Browse files Browse the repository at this point in the history
…blewrapper-to-tsx

likhith/migrated swipeablewrapper component to tsx
  • Loading branch information
shayan-deriv committed Nov 21, 2022
2 parents 521a61e + d9d4a87 commit 11b9912
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
7 changes: 0 additions & 7 deletions packages/components/src/components/swipeable-wrapper/index.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/components/src/components/swipeable-wrapper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import SwipeableWrapper from './swipeable-wrapper';
import './swipeable-wrapper.scss';

export default SwipeableWrapper;
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { Swipeable } from 'react-swipeable';
import { Swipeable, SwipeableProps, useSwipeable } from 'react-swipeable';
import Icon from '../icon';

const SwipeableWrapper = ({ children, className, onChange, ...props }) => {
type TSwipeableWrapper = {
className?: string;
onChange: (prop?: number) => void;
is_disabled?: boolean;
} & SwipeableProps;

const SwipeableWrapper = ({ children, className, onChange, ...props }: TSwipeableWrapper) => {
const [active_index, setActiveIndex] = React.useState(0);

React.useEffect(() => {
if (typeof onChange === 'function') onChange(active_index);
onChange(active_index);
return () => {
// Makes an empty callback when unmounted so that we can reset
if (typeof onChange === 'function') onChange();
onChange();
};
}, [active_index, onChange]);

Expand Down Expand Up @@ -73,11 +78,6 @@ const SwipeableWrapper = ({ children, className, onChange, ...props }) => {
);
};

SwipeableWrapper.propTypes = {
className: PropTypes.string,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node), PropTypes.object]),
onChange: PropTypes.func,
is_disabled: PropTypes.bool,
};
SwipeableWrapper.useSwipeable = useSwipeable;

export default SwipeableWrapper;

0 comments on commit 11b9912

Please sign in to comment.