@hipay/hipay-material-ui 2.0.0-beta.40 → 2.0.0-beta.42

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,15 @@ import { withStyles } from '../styles';
8
8
  import { fade } from '../styles/colorManipulator';
9
9
  import Button from '@material-ui/core/Button';
10
10
  export const styles = theme => ({
11
- root: {},
11
+ root: {
12
+ '&$disabled': {
13
+ color: theme.palette.neutral.contrastText,
14
+ backgroundColor: theme.palette.neutral.main
15
+ }
16
+ },
17
+ flatNeutral: {
18
+ color: theme.palette.neutral.main
19
+ },
12
20
  flatPositive: {
13
21
  color: theme.palette.positive.main,
14
22
  '&:hover': {
@@ -39,16 +47,6 @@ export const styles = theme => ({
39
47
  }
40
48
  }
41
49
  },
42
- flatNeutral: {
43
- color: theme.palette.neutral.main,
44
- '&:hover': {
45
- backgroundColor: fade(theme.palette.neutral.main, theme.palette.action.hoverOpacity),
46
- // Reset on touch devices, it doesn't add specificity
47
- '@media (hover: none)': {
48
- backgroundColor: 'transparent'
49
- }
50
- }
51
- },
52
50
 
53
51
  /* Styles applied to the root element if `variant="[contained | fab]"` and `color="positive"`. */
54
52
  containedPositive: {
@@ -132,7 +130,8 @@ export const styles = theme => ({
132
130
  '&:hover': {
133
131
  border: `1px solid ${theme.palette.neutral.main}`
134
132
  }
135
- }
133
+ },
134
+ disabled: {}
136
135
  });
137
136
 
138
137
  function HiButton(props) {
@@ -141,9 +140,10 @@ function HiButton(props) {
141
140
  classes,
142
141
  className,
143
142
  color,
144
- variant
143
+ variant,
144
+ disabled
145
145
  } = props,
146
- other = _objectWithoutProperties(props, ["children", "classes", "className", "color", "variant"]);
146
+ other = _objectWithoutProperties(props, ["children", "classes", "className", "color", "variant", "disabled"]);
147
147
 
148
148
  const hcolor = ['positive', 'negative', 'middle', 'neutral'].includes(color) ? 'inherit' : color;
149
149
  const fab = variant === 'fab' || variant === 'extendedFab';
@@ -152,15 +152,16 @@ function HiButton(props) {
152
152
  [classes.flatPositive]: (variant === 'text' || variant === 'flat' || variant === 'outlined') && color === 'positive',
153
153
  [classes.flatNegative]: (variant === 'text' || variant === 'flat' || variant === 'outlined') && color === 'negative',
154
154
  [classes.flatMiddle]: (variant === 'text' || variant === 'flat' || variant === 'outlined') && color === 'middle',
155
- [classes.flatNeutral]: (variant === 'text' || variant === 'flat' || variant === 'outlined') && color === 'neutral',
155
+ [classes.flatNeutral]: (variant === 'text' || variant === 'flat' || variant === 'outlined') && (color === 'default' || color === 'neutral'),
156
156
  [classes.containedPositive]: (contained || fab) && color === 'positive',
157
157
  [classes.containedNegative]: (contained || fab) && color === 'negative',
158
158
  [classes.containedMiddle]: (contained || fab) && color === 'middle',
159
- [classes.containedNeutral]: (contained || fab) && color === 'neutral',
159
+ [classes.containedNeutral]: (contained || fab) && (color === 'default' || color === 'neutral'),
160
160
  [classes.outlinedPositive]: variant === 'outlined' && color === 'positive',
161
161
  [classes.outlinedNegative]: variant === 'outlined' && color === 'negative',
162
162
  [classes.outlinedMiddle]: variant === 'outlined' && color === 'middle',
163
- [classes.outlinedNeutral]: variant === 'outlined' && color === 'neutral'
163
+ [classes.outlinedNeutral]: variant === 'outlined' && (color === 'default' || color === 'neutral'),
164
+ [classes.disabled]: disabled
164
165
  });
165
166
  return React.createElement(Button, _extends({
166
167
  className: className,
@@ -168,7 +169,8 @@ function HiButton(props) {
168
169
  root: buttonClassNames
169
170
  },
170
171
  color: hcolor,
171
- variant: variant
172
+ variant: variant,
173
+ disabled: disabled
172
174
  }, other), children);
173
175
  }
174
176
 
@@ -194,7 +196,7 @@ HiButton.propTypes = process.env.NODE_ENV !== "production" ? {
194
196
  variant: PropTypes.oneOf(['text', 'flat', 'outlined', 'contained', 'raised', 'fab', 'extendedFab'])
195
197
  } : {};
196
198
  HiButton.defaultProps = {
197
- color: 'default',
199
+ color: 'neutral',
198
200
  variant: 'text'
199
201
  };
200
202
  export default withStyles(styles, {
@@ -141,6 +141,14 @@ class HiInput extends React.PureComponent {
141
141
  this.handleOverlayRef = this.handleOverlayRef.bind(this);
142
142
  }
143
143
 
144
+ static getDerivedStateFromProps(nextProps, prevState) {
145
+ if (typeof nextProps.focused !== 'undefined' && nextProps.focused !== prevState.focused) {
146
+ return {
147
+ focused: nextProps.focused
148
+ };
149
+ }
150
+ }
151
+
144
152
  getInputElement(el) {
145
153
  this.inputElement = el;
146
154
 
@@ -403,6 +411,12 @@ HiInput.propTypes = process.env.NODE_ENV !== "production" ? {
403
411
  */
404
412
  error: PropTypes.bool,
405
413
 
414
+ /**
415
+ * Force le focus de l'input et surcharge le comportement par défaut
416
+ * où le focus est géré dans le state.
417
+ */
418
+ focused: PropTypes.bool,
419
+
406
420
  /**
407
421
  * Utile pour surcharger les classes de l'input
408
422
  */
@@ -488,6 +488,13 @@ class HiSelect extends React.PureComponent {
488
488
  }
489
489
  }
490
490
 
491
+ handleReset(event) {
492
+ if (this.props.onReset) {
493
+ event.stopPropagation();
494
+ this.props.onReset(event);
495
+ }
496
+ }
497
+
491
498
  render() {
492
499
  const _this$props = this.props,
493
500
  {
@@ -683,14 +690,14 @@ class HiSelect extends React.PureComponent {
683
690
  onMouseLeave: this.props.onMouseLeave,
684
691
  refElement: el => {
685
692
  this.selectInputElement = el;
686
- }
693
+ },
694
+ onReset: this.props.onReset
687
695
  }), open && staticPosition ? React.createElement("div", {
688
696
  style: popperStyle
689
697
  }, content) : React.createElement(Popper, {
690
698
  anchorEl: this.inputEl,
691
699
  placement: "bottom-start",
692
700
  open: open,
693
- eventsEnabled: open,
694
701
  className: popperClass,
695
702
  style: popperStyle,
696
703
  disablePortal: true
@@ -861,6 +868,11 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
861
868
  */
862
869
  onMouseLeave: PropTypes.func,
863
870
 
871
+ /**
872
+ * Fonction de callback appelée lorsqu'on vide le champs
873
+ */
874
+ onReset: PropTypes.func,
875
+
864
876
  /**
865
877
  * Fonction de callback appelée lorsqu'on écrit dans la barre de recherche
866
878
  * A utiliser pour les selects avec des données dynamiques
@@ -126,7 +126,14 @@ class SelectInput extends React.PureComponent {
126
126
  }
127
127
  };
128
128
 
129
+ this.handleClick = event => {
130
+ if ((!this.resetIcon || !this.resetIcon.contains(event.target)) && this.props.onClick) {
131
+ this.props.onClick(event);
132
+ }
133
+ };
134
+
129
135
  this.handleKeyDown = this.handleKeyDown.bind(this);
136
+ this.handleClick = this.handleClick.bind(this);
130
137
  }
131
138
 
132
139
  render() {
@@ -135,12 +142,14 @@ class SelectInput extends React.PureComponent {
135
142
  noButton,
136
143
  disabled,
137
144
  onClick,
145
+ onReset,
138
146
  value,
139
147
  open,
140
148
  focused,
141
149
  error,
142
150
  id,
143
- refElement
151
+ refElement,
152
+ theme
144
153
  } = this.props; // On utilise classNames pour variabiliser les styles et merge les classes appliquées
145
154
 
146
155
  const rootClass = classNames(classes.root, classes.inkbar, classes.underline, {
@@ -177,7 +186,7 @@ class SelectInput extends React.PureComponent {
177
186
  classes: {
178
187
  root: rootClass
179
188
  },
180
- onClick: onClick,
189
+ onClick: this.handleClick,
181
190
  disabled: disabled,
182
191
  onMouseEnter: this.props.onMouseEnter,
183
192
  onMouseLeave: this.props.onMouseLeave,
@@ -189,7 +198,16 @@ class SelectInput extends React.PureComponent {
189
198
  }
190
199
  }, React.createElement("span", {
191
200
  className: classes.label
192
- }, value), React.createElement(HiIcon, {
201
+ }, value), onReset && focused && React.createElement("div", {
202
+ ref: el => {
203
+ this.resetIcon = el;
204
+ }
205
+ }, React.createElement(HiIcon, {
206
+ icon: "close",
207
+ size: 24,
208
+ color: theme.palette.neutral.main,
209
+ onClick: onReset
210
+ })), React.createElement(HiIcon, {
193
211
  className: iconClass,
194
212
  icon: "arrow_drop_down"
195
213
  }));
@@ -262,6 +280,11 @@ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
262
280
  */
263
281
  onMouseLeave: PropTypes.func,
264
282
 
283
+ /**
284
+ * Fonction de callback appelée lorsqu'on vide le champs
285
+ */
286
+ onReset: PropTypes.func,
287
+
265
288
  /**
266
289
  * Fonction de callback à la pression de la touche "Entrée"
267
290
  */
@@ -284,5 +307,6 @@ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
284
307
  } : {};
285
308
  export default withStyles(styles, {
286
309
  hiComponent: true,
287
- name: 'HmuiSelectInput'
310
+ name: 'HmuiSelectInput',
311
+ withTheme: true
288
312
  })(SelectInput);
@@ -0,0 +1,111 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ // @inheritedComponent HiDynamicSelect
4
+ import React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import HiFormControl from '../HiForm/HiFormControl';
7
+ import HiNestedSelect from './HiNestedSelect';
8
+ /**
9
+ * Champs input pour formulaire
10
+ */
11
+
12
+ class HiNestedSelectField extends React.PureComponent {
13
+ render() {
14
+ const _this$props = this.props,
15
+ {
16
+ label,
17
+ required,
18
+ disabled,
19
+ error,
20
+ errorText,
21
+ helperText,
22
+ helperIcon,
23
+ id,
24
+ name,
25
+ value,
26
+ options,
27
+ type,
28
+ multiple,
29
+ iconAll,
30
+ checkbox,
31
+ searchable,
32
+ translations,
33
+ className
34
+ } = _this$props,
35
+ others = _objectWithoutProperties(_this$props, ["label", "required", "disabled", "error", "errorText", "helperText", "helperIcon", "id", "name", "value", "options", "type", "multiple", "iconAll", "checkbox", "searchable", "translations", "className"]);
36
+
37
+ return React.createElement(HiFormControl, {
38
+ id: id,
39
+ label: label,
40
+ required: required,
41
+ disabled: disabled,
42
+ error: error,
43
+ errorText: errorText,
44
+ helperText: helperText,
45
+ helperIcon: helperIcon,
46
+ className: className
47
+ }, React.createElement(HiNestedSelect, _extends({
48
+ id: id,
49
+ name: name,
50
+ value: value,
51
+ options: options,
52
+ type: type,
53
+ multiple: multiple,
54
+ iconAll: iconAll,
55
+ checkbox: checkbox,
56
+ searchable: searchable,
57
+ translations: translations,
58
+ disabled: disabled,
59
+ error: error
60
+ }, others)));
61
+ }
62
+
63
+ }
64
+
65
+ HiNestedSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
66
+ /**
67
+ * Surcharge des styles
68
+ */
69
+ className: PropTypes.string,
70
+
71
+ /**
72
+ * Si `true`, l'input sera inactif.
73
+ */
74
+ disabled: PropTypes.bool,
75
+
76
+ /**
77
+ * Si `true`, le champs sera en erreur.
78
+ */
79
+ error: PropTypes.bool,
80
+
81
+ /**
82
+ * Texte de l'erreur
83
+ */
84
+ errorText: PropTypes.string,
85
+
86
+ /**
87
+ * Si "true", le texte d'aide s'affichera seulement au clic sur l'icône "Information"
88
+ */
89
+ helperIcon: PropTypes.bool,
90
+
91
+ /**
92
+ * Texte de l'aide
93
+ */
94
+ helperText: PropTypes.string,
95
+
96
+ /**
97
+ * id de l'élément input
98
+ */
99
+ id: PropTypes.string.isRequired,
100
+
101
+ /**
102
+ * Label du champs
103
+ */
104
+ label: PropTypes.string,
105
+
106
+ /**
107
+ * true si champs obligatoire
108
+ */
109
+ required: PropTypes.bool
110
+ } : {};
111
+ export default HiNestedSelectField;
@@ -20,11 +20,11 @@ export const styles = theme => ({
20
20
  backgroundColor: theme.palette.background2,
21
21
  maxWidth: 500,
22
22
  width: '100%',
23
- position: 'relative'
23
+ position: 'relative',
24
+ zIndex: 1
24
25
  },
25
26
  popper: {
26
- width: '100%',
27
- zIndex: 1200
27
+ width: '100%'
28
28
  },
29
29
  paper: {
30
30
  borderRadius: '0px 2px',
@@ -339,6 +339,7 @@ class HiSelect extends React.PureComponent {
339
339
  this.handleSearchReset = this.handleSearchReset.bind(this);
340
340
  this.handleSelect = this.handleSelect.bind(this);
341
341
  this.handleSuggestions = this.handleSuggestions.bind(this);
342
+ this.getInputElement = this.getInputElement.bind(this);
342
343
  }
343
344
 
344
345
  static getDerivedStateFromProps(nextProps, prevState) {
@@ -351,6 +352,14 @@ class HiSelect extends React.PureComponent {
351
352
  return null;
352
353
  }
353
354
 
355
+ getInputElement(el) {
356
+ this.searchField = el;
357
+
358
+ if (this.props.inputRef) {
359
+ this.props.inputRef(this.searchField);
360
+ }
361
+ }
362
+
354
363
  render() {
355
364
  const {
356
365
  classes,
@@ -410,9 +419,7 @@ class HiSelect extends React.PureComponent {
410
419
  }, !!searchable && React.createElement(HiInput, {
411
420
  value: searchValue,
412
421
  autoFocus: true,
413
- inputRef: el => {
414
- this.searchField = el;
415
- },
422
+ inputRef: this.getInputElement,
416
423
  onKeyDown: this.handleKeyDownSearch,
417
424
  onChange: this.handleSearch,
418
425
  onReset: this.handleSearchReset,
@@ -456,6 +463,7 @@ class HiSelect extends React.PureComponent {
456
463
  onSubmit: onSubmit,
457
464
  onMouseEnter: this.props.onMouseEnter,
458
465
  onMouseLeave: this.props.onMouseLeave,
466
+ onReset: this.props.onReset,
459
467
  placeholder: placeholder
460
468
  }, hiSelectInputProps, {
461
469
  refElement: el => {
@@ -467,7 +475,6 @@ class HiSelect extends React.PureComponent {
467
475
  anchorEl: this.inputEl,
468
476
  placement: "bottom-start",
469
477
  open: open,
470
- eventsEnabled: open,
471
478
  className: classes.popper,
472
479
  disablePortal: true
473
480
  }, content));
@@ -586,6 +593,11 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
586
593
  */
587
594
  onMouseLeave: PropTypes.func,
588
595
 
596
+ /**
597
+ * Fonction de callback appelée lorsqu'on vide le champs
598
+ */
599
+ onReset: PropTypes.func,
600
+
589
601
  /**
590
602
  * Fonction de callback appelée lorsque le scroll atteint le bas de la liste
591
603
  */
@@ -5,6 +5,7 @@ import classNames from 'classnames';
5
5
  import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
6
6
  import ButtonBase from '@material-ui/core/ButtonBase';
7
7
  import Icon from '@material-ui/core/Icon';
8
+ import HiIcon from '../HiIcon';
8
9
  import withStyles from '../styles/withStyles';
9
10
  import keycode from 'keycode';
10
11
  export const styles = theme => ({
@@ -134,7 +135,53 @@ class HiSelectInput extends React.PureComponent {
134
135
  }
135
136
  };
136
137
 
138
+ this.handleKeyDownReset = event => {
139
+ const key = keycode(event);
140
+
141
+ if (key === 'enter' || key === 'space') {
142
+ this.handleReset(event);
143
+ event.stopPropagation();
144
+ event.preventDefault();
145
+ }
146
+ };
147
+
148
+ this.handleClick = event => {
149
+ if ((!this.resetIcon || !this.resetIcon.contains(event.target)) && this.props.onClick) {
150
+ this.props.onClick(event);
151
+ }
152
+ };
153
+
154
+ this.handleReset = event => {
155
+ this.props.onReset(event);
156
+
157
+ if (this.input) {
158
+ this.input.focus();
159
+ }
160
+ };
161
+
162
+ this.handleBlur = event => {
163
+ if ((!this.input || !this.input.contains(event.relatedTarget)) && this.props.onBlur) {
164
+ this.props.onBlur(event);
165
+ } else {
166
+ if (this.input && (!this.resetIcon || !this.resetIcon.contains(event.relatedTarget))) {
167
+ this.input.focus();
168
+ }
169
+ }
170
+ };
171
+
172
+ this.handleRef = el => {
173
+ this.input = el;
174
+
175
+ if (this.props.refElement) {
176
+ this.props.refElement(el);
177
+ }
178
+ };
179
+
137
180
  this.handleKeyDown = this.handleKeyDown.bind(this);
181
+ this.handleClick = this.handleClick.bind(this);
182
+ this.handleBlur = this.handleBlur.bind(this);
183
+ this.handleRef = this.handleRef.bind(this);
184
+ this.handleReset = this.handleReset.bind(this);
138
185
  }
139
186
 
140
187
  render() {
@@ -143,13 +190,13 @@ class HiSelectInput extends React.PureComponent {
143
190
  noButton,
144
191
  disabled,
145
192
  onClick,
193
+ onReset,
146
194
  value,
147
195
  open,
148
196
  focused,
149
197
  error,
150
198
  id,
151
- placeholder,
152
- refElement
199
+ placeholder
153
200
  } = this.props; // On utilise classNames pour variabiliser les styles et merge les classes appliquées
154
201
 
155
202
  const rootClass = classNames(classes.root, classes.inkbar, classes.underline, {
@@ -172,9 +219,7 @@ class HiSelectInput extends React.PureComponent {
172
219
  onBlur: this.props.onBlur,
173
220
  role: "button",
174
221
  tabIndex: "0",
175
- ref: el => {
176
- if (refElement) refElement(el);
177
- }
222
+ ref: this.handleRef
178
223
  }, React.createElement("span", {
179
224
  className: classNames(classes.label, {
180
225
  [classes.placeholder]: value === undefined
@@ -184,21 +229,30 @@ class HiSelectInput extends React.PureComponent {
184
229
  })) : React.createElement(ButtonBase, {
185
230
  id: id,
186
231
  className: rootClass,
187
- onClick: onClick,
232
+ onClick: this.handleClick,
188
233
  disabled: disabled,
189
234
  onMouseEnter: this.props.onMouseEnter,
190
235
  onMouseLeave: this.props.onMouseLeave,
191
236
  onKeyDown: this.handleKeyDown,
192
237
  onFocus: this.props.onFocus,
193
- onBlur: this.props.onBlur,
194
- buttonRef: el => {
195
- if (refElement) refElement(el);
196
- }
238
+ onBlur: this.handleBlur,
239
+ buttonRef: this.handleRef
197
240
  }, React.createElement("span", {
198
241
  className: classNames(classes.label, {
199
242
  [classes.placeholder]: value === undefined
200
243
  })
201
- }, value || placeholder), React.createElement(Icon, {
244
+ }, value || placeholder), onReset && focused && React.createElement("div", {
245
+ ref: el => {
246
+ this.resetIcon = el;
247
+ }
248
+ }, React.createElement(HiIcon, {
249
+ icon: "close",
250
+ size: 20,
251
+ color: "neutral",
252
+ onClick: this.handleReset,
253
+ onKeyDown: this.handleKeyDownReset,
254
+ tabIndex: 0
255
+ })), React.createElement(Icon, {
202
256
  classes: {
203
257
  root: iconClass
204
258
  }
@@ -276,6 +330,11 @@ HiSelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
276
330
  */
277
331
  onMouseLeave: PropTypes.func,
278
332
 
333
+ /**
334
+ * Fonction de callback appelée lorsqu'on vide le champs
335
+ */
336
+ onReset: PropTypes.func,
337
+
279
338
  /**
280
339
  * Fonction de callback à la pression de la touche "Entrée"
281
340
  */
package/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license HiPay-Material-UI v2.0.0-beta.4
1
+ /** @license HiPay-Material-UI v2.0.0-beta.42
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license HiPay-Material-UI v2.0.0-beta.4
1
+ /** @license HiPay-Material-UI v2.0.0-beta.42
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@hipay/hipay-material-ui",
3
3
  "private": false,
4
4
  "author": "HiPay PSYCHE Team",
5
- "version": "2.0.0-beta.40",
5
+ "version": "2.0.0-beta.42",
6
6
  "description": "React components that implement Google's Material Design.",
7
7
  "keywords": [
8
8
  "react",
@@ -71,4 +71,4 @@
71
71
  },
72
72
  "main": "./index.js",
73
73
  "module": "./index.es.js"
74
- }
74
+ }