@hipay/hipay-material-ui 1.0.0-beta.13 → 1.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HiBreadcrumb/HiBreadcrumb.js +28 -22
- package/HiBreadcrumb/HiStep.js +96 -60
- package/HiBreadcrumb/HiStepConnector.js +91 -26
- package/HiBreadcrumb/HiStepContent.js +122 -0
- package/HiBreadcrumb/HiStepIcon.js +86 -29
- package/HiBreadcrumb/HiStepLabel.js +128 -62
- package/HiBreadcrumb/HiStepper.js +5 -24
- package/HiDatePicker/HiDateRangePicker.js +69 -28
- package/HiDatePicker/HiDateRangeSelector.js +14 -6
- package/HiDatePicker/Overlays/CustomOverlayLayout.js +3 -1
- package/HiDatePicker/Overlays/Overlay.js +22 -4
- package/HiDatePicker/stylesheet.js +7 -0
- package/HiForm/HiInput.js +24 -11
- package/HiForm/HiSlider.js +399 -0
- package/HiForm/index.js +9 -0
- package/HiSelect/HiSelect.js +1 -1
- package/HiTable/BodyCellBuilder.js +3 -0
- package/HiTable/BodyCells/CellIcon.js +26 -19
- package/HiTable/BodyCells/CellImage.js +17 -13
- package/HiTable/BodyCells/CellNumeric.js +7 -2
- package/HiTable/BodyCells/CellSentinel.js +14 -13
- package/HiTable/BodyCells/CellThirdPartySecurity.js +43 -19
- package/HiTable/HeaderCell.js +3 -2
- package/es/HiBreadcrumb/HiBreadcrumb.js +27 -19
- package/es/HiBreadcrumb/HiStep.js +55 -54
- package/es/HiBreadcrumb/HiStepConnector.js +86 -26
- package/es/HiBreadcrumb/HiStepContent.js +63 -0
- package/es/HiBreadcrumb/HiStepIcon.js +103 -35
- package/es/HiBreadcrumb/HiStepLabel.js +106 -63
- package/es/HiBreadcrumb/HiStepper.js +5 -21
- package/es/HiDatePicker/HiDateRangePicker.js +65 -27
- package/es/HiDatePicker/HiDateRangeSelector.js +15 -7
- package/es/HiDatePicker/Overlays/CustomOverlayLayout.js +3 -1
- package/es/HiDatePicker/Overlays/Overlay.js +18 -4
- package/es/HiDatePicker/stylesheet.js +7 -0
- package/es/HiForm/HiInput.js +19 -10
- package/es/HiForm/HiSlider.js +309 -0
- package/es/HiForm/index.js +1 -0
- package/es/HiSelect/HiSelect.js +1 -1
- package/es/HiTable/BodyCellBuilder.js +3 -0
- package/es/HiTable/BodyCells/CellIcon.js +15 -8
- package/es/HiTable/BodyCells/CellImage.js +16 -14
- package/es/HiTable/BodyCells/CellNumeric.js +6 -2
- package/es/HiTable/BodyCells/CellSentinel.js +8 -5
- package/es/HiTable/BodyCells/CellThirdPartySecurity.js +40 -15
- package/es/HiTable/HeaderCell.js +3 -2
- package/es/utils/hiHelpers.js +4 -3
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +43 -43
- package/umd/hipay-material-ui.development.js +7680 -7171
- package/umd/hipay-material-ui.production.min.js +5 -5
- package/utils/hiHelpers.js +4 -2
@@ -6,6 +6,8 @@ import React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
7
7
|
import { formatDate, parseDate } from 'react-day-picker/moment';
|
8
8
|
import DayPickerInput from 'react-day-picker/DayPickerInput';
|
9
|
+
import classNames from 'classnames';
|
10
|
+
|
9
11
|
import withStyles from '../styles/withStyles';
|
10
12
|
import { capitalizeFirstLetter } from '../utils/helpers';
|
11
13
|
import Caption from './Caption';
|
@@ -23,11 +25,14 @@ class HiDateRangePicker extends React.Component {
|
|
23
25
|
constructor(props) {
|
24
26
|
super();
|
25
27
|
|
28
|
+
this.handleDayPickerFocus = name => () => {
|
29
|
+
this.setState({ focusedInput: name });
|
30
|
+
};
|
31
|
+
|
26
32
|
this.state = {
|
27
|
-
fromOpenedPanel: 'calendar',
|
28
33
|
fromCurrentMonth: props.from ? props.from : new Date(),
|
29
|
-
|
30
|
-
|
34
|
+
toCurrentMonth: props.to ? props.to : new Date(),
|
35
|
+
focusedInput: ''
|
31
36
|
};
|
32
37
|
|
33
38
|
this.handleReset = this.handleReset.bind(this);
|
@@ -51,6 +56,8 @@ class HiDateRangePicker extends React.Component {
|
|
51
56
|
this.handleYearClick = this.handleYearClick.bind(this);
|
52
57
|
this.handleYearClickFrom = this.handleYearClickFrom.bind(this);
|
53
58
|
this.handleYearClickTo = this.handleYearClickTo.bind(this);
|
59
|
+
this.handleDayPickerFocus = this.handleDayPickerFocus.bind(this);
|
60
|
+
this.handleDayPickerBlur = this.handleDayPickerBlur.bind(this);
|
54
61
|
|
55
62
|
this.openPanel = this.openPanel.bind(this);
|
56
63
|
|
@@ -207,6 +214,10 @@ class HiDateRangePicker extends React.Component {
|
|
207
214
|
}
|
208
215
|
}
|
209
216
|
|
217
|
+
handleDayPickerBlur() {
|
218
|
+
this.setState({ focusedInput: '' });
|
219
|
+
}
|
220
|
+
|
210
221
|
openPanel(name, panel) {
|
211
222
|
this.setState({
|
212
223
|
[`${name}OpenedPanel`]: panel
|
@@ -239,9 +250,10 @@ class HiDateRangePicker extends React.Component {
|
|
239
250
|
return this.renderNavbar('to', propsNavbar);
|
240
251
|
}
|
241
252
|
|
242
|
-
renderOverlay(name, propsOverlay) {
|
253
|
+
renderOverlay(name, propsOverlay, staticPosition) {
|
243
254
|
const rangeOverlayProps = _extends({}, propsOverlay, {
|
244
|
-
side: name
|
255
|
+
side: name,
|
256
|
+
staticPosition
|
245
257
|
});
|
246
258
|
|
247
259
|
switch (this.state[`${name}OpenedPanel`]) {
|
@@ -257,10 +269,10 @@ class HiDateRangePicker extends React.Component {
|
|
257
269
|
}
|
258
270
|
}
|
259
271
|
renderOverlayFrom(propsOverlay) {
|
260
|
-
return this.renderOverlay('from', propsOverlay);
|
272
|
+
return this.renderOverlay('from', propsOverlay, this.props.staticPosition);
|
261
273
|
}
|
262
274
|
renderOverlayTo(propsOverlay) {
|
263
|
-
return this.renderOverlay('to', propsOverlay);
|
275
|
+
return this.renderOverlay('to', propsOverlay, this.props.staticPosition);
|
264
276
|
}
|
265
277
|
|
266
278
|
renderMonthPickerOverlay(name, propsOverlay) {
|
@@ -315,9 +327,10 @@ class HiDateRangePicker extends React.Component {
|
|
315
327
|
onReset,
|
316
328
|
to,
|
317
329
|
translations,
|
318
|
-
id
|
330
|
+
id,
|
331
|
+
staticPosition
|
319
332
|
} = _props,
|
320
|
-
props = _objectWithoutProperties(_props, ['classes', 'disabledDays', 'disablePastDays', 'disableFutureDays', 'enableTime', 'labelFrom', 'labelTo', 'locale', 'format', 'from', 'minimumDate', 'onReset', 'to', 'translations', 'id']);
|
333
|
+
props = _objectWithoutProperties(_props, ['classes', 'disabledDays', 'disablePastDays', 'disableFutureDays', 'enableTime', 'labelFrom', 'labelTo', 'locale', 'format', 'from', 'minimumDate', 'onReset', 'to', 'translations', 'id', 'staticPosition']);
|
321
334
|
|
322
335
|
const { fromCurrentMonth, toCurrentMonth } = this.state;
|
323
336
|
|
@@ -429,32 +442,52 @@ class HiDateRangePicker extends React.Component {
|
|
429
442
|
id: `${id}-to`
|
430
443
|
});
|
431
444
|
|
445
|
+
let fromClass = classNames({
|
446
|
+
[classes.absolute]: staticPosition === true && this.state.focusedInput === 'to',
|
447
|
+
[classes.dayPickerMargin]: staticPosition === true && this.state.focusedInput === 'to'
|
448
|
+
});
|
449
|
+
let toClass = classNames(classes.toInput, {
|
450
|
+
[classes.absolute]: staticPosition === true && this.state.focusedInput === 'from'
|
451
|
+
});
|
452
|
+
|
432
453
|
return React.createElement(
|
433
454
|
'div',
|
434
455
|
{ className: classes.root },
|
435
456
|
React.createElement(
|
436
457
|
'div',
|
437
|
-
{
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
458
|
+
{
|
459
|
+
className: classes.fromInput,
|
460
|
+
onFocus: this.handleDayPickerFocus('from'),
|
461
|
+
onBlur: this.handleDayPickerBlur
|
462
|
+
},
|
463
|
+
React.createElement(
|
464
|
+
'div',
|
465
|
+
{ className: fromClass },
|
466
|
+
React.createElement(DayPickerInput, {
|
467
|
+
ref: el => {
|
468
|
+
this.fromInput = el;
|
469
|
+
},
|
470
|
+
value: from,
|
471
|
+
hideOnDayClick: false,
|
472
|
+
overlayComponent: this.renderOverlayFrom,
|
473
|
+
dayPickerProps: fromDayPickerProps,
|
474
|
+
component: HiTextField,
|
475
|
+
inputProps: fromInputProps,
|
476
|
+
format: enableTime ? `${format} HH:mm` : format,
|
477
|
+
formatDate: formatDate,
|
478
|
+
parseDate: parseDate,
|
479
|
+
onDayChange: this.handleDayChangeFrom,
|
480
|
+
placeholder: ''
|
481
|
+
})
|
482
|
+
)
|
454
483
|
),
|
455
484
|
React.createElement(
|
456
485
|
'div',
|
457
|
-
{
|
486
|
+
{
|
487
|
+
className: toClass,
|
488
|
+
onFocus: this.handleDayPickerFocus('to'),
|
489
|
+
onBlur: this.handleDayPickerBlur
|
490
|
+
},
|
458
491
|
React.createElement(DayPickerInput, {
|
459
492
|
ref: el => {
|
460
493
|
this.toInput = el;
|
@@ -480,6 +513,7 @@ HiDateRangePicker.defaultProps = {
|
|
480
513
|
disabledDays: [],
|
481
514
|
disablePastDays: false,
|
482
515
|
disableFutureDays: false,
|
516
|
+
staticPosition: false,
|
483
517
|
enableTime: false,
|
484
518
|
format: 'YYYY-DD-MM',
|
485
519
|
labelFrom: 'Start',
|
@@ -555,6 +589,10 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
555
589
|
* Callback au reset de l'input
|
556
590
|
*/
|
557
591
|
onReset: PropTypes.func,
|
592
|
+
/**
|
593
|
+
* Si true, le calendrier sera dans une div static plutot que dans une popper absolute
|
594
|
+
*/
|
595
|
+
staticPosition: PropTypes.bool,
|
558
596
|
/**
|
559
597
|
* Date de fin sélectionnée
|
560
598
|
*/
|
@@ -127,11 +127,11 @@ class HiDateRangeSelector extends React.Component {
|
|
127
127
|
if (selectedOption) {
|
128
128
|
this.props.onChange('from', selectedOption.from.toDate());
|
129
129
|
this.props.onChange('to', selectedOption.to.toDate());
|
130
|
-
if (this.props.returnSelectValue === true) {
|
131
|
-
this.props.onChange('period', value);
|
132
|
-
}
|
133
130
|
}
|
134
131
|
}
|
132
|
+
if (this.props.returnSelectValue === true) {
|
133
|
+
this.props.onChange('period', value);
|
134
|
+
}
|
135
135
|
};
|
136
136
|
|
137
137
|
this.state = {
|
@@ -177,9 +177,10 @@ class HiDateRangeSelector extends React.Component {
|
|
177
177
|
to,
|
178
178
|
translations,
|
179
179
|
classes,
|
180
|
-
selectProps
|
180
|
+
selectProps,
|
181
|
+
staticPosition
|
181
182
|
} = _props,
|
182
|
-
props = _objectWithoutProperties(_props, ['disabled', 'enableTime', 'error', 'errorText', 'helperIcon', 'helperText', 'idRange', 'idSelect', 'label', 'from', 'onChange', 'required', 'to', 'translations', 'classes', 'selectProps']);
|
183
|
+
props = _objectWithoutProperties(_props, ['disabled', 'enableTime', 'error', 'errorText', 'helperIcon', 'helperText', 'idRange', 'idSelect', 'label', 'from', 'onChange', 'required', 'to', 'translations', 'classes', 'selectProps', 'staticPosition']);
|
183
184
|
|
184
185
|
const { selectedPreset } = this.state;
|
185
186
|
|
@@ -209,7 +210,8 @@ class HiDateRangeSelector extends React.Component {
|
|
209
210
|
translations: translations,
|
210
211
|
value: selectedPreset,
|
211
212
|
containerWidth: this.state.containerWidth,
|
212
|
-
classes: { root: classes.dateSelect }
|
213
|
+
classes: { root: classes.dateSelect },
|
214
|
+
staticPosition: staticPosition
|
213
215
|
}, selectProps))
|
214
216
|
),
|
215
217
|
React.createElement(
|
@@ -224,7 +226,8 @@ class HiDateRangeSelector extends React.Component {
|
|
224
226
|
onChange: onChange,
|
225
227
|
onReset: this.handleReset,
|
226
228
|
disabled: disabled || selectedPreset !== 'custom',
|
227
|
-
translations: translations
|
229
|
+
translations: translations,
|
230
|
+
staticPosition: staticPosition
|
228
231
|
}, props))
|
229
232
|
)
|
230
233
|
);
|
@@ -236,6 +239,7 @@ HiDateRangeSelector.defaultProps = {
|
|
236
239
|
defaultPreset: 'cd',
|
237
240
|
enableTime: false,
|
238
241
|
returnSelectValue: false,
|
242
|
+
staticPosition: false,
|
239
243
|
locale: 'fr-FR',
|
240
244
|
format: 'YYYY-DD-MM',
|
241
245
|
translations: {
|
@@ -337,6 +341,10 @@ HiDateRangeSelector.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
337
341
|
* Props passées au HiSelectField
|
338
342
|
*/
|
339
343
|
selectProps: PropTypes.object,
|
344
|
+
/**
|
345
|
+
* Si true, le calendrier sera dans une div static plutot que dans une popper absolute
|
346
|
+
*/
|
347
|
+
staticPosition: PropTypes.bool,
|
340
348
|
/**
|
341
349
|
* Date de fin sélectionnée
|
342
350
|
*/
|
@@ -70,9 +70,11 @@ const CustomOverlayLayout = (_ref) => {
|
|
70
70
|
[classes.right]: side === 'to'
|
71
71
|
});
|
72
72
|
|
73
|
+
let paperProps = _extends({}, props);
|
74
|
+
|
73
75
|
return React.createElement(
|
74
76
|
Paper,
|
75
|
-
{ className: paperClass },
|
77
|
+
{ className: paperClass, onBlur: paperProps.onBlur, onFocus: paperProps.onFocus },
|
76
78
|
React.createElement(
|
77
79
|
'div',
|
78
80
|
{ className: classes.overlay },
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import _extends from 'babel-runtime/helpers/extends';
|
2
|
+
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
1
3
|
// weak
|
2
4
|
|
3
5
|
import React from 'react';
|
@@ -9,10 +11,15 @@ import withStyles from '../../styles/withStyles';
|
|
9
11
|
|
10
12
|
export const styles = () => ({
|
11
13
|
paper: {
|
12
|
-
position: 'absolute',
|
13
14
|
width: '100%',
|
14
15
|
zIndex: 10
|
15
16
|
},
|
17
|
+
absolute: {
|
18
|
+
position: 'absolute'
|
19
|
+
},
|
20
|
+
relative: {
|
21
|
+
position: 'relative'
|
22
|
+
},
|
16
23
|
left: {
|
17
24
|
width: '200%',
|
18
25
|
left: 0
|
@@ -26,15 +33,22 @@ export const styles = () => ({
|
|
26
33
|
}
|
27
34
|
});
|
28
35
|
|
29
|
-
const Overlay = (
|
36
|
+
const Overlay = (_ref) => {
|
37
|
+
let { classes, children, side, staticPosition } = _ref,
|
38
|
+
props = _objectWithoutProperties(_ref, ['classes', 'children', 'side', 'staticPosition']);
|
39
|
+
|
30
40
|
const paperClass = classNames(classes.paper, {
|
31
41
|
[classes.left]: side === 'from',
|
32
|
-
[classes.right]: side === 'to'
|
42
|
+
[classes.right]: side === 'to',
|
43
|
+
[classes.absolute]: staticPosition !== true,
|
44
|
+
[classes.relative]: staticPosition === true
|
33
45
|
});
|
34
46
|
|
47
|
+
let paperProps = _extends({}, props);
|
48
|
+
|
35
49
|
return React.createElement(
|
36
50
|
Paper,
|
37
|
-
{ className: paperClass },
|
51
|
+
{ onBlur: paperProps.onBlur, onFocus: paperProps.onFocus, className: paperClass },
|
38
52
|
React.createElement(
|
39
53
|
'div',
|
40
54
|
{ className: classes.overlay },
|
@@ -19,6 +19,13 @@ export default (theme => ({
|
|
19
19
|
width: 'calc(50% - 4px)',
|
20
20
|
marginLeft: 4
|
21
21
|
},
|
22
|
+
absolute: {
|
23
|
+
position: 'absolute'
|
24
|
+
},
|
25
|
+
dayPickerMargin: {
|
26
|
+
top: -337,
|
27
|
+
width: 'calc(100% - 4px)'
|
28
|
+
},
|
22
29
|
// The container element
|
23
30
|
container: {
|
24
31
|
width: '100%',
|
package/es/HiForm/HiInput.js
CHANGED
@@ -170,19 +170,28 @@ class HiInput extends React.PureComponent {
|
|
170
170
|
}
|
171
171
|
|
172
172
|
handleFocus(event) {
|
173
|
-
if (
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
|
173
|
+
if (this.endAdornmentNode && this.endAdornmentNode.contains(event.target)) {
|
174
|
+
event.stopPropagation();
|
175
|
+
} else {
|
176
|
+
if (!this.state.focused) {
|
177
|
+
this.setState({ focused: true });
|
178
|
+
}
|
179
|
+
if (this.props.onFocus) {
|
180
|
+
this.props.onFocus(event);
|
181
|
+
}
|
182
|
+
this.inputElement.focus();
|
178
183
|
}
|
179
184
|
}
|
180
185
|
|
181
|
-
handleDivClick() {
|
182
|
-
if (
|
183
|
-
|
186
|
+
handleDivClick(event) {
|
187
|
+
if (this.endAdornmentNode && this.endAdornmentNode.contains(event.target)) {
|
188
|
+
event.stopPropagation();
|
189
|
+
} else {
|
190
|
+
if (!this.state.focused) {
|
191
|
+
this.setState({ focused: true });
|
192
|
+
}
|
193
|
+
this.inputElement.focus();
|
184
194
|
}
|
185
|
-
this.inputElement.focus();
|
186
195
|
}
|
187
196
|
|
188
197
|
handleMouseEnter() {
|
@@ -305,7 +314,7 @@ class HiInput extends React.PureComponent {
|
|
305
314
|
startAdornment: leftIcon,
|
306
315
|
endAdornment: React.createElement(
|
307
316
|
'div',
|
308
|
-
{ className: classes.endAdornment },
|
317
|
+
{ className: classes.endAdornment, ref: el => this.endAdornmentNode = el },
|
309
318
|
eraseIcon,
|
310
319
|
endAdornment
|
311
320
|
),
|
@@ -0,0 +1,309 @@
|
|
1
|
+
import _extends from 'babel-runtime/helpers/extends';
|
2
|
+
import React from 'react';
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
import classNames from 'classnames';
|
5
|
+
import withStyles from '../styles/withStyles';
|
6
|
+
import HiIconBuilder from '../utils/HiIconBuilder';
|
7
|
+
import HiFormControl from '../HiForm/HiFormControl';
|
8
|
+
|
9
|
+
export const styles = theme => ({
|
10
|
+
barContainer: {
|
11
|
+
width: '100%',
|
12
|
+
position: 'relative',
|
13
|
+
margin: '0 7px'
|
14
|
+
},
|
15
|
+
barHidden: {
|
16
|
+
width: '100%',
|
17
|
+
opacity: 0,
|
18
|
+
position: 'absolute',
|
19
|
+
top: '7px',
|
20
|
+
zIndex: '2'
|
21
|
+
},
|
22
|
+
mainContainer: _extends({}, theme.typography.body1, {
|
23
|
+
display: 'flex',
|
24
|
+
flexWrap: 'nowrap',
|
25
|
+
alignItems: 'center'
|
26
|
+
}),
|
27
|
+
topContainer: {
|
28
|
+
display: 'flex',
|
29
|
+
flexWrap: 'nowrap',
|
30
|
+
height: '18px'
|
31
|
+
},
|
32
|
+
bottomContainer: {
|
33
|
+
display: 'flex',
|
34
|
+
flexWrap: 'nowrap',
|
35
|
+
height: '18px'
|
36
|
+
},
|
37
|
+
barValue: {
|
38
|
+
display: 'flex',
|
39
|
+
width: '100%',
|
40
|
+
height: '4px',
|
41
|
+
borderRadius: '2px',
|
42
|
+
backgroundColor: theme.palette.business.primary.normal,
|
43
|
+
position: 'absolute',
|
44
|
+
zIndex: '2'
|
45
|
+
},
|
46
|
+
arrow: {
|
47
|
+
position: 'absolute',
|
48
|
+
zIndex: '1',
|
49
|
+
color: theme.palette.business.primary.normal,
|
50
|
+
transform: 'translate(-50%,-25%)',
|
51
|
+
transition: 'transform 300ms cubic-bezier(0.4, 0, 0.2, 1)',
|
52
|
+
transitionProperty: 'transform color'
|
53
|
+
},
|
54
|
+
focused: {
|
55
|
+
transform: 'scale(1.7) translate(-29%, -11%)',
|
56
|
+
color: theme.palette.business.primary.dark
|
57
|
+
},
|
58
|
+
leftLabel: {
|
59
|
+
color: theme.palette.business.primary.normal,
|
60
|
+
left: '0px',
|
61
|
+
position: 'absolute',
|
62
|
+
fontSize: '11px',
|
63
|
+
alignSelf: 'flex-end'
|
64
|
+
},
|
65
|
+
rightLabel: {
|
66
|
+
color: '#737373',
|
67
|
+
right: '0px',
|
68
|
+
position: 'absolute',
|
69
|
+
fontSize: '11px',
|
70
|
+
alignSelf: 'flex-end'
|
71
|
+
},
|
72
|
+
textValue: {
|
73
|
+
position: 'absolute',
|
74
|
+
zIndex: '2'
|
75
|
+
}
|
76
|
+
});
|
77
|
+
|
78
|
+
/**
|
79
|
+
* HiSlider component
|
80
|
+
*/
|
81
|
+
class HiSlider extends React.Component {
|
82
|
+
|
83
|
+
constructor(props) {
|
84
|
+
super(props);
|
85
|
+
this.leftLabelWidth = 0;
|
86
|
+
this.rightLabelWidth = 0;
|
87
|
+
this.textValueWidth = 0;
|
88
|
+
this.barContainerWidth = 0;
|
89
|
+
|
90
|
+
this.handleFocus = isFocused => () => {
|
91
|
+
this.setState({ focused: isFocused });
|
92
|
+
};
|
93
|
+
|
94
|
+
this.state = {
|
95
|
+
focused: false
|
96
|
+
};
|
97
|
+
|
98
|
+
this.leftLabel;
|
99
|
+
this.rightLabel;
|
100
|
+
this.textValue;
|
101
|
+
this.barContainer;
|
102
|
+
|
103
|
+
this.handleChange = this.handleChange.bind(this);
|
104
|
+
this.handleFocus = this.handleFocus.bind(this);
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Measures several components once they are mounted.
|
109
|
+
* If the value and a label (left or right) are hovered,
|
110
|
+
* we hide this label.
|
111
|
+
*/
|
112
|
+
componentDidMount() {
|
113
|
+
this.leftLabelWidth = this.leftLabel.offsetWidth;
|
114
|
+
this.rightLabelWidth = this.rightLabel.offsetWidth;
|
115
|
+
this.textValueWidth = this.textValue.offsetWidth;
|
116
|
+
this.barContainerWidth = this.barContainer.offsetWidth;
|
117
|
+
let { hoveringLeft, hoveringRight } = this.getHovering();
|
118
|
+
if (hoveringLeft || hoveringRight) {
|
119
|
+
this.forceUpdate();
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
handleChange(event) {
|
124
|
+
this.props.onChange(parseFloat(event.target.value));
|
125
|
+
this.textValueWidth = this.textValue.offsetWidth;
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Calculates if the labels are hovered.
|
130
|
+
*/
|
131
|
+
getHovering() {
|
132
|
+
const ratio = (this.props.value - this.props.min) / (this.props.max - this.props.min);
|
133
|
+
const hoveringLeft = this.leftLabelWidth - (ratio * this.barContainerWidth - ratio * this.textValueWidth) > 0;
|
134
|
+
const hoveringRight = this.barContainerWidth - ratio * this.barContainerWidth - this.rightLabelWidth - (1 - ratio) * this.textValueWidth < 0;
|
135
|
+
return { hoveringLeft, hoveringRight };
|
136
|
+
}
|
137
|
+
|
138
|
+
render() {
|
139
|
+
const {
|
140
|
+
classes,
|
141
|
+
className,
|
142
|
+
min,
|
143
|
+
max,
|
144
|
+
leftLabel,
|
145
|
+
rightLabel,
|
146
|
+
step,
|
147
|
+
suffix,
|
148
|
+
id,
|
149
|
+
label,
|
150
|
+
theme,
|
151
|
+
value
|
152
|
+
} = this.props;
|
153
|
+
const { focused } = this.state;
|
154
|
+
const ratio = (value - min) / (max - min);
|
155
|
+
const percentage = ratio * 100;
|
156
|
+
const { hoveringLeft, hoveringRight } = this.getHovering();
|
157
|
+
const barColor = focused ? theme.palette.business.primary.dark : theme.palette.business.primary.normal;
|
158
|
+
return (
|
159
|
+
// HiFormControl pour l'affichage du label
|
160
|
+
React.createElement(
|
161
|
+
HiFormControl,
|
162
|
+
{
|
163
|
+
id: id,
|
164
|
+
label: label,
|
165
|
+
className: className,
|
166
|
+
onFocus: this.handleFocus(true),
|
167
|
+
onBlur: this.handleFocus(false)
|
168
|
+
},
|
169
|
+
React.createElement(
|
170
|
+
'div',
|
171
|
+
{ className: classes.mainContainer },
|
172
|
+
React.createElement(
|
173
|
+
'div',
|
174
|
+
null,
|
175
|
+
min,
|
176
|
+
suffix
|
177
|
+
),
|
178
|
+
React.createElement(
|
179
|
+
'div',
|
180
|
+
{ className: classes.barContainer, ref: div => this.barContainer = div },
|
181
|
+
React.createElement(
|
182
|
+
'div',
|
183
|
+
{ className: classes.topContainer },
|
184
|
+
!hoveringLeft && React.createElement(
|
185
|
+
'div',
|
186
|
+
{
|
187
|
+
className: classes.leftLabel,
|
188
|
+
ref: div => this.leftLabel = div
|
189
|
+
},
|
190
|
+
leftLabel
|
191
|
+
),
|
192
|
+
React.createElement(
|
193
|
+
'div',
|
194
|
+
{
|
195
|
+
className: classes.textValue,
|
196
|
+
style: {
|
197
|
+
left: `${percentage}%`,
|
198
|
+
transform: `translate(-${percentage}%)`
|
199
|
+
},
|
200
|
+
ref: div => this.textValue = div
|
201
|
+
},
|
202
|
+
value,
|
203
|
+
suffix
|
204
|
+
),
|
205
|
+
!hoveringRight && React.createElement(
|
206
|
+
'div',
|
207
|
+
{
|
208
|
+
className: classes.rightLabel,
|
209
|
+
ref: div => this.rightLabel = div
|
210
|
+
},
|
211
|
+
rightLabel
|
212
|
+
)
|
213
|
+
),
|
214
|
+
React.createElement('div', {
|
215
|
+
className: classes.barValue,
|
216
|
+
style: {
|
217
|
+
background: `linear-gradient(to right, ${barColor}, ${barColor} ${percentage}%, #E0E0E0 ${percentage}%, #E0E0E0)`
|
218
|
+
}
|
219
|
+
}),
|
220
|
+
React.createElement('input', {
|
221
|
+
type: 'range',
|
222
|
+
min: min,
|
223
|
+
max: max,
|
224
|
+
value: value,
|
225
|
+
onChange: this.handleChange,
|
226
|
+
className: classes.barHidden,
|
227
|
+
step: step
|
228
|
+
}),
|
229
|
+
React.createElement(
|
230
|
+
'div',
|
231
|
+
{ className: classes.bottomContainer },
|
232
|
+
React.createElement(HiIconBuilder, {
|
233
|
+
className: classNames(classes.arrow, {
|
234
|
+
[classes.focused]: focused
|
235
|
+
}),
|
236
|
+
icon: 'menu_up',
|
237
|
+
size: 24,
|
238
|
+
style: { left: `${percentage}%` }
|
239
|
+
})
|
240
|
+
)
|
241
|
+
),
|
242
|
+
React.createElement(
|
243
|
+
'div',
|
244
|
+
null,
|
245
|
+
max,
|
246
|
+
suffix
|
247
|
+
)
|
248
|
+
)
|
249
|
+
)
|
250
|
+
);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
HiSlider.propTypes = process.env.NODE_ENV !== "production" ? {
|
255
|
+
/**
|
256
|
+
* Useful to extend the style applied to components.
|
257
|
+
*/
|
258
|
+
classes: PropTypes.object,
|
259
|
+
/**
|
260
|
+
* Classes CSS appliquées.
|
261
|
+
*/
|
262
|
+
className: PropTypes.string,
|
263
|
+
/**
|
264
|
+
* Id de l'élément input
|
265
|
+
*/
|
266
|
+
id: PropTypes.string.isRequired,
|
267
|
+
/**
|
268
|
+
* Label du champ
|
269
|
+
*/
|
270
|
+
label: PropTypes.string,
|
271
|
+
/**
|
272
|
+
* The label to show on the left.
|
273
|
+
*/
|
274
|
+
leftLabel: PropTypes.string,
|
275
|
+
/**
|
276
|
+
* The Maximum value for the slider.
|
277
|
+
*/
|
278
|
+
max: PropTypes.number.isRequired,
|
279
|
+
/**
|
280
|
+
* The Minimum value for the slider.
|
281
|
+
*/
|
282
|
+
min: PropTypes.number.isRequired,
|
283
|
+
/**
|
284
|
+
* Fonction de callback appelée lorsqu'on change la valeur du slider.
|
285
|
+
*/
|
286
|
+
onChange: PropTypes.func,
|
287
|
+
/**
|
288
|
+
* The label to show on the right
|
289
|
+
*/
|
290
|
+
rightLabel: PropTypes.string,
|
291
|
+
/**
|
292
|
+
* The step between two selectable values.
|
293
|
+
*/
|
294
|
+
step: PropTypes.number,
|
295
|
+
/**
|
296
|
+
* The suffix to show after each number.
|
297
|
+
*/
|
298
|
+
suffix: PropTypes.string,
|
299
|
+
/**
|
300
|
+
* @ignore
|
301
|
+
*/
|
302
|
+
theme: PropTypes.object,
|
303
|
+
/**
|
304
|
+
* The
|
305
|
+
* value of the input.
|
306
|
+
*/
|
307
|
+
value: PropTypes.number
|
308
|
+
} : {};
|
309
|
+
export default withStyles(styles, { name: 'HmuiHiSlider', withTheme: true })(HiSlider);
|
package/es/HiForm/index.js
CHANGED
@@ -5,4 +5,5 @@ export { default as HiInput } from './HiInput';
|
|
5
5
|
export { default as HiPasswordField } from './HiPasswordField';
|
6
6
|
export { default as HiTextField } from './HiTextField';
|
7
7
|
export { default as HiSearchField } from './HiSearchField';
|
8
|
+
export { default as HiSlider } from './HiSlider';
|
8
9
|
export { default as HiAddressField } from './HiAddressField';
|