|
1 |
| -// Type definitions for react-redux-form v1.2.2 |
| 1 | +// Type definitions for react-redux-form |
2 | 2 | // Project: https://github.com/davidkpiano/react-redux-form
|
3 | 3 | // Definitions by: Robert Parker (Flavorus) <https://github.com/hsrobflavorus>, Flavorus <http://www.flavorus.com>, Alexey Svetliakov (@asvetliakov), Zach Waggoner <https://github.com/zach-waggoner>
|
4 | 4 |
|
@@ -87,7 +87,21 @@ interface CustomComponentProps extends WrapperProps {
|
87 | 87 | children: any;
|
88 | 88 | }
|
89 | 89 |
|
90 |
| -export interface FieldProps { |
| 90 | +interface MapPropsProps { |
| 91 | + onChange: (event: any) => void; |
| 92 | + onBlur: (event: any) => void; |
| 93 | + onFocus: (event: any) => void; |
| 94 | + fieldValue: FieldState; |
| 95 | + modelValue: any; |
| 96 | + viewValue: any; |
| 97 | +} |
| 98 | + |
| 99 | +type MapPropsFunc = (props: MapPropsProps) => any; |
| 100 | +type MapPropsObject = { [key: string]: (props: MapPropsProps) => any }; |
| 101 | + |
| 102 | +type MapProps = MapPropsFunc | MapPropsObject; |
| 103 | + |
| 104 | +export interface ControlProps<T> extends React.HTMLProps<T> { |
91 | 105 | /**
|
92 | 106 | * Wrap field into custom component
|
93 | 107 | */
|
@@ -168,44 +182,70 @@ export interface FieldProps {
|
168 | 182 | * @param value The value that the model is being changed to
|
169 | 183 | */
|
170 | 184 | changeAction?: (model: string, value: any) => void;
|
171 |
| -} |
172 |
| - |
173 |
| -export class Field extends React.Component<FieldProps, {}> { |
174 |
| - |
175 |
| -} |
176 |
| - |
177 |
| -interface MapPropsProps { |
178 |
| - onChange: (event: any) => void; |
179 |
| - onBlur: (event: any) => void; |
180 |
| - onFocus: (event: any) => void; |
181 |
| - fieldValue: FieldState; |
182 |
| - modelValue: any; |
183 |
| - viewValue: any; |
184 |
| -} |
185 |
| - |
186 |
| -type MapPropsFunc = (props: MapPropsProps) => any; |
187 |
| -type MapPropsObject = { [key: string]: (props: MapPropsProps) => any }; |
188 |
| - |
189 |
| -type MapProps = MapPropsFunc | MapPropsObject; |
190 |
| - |
191 |
| -export interface ControlProps extends FieldProps { |
192 | 185 | /**
|
193 | 186 | * A mapping of control-specific property keys to prop-getter functions that taken in the original props and return the result prop.
|
194 | 187 | * See {@link https://davidkpiano.github.io/react-redux-form/docs/guides/custom-controls.html the documentation on custom controls} for more information.
|
195 | 188 | */
|
196 | 189 | mapProps?: MapProps;
|
197 | 190 | controlProps?: any;
|
| 191 | + /** |
| 192 | + * Calls the callback provided to the getRef prop with the node instance. Similar to ref. |
| 193 | + */ |
| 194 | + getRef?: () => void; |
| 195 | +} |
| 196 | + |
| 197 | +export class Control<T> extends React.Component<ControlProps<T>, {}> { |
| 198 | + static input: React.ComponentClass<ControlProps<HTMLInputElement>>; |
| 199 | + static text: React.ComponentClass<ControlProps<HTMLInputElement>>; |
| 200 | + static textarea: React.ComponentClass<ControlProps<HTMLTextAreaElement>>; |
| 201 | + static radio: React.ComponentClass<ControlProps<HTMLInputElement>>; |
| 202 | + static checkbox: React.ComponentClass<ControlProps<HTMLInputElement>>; |
| 203 | + static file: React.ComponentClass<ControlProps<HTMLInputElement>>; |
| 204 | + static select: React.ComponentClass<ControlProps<HTMLSelectElement>>; |
| 205 | + static reset: React.ComponentClass<ControlProps<HTMLButtonElement>>; |
198 | 206 | }
|
199 | 207 |
|
200 |
| -export class Control extends React.Component<ControlProps, {}> { |
201 |
| - static input: React.ComponentClass<ControlProps>; |
202 |
| - static text: React.ComponentClass<ControlProps>; |
203 |
| - static textarea: React.ComponentClass<ControlProps>; |
204 |
| - static radio: React.ComponentClass<ControlProps>; |
205 |
| - static checkbox: React.ComponentClass<ControlProps>; |
206 |
| - static file: React.ComponentClass<ControlProps>; |
207 |
| - static select: React.ComponentClass<ControlProps>; |
208 |
| - static reset: React.ComponentClass<ControlProps>; |
| 208 | +export interface FieldProps<T> extends ControlProps<T> { |
| 209 | + /** |
| 210 | + * Specifies whether the children inside <Field> are dynamic; that is, whether they are subject to change based on outside values. |
| 211 | + * Default value: true. To optimize for performance, set dynamic={false} for any <Field> that does not have dynamic children. |
| 212 | + * @example |
| 213 | + * // Does NOT have dynamic children |
| 214 | + * <Field model="user.favoriteColors" dynamic={false}> |
| 215 | + * <select> |
| 216 | + * <option value="red">red</option> |
| 217 | + * <option value="green">green</option> |
| 218 | + * <option value="blue">blue</option> |
| 219 | + * </select> |
| 220 | + * </Field> |
| 221 | + * |
| 222 | + * // DOES have dynamic children |
| 223 | + * <Field model="user.favoriteColors"> |
| 224 | + * <select> |
| 225 | + * {showWhite && <option value="white">white</option>} |
| 226 | + * <option value="red">red</option> |
| 227 | + * <option value="green">green</option> |
| 228 | + * <option value="blue">blue</option> |
| 229 | + * </select> |
| 230 | + * </Field> |
| 231 | + * |
| 232 | + * // Does NOT have dynamic children |
| 233 | + * <Field model="user.state" mapProps={...} dynamic={false}> |
| 234 | + * <StatePicker /> |
| 235 | + * </Field> |
| 236 | + * |
| 237 | + * // DOES have dynamic children |
| 238 | + * const { showTerritories } = this.props; |
| 239 | + * |
| 240 | + * <Field model="user.state" mapProps={...}> |
| 241 | + * <StatePicker territories={showTerritories} /> |
| 242 | + * </Field> |
| 243 | + */ |
| 244 | + dynamic?: boolean; |
| 245 | +} |
| 246 | + |
| 247 | +export class Field<T> extends React.Component<FieldProps<T>, {}> { |
| 248 | + |
209 | 249 | }
|
210 | 250 |
|
211 | 251 | interface BaseFormProps {
|
@@ -532,7 +572,7 @@ interface ComponentFieldClassPropsMappings<P> {
|
532 | 572 | * @param propsMapping
|
533 | 573 | * @param defaultProps
|
534 | 574 | */
|
535 |
| -export function createFieldClass<P>(propsMapping: ComponentFieldClassPropsMappings<P>, defaultProps?: any): React.ComponentClass<FieldProps>; |
| 575 | +export function createFieldClass<P, T>(propsMapping: ComponentFieldClassPropsMappings<P>, defaultProps?: any): React.ComponentClass<FieldProps<T>>; |
536 | 576 |
|
537 | 577 |
|
538 | 578 | interface ControlPropsMap {
|
|
0 commit comments