@itwin/itwinui-react 2.5.1 → 2.6.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 (50) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/cjs/core/ComboBox/ComboBox.js +4 -1
  3. package/cjs/core/FileUpload/FileEmptyCard.d.ts +29 -0
  4. package/cjs/core/FileUpload/FileEmptyCard.js +50 -0
  5. package/cjs/core/FileUpload/FileUploadCard.d.ts +116 -0
  6. package/cjs/core/FileUpload/FileUploadCard.js +144 -0
  7. package/cjs/core/FileUpload/FileUploadTemplate.d.ts +1 -1
  8. package/cjs/core/FileUpload/FileUploadTemplate.js +4 -3
  9. package/cjs/core/FileUpload/index.d.ts +4 -0
  10. package/cjs/core/FileUpload/index.js +5 -1
  11. package/cjs/core/Header/HeaderLogo.d.ts +8 -11
  12. package/cjs/core/Header/HeaderLogo.js +7 -12
  13. package/cjs/core/ToggleSwitch/ToggleSwitch.d.ts +12 -2
  14. package/cjs/core/ToggleSwitch/ToggleSwitch.js +2 -2
  15. package/cjs/core/index.d.ts +2 -2
  16. package/cjs/core/index.js +5 -3
  17. package/cjs/core/utils/hooks/index.d.ts +1 -0
  18. package/cjs/core/utils/hooks/index.js +1 -0
  19. package/cjs/core/utils/hooks/useId.d.ts +5 -0
  20. package/cjs/core/utils/hooks/useId.js +20 -0
  21. package/cjs/core/utils/hooks/useTheme.js +5 -0
  22. package/cjs/core/utils/icons/SvgDocument.d.ts +2 -0
  23. package/cjs/core/utils/icons/SvgDocument.js +36 -0
  24. package/cjs/core/utils/icons/index.d.ts +1 -0
  25. package/cjs/core/utils/icons/index.js +1 -0
  26. package/esm/core/ComboBox/ComboBox.js +4 -1
  27. package/esm/core/FileUpload/FileEmptyCard.d.ts +29 -0
  28. package/esm/core/FileUpload/FileEmptyCard.js +44 -0
  29. package/esm/core/FileUpload/FileUploadCard.d.ts +116 -0
  30. package/esm/core/FileUpload/FileUploadCard.js +138 -0
  31. package/esm/core/FileUpload/FileUploadTemplate.d.ts +1 -1
  32. package/esm/core/FileUpload/FileUploadTemplate.js +4 -3
  33. package/esm/core/FileUpload/index.d.ts +4 -0
  34. package/esm/core/FileUpload/index.js +2 -0
  35. package/esm/core/Header/HeaderLogo.d.ts +8 -11
  36. package/esm/core/Header/HeaderLogo.js +7 -11
  37. package/esm/core/ToggleSwitch/ToggleSwitch.d.ts +12 -2
  38. package/esm/core/ToggleSwitch/ToggleSwitch.js +2 -2
  39. package/esm/core/index.d.ts +2 -2
  40. package/esm/core/index.js +1 -1
  41. package/esm/core/utils/hooks/index.d.ts +1 -0
  42. package/esm/core/utils/hooks/index.js +1 -0
  43. package/esm/core/utils/hooks/useId.d.ts +5 -0
  44. package/esm/core/utils/hooks/useId.js +14 -0
  45. package/esm/core/utils/hooks/useTheme.js +5 -0
  46. package/esm/core/utils/icons/SvgDocument.d.ts +2 -0
  47. package/esm/core/utils/icons/SvgDocument.js +9 -0
  48. package/esm/core/utils/icons/index.d.ts +1 -0
  49. package/esm/core/utils/icons/index.js +1 -0
  50. package/package.json +2 -2
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ var _a;
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.useId = void 0;
12
+ const react_1 = __importDefault(require("react"));
13
+ const numbers_1 = require("../functions/numbers");
14
+ /**
15
+ * Return custom useId function as a fallback for React.useId
16
+ */
17
+ exports.useId = (_a = react_1.default.useId) !== null && _a !== void 0 ? _a : (() => {
18
+ const [id] = react_1.default.useState(() => `iui-${(0, numbers_1.getRandomValue)(10)}`);
19
+ return id;
20
+ });
@@ -27,6 +27,11 @@ const useTheme = (theme, themeOptions) => {
27
27
  if (!ownerDocument || isThemeAlreadySet.current) {
28
28
  return;
29
29
  }
30
+ // do nothing if using v1 for the main page (incremental migration)
31
+ if (ownerDocument.documentElement.className.includes('iui-theme-') ||
32
+ ownerDocument.body.classList.contains('iui-body')) {
33
+ return;
34
+ }
30
35
  ownerDocument.body.classList.toggle('iui-root', true);
31
36
  switch (theme) {
32
37
  case 'light':
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare const SvgDocument: (props: React.ComponentProps<'svg'>) => JSX.Element;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.SvgDocument = void 0;
27
+ /*---------------------------------------------------------------------------------------------
28
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
29
+ * See LICENSE.md in the project root for license terms and full copyright notice.
30
+ *--------------------------------------------------------------------------------------------*/
31
+ const React = __importStar(require("react"));
32
+ const SvgDocument = (props) => {
33
+ return (React.createElement("svg", { viewBox: '0 0 16 16', ...props },
34
+ React.createElement("path", { d: 'M10 0H2v16h12V4h-4zm1 0v3h3z' })));
35
+ };
36
+ exports.SvgDocument = SvgDocument;
@@ -27,3 +27,4 @@ export * from './SvgNew';
27
27
  export * from './SvgFilter';
28
28
  export * from './SvgFilterHollow';
29
29
  export * from './SvgCalendar';
30
+ export * from './SvgDocument';
@@ -47,3 +47,4 @@ __exportStar(require("./SvgNew"), exports);
47
47
  __exportStar(require("./SvgFilter"), exports);
48
48
  __exportStar(require("./SvgFilterHollow"), exports);
49
49
  __exportStar(require("./SvgCalendar"), exports);
50
+ __exportStar(require("./SvgDocument"), exports);
@@ -77,7 +77,10 @@ export const ComboBox = (props) => {
77
77
  if (isMultipleEnabled(valueProp, multiple)) {
78
78
  const indexArray = [];
79
79
  valueProp === null || valueProp === void 0 ? void 0 : valueProp.forEach((value) => {
80
- indexArray.push(options.findIndex((option) => option.value === value));
80
+ const indexToAdd = options.findIndex((option) => option.value === value);
81
+ if (indexToAdd > -1) {
82
+ indexArray.push(indexToAdd);
83
+ }
81
84
  });
82
85
  return indexArray;
83
86
  }
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ export declare type FileEmptyCardIconProps = React.ComponentPropsWithRef<'span'>;
3
+ export declare type FileEmptyCardTextProps = React.ComponentPropsWithRef<'span'>;
4
+ export declare type FileEmptyCardProps = React.ComponentPropsWithoutRef<'div'>;
5
+ /**
6
+ * Empty file card to be used with the `FileUploadCard` component when no file has been uploaded.
7
+ * @example
8
+ * <FileEmptyCard />
9
+ * <FileEmptyCard>
10
+ * <FileEmptyCard.Icon>
11
+ * <SvgSmileySadVery />
12
+ * </FileEmptyCard.Icon>
13
+ * <FileEmptyCard.Text>
14
+ * <FileUploadCard.InputLabel>
15
+ * Custom Label Text
16
+ * </FileUploadCard.InputLabel>
17
+ * <div>Custom Description Text</div>
18
+ * </FileEmptyCard.Text>
19
+ * </FileEmptyCard>
20
+ */
21
+ export declare const FileEmptyCard: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>> & {
22
+ Icon: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
23
+ ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
24
+ }, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & React.RefAttributes<HTMLSpanElement>>;
25
+ Text: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
26
+ ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
27
+ }, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & React.RefAttributes<HTMLSpanElement>>;
28
+ };
29
+ export default FileEmptyCard;
@@ -0,0 +1,44 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import React from 'react';
6
+ import { SvgUpload } from '../utils';
7
+ import cx from 'classnames';
8
+ import FileUploadCard from './FileUploadCard';
9
+ const FileEmptyCardIcon = React.forwardRef((props, ref) => {
10
+ const { children, className, ...rest } = props;
11
+ return (React.createElement("span", { className: cx('iui-file-card-empty-icon', className), ref: ref, ...rest }, children !== null && children !== void 0 ? children : React.createElement(SvgUpload, null)));
12
+ });
13
+ const FileEmptyCardText = React.forwardRef((props, ref) => {
14
+ const { children, className, ...rest } = props;
15
+ return (React.createElement("span", { className: cx('iui-file-card-empty-action', className), ref: ref, ...rest }, children));
16
+ });
17
+ /**
18
+ * Empty file card to be used with the `FileUploadCard` component when no file has been uploaded.
19
+ * @example
20
+ * <FileEmptyCard />
21
+ * <FileEmptyCard>
22
+ * <FileEmptyCard.Icon>
23
+ * <SvgSmileySadVery />
24
+ * </FileEmptyCard.Icon>
25
+ * <FileEmptyCard.Text>
26
+ * <FileUploadCard.InputLabel>
27
+ * Custom Label Text
28
+ * </FileUploadCard.InputLabel>
29
+ * <div>Custom Description Text</div>
30
+ * </FileEmptyCard.Text>
31
+ * </FileEmptyCard>
32
+ */
33
+ export const FileEmptyCard = Object.assign(React.forwardRef((props, ref) => {
34
+ const { children, className, ...rest } = props;
35
+ return (React.createElement("div", { className: cx('iui-file-card-empty', className), ref: ref, ...rest }, children !== null && children !== void 0 ? children : (React.createElement(React.Fragment, null,
36
+ React.createElement(FileEmptyCard.Icon, null),
37
+ React.createElement(FileEmptyCard.Text, null,
38
+ React.createElement(FileUploadCard.InputLabel, null, "Choose a file"),
39
+ React.createElement("div", null, "to upload."))))));
40
+ }), {
41
+ Icon: FileEmptyCardIcon,
42
+ Text: FileEmptyCardText,
43
+ });
44
+ export default FileEmptyCard;
@@ -0,0 +1,116 @@
1
+ import React from 'react';
2
+ export declare type FileUploadCardIconProps = React.ComponentPropsWithRef<'span'>;
3
+ export declare type FileUploadCardInfoProps = React.ComponentPropsWithRef<'span'>;
4
+ export declare type FileUploadCardTitleProps = React.ComponentPropsWithRef<'span'>;
5
+ export declare type FileUploadCardDescriptionProps = React.ComponentPropsWithRef<'span'>;
6
+ export declare type FileUploadCardActionProps = React.ComponentPropsWithRef<'div'>;
7
+ export declare type FileUploadCardInputLabelProps = React.ComponentPropsWithRef<'label'>;
8
+ export declare type FileUploadCardInputProps = React.ComponentPropsWithRef<'input'>;
9
+ export declare type FileUploadCardProps = {
10
+ /**
11
+ * Files to pass (only needed when passing a custom action)
12
+ */
13
+ files?: File[];
14
+ /**
15
+ * Callback fired when files has changed (only needed passing custom action)
16
+ */
17
+ onFilesChange?: (files: File[]) => void;
18
+ /**
19
+ * Node that is shown when there is no file uploaded
20
+ * Either pass `FileEmptyCard` (for default state) or a different component to show
21
+ * @default <FileEmptyCard />
22
+ */
23
+ emptyCard?: React.ReactNode;
24
+ /**
25
+ * Input node
26
+ * @default <FileUploadCard.Input />
27
+ */
28
+ input?: React.ReactNode;
29
+ } & React.ComponentPropsWithoutRef<'div'>;
30
+ /**
31
+ * Default card to be used with the `FileUpload` wrapper component for single-file uploading.
32
+ * @example
33
+ * <FileUploadCard />
34
+ * <FileUploadCard files={files} onFilesChange={(files) => setFiles(files)}>
35
+ * <FileUploadCard.Icon>
36
+ * <SvgSmileyHappyVery />
37
+ * </FileUploadCard.Icon>
38
+ * <FileUploadCard.Info>
39
+ * <FileUploadCard.Title>Custom File Name</FileUploadCard.Title>
40
+ * <FileUploadCard.Description>
41
+ * Custom File Description
42
+ * </FileUploadCard.Description>
43
+ * </FileUploadCard.Info>
44
+ * <FileUploadCard.Action>
45
+ * <Button
46
+ * onClick={() => {
47
+ * setFiles([]);
48
+ * }}
49
+ * />
50
+ * <FileUploadCard.Input name={fileInputId} ref={inputRef} />
51
+ * </FileUploadCard.Action>
52
+ * </FileUploadCard>
53
+ */
54
+ export declare const FileUploadCard: React.ForwardRefExoticComponent<{
55
+ /**
56
+ * Files to pass (only needed when passing a custom action)
57
+ */
58
+ files?: File[] | undefined;
59
+ /**
60
+ * Callback fired when files has changed (only needed passing custom action)
61
+ */
62
+ onFilesChange?: ((files: File[]) => void) | undefined;
63
+ /**
64
+ * Node that is shown when there is no file uploaded
65
+ * Either pass `FileEmptyCard` (for default state) or a different component to show
66
+ * @default <FileEmptyCard />
67
+ */
68
+ emptyCard?: React.ReactNode;
69
+ /**
70
+ * Input node
71
+ * @default <FileUploadCard.Input />
72
+ */
73
+ input?: React.ReactNode;
74
+ } & Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>> & {
75
+ Icon: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
76
+ ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
77
+ }, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & React.RefAttributes<HTMLSpanElement>>;
78
+ Info: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
79
+ ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
80
+ }, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & React.RefAttributes<HTMLSpanElement>>;
81
+ Title: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
82
+ ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
83
+ }, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & React.RefAttributes<HTMLSpanElement>>;
84
+ Description: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
85
+ ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
86
+ }, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & React.RefAttributes<HTMLSpanElement>>;
87
+ Action: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
88
+ ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
89
+ }, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
90
+ InputLabel: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "key" | keyof React.LabelHTMLAttributes<HTMLLabelElement>> & {
91
+ ref?: ((instance: HTMLLabelElement | null) => void) | React.RefObject<HTMLLabelElement> | null | undefined;
92
+ }, "key" | keyof React.LabelHTMLAttributes<HTMLLabelElement>> & React.RefAttributes<HTMLLabelElement>>;
93
+ Input: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "key" | keyof React.InputHTMLAttributes<HTMLInputElement>> & {
94
+ ref?: ((instance: HTMLInputElement | null) => void) | React.RefObject<HTMLInputElement> | null | undefined;
95
+ }, "key" | keyof React.InputHTMLAttributes<HTMLInputElement>> & React.RefAttributes<HTMLInputElement>>;
96
+ };
97
+ export default FileUploadCard;
98
+ export declare const FileUploadCardContext: React.Context<{
99
+ /**
100
+ * Files to pass
101
+ */
102
+ files: File[];
103
+ /**
104
+ * Callback fired when files have changed
105
+ */
106
+ onFilesChange?: ((files: File[]) => void) | undefined;
107
+ /**
108
+ * Sets the state of the files within FileUploadCard
109
+ */
110
+ setInternalFiles: (files: File[]) => void;
111
+ /**
112
+ * Id to pass to input
113
+ */
114
+ inputId?: string | undefined;
115
+ setInputId: (inputId: string) => void;
116
+ } | undefined>;
@@ -0,0 +1,138 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import React from 'react';
6
+ import { getWindow, SvgDocument, useMergedRefs, useSafeContext, } from '../utils';
7
+ import cx from 'classnames';
8
+ import { FileEmptyCard } from './FileEmptyCard';
9
+ import { useId } from '../utils';
10
+ const toBytes = (bytes) => {
11
+ const units = [' bytes', 'KB', 'MB', 'GB', 'TB'];
12
+ let i = 0;
13
+ while (bytes >= 1024 && ++i) {
14
+ bytes = bytes / 1024;
15
+ }
16
+ return bytes.toFixed(bytes < 10 && i > 0 ? 2 : 0) + units[i];
17
+ };
18
+ const toDate = (dateNumber) => {
19
+ const date = new Date(dateNumber);
20
+ return date.toDateString() + ' ' + date.toLocaleTimeString();
21
+ };
22
+ const FileUploadCardIcon = React.forwardRef((props, ref) => {
23
+ const { children, className, ...rest } = props;
24
+ return (React.createElement("span", { className: cx('iui-file-card-icon', className), ref: ref, ...rest }, children !== null && children !== void 0 ? children : React.createElement(SvgDocument, null)));
25
+ });
26
+ const FileUploadCardInfo = React.forwardRef((props, ref) => {
27
+ const { children, className, ...rest } = props;
28
+ return (React.createElement("span", { className: cx('iui-file-card-text', className), ref: ref, ...rest }, children));
29
+ });
30
+ const FileUploadCardTitle = React.forwardRef((props, ref) => {
31
+ const { children, className, ...rest } = props;
32
+ const { files } = useSafeContext(FileUploadCardContext);
33
+ const title = files.length > 1 ? files.length + ' files selected' : files[0].name;
34
+ return (React.createElement("span", { className: cx('iui-file-card-title', className), ref: ref, ...rest }, children !== null && children !== void 0 ? children : title));
35
+ });
36
+ const FileUploadCardDescription = React.forwardRef((props, ref) => {
37
+ const { children, className, ...rest } = props;
38
+ const { files } = useSafeContext(FileUploadCardContext);
39
+ let description = files.length > 1
40
+ ? files[0].name + ', ' + files[1].name
41
+ : toBytes(files[0].size) + ' ' + toDate(files[0].lastModified);
42
+ if (files.length > 2) {
43
+ description += ', and ' + (files.length - 2) + ' others';
44
+ }
45
+ return (React.createElement("span", { className: cx('iui-file-card-description', className), ref: ref, ...rest }, children !== null && children !== void 0 ? children : description));
46
+ });
47
+ const FileUploadCardAction = React.forwardRef((props, ref) => {
48
+ const { children, className, ...rest } = props;
49
+ return (React.createElement("div", { className: cx('iui-file-card-action', className), ref: ref, ...rest }, children));
50
+ });
51
+ const FileUploadCardInputLabel = React.forwardRef((props, ref) => {
52
+ const { children, className, ...rest } = props;
53
+ const { inputId } = useSafeContext(FileUploadCardContext);
54
+ return (React.createElement("label", { className: cx('iui-anchor', className), ref: ref, htmlFor: inputId, ...rest }, children));
55
+ });
56
+ const FileUploadCardInput = React.forwardRef((props, ref) => {
57
+ const { children, className, onChange, id, ...rest } = props;
58
+ const { files, onFilesChange, setInternalFiles, inputId, setInputId } = useSafeContext(FileUploadCardContext);
59
+ const setNativeFilesRef = React.useCallback((node) => {
60
+ var _a;
61
+ if (!node || !((_a = getWindow()) === null || _a === void 0 ? void 0 : _a.DataTransfer)) {
62
+ return;
63
+ }
64
+ const dataTransfer = new DataTransfer();
65
+ dataTransfer.items.clear();
66
+ Array.from(files).forEach((file) => dataTransfer.items.add(file));
67
+ node.files = dataTransfer.files;
68
+ }, [files]);
69
+ const refs = useMergedRefs(ref, setNativeFilesRef);
70
+ if (id && id !== inputId) {
71
+ setInputId(id);
72
+ }
73
+ return (React.createElement(React.Fragment, null,
74
+ React.createElement("input", { className: cx('iui-visually-hidden', className), type: 'file', onChange: (e) => {
75
+ onChange === null || onChange === void 0 ? void 0 : onChange(e);
76
+ if (!e.isDefaultPrevented()) {
77
+ const _files = Array.from(e.currentTarget.files || []);
78
+ onFilesChange === null || onFilesChange === void 0 ? void 0 : onFilesChange(_files);
79
+ setInternalFiles(_files);
80
+ }
81
+ }, ref: refs, id: id !== null && id !== void 0 ? id : inputId, ...rest }),
82
+ children));
83
+ });
84
+ /**
85
+ * Default card to be used with the `FileUpload` wrapper component for single-file uploading.
86
+ * @example
87
+ * <FileUploadCard />
88
+ * <FileUploadCard files={files} onFilesChange={(files) => setFiles(files)}>
89
+ * <FileUploadCard.Icon>
90
+ * <SvgSmileyHappyVery />
91
+ * </FileUploadCard.Icon>
92
+ * <FileUploadCard.Info>
93
+ * <FileUploadCard.Title>Custom File Name</FileUploadCard.Title>
94
+ * <FileUploadCard.Description>
95
+ * Custom File Description
96
+ * </FileUploadCard.Description>
97
+ * </FileUploadCard.Info>
98
+ * <FileUploadCard.Action>
99
+ * <Button
100
+ * onClick={() => {
101
+ * setFiles([]);
102
+ * }}
103
+ * />
104
+ * <FileUploadCard.Input name={fileInputId} ref={inputRef} />
105
+ * </FileUploadCard.Action>
106
+ * </FileUploadCard>
107
+ */
108
+ export const FileUploadCard = Object.assign(React.forwardRef((props, ref) => {
109
+ var _a;
110
+ const { className, children, files: filesProp, onFilesChange, emptyCard = React.createElement(FileEmptyCard, null), input, ...rest } = props;
111
+ const [internalFiles, setInternalFiles] = React.useState();
112
+ const [inputId, setInputId] = React.useState(useId());
113
+ const files = (_a = filesProp !== null && filesProp !== void 0 ? filesProp : internalFiles) !== null && _a !== void 0 ? _a : [];
114
+ return (React.createElement(FileUploadCardContext.Provider, { value: {
115
+ files,
116
+ onFilesChange,
117
+ setInternalFiles,
118
+ inputId,
119
+ setInputId,
120
+ } },
121
+ (files === null || files === void 0 ? void 0 : files.length) ? (React.createElement("div", { className: cx('iui-file-card', className), ref: ref, ...rest }, children !== null && children !== void 0 ? children : (React.createElement(React.Fragment, null,
122
+ React.createElement(FileUploadCard.Icon, null),
123
+ React.createElement(FileUploadCard.Info, null,
124
+ React.createElement(FileUploadCard.Title, null),
125
+ React.createElement(FileUploadCard.Description, null)),
126
+ React.createElement(FileUploadCard.Action, null,
127
+ React.createElement(FileUploadCard.InputLabel, null, "Replace")))))) : (emptyCard), input !== null && input !== void 0 ? input : React.createElement(FileUploadCard.Input, null)));
128
+ }), {
129
+ Icon: FileUploadCardIcon,
130
+ Info: FileUploadCardInfo,
131
+ Title: FileUploadCardTitle,
132
+ Description: FileUploadCardDescription,
133
+ Action: FileUploadCardAction,
134
+ InputLabel: FileUploadCardInputLabel,
135
+ Input: FileUploadCardInput,
136
+ });
137
+ export default FileUploadCard;
138
+ export const FileUploadCardContext = React.createContext(undefined);
@@ -30,7 +30,7 @@ export declare type FileUploadTemplateProps = {
30
30
  * Optional children appended to the template.
31
31
  */
32
32
  children?: React.ReactNode;
33
- };
33
+ } & React.ComponentProps<'div'>;
34
34
  /**
35
35
  * Default template to be used with the `FileUpload` wrapper component.
36
36
  * Contains a hidden input with styled labels (customizable).
@@ -3,6 +3,7 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import React from 'react';
6
+ import cx from 'classnames';
6
7
  import { useTheme, SvgUpload } from '../utils';
7
8
  import '@itwin/itwinui-css/css/file-upload.css';
8
9
  /**
@@ -12,10 +13,10 @@ import '@itwin/itwinui-css/css/file-upload.css';
12
13
  * <FileUploadTemplate onChange={(e) => console.log(e.target.files)} />
13
14
  */
