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

[type] Move type definitions from DefinitelyTyped #609

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"size": "size-limit",
"size:why": "size-limit --why packages/react-swipeable-views/lib/index.js",
"watch": "lerna exec --concurrency 99 -- babel src --out-dir lib --watch",
"build": "rm -rf packages/*/lib && cross-env NODE_ENV=production lerna exec -- babel --config-file ../../babel.config.js src --out-dir lib --ignore test.js",
"build": "yarn prebuild && cross-env NODE_ENV=production lerna exec -- babel --config-file ../../babel.config.js src --out-dir lib --ignore test.js && yarn build:copy-files",
"prebuild": "rm -rf packages/*/lib",
"build:copy-files": "lerna exec node ../../scripts/copy-files.js",
"release": "yarn build && yarn lerna exec yarn prepublish && lerna publish",
"postrelease": "yarn docs:deploy"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/react-swipeable-views-core/src/checkIndexBounds.d.ts
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;
17 changes: 17 additions & 0 deletions packages/react-swipeable-views-core/src/computeIndex.d.ts
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;
};
4 changes: 4 additions & 0 deletions packages/react-swipeable-views-core/src/constant.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const constant: {
RESISTANCE_COEF: number;
UNCERTAINTY_THRESHOLD: number;
};
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;
5 changes: 5 additions & 0 deletions packages/react-swipeable-views-core/src/index.d.ts
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';
1 change: 1 addition & 0 deletions packages/react-swipeable-views-core/src/mod.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function mod(n: number, m: number): number;
3 changes: 2 additions & 1 deletion packages/react-swipeable-views-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"prop-types": "^15.6.0",
"react-event-listener": "^0.6.0",
"react-swipeable-views-core": "^0.13.7",
"shallow-equal": "^1.2.1"
"shallow-equal": "^1.2.1",
"@material-ui/types": "^4.0.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated

Suggested change
"@material-ui/types": "^4.0.0"

Copy link

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

Copy link
Owner

@oliviertassinari oliviertassinari May 30, 2021

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.

},
"devDependencies": {
"pkgfiles": "^2.3.2"
Expand Down
18 changes: 18 additions & 0 deletions packages/react-swipeable-views-utils/src/autoPlay.d.ts
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 packages/react-swipeable-views-utils/src/bindKeyboard.d.ts
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>;
3 changes: 3 additions & 0 deletions packages/react-swipeable-views-utils/src/index.d.ts
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';
29 changes: 29 additions & 0 deletions packages/react-swipeable-views-utils/src/virtualize.d.ts
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>;
56 changes: 56 additions & 0 deletions packages/react-swipeable-views/src/SwipeableViews.d.ts
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,
> {}
2 changes: 2 additions & 0 deletions packages/react-swipeable-views/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './SwipeableViews';
export { default } from './SwipeableViews';
31 changes: 31 additions & 0 deletions scripts/copy-files.js
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();
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,13 @@
"@babel/runtime" "7.0.0"
recompose "^0.29.0"

"@material-ui/types@^4.0.0":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@material-ui/types/-/types-4.1.1.tgz#b65e002d926089970a3271213a3ad7a21b17f02b"
integrity sha512-AN+GZNXytX9yxGi0JOfxHrRTbhFybjUJ05rnsBVjcB+16e466Z0Xe5IxawuOayVZgTBNDxmPKo5j4V6OnMtaSQ==
dependencies:
"@types/react" "*"

"@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
Expand Down