carbon-react 124.2.2 → 124.3.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.
Files changed (49) hide show
  1. package/esm/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +1 -1
  2. package/esm/__internal__/utils/helpers/tags/tags-specs/tags-specs.js +6 -4
  3. package/esm/__spec_helper__/index.js +3 -1
  4. package/esm/__spec_helper__/mock-element-scrollto.d.ts +2 -0
  5. package/esm/__spec_helper__/mock-element-scrollto.js +6 -0
  6. package/esm/__spec_helper__/select-test-utils.d.ts +3 -0
  7. package/esm/__spec_helper__/select-test-utils.js +39 -0
  8. package/esm/components/file-input/__internal__/file-upload-status/file-upload-status.component.d.ts +35 -0
  9. package/esm/components/file-input/__internal__/file-upload-status/file-upload-status.component.js +73 -0
  10. package/esm/components/file-input/__internal__/file-upload-status/file-upload-status.style.d.ts +12 -0
  11. package/esm/components/file-input/__internal__/file-upload-status/file-upload-status.style.js +97 -0
  12. package/esm/components/file-input/__internal__/file-upload-status/index.d.ts +2 -0
  13. package/esm/components/file-input/__internal__/file-upload-status/index.js +1 -0
  14. package/esm/components/file-input/file-input.component.d.ts +36 -0
  15. package/esm/components/file-input/file-input.component.js +353 -0
  16. package/esm/components/file-input/file-input.style.d.ts +14 -0
  17. package/esm/components/file-input/file-input.style.js +58 -0
  18. package/esm/components/file-input/index.d.ts +3 -0
  19. package/esm/components/file-input/index.js +1 -0
  20. package/esm/components/select/select-list/select-list.component.js +41 -7
  21. package/esm/locales/en-gb.js +10 -0
  22. package/esm/locales/locale.d.ts +10 -0
  23. package/esm/locales/pl-pl.js +10 -0
  24. package/lib/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +1 -1
  25. package/lib/__internal__/utils/helpers/tags/tags-specs/tags-specs.js +6 -4
  26. package/lib/__spec_helper__/index.js +3 -1
  27. package/lib/__spec_helper__/mock-element-scrollto.d.ts +2 -0
  28. package/lib/__spec_helper__/mock-element-scrollto.js +12 -0
  29. package/lib/__spec_helper__/select-test-utils.d.ts +3 -0
  30. package/lib/__spec_helper__/select-test-utils.js +47 -0
  31. package/lib/components/file-input/__internal__/file-upload-status/file-upload-status.component.d.ts +35 -0
  32. package/lib/components/file-input/__internal__/file-upload-status/file-upload-status.component.js +81 -0
  33. package/lib/components/file-input/__internal__/file-upload-status/file-upload-status.style.d.ts +12 -0
  34. package/lib/components/file-input/__internal__/file-upload-status/file-upload-status.style.js +106 -0
  35. package/lib/components/file-input/__internal__/file-upload-status/index.d.ts +2 -0
  36. package/lib/components/file-input/__internal__/file-upload-status/index.js +13 -0
  37. package/lib/components/file-input/__internal__/file-upload-status/package.json +6 -0
  38. package/lib/components/file-input/file-input.component.d.ts +36 -0
  39. package/lib/components/file-input/file-input.component.js +361 -0
  40. package/lib/components/file-input/file-input.style.d.ts +14 -0
  41. package/lib/components/file-input/file-input.style.js +67 -0
  42. package/lib/components/file-input/index.d.ts +3 -0
  43. package/lib/components/file-input/index.js +13 -0
  44. package/lib/components/file-input/package.json +6 -0
  45. package/lib/components/select/select-list/select-list.component.js +40 -6
  46. package/lib/locales/en-gb.js +10 -0
  47. package/lib/locales/locale.d.ts +10 -0
  48. package/lib/locales/pl-pl.js +10 -0
  49. package/package.json +3 -2
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.simulateDropdownEvent = simulateDropdownEvent;
7
+ exports.simulateSelectTextboxEvent = simulateSelectTextboxEvent;
8
+ var _testUtils = require("react-dom/test-utils");
9
+ var _jsdomTestingMocks = require("jsdom-testing-mocks");
10
+ var _selectListContainer = _interopRequireDefault(require("../components/select/select-list/select-list-container.style"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const resizeObserver = (0, _jsdomTestingMocks.mockResizeObserver)();
13
+ function simulateSelectTextboxEvent(container, eventType,
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ ...eventArgs) {
16
+ const selectText = container.find('input[type="text"]').first();
17
+ selectText.simulate(eventType, ...eventArgs);
18
+ const selectList = container.find(_selectListContainer.default).getDOMNode();
19
+ // need to manually trigger a resize to make react-virtual realise that child options should be rendered
20
+ (0, _testUtils.act)(() => {
21
+ resizeObserver.mockElementSize(selectList, {
22
+ contentBoxSize: {
23
+ inlineSize: 500,
24
+ blockSize: 180
25
+ }
26
+ });
27
+ resizeObserver.resize();
28
+ });
29
+ if (eventType === "focus") jest.runOnlyPendingTimers();
30
+ container.update();
31
+ }
32
+ function simulateDropdownEvent(container, eventType) {
33
+ const dropdown = container.find('[type="dropdown"]').first();
34
+ dropdown.simulate(eventType);
35
+ const selectList = container.find(_selectListContainer.default).getDOMNode();
36
+ // need to manually trigger a resize to make react-virtual realise that child options should be rendered
37
+ (0, _testUtils.act)(() => {
38
+ resizeObserver.mockElementSize(selectList, {
39
+ contentBoxSize: {
40
+ inlineSize: 500,
41
+ blockSize: 180
42
+ }
43
+ });
44
+ resizeObserver.resize();
45
+ });
46
+ container.update();
47
+ }
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+ import { LinkProps } from "../../../link";
3
+ import { IconType } from "../../../icon";
4
+ interface StatusUploadingProps {
5
+ /** the status of the upload */
6
+ status: "uploading";
7
+ /** a number from 0-100 giving the current upload progress as a percentage. Only used for the `uploading` status.
8
+ * If the progress prop is not specified in the `uploading` status, a loading animation will be shown instead
9
+ * (or text equivalent for users with a reduced-motion operating system preference).
10
+ */
11
+ progress?: number;
12
+ }
13
+ interface StatusDoneProps extends LinkProps {
14
+ /** the status of the upload */
15
+ status: "completed" | "previously";
16
+ /** the URL opened by the file link. Must be provided for only the `completed` and `previously` statuses. */
17
+ href: string;
18
+ }
19
+ interface StatusErrorProps {
20
+ /** the status of the upload */
21
+ status: "error";
22
+ }
23
+ interface MandatoryStatusProps {
24
+ /** the name of the file */
25
+ filename: string;
26
+ /** a function to be executed when the user clicks the appropriate action button (Clear/Delete File/Cancel Upload) */
27
+ onAction: () => void;
28
+ /** The status message. Used to display the current upload progress, including error messages where appropriate. Not used for the `previously` status. */
29
+ message?: string;
30
+ /** The icon to use for the file during or after upload */
31
+ iconType?: IconType;
32
+ }
33
+ export declare type FileUploadStatusProps = MandatoryStatusProps & (StatusUploadingProps | StatusErrorProps | StatusDoneProps);
34
+ export declare const FileUploadStatus: ({ status, filename, message, onAction, iconType, ...statusProps }: FileUploadStatusProps) => React.JSX.Element;
35
+ export default FileUploadStatus;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.FileUploadStatus = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _link = _interopRequireDefault(require("../../../link"));
10
+ var _buttonMinor = _interopRequireDefault(require("../../../button-minor"));
11
+ var _typography = _interopRequireDefault(require("../../../typography/typography.style"));
12
+ var _progressTracker = _interopRequireDefault(require("../../../progress-tracker"));
13
+ var _loaderBar = _interopRequireDefault(require("../../../loader-bar"));
14
+ var _icon = _interopRequireDefault(require("../../../icon"));
15
+ var _fileUploadStatus = require("./file-upload-status.style");
16
+ var _useLocale = _interopRequireDefault(require("../../../../hooks/__internal__/useLocale"));
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ const FileUploadStatus = ({
19
+ status,
20
+ filename,
21
+ message,
22
+ onAction,
23
+ iconType = "file_generic",
24
+ ...statusProps
25
+ }) => {
26
+ const locale = (0, _useLocale.default)();
27
+ const statusMessage = message || locale.fileInput.fileUploadStatus();
28
+ let buttonText;
29
+ let linkProps;
30
+ let progressBar = null;
31
+ switch (status) {
32
+ case "uploading":
33
+ buttonText = locale.fileInput.actions.cancel();
34
+ progressBar = statusProps.progress === undefined ? /*#__PURE__*/_react.default.createElement(_loaderBar.default, {
35
+ size: "small"
36
+ }) : /*#__PURE__*/_react.default.createElement(_progressTracker.default, {
37
+ size: "small",
38
+ progress: statusProps.progress,
39
+ length: "100%"
40
+ });
41
+ break;
42
+ case "previously":
43
+ case "completed":
44
+ buttonText = locale.fileInput.actions.delete();
45
+ linkProps = {
46
+ ...statusProps,
47
+ icon: iconType
48
+ };
49
+ break;
50
+ case "error":
51
+ buttonText = locale.fileInput.actions.clear();
52
+ break;
53
+ // istanbul ignore next
54
+ default:
55
+ // no other cases if consumers are using TS, but ESLint still insists on it
56
+ break;
57
+ }
58
+ const actionButton = /*#__PURE__*/_react.default.createElement(_buttonMinor.default, {
59
+ onClick: onAction,
60
+ buttonType: "tertiary"
61
+ }, buttonText);
62
+ const fileLink = linkProps ? /*#__PURE__*/_react.default.createElement(_link.default, linkProps, filename) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
63
+ type: iconType
64
+ }), /*#__PURE__*/_react.default.createElement("span", null, filename));
65
+ const mainRow = status !== "previously" ? /*#__PURE__*/_react.default.createElement(_fileUploadStatus.StyledFileUploadStatusRow, null, /*#__PURE__*/_react.default.createElement(_typography.default, {
66
+ as: "p",
67
+ mb: 0,
68
+ "aria-live": "polite"
69
+ }, statusMessage), actionButton) : /*#__PURE__*/_react.default.createElement(_fileUploadStatus.StyledFileUploadStatusRow, {
70
+ onlyRow: true
71
+ }, /*#__PURE__*/_react.default.createElement(_fileUploadStatus.StyledFileLinkContainer, null, fileLink), actionButton);
72
+ const secondRow = status !== "previously" ? /*#__PURE__*/_react.default.createElement(_fileUploadStatus.StyledFileUploadStatusRow, {
73
+ upperPadding: true,
74
+ lowerPadding: true
75
+ }, /*#__PURE__*/_react.default.createElement(_fileUploadStatus.StyledFileLinkContainer, null, fileLink)) : null;
76
+ return /*#__PURE__*/_react.default.createElement(_fileUploadStatus.StyledFileUploadStatus, {
77
+ hasError: status === "error"
78
+ }, mainRow, secondRow, progressBar);
79
+ };
80
+ exports.FileUploadStatus = FileUploadStatus;
81
+ var _default = exports.default = FileUploadStatus;
@@ -0,0 +1,12 @@
1
+ export declare const StyledFileLinkContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ interface StyledFileUploadStatusRowProps {
3
+ upperPadding?: boolean;
4
+ lowerPadding?: boolean;
5
+ onlyRow?: boolean;
6
+ }
7
+ export declare const StyledFileUploadStatusRow: import("styled-components").StyledComponent<"div", any, StyledFileUploadStatusRowProps, never>;
8
+ interface StyledFileUploadStatusProps {
9
+ hasError: boolean;
10
+ }
11
+ export declare const StyledFileUploadStatus: import("styled-components").StyledComponent<"div", any, StyledFileUploadStatusProps, never>;
12
+ export {};
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StyledFileUploadStatusRow = exports.StyledFileUploadStatus = exports.StyledFileLinkContainer = void 0;
7
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
8
+ var _typography = _interopRequireDefault(require("../../../typography/typography.style"));
9
+ var _icon = _interopRequireDefault(require("../../../icon/icon.style"));
10
+ var _progressTracker = require("../../../progress-tracker/progress-tracker.style");
11
+ var _loaderBar = _interopRequireWildcard(require("../../../loader-bar/loader-bar.style"));
12
+ var _link = require("../../../link/link.style");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
+ const StyledFileLinkContainer = exports.StyledFileLinkContainer = _styledComponents.default.div`
17
+ color: var(--colorsActionMajorYin090);
18
+ display: flex;
19
+ align-items: center;
20
+ overflow-x: clip;
21
+ overflow-y: visible;
22
+ padding-right: var(--spacing150);
23
+
24
+ ${_link.StyledLink} {
25
+ overflow: hidden;
26
+ }
27
+
28
+ ${_link.StyledLink} a {
29
+ overflow: hidden;
30
+ display: flex;
31
+ text-decoration: none;
32
+ }
33
+
34
+ ${_link.StyledContent} {
35
+ overflow: hidden;
36
+ text-overflow: ellipsis;
37
+ text-decoration: underline;
38
+ }
39
+
40
+ &&& ${_icon.default} {
41
+ display: inline-flex;
42
+ justify-content: center;
43
+ align-items: flex-start;
44
+ width: 24px;
45
+ height: 24px;
46
+
47
+ // only apply these styles when the icon is not part of a Link component
48
+ :not(${_link.StyledLink} ${_icon.default}) {
49
+ color: var(--colorsUtilityYin065);
50
+ padding-right: var(--spacing100);
51
+ }
52
+ }
53
+ `;
54
+ const StyledFileUploadStatusRow = exports.StyledFileUploadStatusRow = _styledComponents.default.div`
55
+ display: flex;
56
+ justify-content: space-between;
57
+ ${({
58
+ onlyRow
59
+ }) => onlyRow ? "" : "align-items: baseline;"}
60
+ padding-left: var(--spacing150);
61
+ ${({
62
+ upperPadding
63
+ }) => upperPadding ? "padding-top: var(--spacing050);" : ""}
64
+ ${({
65
+ lowerPadding
66
+ }) => lowerPadding ? "padding-bottom: var(--spacing125);" : ""}
67
+
68
+ ${_typography.default} {
69
+ color: var(--colorsUtilityYin055);
70
+ }
71
+ `;
72
+ const StyledFileUploadStatus = exports.StyledFileUploadStatus = _styledComponents.default.div`
73
+ background-color: var(--colorsUtilityYang100);
74
+ ${({
75
+ hasError
76
+ }) => {
77
+ const borderWidthToken = hasError ? "borderWidth200" : "borderWidth100";
78
+ const colorToken = hasError ? "colorsSemanticNegative500" : "colorsUtilityMajor300";
79
+ return (0, _styledComponents.css)`
80
+ border: var(--${borderWidthToken}) solid var(--${colorToken});
81
+ ${hasError && `&& ${_typography.default} {
82
+ color: var(--${colorToken});
83
+ font-weight: 500;
84
+ }`}
85
+ `;
86
+ }}
87
+ border-radius: var(--borderRadius050);
88
+ width: 100%;
89
+
90
+ ${_progressTracker.StyledProgressBar}, ${_progressTracker.InnerBar} {
91
+ border-radius: var(--borderRadius050);
92
+ border: none;
93
+ }
94
+
95
+ ${_loaderBar.StyledLoader} {
96
+ display: flex;
97
+ }
98
+
99
+ ${_loaderBar.default} {
100
+ background-color: var(--colorsSemanticNeutral200);
101
+ }
102
+
103
+ ${_loaderBar.InnerBar} {
104
+ background-color: var(--colorsSemanticNeutral500);
105
+ }
106
+ `;
@@ -0,0 +1,2 @@
1
+ export { default } from "./file-upload-status.component";
2
+ export type { FileUploadStatusProps } from "./file-upload-status.component";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _fileUploadStatus.default;
10
+ }
11
+ });
12
+ var _fileUploadStatus = _interopRequireDefault(require("./file-upload-status.component"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../../../../../esm/components/file-input/__internal__/file-upload-status/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import { MarginProps } from "styled-system";
3
+ import { ValidationProps } from "../../__internal__/validations";
4
+ import { InputProps } from "../../__internal__/input";
5
+ import { TagProps } from "../../__internal__/utils/helpers/tags";
6
+ import { FileUploadStatusProps } from "./__internal__/file-upload-status";
7
+ export interface FileInputProps extends Pick<ValidationProps, "error">, Pick<InputProps, "id" | "name" | "required">, TagProps, MarginProps {
8
+ /** Which file format(s) to accept. Will be passed to the underlying HTML input.
9
+ * See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept */
10
+ accept?: string;
11
+ /** Text to appear on the main button. Defaults to "Select file" */
12
+ buttonText?: string;
13
+ /** Explanatory text to appear inside the input area. Defaults to "or drag and drop your file" */
14
+ dragAndDropText?: string;
15
+ /** A hint string rendered before the input but after the label. Intended to describe the purpose or content of the input. */
16
+ inputHint?: React.ReactNode;
17
+ /** Sets the default layout to vertical - with the button below the explanatory text rather than next to it.
18
+ * This is the equivalent of removing the maxHeight prop - it will be over-ridden if this prop is set explicitly. */
19
+ isVertical?: boolean;
20
+ /** Label content */
21
+ label?: string;
22
+ /** A valid CSS string for the max-height CSS property. Defaults to the same as the minHeight. */
23
+ maxHeight?: string;
24
+ /** A valid CSS string for the max-width CSS property. Defaults to the same as the minWidth. */
25
+ maxWidth?: string;
26
+ /** A valid CSS string for the min-height CSS property. Defaults to 40px. */
27
+ minHeight?: string;
28
+ /** A valid CSS string for the min-width CSS property. Defaults to 256px. */
29
+ minWidth?: string;
30
+ /** onChange event handler. Accepts a list of all files currently entered to the input. */
31
+ onChange: (files: FileList) => void;
32
+ /** used to control how to display the progress of uploaded file(s) within the component */
33
+ uploadStatus?: FileUploadStatusProps | FileUploadStatusProps[];
34
+ }
35
+ export declare const FileInput: React.ForwardRefExoticComponent<FileInputProps & React.RefAttributes<HTMLInputElement>>;
36
+ export default FileInput;