14
15
  export const FileUploadTemplate = (props) => {
15
- const { onChange, acceptMultiple = true, acceptType, label = 'Choose a file', subtitle = 'or drag & drop it here.', children, } = props;
16
+ const { onChange, acceptMultiple = true, acceptType, label = 'Choose a file', subtitle = 'or drag & drop it here.', children, className, ...rest } = props;
16
17
  useTheme();
17
- return (React.createElement(React.Fragment, null,
18
- React.createElement(SvgUpload, { className: 'iui-icon', "aria-hidden": true }),
18
+ return (React.createElement("div", { className: cx('iui-file-upload-template', className), ...rest },
19
+ React.createElement(SvgUpload, { className: 'iui-template-icon', "aria-hidden": true }),
19
20
  React.createElement("div", { className: 'iui-template-text' },
20
21
  React.createElement("label", { className: 'iui-anchor' },
21
22
  React.createElement("input", { className: 'iui-browse-input', type: 'file', onChange: onChange, multiple: acceptMultiple, accept: acceptType }),
@@ -4,3 +4,7 @@ declare const _default: "./FileUpload";
4
4
  export default _default;
5
5
  export { FileUploadTemplate } from './FileUploadTemplate';
6
6
  export type { FileUploadTemplateProps } from './FileUploadTemplate';
7
+ export { FileUploadCard } from './FileUploadCard';
8
+ export type { FileUploadCardProps, FileUploadCardIconProps, FileUploadCardInfoProps, FileUploadCardTitleProps, FileUploadCardDescriptionProps, FileUploadCardActionProps, FileUploadCardInputLabelProps, FileUploadCardInputProps, } from './FileUploadCard';
9
+ export { FileEmptyCard } from './FileEmptyCard';
10
+ export type { FileEmptyCardProps, FileEmptyCardIconProps, FileEmptyCardTextProps, } from './FileEmptyCard';
@@ -5,3 +5,5 @@
5
5
  export { FileUpload } from './FileUpload';
6
6
  export default './FileUpload';
7
7
  export { FileUploadTemplate } from './FileUploadTemplate';
8
+ export { FileUploadCard } from './FileUploadCard';
9
+ export { FileEmptyCard } from './FileEmptyCard';
@@ -1,21 +1,18 @@
1
- import React from 'react';
2
- import { CommonProps } from '../utils';
1
+ /// <reference types="react" />
2
+ import type { PolymorphicForwardRefComponent, PolymorphicComponentProps } from '../utils';
3
3
  import '@itwin/itwinui-css/css/header.css';
4
- export declare type HeaderLogoProps = {
4
+ declare type HeaderLogoOwnProps = {
5
5
  /**
6
6
  * Logo shown before the main content.
7
7
  */
8
8
  logo: JSX.Element;
9
9
  /**
10
10
  * Click event handler.
11
- * Will update the Logo to have mouse and keyboard interaction if provided.
11
+ * If passed, the component will be rendered as a `<button>` rather than `<div>`.
12
12
  */
13
- onClick?: () => void;
14
- /**
15
- * Expects the app name, is put on the right of the logo.
16
- */
17
- children?: React.ReactNode;
18
- } & CommonProps;
13
+ onClick?: (e: unknown) => void;
14
+ };
15
+ export declare type HeaderLogoProps = PolymorphicComponentProps<'div', HeaderLogoOwnProps>;
19
16
  /**
20
17
  * Header Title section
21
18
  * @example
@@ -24,5 +21,5 @@ export declare type HeaderLogoProps = {
24
21
  * <HeaderLogo logo={<img src='image.png' />} />
25
22
  * <HeaderLogo logo={<img src='data:image/png;base64,...' />}>Downloaded Image</HeaderLogo>
26
23
  */
27
- export declare const HeaderLogo: (props: HeaderLogoProps) => JSX.Element;
24
+ export declare const HeaderLogo: PolymorphicForwardRefComponent<"div", HeaderLogoOwnProps>;
28
25
  export default HeaderLogo;
@@ -14,22 +14,18 @@ import '@itwin/itwinui-css/css/header.css';
14
14
  * <HeaderLogo logo={<img src='image.png' />} />
15
15
  * <HeaderLogo logo={<img src='data:image/png;base64,...' />}>Downloaded Image</HeaderLogo>
16
16
  */
17
- export const HeaderLogo = (props) => {
18
- const { className, children, logo, onClick, ...rest } = props;
19
- const keyDownHandler = (e) => {
20
- if (onClick &&
21
- (e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar')) {
22
- e.preventDefault();
23
- onClick();
24
- }
25
- };
17
+ export const HeaderLogo = React.forwardRef((props, ref) => {
18
+ const { className, children, logo, onClick, as: Element = !!onClick ? 'button' : 'div', ...rest } = props;
26
19
  useTheme();
27
- return (React.createElement("div", { className: cx('iui-header-brand', className), role: onClick && 'button', tabIndex: onClick && 0, onKeyDown: keyDownHandler, onClick: onClick, ...rest },
20
+ return (React.createElement(Element, { className: cx('iui-header-brand', className), onClick: onClick,
21
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- TS complains here but it's ok; it is an implementation detail
22
+ // @ts-ignore
23
+ ref: ref, ...rest },
28
24
  React.isValidElement(logo)
29
25
  ? React.cloneElement(logo, {
30
26
  className: cx('iui-header-brand-icon', logo.props.className),
31
27
  })
32
28
  : undefined,
33
29
  children && React.createElement("span", { className: 'iui-header-brand-label' }, children)));
34
- };
30
+ });
35
31
  export default HeaderLogo;
@@ -19,7 +19,12 @@ export declare type ToggleSwitchProps = {
19
19
  * Icon inside the toggle switch. Shown only when toggle is checked.
20
20
  */
21
21
  icon?: JSX.Element;
22
- } & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'>;
22
+ /**
23
+ * Size of the toggle switch.
24
+ * @default 'default'
25
+ */
26
+ size?: 'default' | 'small';
27
+ } & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'>;
23
28
  /**
24
29
  * A switch for turning on and off.
25
30
  * @example
@@ -57,5 +62,10 @@ export declare const ToggleSwitch: React.ForwardRefExoticComponent<{
57
62
  * Icon inside the toggle switch. Shown only when toggle is checked.
58
63
  */
59
64
  icon?: JSX.Element | undefined;
60
- } & Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & React.RefAttributes<HTMLInputElement>>;
65
+ /**
66
+ * Size of the toggle switch.
67
+ * @default 'default'
68
+ */
69
+ size?: "small" | "default" | undefined;
70
+ } & Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & React.RefAttributes<HTMLInputElement>>;
61
71
  export default ToggleSwitch;
@@ -25,7 +25,7 @@ import '@itwin/itwinui-css/css/toggle-switch.css';
25
25
  * <ToggleSwitch label='With icon toggle' icon={<svg viewBox='0 0 16 16'><path d='M1 1v14h14V1H1zm13 1.7v10.6L8.7 8 14 2.7zM8 7.3L2.7 2h10.6L8 7.3zm-.7.7L2 13.3V2.7L7.3 8zm.7.7l5.3 5.3H2.7L8 8.7z' /></svg>} />
26
26
  */
27
27
  export const ToggleSwitch = React.forwardRef((props, ref) => {
28
- const { disabled = false, labelPosition = 'right', icon, label, setFocus = false, className, style, ...rest } = props;
28
+ const { disabled = false, labelPosition = 'right', icon, label, setFocus = false, className, style, size = 'default', ...rest } = props;
29
29
  useTheme();
30
30
  const inputElementRef = React.useRef(null);
31
31
  const refs = useMergedRefs(inputElementRef, ref);
@@ -39,7 +39,7 @@ export const ToggleSwitch = React.forwardRef((props, ref) => {
39
39
  'iui-disabled': disabled,
40
40
  'iui-label-on-right': label && labelPosition === 'right',
41
41
  'iui-label-on-left': label && labelPosition === 'left',
42
- }, className), style: style },
42
+ }, className), "data-iui-size": size, style: style },
43
43
  React.createElement("input", { className: 'iui-toggle-switch', type: 'checkbox', role: 'switch', disabled: disabled, ref: refs, ...rest }),
44
44
  icon &&
45
45
  React.cloneElement(icon, {
@@ -34,8 +34,8 @@ export { ExpandableBlock } from './ExpandableBlock';
34
34
  export type { ExpandableBlockProps } from './ExpandableBlock';
35
35
  export { Fieldset } from './Fieldset';
36
36
  export type { FieldsetProps } from './Fieldset';
37
- export { FileUpload, FileUploadTemplate } from './FileUpload';
38
- export type { FileUploadProps, FileUploadTemplateProps } from './FileUpload';
37
+ export { FileUpload, FileUploadTemplate, FileUploadCard, FileEmptyCard, } from './FileUpload';
38
+ export type { FileUploadProps, FileUploadTemplateProps, FileUploadCardProps, FileUploadCardIconProps, FileUploadCardInfoProps, FileUploadCardTitleProps, FileUploadCardDescriptionProps, FileUploadCardActionProps, FileUploadCardInputLabelProps, FileUploadCardInputProps, FileEmptyCardProps, FileEmptyCardIconProps, FileEmptyCardTextProps, } from './FileUpload';
39
39
  export { Footer, defaultFooterElements } from './Footer';
40
40
  export type { FooterProps, FooterElement, TitleTranslations } from './Footer';
41
41
  export { Header, HeaderBreadcrumbs, HeaderButton, HeaderLogo } from './Header';
package/esm/core/index.js CHANGED
@@ -20,7 +20,7 @@ export { DropdownMenu } from './DropdownMenu';
20
20
  export { ErrorPage, NonIdealState } from './NonIdealState';
21
21
  export { ExpandableBlock } from './ExpandableBlock';
22
22
  export { Fieldset } from './Fieldset';
23
- export { FileUpload, FileUploadTemplate } from './FileUpload';
23
+ export { FileUpload, FileUploadTemplate, FileUploadCard, FileEmptyCard, } from './FileUpload';
24
24
  export { Footer, defaultFooterElements } from './Footer';
25
25
  export { Header, HeaderBreadcrumbs, HeaderButton, HeaderLogo } from './Header';
26
26
  export { VerticalTabs, Tabs, Tab, HorizontalTabs } from './Tabs';
@@ -10,3 +10,4 @@ export * from './useSafeContext';
10
10
  export * from './useLatestRef';
11
11
  export * from './useIsomorphicLayoutEffect';
12
12
  export * from './useIsThemeAlreadySet';
13
+ export * from './useId';
@@ -14,3 +14,4 @@ export * from './useSafeContext';
14
14
  export * from './useLatestRef';
15
15
  export * from './useIsomorphicLayoutEffect';
16
16
  export * from './useIsThemeAlreadySet';
17
+ export * from './useId';
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ /**
3
+ * Return custom useId function as a fallback for React.useId
4
+ */
5
+ export declare const useId: typeof React.useId;