Skip to content

Commit 2a7010b

Browse files
committed
Merge branch 'dev' of github.com:soyjavi/react-toolbox into dev
* 'dev' of github.com:soyjavi/react-toolbox: fix few missing propTypes update typings to 1.3.3 Declare immutability-helper as direct dependency Add disabled dropdown item feature & add its test cases & update docs Reformat Cleaned up isValueAnObject check
2 parents 323ea32 + e2be2a3 commit 2a7010b

File tree

48 files changed

+972
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+972
-352
lines changed

components/app_bar/AppBar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const factory = (IconButton) => {
2828
flat: PropTypes.string,
2929
leftIcon: PropTypes.string,
3030
rightIcon: PropTypes.string,
31+
scrollHide: PropTypes.string,
3132
title: PropTypes.string
3233
}),
3334
title: PropTypes.string

components/app_bar/index.d.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface AppBarTheme {
1717
/**
1818
* Used as the app bar title.
1919
*/
20-
title ?: string;
20+
title?: string;
2121
/**
2222
* Added to the left icon app bar element.
2323
*/
@@ -26,9 +26,13 @@ export interface AppBarTheme {
2626
* Added to the right icon app bar element.
2727
*/
2828
rightIcon?: string;
29+
/**
30+
* Added to the root element when the app bar is hidden during scroll.
31+
*/
32+
scrollHide?: string;
2933
}
3034

31-
interface AppBarProps extends ReactToolbox.Props {
35+
export interface AppBarProps extends ReactToolbox.Props {
3236
/**
3337
* Children to pass through the component.
3438
*/
@@ -50,19 +54,24 @@ interface AppBarProps extends ReactToolbox.Props {
5054
/**
5155
* If it exists it is used as the AppBar left icon
5256
*/
53-
leftIcon?: string;
57+
leftIcon?: string | React.ReactNode;
5458
/**
5559
* Called when the left icon is clicked
5660
*/
5761
onLeftIconClick?: Function;
5862
/**
5963
* If it exists it is used as the AppBar right icon
6064
*/
61-
rightIcon?: string;
65+
rightIcon?: string | React.ReactNode;
6266
/**
6367
* Called when the righticon is clicked
6468
*/
6569
onRightIconClick?: Function;
70+
/**
71+
* Whether AppBar should be hidden during scroll.
72+
* @default false
73+
*/
74+
scrollHide?: boolean;
6675
/**
6776
* Classnames object defining the component style.
6877
*/

components/app_bar/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The `AppBar` component provides properties for the common use cases of `title`,
4141
| `onLeftIconClick` | `Function` | `null` | Called on left icon click event.|
4242
| `rightIcon` | `String|Element` | `null` | Right icon.|
4343
| `onRightIconClick` | `Function` | `null` | Called on right icon click event.|
44+
| `scrollHide` | `Bool` | `false` | Whether AppBar should be hidden during scroll.|
4445

4546
## Theme
4647

components/autocomplete/Autocomplete.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,12 @@ const factory = (Chip, Input) => {
7474
isValueAnObject: false
7575
};
7676

77-
componentDidMount () {
78-
this.setIsValueAnObject();
79-
}
80-
8177
componentWillReceiveProps (nextProps) {
8278
if (!this.props.multiple) {
8379
this.setState({
8480
query: this.query(nextProps.value)
8581
});
8682
}
87-
88-
if (nextProps.multiple && this.props.value !== nextProps.value) {
89-
this.setIsValueAnObject();
90-
}
9183
}
9284

9385
shouldComponentUpdate (nextProps, nextState) {
@@ -257,7 +249,7 @@ const factory = (Chip, Input) => {
257249

258250
if (!vals) vals = [];
259251

260-
if (this.props.showSelectedWhenNotInSource && this.state.isValueAnObject) {
252+
if (this.props.showSelectedWhenNotInSource && this.isValueAnObject()) {
261253
return new Map(Object.entries(vals));
262254
}
263255

@@ -277,7 +269,7 @@ const factory = (Chip, Input) => {
277269
const source = this.source();
278270
const newValue = target === void 0 ? event.target.id : target;
279271

280-
if (this.state.isValueAnObject) {
272+
if (this.isValueAnObject()) {
281273
const newItem = Array.from(source).reduce((obj, [k, value]) => {
282274
if (k === newValue) {
283275
obj[k] = value;
@@ -297,26 +289,24 @@ const factory = (Chip, Input) => {
297289

298290
values.delete(key);
299291

300-
if (this.state.isValueAnObject) {
292+
if (this.isValueAnObject()) {
301293
return this.handleChange(this.mapToObject(values), event);
302294
}
303295

304296
this.handleChange([...values.keys()], event);
305297
}
306298
}
307299

308-
setIsValueAnObject () {
309-
this.setState({
310-
isValueAnObject: !Array.isArray(this.props.value) && typeof this.props.value === 'object'
311-
});
312-
}
300+
isValueAnObject () {
301+
return !Array.isArray(this.props.value) && typeof this.props.value === 'object';
302+
}
313303

314-
mapToObject (map) {
304+
mapToObject (map) {
315305
return Array.from(map).reduce((obj, [k, value]) => {
316306
obj[k] = value;
317307
return obj;
318308
}, {});
319-
}
309+
}
320310

321311
renderSelected () {
322312
if (this.props.multiple) {

components/autocomplete/index.d.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react";
22
import ReactToolbox from "../index";
3+
import { InputTheme } from "../input"
34

45
export interface AutocompleteTheme {
56
/**
@@ -18,10 +19,6 @@ export interface AutocompleteTheme {
1819
* Used to style the Input component.
1920
*/
2021
input?: string;
21-
/**
22-
* Used for the label.
23-
*/
24-
label?: string;
2522
/**
2623
* Used to style each suggestion.
2724
*/
@@ -44,37 +41,55 @@ export interface AutocompleteTheme {
4441
values?: string;
4542
}
4643

47-
interface AutocompleteProps extends ReactToolbox.Props {
44+
export interface AutocompleteProps extends ReactToolbox.Props {
45+
/**
46+
* Determines if user can create a new option with the current typed value.
47+
* @default false
48+
*/
49+
allowCreate?: boolean;
4850
/**
4951
* Determines the opening direction. It can be auto, up or down.
5052
* @default auto
5153
*/
5254
direction?: "auto" | "up" | "down";
5355
/**
5456
* If true, component will be disabled.
57+
* @default false
5558
*/
5659
disabled?: boolean;
5760
/**
5861
* Sets the error string for the internal input element.
5962
* @default false
6063
*/
6164
error?: string | React.ReactNode;
65+
/**
66+
* Whether component should keep focus after value change.
67+
* @default false
68+
*/
69+
keepFocusOnChange?: boolean;
6270
/**
6371
* The text string to use for the floating label element.
6472
*/
6573
label?: string | React.ReactNode;
6674
/**
6775
* If true, component can hold multiple values.
76+
* @default true
6877
*/
6978
multiple?: boolean;
79+
/**
80+
* Callback function that is fired when component is blurred.
81+
*/
82+
onBlur?: Function;
7083
/**
7184
* Callback function that is fired when the components's value changes.
72-
* @default auto
7385
*/
7486
onChange?: Function;
87+
/**
88+
* Callback function that is fired when component is focused.
89+
*/
90+
onFocus?: Function;
7591
/**
7692
* Callback function that is fired when the components's query value changes.
77-
* @default auto
7893
*/
7994
onQueryChange?: Function;
8095
/**
@@ -104,11 +119,15 @@ interface AutocompleteProps extends ReactToolbox.Props {
104119
/**
105120
* Classnames object defining the component style.
106121
*/
107-
theme?: AutocompleteTheme;
122+
theme?: AutocompleteTheme & InputTheme;
108123
/**
109124
* Value or array of values currently selected component.
110125
*/
111126
value?: any;
127+
/**
128+
* Additional properties passed to inner Input component.
129+
*/
130+
[key: string]: any;
112131
}
113132

114133
export class Autocomplete extends React.Component<AutocompleteProps, {}> { }

components/autocomplete/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ If you want to provide a theme via context, the component key is `RTAutocomplete
4848
| `direction` | `String` | `auto` | Determines the opening direction. It can be `auto`, `top` or `down`. |
4949
| `disabled` | `Bool` | `false` | If true, component will be disabled. |
5050
| `error` | `String` or `Node` | | Sets the error string for the internal input element. |
51+
| `keepFocusOnChange` | `Bool` | `false` | Whether component should keep focus after value change. |
5152
| `label` | `String` or `Node` | | The text string to use for the floating label element. |
5253
| `multiple` | `Bool` | `true` | If true, component can hold multiple values. |
5354
| `onBlur` | `Function` | | Callback function that is fired when component is blurred. |

components/avatar/index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ export interface AvatarTheme {
1616
letter?: string;
1717
}
1818

19-
interface AvatarProps extends ReactToolbox.Props {
19+
export interface AvatarProps extends ReactToolbox.Props {
2020
/**
2121
* Children to pass through the component.
2222
*/
2323
children?: React.ReactNode;
2424
/**
2525
* Set to true if your image is not squared so it will be used as a cover for the element.
26+
* @default false
2627
*/
2728
cover?: boolean;
2829
/**
@@ -41,6 +42,10 @@ interface AvatarProps extends ReactToolbox.Props {
4142
* A title for the image. If no image is provided, the first letter will be displayed as the avatar.
4243
*/
4344
title?: string;
45+
/**
46+
* Additional properties for component root element.
47+
*/
48+
[key: string]: any;
4449
}
4550

4651
export class Avatar extends React.Component<AvatarProps, {}> { }

0 commit comments

Comments
 (0)