Skip to content

Commit

Permalink
fix(useref): fix type for useref and update documentation (#183)
Browse files Browse the repository at this point in the history
* fix(useref): fix type for useref and update documentation

* style(lint): fix lint issues
  • Loading branch information
femioladeji authored Jul 4, 2022
1 parent 9b82435 commit 03ef61c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-slideshow-image",
"version": "4.0.0",
"version": "4.0.1",
"description": "An image slideshow with react",
"license": "MIT",
"main": "dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/fade.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { FadeZoom } from './fadezoom';
import { defaultProps } from './props';
import { FadeProps } from './types';
import { FadeProps, SlideshowRef } from './types';

export const Fade = React.forwardRef((props: FadeProps, ref) => {
export const Fade = React.forwardRef<SlideshowRef, FadeProps>((props, ref) => {
return <FadeZoom {...props} scale={1} ref={ref} />;
});

Expand Down
4 changes: 2 additions & 2 deletions src/fadezoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
showNextArrow,
showPreviousArrow,
} from './helpers';
import { ButtonClick, ZoomProps } from './types';
import { ButtonClick, SlideshowRef, ZoomProps } from './types';
import { defaultProps } from './props';

export const FadeZoom = React.forwardRef((props: ZoomProps, ref) => {
export const FadeZoom = React.forwardRef<SlideshowRef, ZoomProps>((props, ref) => {
const [index, setIndex] = useState<number>(
getStartingIndex(props.children, props.defaultIndex)
);
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
export { Fade } from './fade';
export { Zoom } from './zoom';
export { Slide } from './slide';
export { FadeProps, ZoomProps, SlideProps } from './types';
export { FadeProps, ZoomProps, SlideProps, SlideshowRef } from './types';
4 changes: 2 additions & 2 deletions src/slide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
showNextArrow,
showPreviousArrow,
} from './helpers';
import { ButtonClick, SlideProps } from './types';
import { ButtonClick, SlideshowRef, SlideProps } from './types';
import { defaultProps } from './props';

export const Slide = React.forwardRef((props: SlideProps, ref) => {
export const Slide = React.forwardRef<SlideshowRef, SlideProps>((props, ref) => {
const [index, setIndex] = useState(getStartingIndex(props.children, props.defaultIndex));
const [wrapperWidth, setWrapperWidth] = useState<number>(0);
const wrapperRef = useRef<HTMLDivElement>(null);
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ export type IndicatorPropsType = {
};

export type TweenEasingFn = (amount: number) => number;

export type SlideshowRef = {
goNext: () => void;
goBack: () => void;
goTo: (index: number) => void;
};
4 changes: 2 additions & 2 deletions src/zoom.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { FadeZoom } from './fadezoom';
import { defaultProps } from './props';
import { ZoomProps } from './types';
import { SlideshowRef, ZoomProps } from './types';

export const Zoom = React.forwardRef((props: ZoomProps, ref) => {
export const Zoom = React.forwardRef<SlideshowRef, ZoomProps>((props, ref) => {
return <FadeZoom {...props} ref={ref} />;
});

Expand Down
6 changes: 3 additions & 3 deletions stories/Methods.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ The `goTo(index)` method goes to a particular index. It takes an integer as the

```tsx
import React from 'react';
import { Slide } from 'react-slideshow-image';
import { Slide, SlideshowRef } from 'react-slideshow-image';
import 'react-slideshow-image/dist/styles.css';

const Example = () => {
const slideRef = useRef(null)
const slideRef = useRef<SlideshowRef>(null)
return (
<>
<Slide indicators={true} ref={slideRef}>
Expand All @@ -25,7 +25,7 @@ const Example = () => {
</Slide>
<div style={{display: 'flex', justifyContent: 'center', margin: '50px 0'}}>
<button type="button" style={{marginRight: '20px'}} onClick={() => slideRef.current.goBack()}>Back</button>
<button type="button" style={{marginRight: '20px'}} onClick={() => slideRef.current.next()}>Next</button>
<button type="button" style={{marginRight: '20px'}} onClick={() => slideRef.current.goNext()}>Next</button>
<select onChange={(event) => slideRef.current.goTo(parseInt(event.currentTarget.value))}>
<option>--Select--</option>
<option value="0">First</option>
Expand Down
9 changes: 4 additions & 5 deletions stories/Methods.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import React, { useRef } from 'react';
import { Meta, Story } from '@storybook/react';
import { Slide } from '../src';
import { Slide, SlideshowRef } from '../src';
import type { SlideProps } from '../src';
import mdx from './Methods.mdx';
import { useRef } from '@storybook/addons';

const meta: Meta = {
title: 'Examples/Methods',
Expand All @@ -19,7 +18,7 @@ const meta: Meta = {
export default meta;

const Template: Story<SlideProps> = args => {
const slideRef = useRef(null)
const slideRef = useRef<SlideshowRef>(null)
return <>
<Slide indicators={true} ref={slideRef}>
<div style={{textAlign: 'center', background: 'red', padding: '200px 0', fontSize: '30px'}}>First Slide</div>
Expand All @@ -29,7 +28,7 @@ const Template: Story<SlideProps> = args => {
</Slide>
<div style={{display: 'flex', justifyContent: 'center', margin: '50px 0'}}>
<button type="button" style={{marginRight: '20px'}} onClick={() => slideRef.current.goBack()}>Back</button>
<button type="button" style={{marginRight: '20px'}} onClick={() => slideRef.current.next()}>Next</button>
<button type="button" style={{marginRight: '20px'}} onClick={() => slideRef.current.goNext()}>Next</button>
<select onChange={(event) => slideRef.current.goTo(parseInt(event.currentTarget.value))}>
<option>--Select--</option>
<option value="0">First</option>
Expand Down

0 comments on commit 03ef61c

Please sign in to comment.