From dd4b74b0afd8f17e4f16f3291f1b9fc545d7430f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20O=C4=9Fuzhan=20Y=C4=B1ld=C4=B1z?= Date: Mon, 25 Mar 2019 20:12:56 +0300 Subject: [PATCH] Add type definitions for react-editext (#34161) * add type definitions for react-editext * set strictFunctionTypes to true * refactor index.d.ts file * format react-editext-tests.tsx file --- types/react-editext/index.d.ts | 104 ++++++++++++++++++++ types/react-editext/react-editext-tests.tsx | 15 +++ types/react-editext/tsconfig.json | 25 +++++ types/react-editext/tslint.json | 1 + 4 files changed, 145 insertions(+) create mode 100644 types/react-editext/index.d.ts create mode 100644 types/react-editext/react-editext-tests.tsx create mode 100644 types/react-editext/tsconfig.json create mode 100644 types/react-editext/tslint.json diff --git a/types/react-editext/index.d.ts b/types/react-editext/index.d.ts new file mode 100644 index 0000000000..69a1872bdd --- /dev/null +++ b/types/react-editext/index.d.ts @@ -0,0 +1,104 @@ +// Type definitions for react-editext 3.1 +// Project: https://github.com/alioguzhan/react-editext +// Definitions by: Ali Oguzhan Yildiz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.3 + +import * as React from 'react'; +export type EdiTextType = + | 'text' + | 'textarea' + | 'email' + | 'number' + | 'date' + | 'datetime-local' + | 'time' + | 'month' + | 'url' + | 'week' + | 'tel'; + +export interface EdiTextProps { + /** + * Props to be passed to input element. + * Any kind of valid DOM attributes are welcome + */ + inputProps?: object; + /** + * Props to be passed to div element that shows the text. + * You can specify your own `styles` or `className` + */ + viewProps?: object; + /** + * Value of the content [in view mode] and input [in edit mode] + */ + value: string; + /** + * A simple hint message appears at the bottom of input element. + * Any valid element is allowed. + */ + hint?: React.ReactNode; + /** + * If validation fails this message will appear + */ + validationMessage?: string; + /** + * Pass your own validation function. + * takes one param -> `value`. + * It must return `true` or `false` + */ + validation?: (...args: string[]) => boolean; + /** + * will be called when validation fails. + * takes one param which is the current value of input + */ + onValidationFail?: (...args: string[]) => any; + /** + * Input type. Possible options are: + * `text`, `number`, `email`, `textarea`, `date`, + * `datetime-local`, `time`, `month`, `url`, `week`, `tel` + */ + type: EdiTextType; + /** + * will be called when user clicked cancel button + */ + onCancel?: (...args: any[]) => any; + /** + * will be called when user clicked save button. + * takes one param which is the current value of input + */ + onSave: (...args: string[]) => any; + /** + * Custom class name for SAVE button. + */ + saveButtonClassName?: string; + /** + * Custom class name for EDIT button. + */ + editButtonClassName?: string; + /** + * Custom class name for CANCEL button. + */ + cancelButtonClassName?: string; + /** + * Content for CANCEL button. Any valid element and node are allowed. + */ + cancelButtonContent?: any; + /** + * Content for SAVE button. Any valid element and node are allowed. + */ + saveButtonContent?: any; + /** + * Content for EDIT button. Any valid element and node are allowed. + */ + editButtonContent?: any; + /** + * Set it to `true` if you don't want to see default icons + * on action buttons.See Examples page for more details. + */ + hideIcons?: boolean; +} + +export default class EdiText extends React.Component { + render(): JSX.Element; +} diff --git a/types/react-editext/react-editext-tests.tsx b/types/react-editext/react-editext-tests.tsx new file mode 100644 index 0000000000..628b1308c3 --- /dev/null +++ b/types/react-editext/react-editext-tests.tsx @@ -0,0 +1,15 @@ +import EdiText from 'react-editext'; + +import * as React from 'react'; +import { render } from 'react-dom'; + +declare const container: Element; + +render( + console.log(value)} + />, + container, +); diff --git a/types/react-editext/tsconfig.json b/types/react-editext/tsconfig.json new file mode 100644 index 0000000000..013302aee5 --- /dev/null +++ b/types/react-editext/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-editext-tests.tsx" + ] +} diff --git a/types/react-editext/tslint.json b/types/react-editext/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-editext/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }