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
@@ -1,5 +1,5 @@
1
1
  import { ReactWrapper, ShallowWrapper } from "enzyme";
2
2
  declare const elementsTagTest: (wrapper: ReactWrapper | ShallowWrapper, elements: string[]) => void;
3
3
  declare const rootTagTest: (rootNode: ReactWrapper | ShallowWrapper, comp: string, elem?: string, role?: string) => void;
4
- declare const rootTagTestRtl: (element: HTMLElement, comp: string, elem?: string, role?: string) => void;
4
+ declare const rootTagTestRtl: (rootNode: HTMLElement, comp: string, elem?: string, role?: string) => void;
5
5
  export { elementsTagTest, rootTagTest, rootTagTestRtl };
@@ -12,9 +12,11 @@ const rootTagTest = (rootNode, comp, elem, role) => {
12
12
  expect(rootNode.prop("data-element")).toEqual(elem);
13
13
  expect(rootNode.prop("data-role")).toEqual(role);
14
14
  };
15
- const rootTagTestRtl = (element, comp, elem, role) => {
16
- expect(element.getAttribute("data-component")).toBe(comp);
17
- expect(element.getAttribute("data-element")).toBe(elem);
18
- expect(element.getAttribute("data-role")).toBe(role);
15
+ const rootTagTestRtl = (rootNode, comp, elem, role) => {
16
+ expect(rootNode).toHaveAttribute("data-component", comp);
17
+ expect(rootNode).toHaveAttribute("data-element", elem);
18
+ expect(rootNode).toHaveAttribute("data-role", role);
19
19
  };
20
+
21
+ // eslint-disable-next-line jest/no-export
20
22
  export { elementsTagTest, rootTagTest, rootTagTestRtl };
@@ -1,6 +1,8 @@
1
1
  import { enableFetchMocks } from "jest-fetch-mock";
2
2
  import { setupMatchMediaMock } from "./mock-match-media";
3
3
  import setupResizeObserverMock from "./mock-resize-observer";
4
+ import setupScrollToMock from "./mock-element-scrollto";
4
5
  enableFetchMocks();
5
6
  setupResizeObserverMock();
6
- setupMatchMediaMock();
7
+ setupMatchMediaMock();
8
+ setupScrollToMock();
@@ -0,0 +1,2 @@
1
+ declare const setupScrollToMock: () => void;
2
+ export default setupScrollToMock;
@@ -0,0 +1,6 @@
1
+ const setupScrollToMock = () => {
2
+ // need to mock the `scrollTo` method, which is undefined in JSDOM. As we're not actually testing this behaviour, just make it
3
+ // do nothing.
4
+ HTMLElement.prototype.scrollTo = () => {};
5
+ };
6
+ export default setupScrollToMock;
@@ -0,0 +1,3 @@
1
+ import type { ReactWrapper } from "enzyme";
2
+ export declare function simulateSelectTextboxEvent(container: ReactWrapper, eventType: string, ...eventArgs: any[]): void;
3
+ export declare function simulateDropdownEvent(container: ReactWrapper, eventType: string): void;
@@ -0,0 +1,39 @@
1
+ import { act } from "react-dom/test-utils";
2
+ import { mockResizeObserver } from "jsdom-testing-mocks";
3
+ import StyledSelectListContainer from "../components/select/select-list/select-list-container.style";
4
+ const resizeObserver = mockResizeObserver();
5
+ export function simulateSelectTextboxEvent(container, eventType,
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ ...eventArgs) {
8
+ const selectText = container.find('input[type="text"]').first();
9
+ selectText.simulate(eventType, ...eventArgs);
10
+ const selectList = container.find(StyledSelectListContainer).getDOMNode();
11
+ // need to manually trigger a resize to make react-virtual realise that child options should be rendered
12
+ act(() => {
13
+ resizeObserver.mockElementSize(selectList, {
14
+ contentBoxSize: {
15
+ inlineSize: 500,
16
+ blockSize: 180
17
+ }
18
+ });
19
+ resizeObserver.resize();
20
+ });
21
+ if (eventType === "focus") jest.runOnlyPendingTimers();
22
+ container.update();
23
+ }
24
+ export function simulateDropdownEvent(container, eventType) {
25
+ const dropdown = container.find('[type="dropdown"]').first();
26
+ dropdown.simulate(eventType);
27
+ const selectList = container.find(StyledSelectListContainer).getDOMNode();
28
+ // need to manually trigger a resize to make react-virtual realise that child options should be rendered
29
+ act(() => {
30
+ resizeObserver.mockElementSize(selectList, {
31
+ contentBoxSize: {
32
+ inlineSize: 500,
33
+ blockSize: 180
34
+ }
35
+ });
36
+ resizeObserver.resize();
37
+ });
38
+ container.update();
39
+ }
@@ -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,73 @@
1
+ import React from "react";
2
+ import PropTypes from "prop-types";
3
+ import Link from "../../../link";
4
+ import ButtonMinor from "../../../button-minor";
5
+ import StyledTypography from "../../../typography/typography.style";
6
+ import ProgressTracker from "../../../progress-tracker";
7
+ import LoaderBar from "../../../loader-bar";
8
+ import Icon from "../../../icon";
9
+ import { StyledFileUploadStatus, StyledFileUploadStatusRow, StyledFileLinkContainer } from "./file-upload-status.style";
10
+ import useLocale from "../../../../hooks/__internal__/useLocale";
11
+ export const FileUploadStatus = ({
12
+ status,
13
+ filename,
14
+ message,
15
+ onAction,
16
+ iconType = "file_generic",
17
+ ...statusProps
18
+ }) => {
19
+ const locale = useLocale();
20
+ const statusMessage = message || locale.fileInput.fileUploadStatus();
21
+ let buttonText;
22
+ let linkProps;
23
+ let progressBar = null;
24
+ switch (status) {
25
+ case "uploading":
26
+ buttonText = locale.fileInput.actions.cancel();
27
+ progressBar = statusProps.progress === undefined ? /*#__PURE__*/React.createElement(LoaderBar, {
28
+ size: "small"
29
+ }) : /*#__PURE__*/React.createElement(ProgressTracker, {
30
+ size: "small",
31
+ progress: statusProps.progress,
32
+ length: "100%"
33
+ });
34
+ break;
35
+ case "previously":
36
+ case "completed":
37
+ buttonText = locale.fileInput.actions.delete();
38
+ linkProps = {
39
+ ...statusProps,
40
+ icon: iconType
41
+ };
42
+ break;
43
+ case "error":
44
+ buttonText = locale.fileInput.actions.clear();
45
+ break;
46
+ // istanbul ignore next
47
+ default:
48
+ // no other cases if consumers are using TS, but ESLint still insists on it
49
+ break;
50
+ }
51
+ const actionButton = /*#__PURE__*/React.createElement(ButtonMinor, {
52
+ onClick: onAction,
53
+ buttonType: "tertiary"
54
+ }, buttonText);
55
+ const fileLink = linkProps ? /*#__PURE__*/React.createElement(Link, linkProps, filename) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, {
56
+ type: iconType
57
+ }), /*#__PURE__*/React.createElement("span", null, filename));
58
+ const mainRow = status !== "previously" ? /*#__PURE__*/React.createElement(StyledFileUploadStatusRow, null, /*#__PURE__*/React.createElement(StyledTypography, {
59
+ as: "p",
60
+ mb: 0,
61
+ "aria-live": "polite"
62
+ }, statusMessage), actionButton) : /*#__PURE__*/React.createElement(StyledFileUploadStatusRow, {
63
+ onlyRow: true
64
+ }, /*#__PURE__*/React.createElement(StyledFileLinkContainer, null, fileLink), actionButton);
65
+ const secondRow = status !== "previously" ? /*#__PURE__*/React.createElement(StyledFileUploadStatusRow, {
66
+ upperPadding: true,
67
+ lowerPadding: true
68
+ }, /*#__PURE__*/React.createElement(StyledFileLinkContainer, null, fileLink)) : null;
69
+ return /*#__PURE__*/React.createElement(StyledFileUploadStatus, {
70
+ hasError: status === "error"
71
+ }, mainRow, secondRow, progressBar);
72
+ };
73
+ export 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,97 @@
1
+ import styled, { css } from "styled-components";
2
+ import StyledTypography from "../../../typography/typography.style";
3
+ import StyledIcon from "../../../icon/icon.style";
4
+ import { StyledProgressBar, InnerBar as ProgressTrackerInnerBar } from "../../../progress-tracker/progress-tracker.style";
5
+ import StyledLoaderBar, { StyledLoader, InnerBar as LoaderBarInnerBar } from "../../../loader-bar/loader-bar.style";
6
+ import { StyledLink, StyledContent } from "../../../link/link.style";
7
+ export const StyledFileLinkContainer = styled.div`
8
+ color: var(--colorsActionMajorYin090);
9
+ display: flex;
10
+ align-items: center;
11
+ overflow-x: clip;
12
+ overflow-y: visible;
13
+ padding-right: var(--spacing150);
14
+
15
+ ${StyledLink} {
16
+ overflow: hidden;
17
+ }
18
+
19
+ ${StyledLink} a {
20
+ overflow: hidden;
21
+ display: flex;
22
+ text-decoration: none;
23
+ }
24
+
25
+ ${StyledContent} {
26
+ overflow: hidden;
27
+ text-overflow: ellipsis;
28
+ text-decoration: underline;
29
+ }
30
+
31
+ &&& ${StyledIcon} {
32
+ display: inline-flex;
33
+ justify-content: center;
34
+ align-items: flex-start;
35
+ width: 24px;
36
+ height: 24px;
37
+
38
+ // only apply these styles when the icon is not part of a Link component
39
+ :not(${StyledLink} ${StyledIcon}) {
40
+ color: var(--colorsUtilityYin065);
41
+ padding-right: var(--spacing100);
42
+ }
43
+ }
44
+ `;
45
+ export const StyledFileUploadStatusRow = styled.div`
46
+ display: flex;
47
+ justify-content: space-between;
48
+ ${({
49
+ onlyRow
50
+ }) => onlyRow ? "" : "align-items: baseline;"}
51
+ padding-left: var(--spacing150);
52
+ ${({
53
+ upperPadding
54
+ }) => upperPadding ? "padding-top: var(--spacing050);" : ""}
55
+ ${({
56
+ lowerPadding
57
+ }) => lowerPadding ? "padding-bottom: var(--spacing125);" : ""}
58
+
59
+ ${StyledTypography} {
60
+ color: var(--colorsUtilityYin055);
61
+ }
62
+ `;
63
+ export const StyledFileUploadStatus = styled.div`
64
+ background-color: var(--colorsUtilityYang100);
65
+ ${({
66
+ hasError
67
+ }) => {
68
+ const borderWidthToken = hasError ? "borderWidth200" : "borderWidth100";
69
+ const colorToken = hasError ? "colorsSemanticNegative500" : "colorsUtilityMajor300";
70
+ return css`
71
+ border: var(--${borderWidthToken}) solid var(--${colorToken});
72
+ ${hasError && `&& ${StyledTypography} {
73
+ color: var(--${colorToken});
74
+ font-weight: 500;
75
+ }`}
76
+ `;
77
+ }}
78
+ border-radius: var(--borderRadius050);
79
+ width: 100%;
80
+
81
+ ${StyledProgressBar}, ${ProgressTrackerInnerBar} {
82
+ border-radius: var(--borderRadius050);
83
+ border: none;
84
+ }
85
+
86
+ ${StyledLoader} {
87
+ display: flex;
88
+ }
89
+
90
+ ${StyledLoaderBar} {
91
+ background-color: var(--colorsSemanticNeutral200);
92
+ }
93
+
94
+ ${LoaderBarInnerBar} {
95
+ background-color: var(--colorsSemanticNeutral500);
96
+ }
97
+ `;
@@ -0,0 +1,2 @@
1
+ export { default } from "./file-upload-status.component";
2
+ export type { FileUploadStatusProps } from "./file-upload-status.component";
@@ -0,0 +1 @@
1
+ export { default } from "./file-upload-status.component";
@@ -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;