@carbon/react 1.29.0-rc.0 → 1.29.1

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.
@@ -199,12 +199,11 @@ const DatePicker = /*#__PURE__*/React__default.forwardRef(function DatePicker(_r
199
199
  onClose(calendarRef.current.selectedDates, dateStr, calendarRef.current);
200
200
  }
201
201
  });
202
- }; //const savedOnOpen = useSavedCallback(onOpen);
203
-
202
+ };
204
203
 
205
204
  const endInputField = useRef(null);
206
205
  const calendarRef = useRef(null);
207
- const savedOnChange = useSavedCallback(() => onChange);
206
+ const savedOnChange = useSavedCallback(onChange);
208
207
  const savedOnClose = useSavedCallback(datePickerType === 'range' ? onCalendarClose : onClose);
209
208
  const savedOnOpen = useSavedCallback(() => onOpen);
210
209
  const datePickerClasses = cx(`${prefix}--date-picker`, {
@@ -41,9 +41,13 @@ export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
41
41
  */
42
42
  inputType?: string;
43
43
  /**
44
- * `true` to specify if the control is invalid.
44
+ * `Specify whether the Slider is currently invalid
45
45
  */
46
46
  invalid?: boolean;
47
+ /**
48
+ * Provide the text that is displayed when the Slider is in an invalid state
49
+ */
50
+ invalidText?: React.ReactNode;
47
51
  /**
48
52
  * The label for the slider.
49
53
  */
@@ -119,6 +123,14 @@ export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
119
123
  * The value.
120
124
  */
121
125
  value: number;
126
+ /**
127
+ * Specify whether the control is currently in warning state
128
+ */
129
+ warn?: boolean;
130
+ /**
131
+ * Provide the text that is displayed when the control is in warning state
132
+ */
133
+ warnText?: React.ReactNode;
122
134
  }
123
135
  interface CalcValueProps {
124
136
  clientX?: number;
@@ -160,9 +172,13 @@ export default class Slider extends PureComponent<SliderProps> {
160
172
  */
161
173
  inputType: PropTypes.Requireable<string>;
162
174
  /**
163
- * `true` to specify if the control is invalid.
175
+ * `Specify whether the Slider is currently invalid
164
176
  */
165
177
  invalid: PropTypes.Requireable<boolean>;
178
+ /**
179
+ * Provide the text that is displayed when the Slider is in an invalid state
180
+ */
181
+ invalidText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
166
182
  /**
167
183
  * The label for the slider.
168
184
  */
@@ -229,6 +245,14 @@ export default class Slider extends PureComponent<SliderProps> {
229
245
  * The value.
230
246
  */
231
247
  value: PropTypes.Validator<number>;
248
+ /**
249
+ * `Specify whether the Slider is in a warn state
250
+ */
251
+ warn: PropTypes.Requireable<boolean>;
252
+ /**
253
+ * Provide the text that is displayed when the Slider is in an warn state
254
+ */
255
+ warnText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
232
256
  };
233
257
  static defaultProps: {
234
258
  hideTextInput: boolean;
@@ -16,6 +16,7 @@ import { matches } from '../../internal/keyboard/match.js';
16
16
  import { PrefixContext } from '../../internal/usePrefix.js';
17
17
  import deprecate from '../../prop-types/deprecate.js';
18
18
  import { FeatureFlagContext } from '../FeatureFlags/index.js';
19
+ import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
19
20
 
20
21
  const defaultFormatLabel = (value, label) => {
21
22
  return typeof label === 'function' ? label(value) : `${value}${label}`;
@@ -414,11 +415,14 @@ class Slider extends PureComponent {
414
415
  step,
415
416
  stepMultiplier: _stepMultiplier,
416
417
  inputType,
418
+ invalidText,
417
419
  required,
418
420
  disabled,
419
421
  name,
420
422
  light,
421
423
  readOnly,
424
+ warn,
425
+ warnText,
422
426
  ...other
423
427
  } = this.props;
424
428
  delete other.onRelease;
@@ -446,8 +450,9 @@ class Slider extends PureComponent {
446
450
  }, [enabled ? null : className]);
447
451
  const inputClasses = cx(`${prefix}--text-input`, `${prefix}--slider-text-input`, {
448
452
  [`${prefix}--text-input--light`]: light,
449
- [`${prefix}--text-input--invalid`]: isValid === false,
450
- [`${prefix}--slider-text-input--hidden`]: hideTextInput
453
+ [`${prefix}--text-input--invalid`]: !readOnly && isValid === false,
454
+ [`${prefix}--slider-text-input--hidden`]: hideTextInput,
455
+ [`${prefix}--slider-text-input--warn`]: !readOnly && warn
451
456
  });
452
457
  return /*#__PURE__*/React__default.createElement("div", {
453
458
  className: enabled ? cx(`${prefix}--form-item`, className) : `${prefix}--form-item`
@@ -469,7 +474,7 @@ class Slider extends PureComponent {
469
474
  onKeyDown: this.onKeyDown,
470
475
  role: "presentation",
471
476
  tabIndex: -1,
472
- "data-invalid": isValid ? null : true
477
+ "data-invalid": !isValid && !readOnly ? true : null
473
478
  }, other), /*#__PURE__*/React__default.createElement("div", {
474
479
  className: `${prefix}--slider__thumb`,
475
480
  role: "slider",
@@ -506,10 +511,18 @@ class Slider extends PureComponent {
506
511
  onChange: this.onChange,
507
512
  onBlur: this.onBlur,
508
513
  onKeyUp: this.props.onInputKeyUp,
509
- "data-invalid": isValid ? null : true,
510
- "aria-invalid": isValid ? undefined : true,
514
+ "data-invalid": !isValid && !readOnly ? true : null,
515
+ "aria-invalid": !isValid && !readOnly ? true : undefined,
511
516
  readOnly: readOnly
512
- })));
517
+ }), !readOnly && isValid === false && /*#__PURE__*/React__default.createElement(WarningFilled, {
518
+ className: `${prefix}--slider__invalid-icon`
519
+ }), !readOnly && warn && isValid && /*#__PURE__*/React__default.createElement(WarningAltFilled, {
520
+ className: `${prefix}--slider__invalid-icon ${prefix}--slider__invalid-icon--warning`
521
+ })), !readOnly && isValid === false && /*#__PURE__*/React__default.createElement("div", {
522
+ className: cx(`${prefix}--slider__validation-msg`, `${prefix}--slider__validation-msg--invalid`, `${prefix}--form-requirement`)
523
+ }, invalidText), !readOnly && warn && isValid && /*#__PURE__*/React__default.createElement("div", {
524
+ className: cx(`${prefix}--slider__validation-msg`, `${prefix}--form-requirement`)
525
+ }, warnText));
513
526
  });
