carbon-react 119.9.0 → 119.9.2

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/README.md CHANGED
@@ -4,7 +4,7 @@ Carbon is a [React](https://facebook.github.io/react/) component library develop
4
4
 
5
5
  ## Getting started
6
6
 
7
- Our [getting started guide](docs/getting-started.stories.mdx) provides instructions on how to install and use the Carbon library.
7
+ Our [getting started guide](https://carbon.sage.com/?path=/story/getting-started-installation--page) provides instructions on how to install and use the Carbon library.
8
8
 
9
9
  ## Examples
10
10
 
@@ -3,7 +3,11 @@ import { MarginProps } from "styled-system";
3
3
  import { IconType } from "../icon";
4
4
  export declare type PortraitShapes = "circle" | "square";
5
5
  export declare type PortraitSizes = "XS" | "S" | "M" | "ML" | "L" | "XL" | "XXL";
6
- export interface PortraitBaseProps extends MarginProps {
6
+ export interface PortraitProps extends MarginProps {
7
+ /** An email address registered with Gravatar. */
8
+ gravatar?: string;
9
+ /** A custom image URL. */
10
+ src?: string;
7
11
  /** The size of the Portrait. */
8
12
  size?: PortraitSizes;
9
13
  /** The `alt` HTML string. */
@@ -35,16 +39,5 @@ export interface PortraitBaseProps extends MarginProps {
35
39
  /** Override font color of the Tooltip, provide any color from palette or any valid css color value. */
36
40
  tooltipFontColor?: string;
37
41
  }
38
- export interface PortraitWithGravatar extends PortraitBaseProps {
39
- /** An email address registered with Gravatar. */
40
- gravatar?: string;
41
- src?: never;
42
- }
43
- export interface PortraitWithSrc extends PortraitBaseProps {
44
- /** A custom image URL. */
45
- src?: string;
46
- gravatar?: never;
47
- }
48
- export declare type PortraitProps = PortraitWithGravatar | PortraitWithSrc;
49
42
  export declare const Portrait: ({ alt, darkBackground, gravatar, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
50
43
  export default Portrait;
@@ -1,6 +1,7 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import React, { useEffect, useState, useContext } from "react";
3
3
  import PropTypes from "prop-types";
4
+ import invariant from "invariant";
4
5
  import Tooltip from "../tooltip";
5
6
  import tagComponent from "../../__internal__/utils/helpers/tags/tags";
6
7
  import PortraitGravatar from "./portrait-gravatar.component";
@@ -34,6 +35,7 @@ export const Portrait = _ref => {
34
35
  roundedCornersOptOut
35
36
  } = useContext(RoundedCornersOptOutContext);
36
37
  const defaultShape = roundedCornersOptOut ? "square" : "circle";
38
+ !!(src && gravatar) ? process.env.NODE_ENV !== "production" ? invariant(false, "The `src` prop cannot be used in conjunction with the `gravatar` prop." + " Please use one or the other.") : invariant(false) : void 0;
37
39
  useEffect(() => {
38
40
  setExternalError(false);
39
41
  }, [gravatar, src]);
@@ -92,9 +92,18 @@ const Textarea = /*#__PURE__*/React.forwardRef((_ref, ref) => {
92
92
  const expandTextarea = () => {
93
93
  const textarea = internalRef.current;
94
94
  if (textarea?.scrollHeight && textarea?.scrollHeight > minHeight.current) {
95
+ // need to reset scroll position of the nearest parent which scrolls
96
+ let scrollElement = textarea;
97
+ while (scrollElement && !scrollElement?.scrollTop) {
98
+ scrollElement = scrollElement?.parentElement || null;
99
+ }
100
+ const scrollPosition = scrollElement?.scrollTop;
95
101
  textarea.style.height = "0px";
96
102
  // Set the height so all content is shown
97
103
  textarea.style.height = `${Math.max(textarea.scrollHeight, minHeight.current)}px`;
104
+ if (scrollElement && scrollPosition) {
105
+ scrollElement.scrollTop = scrollPosition;
106
+ }
98
107
  }
99
108
  };
100
109
  const {
@@ -126,10 +135,14 @@ const Textarea = /*#__PURE__*/React.forwardRef((_ref, ref) => {
126
135
  if (expandable) {
127
136
  window.addEventListener("resize", expandTextarea);
128
137
  minHeight.current = internalRef?.current?.clientHeight || 0;
138
+ // need to also run expandTextarea when the Sage UI font completes loading, to prevent strange scroll
139
+ // behaviour when it only loads after the component is rendered
140
+ document.fonts?.addEventListener("loadingdone", expandTextarea);
129
141
  }
130
142
  return () => {
131
143
  if (expandable) {
132
144
  window.removeEventListener("resize", expandTextarea);
145
+ document.fonts?.removeEventListener("loadingdone", expandTextarea);
133
146
  }
134
147
  };
135
148
  }, [expandable]);
@@ -3,7 +3,11 @@ import { MarginProps } from "styled-system";
3
3
  import { IconType } from "../icon";
4
4
  export declare type PortraitShapes = "circle" | "square";
5
5
  export declare type PortraitSizes = "XS" | "S" | "M" | "ML" | "L" | "XL" | "XXL";
6
- export interface PortraitBaseProps extends MarginProps {
6
+ export interface PortraitProps extends MarginProps {
7
+ /** An email address registered with Gravatar. */
8
+ gravatar?: string;
9
+ /** A custom image URL. */
10
+ src?: string;
7
11
  /** The size of the Portrait. */
8
12
  size?: PortraitSizes;
9
13
  /** The `alt` HTML string. */
@@ -35,16 +39,5 @@ export interface PortraitBaseProps extends MarginProps {
35
39
  /** Override font color of the Tooltip, provide any color from palette or any valid css color value. */
36
40
  tooltipFontColor?: string;
37
41
  }
38
- export interface PortraitWithGravatar extends PortraitBaseProps {
39
- /** An email address registered with Gravatar. */
40
- gravatar?: string;
41
- src?: never;
42
- }
43
- export interface PortraitWithSrc extends PortraitBaseProps {
44
- /** A custom image URL. */
45
- src?: string;
46
- gravatar?: never;
47
- }
48
- export declare type PortraitProps = PortraitWithGravatar | PortraitWithSrc;
49
42
  export declare const Portrait: ({ alt, darkBackground, gravatar, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
50
43
  export default Portrait;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = exports.Portrait = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _invariant = _interopRequireDefault(require("invariant"));
9
10
  var _tooltip = _interopRequireDefault(require("../tooltip"));
10
11
  var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags/tags"));
11
12
  var _portraitGravatar = _interopRequireDefault(require("./portrait-gravatar.component"));
@@ -43,6 +44,7 @@ const Portrait = _ref => {
43
44
  roundedCornersOptOut
44
45
  } = (0, _react.useContext)(_carbonProvider.NewValidationContext);
45
46
  const defaultShape = roundedCornersOptOut ? "square" : "circle";
47
+ !!(src && gravatar) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, "The `src` prop cannot be used in conjunction with the `gravatar` prop." + " Please use one or the other.") : (0, _invariant.default)(false) : void 0;
46
48
  (0, _react.useEffect)(() => {
47
49
  setExternalError(false);
48
50
  }, [gravatar, src]);
@@ -101,9 +101,18 @@ const Textarea = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
101
101
  const expandTextarea = () => {
102
102
  const textarea = internalRef.current;
103
103
  if (textarea?.scrollHeight && textarea?.scrollHeight > minHeight.current) {
104
+ // need to reset scroll position of the nearest parent which scrolls
105
+ let scrollElement = textarea;
106
+ while (scrollElement && !scrollElement?.scrollTop) {
107
+ scrollElement = scrollElement?.parentElement || null;
108
+ }
109
+ const scrollPosition = scrollElement?.scrollTop;
104
110
  textarea.style.height = "0px";
105
111
  // Set the height so all content is shown
106
112
  textarea.style.height = `${Math.max(textarea.scrollHeight, minHeight.current)}px`;
113
+ if (scrollElement && scrollPosition) {
114
+ scrollElement.scrollTop = scrollPosition;
115
+ }
107
116
  }
108
117
  };
109
118
  const {
@@ -135,10 +144,14 @@ const Textarea = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
135
144
  if (expandable) {
136
145
  window.addEventListener("resize", expandTextarea);
137
146
  minHeight.current = internalRef?.current?.clientHeight || 0;
147
+ // need to also run expandTextarea when the Sage UI font completes loading, to prevent strange scroll
148
+ // behaviour when it only loads after the component is rendered
149
+ document.fonts?.addEventListener("loadingdone", expandTextarea);
138
150
  }
139
151
  return () => {
140
152
  if (expandable) {
141
153
  window.removeEventListener("resize", expandTextarea);
154
+ document.fonts?.removeEventListener("loadingdone", expandTextarea);
142
155
  }
143
156
  };
144
157
  }, [expandable]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "119.9.0",
3
+ "version": "119.9.2",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",