diff --git a/types/formol/formol-tests.tsx b/types/formol/formol-tests.tsx new file mode 100644 index 0000000000..4b41d885ba --- /dev/null +++ b/types/formol/formol-tests.tsx @@ -0,0 +1,121 @@ +import * as React from 'react'; +import Formol, { Field, Conditional, Inliner } from 'formol'; + +class UpdateForm extends React.PureComponent { + render() { + return ( +
+ + Name + Value + +
+ ); + } +} + +class ComplexForm extends React.PureComponent { + render() { + const item = { firstname: 'first', lastname: 'last' }; + + return ( +
+ ({ + firstname: + (firstname ? firstname.length : 0) + (lastname ? lastname.length : 0) <= 6 + ? 'Your full name must be greater than 6 characters.' + : null, + })} + > + + First Name + + + Last Name + + (new Date(v) < new Date('1950-01-01') ? 'You can’t be too old' : '')} + > + Day of birth + + + + Zip code + + !zip}> + City + + + + Continent + + + ['Asia', 'North America', 'South America'].indexOf(continent) !== -1 + } + > + + Fast shipping + + + + (firstname ? firstname.length : 0) + + (lastname ? lastname.length : 0) + + (zip ? zip.length : 0) + + (city ? city.length : 0) + + (continent ? continent.length : 0) + } + > + + Indicative price + + + + Choose some colors + + +
+ ); + } +} diff --git a/types/formol/index.d.ts b/types/formol/index.d.ts new file mode 100644 index 0000000000..805491de06 --- /dev/null +++ b/types/formol/index.d.ts @@ -0,0 +1,136 @@ +// Type definitions for formol 2.7 +// Project: https://github.com/Kozea/formol +// Definitions by: today- +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from "react"; + +export const ConditionalContext: { + Consumer: any; + Provider: any; +}; + +export const FormolContext: { + Consumer: any; + Provider: any; +}; + +interface FormolProps { + item?: V; + types?: ReadonlyArray; + i18n?: any; + className?: string; + readOnly?: boolean; + submitText?: any; + cancelText?: any; + noCancel?: any; + allowUnmodifiedSubmit?: any; + extra?: React.ReactNode; + classes?: any; + onSubmit?: (e: Event) => void; + validator?: (v: V) => {[K in keyof V]?: string | null}; +} + +declare const Formol: React.ComponentType; +export default Formol; + +export const Inliner: React.ComponentType; + +interface FieldSetProps { + type?: string; + isChecked?: boolean; + value?: V; + choices?: ReadonlyArray; + elementRef?: React.Ref; + dangerousRawHTMLLabels?: boolean; + onChange?: () => void; +} + +export const FieldSet: React.ComponentType; + +interface SwitchButtonProps { + type?: string; + i18n?: { yes: React.ReactNode, no: React.ReactNode } & { [k: string]: any }; + leftLabel?: React.ReactNode; + rightLabel?: React.ReactNode; + className?: string; +} + +export const SwitchButton: React.ComponentType; + +interface ConditionalProps { + show?: ((val: V) => boolean) | boolean; + readOnly?: ((val: V) => boolean) | boolean; + context?: any; + value?: (v: V) => any; +} + +export const Conditional: React.ComponentType; + +export function ConditionalContextWrapper(e: React.Component): React.Component; + +interface FieldProps { + register?: (name: string, element: React.Ref, validator: any, validityErrors: any) => void; + unregister?: (name: string) => void; + name?: string; + validator?: (v: V) => string; + validityErrors?: any; + value?: V; + normalizer?: (v: V) => V; + handleChange?: (name: string, v: V) => void; + handleEntered?: (name: string, v: V) => void; + dangerousRawHTMLLabels?: boolean; + type?: string; + title?: string; + modified?: boolean; + className?: string; + readOnly?: boolean; + disabled?: boolean; + unit?: React.ReactNode; + extras?: React.ReactNode; + formatter?: (v: V) => V; + unformatter?: (v: V) => V; + children?: any; + classNameModifiers?: any; + TypeField?: React.ComponentType; + i18n?: any; + error?: React.ReactNode; + choices?: ReadonlyArray; + size?: number; + max?: number; + required?: boolean; + minLength?: number; +} + +export const Field: React.ComponentType; + +export const NoRequestNeeded: Error; + +export function FormolContextWrapper(WrappedComponent: React.Component): React.Component; + +export function choicesAdapter(WrappedComponent: React.Component): React.Component; + +export function memoizedChoices(WrappedComponent: React.Component): React.Component; + +export function multipleAdapter(WrappedComponent: React.Component): React.Component; + +export function copy(o: any, names: ReadonlyArray): any; + +export function diff(newItem: any, oldItem: any, names: ReadonlyArray): any; + +export function emptyStringToNull(v: string): string | null; + +export function fieldPropsAdapter(v: any): any; + +export function get(data: any, key: string): any; + +export function insert(transientItem: any, name: string, value: any, names: ReadonlyArray): any; + +export function isModified(newItem: any, oldItem: any, names: ReadonlyArray): boolean; + +export function nullishToEmptyString(v?: string): string; + +export function set(data: any, key: string, value: any, noArray?: boolean): any; + +export function unrest(e: any, ...args: any[]): any; diff --git a/types/formol/tsconfig.json b/types/formol/tsconfig.json new file mode 100644 index 0000000000..38e43eeb71 --- /dev/null +++ b/types/formol/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "formol-tests.tsx" + ] +} diff --git a/types/formol/tslint.json b/types/formol/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/formol/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }