Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 03b2913

Browse files
committed
Merge branch 'master' of github.com:davidkpiano/react-redux-form
2 parents 99436c0 + 5981d1c commit 03b2913

File tree

2 files changed

+76
-33
lines changed

2 files changed

+76
-33
lines changed

docs/api/Control.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ The following pre-defined `<Control>`s are available:
3232
- `<Control.select>` for `<select></select>`
3333
- `<Control.button>` for `<button></button>`
3434

35+
You can add your own types to the basic `<Control>` component as an attribute:
36+
`<Control type="password">`
37+
3538
For making custom controls that work with React Redux Form, see the [custom controls documentation](../guides/custom-controls.md).
3639

3740
```jsx

react-redux-form.d.ts

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for react-redux-form v1.2.2
1+
// Type definitions for react-redux-form
22
// Project: https://github.com/davidkpiano/react-redux-form
33
// Definitions by: Robert Parker (Flavorus) <https://github.com/hsrobflavorus>, Flavorus <http://www.flavorus.com>, Alexey Svetliakov (@asvetliakov), Zach Waggoner <https://github.com/zach-waggoner>
44

@@ -87,7 +87,21 @@ interface CustomComponentProps extends WrapperProps {
8787
children: any;
8888
}
8989

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> {
91105
/**
92106
* Wrap field into custom component
93107
*/
@@ -168,44 +182,70 @@ export interface FieldProps {
168182
* @param value The value that the model is being changed to
169183
*/
170184
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 {
192185
/**
193186
* A mapping of control-specific property keys to prop-getter functions that taken in the original props and return the result prop.
194187
* See {@link https://davidkpiano.github.io/react-redux-form/docs/guides/custom-controls.html the documentation on custom controls} for more information.
195188
*/
196189
mapProps?: MapProps;
197190
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>>;
198206
}
199207

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+
209249
}
210250

211251
interface BaseFormProps {
@@ -532,7 +572,7 @@ interface ComponentFieldClassPropsMappings<P> {
532572
* @param propsMapping
533573
* @param defaultProps
534574
*/
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>>;
536576

537577

538578
interface ControlPropsMap {

0 commit comments

Comments
 (0)