-
Notifications
You must be signed in to change notification settings - Fork 32
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
Create index.d.ts #149
base: master
Are you sure you want to change the base?
Create index.d.ts #149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react' | ||
import { ReactNode } from 'react'; | ||
|
||
export interface ViewportTrackerProps { | ||
children: React.ReactNode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
export class ViewportTracker extends React.Component<ViewportTrackerProps> {} | ||
|
||
|
||
export interface ViewportAwareComponentProps { | ||
/** | ||
* Determines pre-triggering of inViewport. Useful for rendering components beforehand to improve user experience. A ratio of 0.5 means that the effective viewport will be twice the size of the real viewport. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should probably be split into several lines. |
||
*/ | ||
preTriggerRatio?: number = 0 | ||
/** | ||
* Invoked when the component enters the viewport. | ||
*/ | ||
onViewportEnter?: () => void | ||
/** | ||
* Invoked when the component leaves the viewport. | ||
*/ | ||
onViewportLeave?: () => void | ||
/** | ||
* Allows access to the reference of the wrapped component. | ||
*/ | ||
innerRef?: React.Ref | ||
} | ||
export class ViewportAware<P> extends React.Component<ViewportAwareComponentProps & P> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are all of the classes and interfaces exported? Isn't the |
||
|
||
export interface ViewportAwarePlaceholderProps { | ||
/** | ||
* Placeholder that can override the one provided on construction | ||
*/ | ||
placeholder?: React.Component | ||
/** | ||
* Whether to keep the wrapped component displayed once it enters the viewport. | ||
*/ | ||
retainOnceInViewport?: boolean | ||
} | ||
export class ViewportAwarePlaceholder extends React.Component<ViewportAwarePlaceholderProps> {} | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great if you can unify the number of blank lines between the code blocks in the file. There are a total of 3 here and a total of 2 at line 9. One blank line is enough. Ideally, we should have TSLint setup, but that is not absolutely necessary at the moment. |
||
export const Viewport = { | ||
Tracker: ViewportTracker, | ||
Aware: (component: typeof React.Component) => ViewportAware, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
WithPlaceholder: (image: React.Component, placeholder: React.Component) => ViewportAwarePlaceholder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wrapped component can be something other than image as well, so I would replace |
||
} |
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 believe that this import is obsolete since you are only accessing
ReactNode
viaReact
a few lines below.