@patternfly/react-core 4.182.3 → 4.183.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.182.3",
3
+ "version": "4.183.3",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -34,16 +34,16 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.33.3",
38
- "@patternfly/react-styles": "^4.32.3",
39
- "@patternfly/react-tokens": "^4.34.3",
37
+ "@patternfly/react-icons": "^4.34.3",
38
+ "@patternfly/react-styles": "^4.33.3",
39
+ "@patternfly/react-tokens": "^4.35.3",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
43
43
  "tslib": "^2.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@patternfly/patternfly": "4.164.2",
46
+ "@patternfly/patternfly": "4.165.1",
47
47
  "@rollup/plugin-commonjs": "^21.0.0",
48
48
  "@rollup/plugin-node-resolve": "^13.0.0",
49
49
  "@rollup/plugin-replace": "^3.0.0",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "becd87f1585fbaeb99bb3df634618d0b356ff9bf"
63
+ "gitHead": "c18bb8c707fd4cb935b8f1357e8881edf20a0320"
64
64
  }
@@ -5,6 +5,7 @@ import { css } from '@patternfly/react-styles';
5
5
  import { SliderStep } from './SliderStep';
6
6
  import { InputGroup, InputGroupText } from '../InputGroup';
7
7
  import { TextInput } from '../TextInput';
8
+ import { Tooltip } from '../Tooltip';
8
9
 
9
10
  export interface SliderStepObject {
10
11
  /** Value of the step. This value is a percentage of the slider where the tick is drawn. */
@@ -44,6 +45,8 @@ export interface SliderProps extends Omit<React.HTMLProps<HTMLDivElement>, 'onCh
44
45
  inputAriaLabel?: string;
45
46
  /* Aria label for the thumb */
46
47
  thumbAriaLabel?: string;
48
+ /* Adds a tooltip over the thumb containing the current value */
49
+ hasTooltipOverThumb?: boolean;
47
50
  /** Label that is place after the input field */
48
51
  inputLabel?: string | number;
49
52
  /** Position of the input */
@@ -73,6 +76,7 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
73
76
  inputLabel,
74
77
  inputAriaLabel = 'Slider value input',
75
78
  thumbAriaLabel = 'Value',
79
+ hasTooltipOverThumb = false,
76
80
  inputPosition = 'right',
77
81
  onChange,
78
82
  leftActions,
@@ -141,7 +145,9 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
141
145
  return matchingStep.label;
142
146
  }
143
147
  }
144
- return localValue.toString();
148
+ // For continuous steps default to showing 2 decimals in tooltip
149
+ // Consider making it configurable via a property
150
+ return Number(Number(localValue).toFixed(2)).toString();
145
151
  };
146
152
 
147
153
  const handleThumbDragEnd = () => {
@@ -209,12 +215,12 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
209
215
 
210
216
  thumbRef.current.style.setProperty('--pf-c-slider--value', `${newPercentage}%`);
211
217
  // convert percentage to value
212
- const newValue = (newPercentage * (max - min)) / 100 + min;
218
+ const newValue = Math.round(((newPercentage * (max - min)) / 100 + min) * 100) / 100;
213
219
  setValue(newValue);
214
220
 
215
221
  if (!customSteps) {
216
222
  // snap to new value if not custom steps
217
- snapValue = Math.round((newValue - min) / step) * step + min;
223
+ snapValue = Math.round((Math.round((newValue - min) / step) * step + min) * 100) / 100;
218
224
  thumbRef.current.style.setProperty('--pf-c-slider--value', `${snapValue}%`);
219
225
  setValue(snapValue);
220
226
  }
@@ -344,6 +350,25 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
344
350
  return builtSteps;
345
351
  };
346
352
 
353
+ const thumbComponent = (
354
+ <div
355
+ className={css(styles.sliderThumb)}
356
+ ref={thumbRef}
357
+ tabIndex={isDisabled ? -1 : 0}
358
+ role="slider"
359
+ aria-valuemin={customSteps ? customSteps[0].value : min}
360
+ aria-valuemax={customSteps ? customSteps[customSteps.length - 1].value : max}
361
+ aria-valuenow={localValue}
362
+ aria-valuetext={findAriaTextValue()}
363
+ aria-label={thumbAriaLabel}
364
+ aria-disabled={isDisabled}
365
+ onMouseDown={!isDisabled ? handleMouseDown : null}
366
+ onTouchStart={!isDisabled ? handleTouchStart : null}
367
+ onKeyDown={!isDisabled ? handleThumbKeys : null}
368
+ onClick={!isDisabled ? onThumbClick : null}
369
+ />
370
+ );
371
+
347
372
  return (
348
373
  <div
349
374
  className={css(styles.slider, className, isDisabled && styles.modifiers.disabled)}
@@ -379,22 +404,13 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
379
404
  {buildSteps()}
380
405
  </div>
381
406
  )}
382
- <div
383
- className={css(styles.sliderThumb)}
384
- ref={thumbRef}
385
- tabIndex={isDisabled ? -1 : 0}
386
- role="slider"
387
- aria-valuemin={customSteps ? customSteps[0].value : min}
388
- aria-valuemax={customSteps ? customSteps[customSteps.length - 1].value : max}
389
- aria-valuenow={localValue}
390
- aria-valuetext={findAriaTextValue()}
391
- aria-label={thumbAriaLabel}
392
- aria-disabled={isDisabled}
393
- onMouseDown={!isDisabled ? handleMouseDown : null}
394
- onTouchStart={!isDisabled ? handleTouchStart : null}
395
- onKeyDown={!isDisabled ? handleThumbKeys : null}
396
- onClick={!isDisabled ? onThumbClick : null}
397
- />
407
+ {hasTooltipOverThumb ? (
408
+ <Tooltip entryDelay={0} content={findAriaTextValue()}>
409
+ {thumbComponent}
410
+ </Tooltip>
411
+ ) : (
412
+ thumbComponent
413
+ )}
398
414
  {isInputVisible && inputPosition === 'aboveThumb' && (
399
415
  <div className={css(styles.sliderValue, styles.modifiers.floating)}>{displayInput()}</div>
400
416
  )}
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { mount } from 'enzyme';
2
+ import { mount, shallow } from 'enzyme';
3
3
  import { Slider } from '../Slider';
