-
Notifications
You must be signed in to change notification settings - Fork 483
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
[type] Move type definitions from DefinitelyTyped #609
Open
kodai3
wants to merge
6
commits into
oliviertassinari:master
Choose a base branch
from
kodai3:feature/swipeable-views-type-definitions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b9ebec1
swipeable views type definitions
kodai3 ef093ee
patch type fixes #545
kodai3 987f9c8
feature core utils type definitions
kodai3 05eb2dd
update lock file
kodai3 318adf4
Revert "patch type fixes #545"
kodai3 9bae6fa
fix import
kodai3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/react-swipeable-views-core/src/checkIndexBounds.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { SwipeableViewsProps } from 'react-swipeable-views'; | ||
|
||
export function checkIndexBounds(props: SwipeableViewsProps): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SwipeableViewsProps } from 'react-swipeable-views'; | ||
|
||
export interface ComputeIndexParams { | ||
children: SwipeableViewsProps['children']; | ||
resistance: SwipeableViewsProps['resistance']; | ||
startIndex: number; | ||
startX: number; | ||
pageX: number; | ||
viewLength: number; | ||
} | ||
|
||
export function computeIndex( | ||
params: ComputeIndexParams, | ||
): { | ||
index: number; | ||
startX: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const constant: { | ||
RESISTANCE_COEF: number; | ||
UNCERTAINTY_THRESHOLD: number; | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/react-swipeable-views-core/src/getDisplaySameSlide.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { SwipeableViewsProps } from 'react-swipeable-views'; | ||
|
||
export function getDisplaySameSlide(props: SwipeableViewsProps, nextProps: SwipeableViewsProps): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { default as checkIndexBounds } from './checkIndexBounds'; | ||
export { default as computeIndex } from './computeIndex'; | ||
export { default as constant } from './constant'; | ||
export { default as getDisplaySameSlide } from './getDisplaySameSlide'; | ||
export { default as mod } from './mod'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function mod(n: number, m: number): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { OnChangeIndexCallback, OnSwitchingCallback } from 'react-swipeable-views'; | ||
import { PropInjector } from '@material-ui/types'; | ||
|
||
export interface WithAutoPlay { | ||
index: number; | ||
onChangeIndex: OnChangeIndexCallback; | ||
onSwitching?: OnSwitchingCallback; | ||
} | ||
|
||
export interface WithAutoPlayProps { | ||
autoplay?: boolean; | ||
direction?: 'incremental' | 'decremental'; | ||
index: number; | ||
interval?: number; | ||
onChangeIndex: OnChangeIndexCallback; | ||
slideCount?: number; | ||
} | ||
export const autoPlay: PropInjector<WithAutoPlay, WithAutoPlayProps>; |
16 changes: 16 additions & 0 deletions
16
packages/react-swipeable-views-utils/src/bindKeyboard.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { PropInjector } from '@material-ui/types'; | ||
import { OnChangeIndexCallback } from 'react-swipeable-views'; | ||
|
||
export interface WithBindKeyboard { | ||
index: number; | ||
onChangeIndex: OnChangeIndexCallback; | ||
} | ||
|
||
export interface WithBindKeyboardProps { | ||
axis?: "x" | "x-reverse" | "y" | "y-reverse"; | ||
index: number; | ||
onChangeIndex: OnChangeIndexCallback; | ||
slidecount?: number; | ||
} | ||
|
||
export const bindKeyboard: PropInjector<WithBindKeyboard, WithBindKeyboardProps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as autoPlay } from './autoPlay'; | ||
export { default as bindKeyboard } from './bindKeyboard'; | ||
export { default as virtualize } from './virtualize'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { PropInjector } from '@material-ui/types'; | ||
import * as React from 'react'; | ||
import { OnChangeIndexCallback, OnTransitionEndCallback } from 'react-swipeable-views'; | ||
|
||
export interface SlideRenderProps { | ||
index: number; | ||
key: number; | ||
} | ||
|
||
export type SlideRendererCallback = (render: SlideRenderProps) => React.ReactNode; | ||
|
||
export interface WithVirtualize { | ||
index: number; | ||
onChangeIndex: OnChangeIndexCallback; | ||
slideRenderer: (render: SlideRendererCallback) => React.ReactNode; | ||
} | ||
|
||
export interface WithVirtualizeProps { | ||
index: number; | ||
onChangeIndex: OnChangeIndexCallback; | ||
onTransitionEnd?: OnTransitionEndCallback; | ||
overscanSlideAfter?: number; | ||
overscanSlideBefore?: number; | ||
slideCount?: number; | ||
children?: React.ReactNode; | ||
slideRenderer: SlideRendererCallback; | ||
} | ||
|
||
export const virtualize: PropInjector<WithVirtualize, WithVirtualizeProps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react'; | ||
|
||
export type OnChangeIndexCallback = (index: number, indexLatest: number) => void; | ||
|
||
export type OnTransitionEndCallback = () => void; | ||
|
||
export type OnSwitchingCallback = (index: number, type: OnSwitchingCallbackTypeDescriptor) => void; | ||
|
||
export type OnSwitchingCallbackTypeDescriptor = 'move' | 'end'; | ||
|
||
export type AxisType = 'x' | 'x-reverse' | 'y' | 'y-reverse'; | ||
|
||
export interface SpringConfig { | ||
duration: string; | ||
easeFunction: string; | ||
delay: string; | ||
} | ||
|
||
export interface SwipeableViewsProps extends React.HTMLProps<HTMLDivElement> { | ||
animateHeight?: boolean; | ||
animateTransitions?: boolean; | ||
axis?: AxisType; | ||
containerStyle?: React.CSSProperties; | ||
disabled?: boolean; | ||
/* | ||
* This is the config used to disable lazy loading, if true it will render all the views in first rendering. | ||
*/ | ||
disableLazyLoading?: boolean; | ||
enableMouseEvents?: boolean; | ||
hysteresis?: number; | ||
ignoreNativeScroll?: boolean; | ||
index?: number; | ||
onChangeIndex?: OnChangeIndexCallback; | ||
onSwitching?: OnSwitchingCallback; | ||
onTransitionEnd?: OnTransitionEndCallback; | ||
resistance?: boolean; | ||
style?: React.CSSProperties; | ||
slideStyle?: React.CSSProperties; | ||
springConfig?: SpringConfig; | ||
slideClassName?: string; | ||
threshold?: number; | ||
} | ||
|
||
export interface SwipeableViewsState { | ||
indexCurrent?: number; | ||
indexLatest?: number; | ||
isDragging?: boolean; | ||
isFirstRender?: boolean; | ||
heightLatest?: number; | ||
displaySameSlide?: boolean; | ||
} | ||
|
||
export default class SwipeableViews extends React.Component< | ||
SwipeableViewsProps, | ||
SwipeableViewsState, | ||
> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './SwipeableViews'; | ||
export { default } from './SwipeableViews'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable no-console */ | ||
const path = require('path'); | ||
const fse = require('fs-extra'); | ||
const glob = require('glob'); | ||
|
||
const packagePath = process.cwd(); | ||
const buildPath = path.join(packagePath, './lib'); | ||
const srcPath = path.join(packagePath, './src'); | ||
|
||
async function typescriptCopy({ from, to }) { | ||
if (!(await fse.exists(to))) { | ||
console.warn(`path ${to} does not exists`); | ||
return []; | ||
} | ||
|
||
const files = glob.sync('**/*.d.ts', { cwd: from }); | ||
const cmds = files.map(file => fse.copy(path.resolve(from, file), path.resolve(to, file))); | ||
return Promise.all(cmds); | ||
} | ||
|
||
async function run() { | ||
try { | ||
// TypeScript | ||
await typescriptCopy({ from: srcPath, to: buildPath }); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kodai3, are you planning to fix this PR? It's the last of 3 opened ones, I guess @oliviertassinari is waiting for it before a potential merge & publish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support the idea to have the types built in the library directly.
The types package of Material-UI is meant for internal usages so it shouldn't be here. As for the other pull requests. This one can be work on independently.