514
527
  }
515
528
 
@@ -557,10 +570,15 @@ _defineProperty(Slider, "propTypes", {
557
570
  inputType: PropTypes.string,
558
571
 
559
572
  /**
560
- * `true` to specify if the control is invalid.
573
+ * `Specify whether the Slider is currently invalid
561
574
  */
562
575
  invalid: PropTypes.bool,
563
576
 
577
+ /**
578
+ * Provide the text that is displayed when the Slider is in an invalid state
579
+ */
580
+ invalidText: PropTypes.node,
581
+
564
582
  /**
565
583
  * The label for the slider.
566
584
  */
@@ -641,7 +659,17 @@ _defineProperty(Slider, "propTypes", {
641
659
  /**
642
660
  * The value.
643
661
  */
644
- value: PropTypes.number.isRequired
662
+ value: PropTypes.number.isRequired,
663
+
664
+ /**
665
+ * `Specify whether the Slider is in a warn state
666
+ */
667
+ warn: PropTypes.bool,
668
+
669
+ /**
670
+ * Provide the text that is displayed when the Slider is in an warn state
671
+ */
672
+ warnText: PropTypes.node
645
673
  });
646
674
 
647
675
  _defineProperty(Slider, "defaultProps", {
@@ -7,7 +7,7 @@
7
7
 
8
8
  import PropTypes from 'prop-types';
9
9
  import React__default, { useState, useCallback } from 'react';
10
- import { useEvent } from '../../internal/useEvent.js';
10
+ import { useWindowEvent } from '../../internal/useEvent.js';
11
11
  import { match } from '../../internal/keyboard/match.js';
12
12
  import { Escape } from '../../internal/keyboard/keys.js';
13
13
 
@@ -18,7 +18,7 @@ const HeaderContainer = _ref => {
18
18
  } = _ref;
19
19
  //state for expandable sidenav
20
20
  const [isSideNavExpandedState, setIsSideNavExpandedState] = useState(isSideNavExpanded);
21
- useEvent(window, 'keydown', event => {
21
+ useWindowEvent('keydown', event => {
22
22
  if (match(event, Escape)) {
23
23
  setIsSideNavExpandedState(false);
24
24
  }
@@ -7,25 +7,6 @@
7
7
 
8
8
  import { useRef, useEffect } from 'react';
9
9
 
10
- function useEvent(elementOrRef, eventName, callback) {
11
- const savedCallback = useRef(null);
12
- useEffect(() => {
13
- savedCallback.current = callback;
14
- });
15
- useEffect(() => {
16
- function handler(event) {
17
- if (savedCallback.current) {
18
- savedCallback.current(event);
19
- }
20
- }
21
-
22
- const element = elementOrRef.current ?? elementOrRef;
23
- element.addEventListener(eventName, handler);
24
- return () => {
25
- element.removeEventListener(eventName, handler);
26
- };
27
- }, [elementOrRef, eventName]);
28
- }
29
10
  function useWindowEvent(eventName, callback) {
30
11
  const savedCallback = useRef(null);
31
12
  useEffect(() => {
@@ -45,4 +26,4 @@ function useWindowEvent(eventName, callback) {
45
26
  }, [eventName]);
46
27
  }
47
28
 
48
- export { useEvent, useWindowEvent };
29
+ export { useWindowEvent };
@@ -13,7 +13,7 @@ import { useRef, useEffect, useCallback } from 'react';
13
13
  * callback prop but don't want it to be added to the dependency array of an
14
14
  * effect.
15
15
  *
16
- * @param {Function} callback
16
+ * @param {Function | undefined} callback
17
17
  * @returns {Function}
18
18
  */
19
19
 
@@ -211,12 +211,11 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
211
211
  onClose(calendarRef.current.selectedDates, dateStr, calendarRef.current);
212
212
  }
213
213
  });
214
- }; //const savedOnOpen = useSavedCallback(onOpen);
215
-
214
+ };
216
215
 
217
216
  const endInputField = React.useRef(null);
218
217
  const calendarRef = React.useRef(null);
219
- const savedOnChange = useSavedCallback.useSavedCallback(() => onChange);
218
+ const savedOnChange = useSavedCallback.useSavedCallback(onChange);
220
219
  const savedOnClose = useSavedCallback.useSavedCallback(datePickerType === 'range' ? onCalendarClose : onClose);
221
220
  const savedOnOpen = useSavedCallback.useSavedCallback(() => onOpen);
222
221
  const datePickerClasses = cx__default["default"](`${prefix}--date-picker`, {
@@ -41,9 +41,13 @@ export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
41
41
  */
42
42
  inputType?: string;
43
43
  /**
44
- * `true` to specify if the control is invalid.
44
+ * `Specify whether the Slider is currently invalid
45
45
  */
46
46
  invalid?: boolean;
47
+ /**
48
+ * Provide the text that is displayed when the Slider is in an invalid state
49
+ */
50
+ invalidText?: React.ReactNode;
47
51
  /**
48
52
  * The label for the slider.
49
53
  */
@@ -119,6 +123,14 @@ export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
119
123
  * The value.
120
124
  */
121
125
  value: number;
126
+ /**
127
+ * Specify whether the control is currently in warning state
128
+ */
129
+ warn?: boolean;
130
+ /**
131
+ * Provide the text that is displayed when the control is in warning state
132
+ */
133
+ warnText?: React.ReactNode;
122
134
  }
123
135
  interface CalcValueProps {
124
136
  clientX?: number;
@@ -160,9 +172,13 @@ export default class Slider extends PureComponent<SliderProps> {
160
172
  */
161
173
  inputType: PropTypes.Requireable<string>;
162
174
  /**
163
- * `true` to specify if the control is invalid.
175
+ * `Specify whether the Slider is currently invalid
164
176
  */
165
177
  invalid: PropTypes.Requireable<boolean>;
178
+ /**
179
+ * Provide the text that is displayed when the Slider is in an invalid state
180
+ */
181
+ invalidText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
166
182
  /**
167
183
  * The label for the slider.
168
184
  */
@@ -229,6 +245,14 @@ export default class Slider extends PureComponent<SliderProps> {
229
245
  * The value.
230
246
  */
231
247
  value: PropTypes.Validator<number>;
248
+ /**
249
+ * `Specify whether the Slider is in a warn state
250
+ */
251
+ warn: PropTypes.Requireable<boolean>;
252
+ /**
253
+ * Provide the text that is displayed when the Slider is in an warn state
254
+ */
255
+ warnText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
232
256
  };
233
257
  static defaultProps: {
234
258
  hideTextInput: boolean;
@@ -20,6 +20,7 @@ var match = require('../../internal/keyboard/match.js');
20
20
  var usePrefix = require('../../internal/usePrefix.js');
21
21
  var deprecate = require('../../prop-types/deprecate.js');
22
22
  var index = require('../FeatureFlags/index.js');
23
+ var iconsReact = require('@carbon/icons-react');
23
24
 
24
25
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
26
 
@@ -444,11 +445,14 @@ class Slider extends React.PureComponent {
444
445
  step,
445
446
  stepMultiplier: _stepMultiplier,
446
447
  inputType,
448
+ invalidText,
447
449
  required,
448
450
  disabled,
449
451
  name,
450
452
  light,
451
453
  readOnly,
454
+ warn,
455
+ warnText,
452
456
  ...other
453
457
  } = this.props;
454
458
  delete other.onRelease;
@@ -476,8 +480,9 @@ class Slider extends React.PureComponent {
476
480
  }, [enabled ? null : className]);
477
481
  const inputClasses = cx__default["default"](`${prefix}--text-input`, `${prefix}--slider-text-input`, {
478
482
  [`${prefix}--text-input--light`]: light,
479
- [`${prefix}--text-input--invalid`]: isValid === false,
480
- [`${prefix}--slider-text-input--hidden`]: hideTextInput
483
+ [`${prefix}--text-input--invalid`]: !readOnly && isValid === false,
484
+ [`${prefix}--slider-text-input--hidden`]: hideTextInput,
485
+ [`${prefix}--slider-text-input--warn`]: !readOnly && warn
481
486
  });
482
487
  return /*#__PURE__*/React__default["default"].createElement("div", {
483
488
  className: enabled ? cx__default["default"](`${prefix}--form-item`, className) : `${prefix}--form-item`
@@ -499,7 +504,7 @@ class Slider extends React.PureComponent {
499
504
  onKeyDown: this.onKeyDown,
500
505
  role: "presentation",
501
506
  tabIndex: -1,
502
- "data-invalid": isValid ? null : true
507
+ "data-invalid": !isValid && !readOnly ? true : null
503
508
  }, other), /*#__PURE__*/React__default["default"].createElement("div", {
504
509
  className: `${prefix}--slider__thumb`,
505
510
  role: "slider",
@@ -536,10 +541,18 @@ class Slider extends React.PureComponent {
536
541
  onChange: this.onChange,
537
542
  onBlur: this.onBlur,
538
543
  onKeyUp: this.props.onInputKeyUp,
539
- "data-invalid": isValid ? null : true,
540
- "aria-invalid": isValid ? undefined : true,
544
+ "data-invalid": !isValid && !readOnly ? true : null,
545
+ "aria-invalid": !isValid && !readOnly ? true : undefined,
541
546
  readOnly: readOnly
542
- })));
547
+ }), !readOnly && isValid === false && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningFilled, {
548
+ className: `${prefix}--slider__invalid-icon`
549
+ }), !readOnly && warn && isValid && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningAltFilled, {
550
+ className: `${prefix}--slider__invalid-icon ${prefix}--slider__invalid-icon--warning`
551
+ })), !readOnly && isValid === false && /*#__PURE__*/React__default["default"].createElement("div", {
552
+ className: cx__default["default"](`${prefix}--slider__validation-msg`, `${prefix}--slider__validation-msg--invalid`, `${prefix}--form-requirement`)
553
+ }, invalidText), !readOnly && warn && isValid && /*#__PURE__*/React__default["default"].createElement("div", {
554
+ className: cx__default["default"](`${prefix}--slider__validation-msg`, `${prefix}--form-requirement`)
555
+ }, warnText));
543
556
  });