4
4
  import { Button } from '../../Button';
5
5
 
@@ -69,4 +69,9 @@ describe('slider', () => {
69
69
  const view = mount(<Slider value={50} isDisabled />);
70
70
  expect(view).toMatchSnapshot();
71
71
  });
72
+
73
+ test('renders slider with tooltip on thumb', () => {
74
+ const view = shallow(<Slider value={50} hasTooltipOverThumb />);
75
+ expect(view).toMatchSnapshot();
76
+ });
72
77
  });
@@ -1194,3 +1194,69 @@ exports[`slider renders slider with input actions 1`] = `
1194
1194
  </div>
1195
1195
  </Slider>
1196
1196
  `;
1197
+
1198
+ exports[`slider renders slider with tooltip on thumb 1`] = `
1199
+ <div
1200
+ className="pf-c-slider"
1201
+ style={
1202
+ Object {
1203
+ "--pf-c-slider--value": "50%",
1204
+ "--pf-c-slider__value--c-form-control--width-chars": 1,
1205
+ }
1206
+ }
1207
+ >
1208
+ <div
1209
+ className="pf-c-slider__main"
1210
+ >
1211
+ <div
1212
+ className="pf-c-slider__rail"
1213
+ onClick={[Function]}
1214
+ >
1215
+ <div
1216
+ className="pf-c-slider__rail-track"
1217
+ />
1218
+ </div>
1219
+ <div
1220
+ aria-hidden="true"
1221
+ className="pf-c-slider__steps"
1222
+ >
1223
+ <SliderStep
1224
+ isActive={true}
1225
+ isLabelHidden={false}
1226
+ isTickHidden={true}
1227
+ key="0"
1228
+ label="0"
1229
+ value={0}
1230
+ />
1231
+ <SliderStep
1232
+ isActive={false}
1233
+ isLabelHidden={false}
1234
+ isTickHidden={true}
1235
+ key="100"
1236
+ label="100"
1237
+ value={100}
1238
+ />
1239
+ </div>
1240
+ <Tooltip
1241
+ content="50"
1242
+ entryDelay={0}
1243
+ >
1244
+ <div
1245
+ aria-disabled={false}
1246
+ aria-label="Value"
1247
+ aria-valuemax={100}
1248
+ aria-valuemin={0}
1249
+ aria-valuenow={50}
1250
+ aria-valuetext="50"
1251
+ className="pf-c-slider__thumb"
1252
+ onClick={[Function]}
1253
+ onKeyDown={[Function]}
1254
+ onMouseDown={[Function]}
1255
+ onTouchStart={[Function]}
1256
+ role="slider"
1257
+ tabIndex={0}
1258
+ />
1259
+ </Tooltip>
1260
+ </div>
1261
+ </div>
1262
+ `;
@@ -134,12 +134,13 @@ class DiscreteInput extends React.Component {
134
134
 
135
135
  ```js
136
136
  import React from 'react';
137
- import { Slider, Text, TextVariants } from '@patternfly/react-core';
137
+ import { Checkbox, Slider, Text, TextVariants } from '@patternfly/react-core';
138
138
 
139
139
  class ContinuousInput extends React.Component {
140
140
  constructor(props) {
141
141
  super(props);
142
142
  this.state = {
143
+ hasTooltipOverThumb: false,
143
144
  value: 50,
144
145
  valueCustom: 50
145
146
  };
@@ -160,14 +161,24 @@ class ContinuousInput extends React.Component {
160
161
  render() {
161
162
  return (
162
163
  <>
163
- <Text component={TextVariants.h3}>Slider value is: {this.state.value.toFixed(2)}</Text>
164
- <Slider value={this.state.value} onChange={this.onChange} />
164
+ <Checkbox
165
+ id="thumb-has-tooltip"
166
+ label="hasTooltipOverThumb"
167
+ isChecked={this.state.hasTooltipOverThumb}
168
+ onChange={hasTooltipOverThumb => this.setState({ hasTooltipOverThumb })}
169
+ style={{ marginBottom: 20 }} />
170
+ <Text component={TextVariants.h3}>Slider Value is: {this.state.value}</Text>
171
+ <Slider
172
+ hasTooltipOverThumb={this.state.hasTooltipOverThumb}
173
+ value={this.state.value}
174
+ onChange={this.onChange} />
165
175
  <br />
166
- <Text component={TextVariants.h3}>Slider value is: {this.state.valueCustom.toFixed(2)}</Text>
176
+ <Text component={TextVariants.h3}>Slider value is: {this.state.valueCustom}</Text>
167
177
  <Slider
168
178
  onChange={this.onChangeCustom}
169
179
  value={this.state.valueCustom}
170
180
  areCustomStepsContinuous
181
+ hasTooltipOverThumb={this.state.hasTooltipOverThumb}
171
182
  customSteps={[
172
183
  { value: 0, label: '0%' },
173
184
  { value: 100, label: '100%' }