Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

likhith/migrated swipeablewrapper component to tsx #31

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;