544
557
  }
545
558
 
@@ -587,10 +600,15 @@ _rollupPluginBabelHelpers.defineProperty(Slider, "propTypes", {
587
600
  inputType: PropTypes__default["default"].string,
588
601
 
589
602
  /**
590
- * `true` to specify if the control is invalid.
603
+ * `Specify whether the Slider is currently invalid
591
604
  */
592
605
  invalid: PropTypes__default["default"].bool,
593
606
 
607
+ /**
608
+ * Provide the text that is displayed when the Slider is in an invalid state
609
+ */
610
+ invalidText: PropTypes__default["default"].node,
611
+
594
612
  /**
595
613
  * The label for the slider.
596
614
  */
@@ -671,7 +689,17 @@ _rollupPluginBabelHelpers.defineProperty(Slider, "propTypes", {
671
689
  /**
672
690
  * The value.
673
691
  */
674
- value: PropTypes__default["default"].number.isRequired
692
+ value: PropTypes__default["default"].number.isRequired,
693
+
694
+ /**
695
+ * `Specify whether the Slider is in a warn state
696
+ */
697
+ warn: PropTypes__default["default"].bool,
698
+
699
+ /**
700
+ * Provide the text that is displayed when the Slider is in an warn state
701
+ */
702
+ warnText: PropTypes__default["default"].node
675
703
  });
676
704
 
677
705
  _rollupPluginBabelHelpers.defineProperty(Slider, "defaultProps", {
@@ -27,7 +27,7 @@ const HeaderContainer = _ref => {
27
27
  } = _ref;
28
28
  //state for expandable sidenav
29
29
  const [isSideNavExpandedState, setIsSideNavExpandedState] = React.useState(isSideNavExpanded);
30
- useEvent.useEvent(window, 'keydown', event => {
30
+ useEvent.useWindowEvent('keydown', event => {
31
31
  if (match.match(event, keys.Escape)) {
32
32
  setIsSideNavExpandedState(false);
33
33
  }
@@ -11,25 +11,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  var React = require('react');
13
13
 
14
- function useEvent(elementOrRef, eventName, callback) {
15
- const savedCallback = React.useRef(null);
16
- React.useEffect(() => {
17
- savedCallback.current = callback;
18
- });
19
- React.useEffect(() => {
20
- function handler(event) {
21
- if (savedCallback.current) {
22
- savedCallback.current(event);
23
- }
24
- }
25
-
26
- const element = elementOrRef.current ?? elementOrRef;
27
- element.addEventListener(eventName, handler);
28
- return () => {
29
- element.removeEventListener(eventName, handler);
30
- };
31
- }, [elementOrRef, eventName]);
32
- }
33
14
  function useWindowEvent(eventName, callback) {
34
15
  const savedCallback = React.useRef(null);
35
16
  React.useEffect(() => {
@@ -49,5 +30,4 @@ function useWindowEvent(eventName, callback) {
49
30
  }, [eventName]);
50
31
  }
51
32
 
52
- exports.useEvent = useEvent;
53
33
  exports.useWindowEvent = useWindowEvent;
@@ -17,7 +17,7 @@ var React = require('react');
17
17
  * callback prop but don't want it to be added to the dependency array of an
18
18
  * effect.
19
19
  *
20
- * @param {Function} callback
20
+ * @param {Function | undefined} callback
21
21
  * @returns {Function}
22
22
  */
23
23
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/react",
3
3
  "description": "React components for the Carbon Design System",
4
- "version": "1.29.0-rc.0",
4
+ "version": "1.29.1",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -46,7 +46,7 @@
46
46
  "@carbon/feature-flags": "^0.13.0",
47
47
  "@carbon/icons-react": "^11.19.0",
48
48
  "@carbon/layout": "^11.13.0",
49
- "@carbon/styles": "^1.29.0-rc.0",
49
+ "@carbon/styles": "^1.29.0",
50
50
  "@carbon/telemetry": "0.1.0",
51
51
  "classnames": "2.3.2",
52
52
  "copy-to-clipboard": "^3.3.1",
@@ -133,5 +133,5 @@
133
133
  "**/*.scss",
134
134
  "**/*.css"
135
135
  ],
136
- "gitHead": "e25cb04ffef0834eac0ef6f05bc9f7978fb4b796"
136
+ "gitHead": "64462e40375df9f33cedb302d7a4e11c84766d24"
137
137
  }