mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 04:49:15 +08:00
add react-mailchimp-subscribe (#24783)
This commit is contained in:
committed by
Mohamed Hegazy
parent
13a7c42013
commit
6235cb3eb1
51
types/react-mailchimp-subscribe/index.d.ts
vendored
Normal file
51
types/react-mailchimp-subscribe/index.d.ts
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
// Type definitions for react-mailchimp-subscribe 2.0
|
||||
// Project: https://revolunet.github.io/react-mailchimp-subscribe/
|
||||
// Definitions by: Omar Diab <https://github.com/osdiab>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
import { Component, ReactNode } from "react";
|
||||
|
||||
// A few common set of form fields, based on defaults in Mailchimp's website
|
||||
export interface EmailFormFields {
|
||||
EMAIL: string;
|
||||
}
|
||||
|
||||
export interface NameFormFields extends EmailFormFields {
|
||||
FNAME: string;
|
||||
LNAME: string;
|
||||
}
|
||||
|
||||
export interface ClassicFormFields extends NameFormFields {
|
||||
"BIRTHDAY[month]": number;
|
||||
"BIRTHDAY[day]": number;
|
||||
}
|
||||
|
||||
// library default form just sends EMAIL
|
||||
export type DefaultFormFields = EmailFormFields;
|
||||
|
||||
export interface ResponseArgs {
|
||||
status: "success" | "error";
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface PendingArgs {
|
||||
status: "sending" | null;
|
||||
message: null;
|
||||
}
|
||||
|
||||
export interface SubscribeArg<FormFields> {
|
||||
subscribe: (data: FormFields) => void;
|
||||
}
|
||||
|
||||
export type FormHooks<FormFields> = SubscribeArg<FormFields> &
|
||||
(ResponseArgs | PendingArgs);
|
||||
|
||||
export interface Props<FormFields> {
|
||||
render?: (hooks: FormHooks<FormFields>) => ReactNode;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export default class MailchimpSubscribe<FormFields = DefaultFormFields> extends Component<
|
||||
Props<FormFields>
|
||||
> {}
|
||||
@@ -0,0 +1,57 @@
|
||||
import * as React from "react";
|
||||
import MailchimpSubscribe, {
|
||||
NameFormFields
|
||||
} from "react-mailchimp-subscribe";
|
||||
|
||||
const Example: React.StatelessComponent = () => (
|
||||
<>
|
||||
<MailchimpSubscribe
|
||||
render={(hooks) => (<>
|
||||
{ hooks.status === "error" &&
|
||||
<span>hooks.message</span>
|
||||
}
|
||||
{ hooks.status === "sending" &&
|
||||
<span>Sending!</span>
|
||||
}
|
||||
{ hooks.status === "success" &&
|
||||
<span>It's been sent! {hooks.message}</span>
|
||||
}
|
||||
<form
|
||||
onSubmit={e => {
|
||||
e.preventDefault();
|
||||
hooks.subscribe({ EMAIL: "8675309@aol.com" });
|
||||
}}
|
||||
/>
|
||||
</>)}
|
||||
url="spam.biz/subscribe"
|
||||
/>
|
||||
{ /* once Typescript 2.9 is out, generics in components will be allowed, at that point uncomment these. */ }
|
||||
{ /* https://github.com/Microsoft/TypeScript/pull/22415 */ }
|
||||
{/* <MailchimpSubscribe<any>
|
||||
render={(hooks) => (
|
||||
<form
|
||||
onSubmit={e => {
|
||||
e.preventDefault();
|
||||
hooks.subscribe({ myArbitraryData: "is here!" });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
url="spam.biz/subscribe"
|
||||
/>
|
||||
<MailchimpSubscribe<NameFormFields>
|
||||
render={(hooks) => (
|
||||
<form
|
||||
onSubmit={e => {
|
||||
e.preventDefault();
|
||||
hooks.subscribe({
|
||||
FNAME: "大",
|
||||
LNAME: "哥",
|
||||
EMAIL: "da.ge@qq.com",
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
url="spam.biz/subscribe"
|
||||
/> */}
|
||||
</>
|
||||
);
|
||||
24
types/react-mailchimp-subscribe/tsconfig.json
Normal file
24
types/react-mailchimp-subscribe/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"jsx": "react",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-mailchimp-subscribe-tests.tsx"
|
||||
]
|
||||
}
|
||||
1
types/react-mailchimp-subscribe/tslint.json
Normal file
1
types/react-mailchimp-subscribe/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user