Update type definitions for "react-copy-to-clipboard" (#38565)

* add required property children to Props

* name function arguments for onCopy

* put required props before optional

* make all Options attributes optional and add format

* extend and add tests

* indicate lib version for these types and add contributor
This commit is contained in:
Ward Delabastita 2019-09-27 18:27:31 +02:00 committed by Ben Lichtman
parent a618db32ef
commit 9ae12bafb1
2 changed files with 20 additions and 6 deletions

View File

@ -1,7 +1,8 @@
// Type definitions for react-copy-to-clipboard 4.2
// Type definitions for react-copy-to-clipboard 4.3
// Project: https://github.com/nkbt/react-copy-to-clipboard
// Definitions by: Meno Abels <https://github.com/mabels>
// Bernabe <https://github.com/BernabeFelix>
// Ward Delabastita <https://github.com/wdlb>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@ -13,13 +14,15 @@ export = CopyToClipboard;
declare namespace CopyToClipboard {
interface Options {
debug: boolean;
message: string;
debug?: boolean;
format?: "text/html" | "text/plain";
message?: string;
}
interface Props {
children: React.ReactNode;
text: string;
onCopy?(a: string, b: boolean): void;
onCopy?(text: string, result: boolean): void;
options?: Options;
}
}

View File

@ -1,11 +1,22 @@
import * as React from "react";
import CopyToClipboard = require("react-copy-to-clipboard");
export class Test extends React.Component {
export class OnlyRequiredProps extends React.Component {
render() {
return (
<CopyToClipboard text={"Hello World"}>
<button>Copy to clipboard with button</button>
</CopyToClipboard>
);
}
}
export class AllProps extends React.Component {
render() {
return (
<CopyToClipboard text={"Hello World"}
onCopy={() => {}}>
onCopy={() => {}}
options={{debug: true, message: "message", format: "text/plain"}}>
<span>Copy to clipboard with span</span>
</CopyToClipboard>
);