Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add initial typescript definition (#591)
- Loading branch information
Showing
12 changed files
with
1,379 additions
and
39 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist/ | ||
coverage/ | ||
typings/* |
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,101 @@ | ||
{ | ||
"jsRules": { | ||
"class-name": true, | ||
"comment-format": [ | ||
true, | ||
"check-space" | ||
], | ||
"indent": [ | ||
true, | ||
"spaces" | ||
], | ||
"no-duplicate-variable": true, | ||
"no-eval": true, | ||
"no-trailing-whitespace": true, | ||
"no-unsafe-finally": true, | ||
"one-line": [ | ||
true, | ||
"check-open-brace", | ||
"check-whitespace" | ||
], | ||
"quotemark": [ | ||
true, | ||
"double" | ||
], | ||
"semicolon": [ | ||
true, | ||
"always" | ||
], | ||
"triple-equals": [ | ||
true, | ||
"allow-null-check" | ||
], | ||
"variable-name": [ | ||
true, | ||
"ban-keywords" | ||
], | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-separator", | ||
"check-type" | ||
] | ||
}, | ||
"rules": { | ||
"class-name": true, | ||
"comment-format": [ | ||
true, | ||
"check-space" | ||
], | ||
"indent": [ | ||
true, | ||
"spaces" | ||
], | ||
"no-eval": true, | ||
"no-internal-module": true, | ||
"no-trailing-whitespace": true, | ||
"no-unsafe-finally": true, | ||
"no-var-keyword": true, | ||
"one-line": [ | ||
true, | ||
"check-open-brace", | ||
"check-whitespace" | ||
], | ||
"quotemark": [ | ||
true, | ||
"double" | ||
], | ||
"semicolon": [ | ||
true, | ||
"always" | ||
], | ||
"triple-equals": [ | ||
true, | ||
"allow-null-check" | ||
], | ||
"typedef-whitespace": [ | ||
true, | ||
{ | ||
"call-signature": "nospace", | ||
"index-signature": "nospace", | ||
"parameter": "nospace", | ||
"property-declaration": "nospace", | ||
"variable-declaration": "nospace" | ||
} | ||
], | ||
"variable-name": [ | ||
true, | ||
"ban-keywords" | ||
], | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-separator", | ||
"check-type" | ||
] | ||
} | ||
} |
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,60 @@ | ||
import { | ||
CSSProperties, | ||
Component, | ||
DragEvent, | ||
InputHTMLAttributes | ||
} from "react"; | ||
|
||
export interface FileWithPreview extends File { | ||
preview?: string; | ||
} | ||
|
||
export type DropFileEventHandler = ( | ||
acceptedOrRejected: FileWithPreview[], | ||
event: DragEvent<HTMLDivElement> | ||
) => void; | ||
export type DropFilesEventHandler = ( | ||
accepted: FileWithPreview[], | ||
rejected: FileWithPreview[], | ||
event: DragEvent<HTMLDivElement> | ||
) => void; | ||
|
||
type DropzoneRenderArgs = { | ||
draggedFiles: FileWithPreview[]; | ||
acceptedFiles: FileWithPreview[]; | ||
rejectedFiles: FileWithPreview[]; | ||
isDragActive: boolean; | ||
isDragAccept: boolean; | ||
isDragReject: boolean; | ||
}; | ||
|
||
export type DropzoneRenderFunction = (x: DropzoneRenderArgs) => JSX.Element; | ||
|
||
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>; | ||
|
||
export type DropzoneProps = Omit<React.HTMLProps<HTMLDivElement>, "onDrop"> & { | ||
disableClick?: boolean; | ||
disabled?: boolean; | ||
disablePreview?: boolean; | ||
preventDropOnDocument?: boolean; | ||
inputProps?: InputHTMLAttributes<HTMLInputElement>; | ||
maxSize?: number; | ||
minSize?: number; | ||
activeClassName?: string; | ||
acceptClassName?: string; | ||
rejectClassName?: string; | ||
disabledClassName?: string; | ||
activeStyle?: CSSProperties; | ||
acceptStyle?: CSSProperties; | ||
rejectStyle?: CSSProperties; | ||
disabledStyle?: CSSProperties; | ||
onDrop?: DropFilesEventHandler; | ||
onDropAccepted?: DropFileEventHandler; | ||
onDropRejected?: DropFileEventHandler; | ||
onFileDialogCancel?: () => void; | ||
children: React.ReactNode | DropzoneRenderFunction; | ||
}; | ||
|
||
export default class Dropzone extends Component<DropzoneProps> { | ||
open: () => 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,76 @@ | ||
import * as React from "react"; | ||
|
||
import Dropzone from "../../"; | ||
|
||
class Accept extends React.Component { | ||
state = { | ||
accepted: [], | ||
rejected: [] | ||
}; | ||
|
||
render() { | ||
return ( | ||
<section> | ||
<div className="dropzone"> | ||
<Dropzone | ||
accept="image/jpeg, image/png" | ||
onDrop={(accepted, rejected) => { | ||
this.setState({ accepted, rejected }); | ||
}} | ||
> | ||
<p> | ||
Try dropping some files here, or click to select files to upload. | ||
</p> | ||
<p>Only *.jpeg and *.png images will be accepted</p> | ||
</Dropzone> | ||
</div> | ||
<aside> | ||
<h2>Accepted files</h2> | ||
<ul> | ||
{this.state.accepted.map(f => ( | ||
<li key={f.name}> | ||
{f.name} - {f.size} bytes | ||
</li> | ||
))} | ||
</ul> | ||
<h2>Rejected files</h2> | ||
<ul> | ||
{this.state.rejected.map(f => ( | ||
<li key={f.name}> | ||
{f.name} - {f.size} bytes | ||
</li> | ||
))} | ||
</ul> | ||
</aside> | ||
</section> | ||
); | ||
} | ||
} | ||
|
||
const a = ( | ||
<Dropzone accept=".jpeg,.png"> | ||
{({ isDragActive, isDragReject }) => { | ||
if (isDragActive) { | ||
return "All files will be accepted"; | ||
} | ||
if (isDragReject) { | ||
return "Some files will be rejected"; | ||
} | ||
return "Dropping some files here..."; | ||
}} | ||
</Dropzone> | ||
); | ||
|
||
const b = ( | ||
<Dropzone accept="image/jpeg, image/png"> | ||
{({ isDragActive, isDragReject }) => { | ||
if (isDragActive) { | ||
return "All files will be accepted"; | ||
} | ||
if (isDragReject) { | ||
return "Some files will be rejected"; | ||
} | ||
return "Dropping some files here..."; | ||
}} | ||
</Dropzone> | ||
); |
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,58 @@ | ||
import * as React from "react"; | ||
|
||
import Dropzone from "../../"; | ||
|
||
class Test extends React.Component { | ||
dz: Dropzone; | ||
|
||
open() { | ||
this.dz.open(); | ||
} | ||
|
||
handleFileDialog = () => {}; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<Dropzone | ||
ref={node => { | ||
this.dz = node; | ||
}} | ||
onClick={event => console.log(event)} | ||
onDrop={(acceptedFiles, rejectedFiles, event) => | ||
console.log(acceptedFiles, rejectedFiles, event)} | ||
onDragStart={event => console.log(event)} | ||
onDragEnter={event => console.log(event)} | ||
onDragOver={event => console.log(event)} | ||
onDragLeave={event => console.log(event)} | ||
onDropAccepted={event => console.log(event)} | ||
onDropRejected={event => console.log(event)} | ||
onFileDialogCancel={() => console.log("abc")} | ||
style={{ borderStyle: "dashed" }} | ||
activeStyle={{ borderStyle: "dotted" }} | ||
acceptStyle={{ borderStyle: "dotted" }} | ||
rejectStyle={{ borderStyle: "dotted" }} | ||
disabledStyle={{ borderStyle: "dotted" }} | ||
className="regular" | ||
activeClassName="active" | ||
acceptClassName="accept" | ||
rejectClassName="reject" | ||
disabledClassName="disabled" | ||
minSize={2000} | ||
maxSize={Infinity} | ||
disablePreview | ||
disableClick | ||
disabled | ||
multiple={false} | ||
accept="*.png" | ||
name="dropzone" | ||
inputProps={{ id: "dropzone" }} | ||
> | ||
Hi | ||
</Dropzone> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Test; |
Oops, something went wrong.