@itwin/itwinui-react 2.5.0 → 2.6.0
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/CHANGELOG.md +36 -0
- package/cjs/core/ComboBox/ComboBox.js +4 -1
- package/cjs/core/FileUpload/FileEmptyCard.d.ts +29 -0
- package/cjs/core/FileUpload/FileEmptyCard.js +50 -0
- package/cjs/core/FileUpload/FileUploadCard.d.ts +116 -0
- package/cjs/core/FileUpload/FileUploadCard.js +144 -0
- package/cjs/core/FileUpload/FileUploadTemplate.d.ts +1 -1
- package/cjs/core/FileUpload/FileUploadTemplate.js +4 -3
- package/cjs/core/FileUpload/index.d.ts +4 -0
- package/cjs/core/FileUpload/index.js +5 -1
- package/cjs/core/Header/HeaderLogo.d.ts +8 -11
- package/cjs/core/Header/HeaderLogo.js +7 -12
- package/cjs/core/Table/SubRowExpander.d.ts +1 -0
- package/cjs/core/Table/SubRowExpander.js +4 -2
- package/cjs/core/Table/Table.js +3 -2
- package/cjs/core/Table/TableCell.d.ts +1 -0
- package/cjs/core/Table/TableCell.js +15 -4
- package/cjs/core/Table/TableRowMemoized.d.ts +2 -0
- package/cjs/core/Table/TableRowMemoized.js +4 -3
- package/cjs/core/Table/columns/selectionColumn.d.ts +1 -0
- package/cjs/core/Table/columns/selectionColumn.js +5 -4
- package/cjs/core/Table/hooks/useSelectionCell.d.ts +1 -1
- package/cjs/core/Table/hooks/useSelectionCell.js +5 -2
- package/cjs/core/ToggleSwitch/ToggleSwitch.d.ts +12 -2
- package/cjs/core/ToggleSwitch/ToggleSwitch.js +2 -2
- package/cjs/core/index.d.ts +2 -2
- package/cjs/core/index.js +5 -3
- package/cjs/core/utils/hooks/index.d.ts +1 -0
- package/cjs/core/utils/hooks/index.js +1 -0
- package/cjs/core/utils/hooks/useId.d.ts +5 -0
- package/cjs/core/utils/hooks/useId.js +20 -0
- package/cjs/core/utils/icons/SvgDocument.d.ts +2 -0
- package/cjs/core/utils/icons/SvgDocument.js +36 -0
- package/cjs/core/utils/icons/index.d.ts +1 -0
- package/cjs/core/utils/icons/index.js +1 -0
- package/esm/core/ComboBox/ComboBox.js +4 -1
- package/esm/core/FileUpload/FileEmptyCard.d.ts +29 -0
- package/esm/core/FileUpload/FileEmptyCard.js +44 -0
- package/esm/core/FileUpload/FileUploadCard.d.ts +116 -0
- package/esm/core/FileUpload/FileUploadCard.js +138 -0
- package/esm/core/FileUpload/FileUploadTemplate.d.ts +1 -1
- package/esm/core/FileUpload/FileUploadTemplate.js +4 -3
- package/esm/core/FileUpload/index.d.ts +4 -0
- package/esm/core/FileUpload/index.js +2 -0
- package/esm/core/Header/HeaderLogo.d.ts +8 -11
- package/esm/core/Header/HeaderLogo.js +7 -11
- package/esm/core/Table/SubRowExpander.d.ts +1 -0
- package/esm/core/Table/SubRowExpander.js +4 -2
- package/esm/core/Table/Table.js +3 -2
- package/esm/core/Table/TableCell.d.ts +1 -0
- package/esm/core/Table/TableCell.js +15 -4
- package/esm/core/Table/TableRowMemoized.d.ts +2 -0
- package/esm/core/Table/TableRowMemoized.js +4 -3
- package/esm/core/Table/columns/selectionColumn.d.ts +1 -0
- package/esm/core/Table/columns/selectionColumn.js +5 -4
- package/esm/core/Table/hooks/useSelectionCell.d.ts +1 -1
- package/esm/core/Table/hooks/useSelectionCell.js +5 -2
- package/esm/core/ToggleSwitch/ToggleSwitch.d.ts +12 -2
- package/esm/core/ToggleSwitch/ToggleSwitch.js +2 -2
- package/esm/core/index.d.ts +2 -2
- package/esm/core/index.js +1 -1
- package/esm/core/utils/hooks/index.d.ts +1 -0
- package/esm/core/utils/hooks/index.js +1 -0
- package/esm/core/utils/hooks/useId.d.ts +5 -0
- package/esm/core/utils/hooks/useId.js +14 -0
- package/esm/core/utils/icons/SvgDocument.d.ts +2 -0
- package/esm/core/utils/icons/SvgDocument.js +9 -0
- package/esm/core/utils/icons/index.d.ts +1 -0
- package/esm/core/utils/icons/index.js +1 -0
- package/package.json +2 -2
|
@@ -25,6 +25,7 @@ export declare const TableRow: <T extends Record<string, unknown>>(props: {
|
|
|
25
25
|
expanderCell?: ((cellProps: CellProps<T, any>) => React.ReactNode) | undefined;
|
|
26
26
|
bodyRef: HTMLDivElement | null;
|
|
27
27
|
tableRowRef?: React.Ref<HTMLDivElement> | undefined;
|
|
28
|
+
density?: "default" | "condensed" | "extra-condensed" | undefined;
|
|
28
29
|
}) => JSX.Element;
|
|
29
30
|
export declare const TableRowMemoized: <T extends Record<string, unknown>>(props: {
|
|
30
31
|
row: Row<T>;
|
|
@@ -45,4 +46,5 @@ export declare const TableRowMemoized: <T extends Record<string, unknown>>(props
|
|
|
45
46
|
expanderCell?: ((cellProps: CellProps<T, any>) => React.ReactNode) | undefined;
|
|
46
47
|
bodyRef: HTMLDivElement | null;
|
|
47
48
|
tableRowRef?: React.Ref<HTMLDivElement> | undefined;
|
|
49
|
+
density?: "default" | "condensed" | "extra-condensed" | undefined;
|
|
48
50
|
}) => JSX.Element;
|
|
@@ -20,7 +20,7 @@ const TableCell_1 = require("./TableCell");
|
|
|
20
20
|
*/
|
|
21
21
|
const TableRow = (props) => {
|
|
22
22
|
var _a;
|
|
23
|
-
const { row, rowProps, isLast, onRowInViewport, onBottomReached, intersectionMargin, onClick, subComponent, isDisabled, tableHasSubRows, tableInstance, expanderCell, bodyRef, tableRowRef, } = props;
|
|
23
|
+
const { row, rowProps, isLast, onRowInViewport, onBottomReached, intersectionMargin, onClick, subComponent, isDisabled, tableHasSubRows, tableInstance, expanderCell, bodyRef, tableRowRef, density, } = props;
|
|
24
24
|
const onIntersect = react_1.default.useCallback(() => {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
(_a = onRowInViewport.current) === null || _a === void 0 ? void 0 : _a.call(onRowInViewport, row.original);
|
|
@@ -62,7 +62,7 @@ const TableRow = (props) => {
|
|
|
62
62
|
(_a = mergedProps === null || mergedProps === void 0 ? void 0 : mergedProps.onClick) === null || _a === void 0 ? void 0 : _a.call(mergedProps, event);
|
|
63
63
|
onClick === null || onClick === void 0 ? void 0 : onClick(event, row);
|
|
64
64
|
} }, row.cells.map((cell, index) => {
|
|
65
|
-
return (react_1.default.createElement(TableCell_1.TableCell, { key: cell.getCellProps().key, cell: cell, cellIndex: index, isDisabled: isDisabled, tableHasSubRows: tableHasSubRows, tableInstance: tableInstance, expanderCell: expanderCell }));
|
|
65
|
+
return (react_1.default.createElement(TableCell_1.TableCell, { key: cell.getCellProps().key, cell: cell, cellIndex: index, isDisabled: isDisabled, tableHasSubRows: tableHasSubRows, tableInstance: tableInstance, expanderCell: expanderCell, density: density }));
|
|
66
66
|
})),
|
|
67
67
|
subComponent && (react_1.default.createElement(utils_1.WithCSSTransition, { in: row.isExpanded },
|
|
68
68
|
react_1.default.createElement("div", { className: (0, classnames_1.default)('iui-table-row', 'iui-table-expanded-content'), "aria-disabled": isDisabled }, subComponent(row))))));
|
|
@@ -104,5 +104,6 @@ exports.TableRowMemoized = react_1.default.memo(exports.TableRow, (prevProp, nex
|
|
|
104
104
|
prevProp.state.sticky.isScrolledToLeft ===
|
|
105
105
|
nextProp.state.sticky.isScrolledToLeft &&
|
|
106
106
|
prevProp.state.sticky.isScrolledToRight ===
|
|
107
|
-
nextProp.state.sticky.isScrolledToRight
|
|
107
|
+
nextProp.state.sticky.isScrolledToRight &&
|
|
108
|
+
prevProp.density === nextProp.density;
|
|
108
109
|
});
|
|
@@ -16,6 +16,7 @@ export declare const SELECTION_CELL_ID = "iui-table-checkbox-selector";
|
|
|
16
16
|
export declare const SelectionColumn: <T extends Record<string, unknown>>(props?: {
|
|
17
17
|
/** Function that returns whether row checkbox should be disabled. */
|
|
18
18
|
isDisabled?: ((rowData: T) => boolean) | undefined;
|
|
19
|
+
density?: "default" | "condensed" | "extra-condensed" | undefined;
|
|
19
20
|
}) => {
|
|
20
21
|
id: string;
|
|
21
22
|
disableResizing: boolean;
|
|
@@ -25,15 +25,16 @@ exports.SELECTION_CELL_ID = 'iui-table-checkbox-selector';
|
|
|
25
25
|
* ], [isCheckboxDisabled]);
|
|
26
26
|
*/
|
|
27
27
|
const SelectionColumn = (props = {}) => {
|
|
28
|
-
const { isDisabled } = props;
|
|
28
|
+
const { isDisabled, density } = props;
|
|
29
|
+
const densityWidth = density === 'condensed' ? 42 : density === 'extra-condensed' ? 34 : 48;
|
|
29
30
|
return {
|
|
30
31
|
id: exports.SELECTION_CELL_ID,
|
|
31
32
|
disableResizing: true,
|
|
32
33
|
disableGroupBy: true,
|
|
33
34
|
disableReordering: true,
|
|
34
|
-
minWidth:
|
|
35
|
-
width:
|
|
36
|
-
maxWidth:
|
|
35
|
+
minWidth: densityWidth,
|
|
36
|
+
width: densityWidth,
|
|
37
|
+
maxWidth: densityWidth,
|
|
37
38
|
columnClassName: 'iui-slot',
|
|
38
39
|
cellClassName: 'iui-slot',
|
|
39
40
|
Header: ({ getToggleAllRowsSelectedProps, toggleAllRowsSelected, rows, initialRows, state, }) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Hooks } from 'react-table';
|
|
2
|
-
export declare const useSelectionCell: <T extends Record<string, unknown>>(isSelectable: boolean, selectionMode: 'multi' | 'single', isRowDisabled?: ((rowData: T) => boolean) | undefined) => (hooks: Hooks<T>) => void;
|
|
2
|
+
export declare const useSelectionCell: <T extends Record<string, unknown>>(isSelectable: boolean, selectionMode: 'multi' | 'single', isRowDisabled?: ((rowData: T) => boolean) | undefined, density?: 'default' | 'condensed' | 'extra-condensed') => (hooks: Hooks<T>) => void;
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSelectionCell = void 0;
|
|
4
4
|
const columns_1 = require("../columns");
|
|
5
|
-
const useSelectionCell = (isSelectable, selectionMode, isRowDisabled) => (hooks) => {
|
|
5
|
+
const useSelectionCell = (isSelectable, selectionMode, isRowDisabled, density = 'default') => (hooks) => {
|
|
6
6
|
if (!isSelectable) {
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
hooks.allColumns.push((columns) => selectionMode === 'single' ||
|
|
10
10
|
columns.find((c) => c.id === columns_1.SELECTION_CELL_ID)
|
|
11
11
|
? columns
|
|
12
|
-
: [
|
|
12
|
+
: [
|
|
13
|
+
(0, columns_1.SelectionColumn)({ isDisabled: isRowDisabled, density: density }),
|
|
14
|
+
...columns,
|
|
15
|
+
]);
|
|
13
16
|
};
|
|
14
17
|
exports.useSelectionCell = useSelectionCell;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -31,7 +31,7 @@ require("@itwin/itwinui-css/css/toggle-switch.css");
|
|
|
31
31
|
* <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>} />
|
|
32
32
|
*/
|
|
33
33
|
exports.ToggleSwitch = react_1.default.forwardRef((props, ref) => {
|
|
34
|
-
const { disabled = false, labelPosition = 'right', icon, label, setFocus = false, className, style, ...rest } = props;
|
|
34
|
+
const { disabled = false, labelPosition = 'right', icon, label, setFocus = false, className, style, size = 'default', ...rest } = props;
|
|
35
35
|
(0, utils_1.useTheme)();
|
|
36
36
|
const inputElementRef = react_1.default.useRef(null);
|
|
37
37
|
const refs = (0, utils_1.useMergedRefs)(inputElementRef, ref);
|
|
@@ -45,7 +45,7 @@ exports.ToggleSwitch = react_1.default.forwardRef((props, ref) => {
|
|
|
45
45
|
'iui-disabled': disabled,
|
|
46
46
|
'iui-label-on-right': label && labelPosition === 'right',
|
|
47
47
|
'iui-label-on-left': label && labelPosition === 'left',
|
|
48
|
-
}, className), style: style },
|
|
48
|
+
}, className), "data-iui-size": size, style: style },
|
|
49
49
|
react_1.default.createElement("input", { className: 'iui-toggle-switch', type: 'checkbox', role: 'switch', disabled: disabled, ref: refs, ...rest }),
|
|
50
50
|
icon &&
|
|
51
51
|
react_1.default.cloneElement(icon, {
|
package/cjs/core/index.d.ts
CHANGED
|
@@ -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/cjs/core/index.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.Flex = exports.Icon = exports.MiddleTextTruncation = exports.ColorValue = exports.useTheme = exports.getUserColor = exports.WorkflowDiagram = exports.Stepper = exports.Wizard = exports.Text = exports.KbdKeys = exports.Kbd = exports.Code = exports.Blockquote = exports.Title = exports.Subheading = exports.Small = exports.Leading = exports.Headline = void 0;
|
|
6
|
+
exports.Input = exports.InformationPanelContent = exports.InformationPanelBody = exports.InformationPanelHeader = exports.InformationPanelWrapper = exports.InformationPanel = exports.HorizontalTabs = exports.Tab = exports.Tabs = exports.VerticalTabs = exports.HeaderLogo = exports.HeaderButton = exports.HeaderBreadcrumbs = exports.Header = exports.defaultFooterElements = exports.Footer = exports.FileEmptyCard = exports.FileUploadCard = exports.FileUploadTemplate = exports.FileUpload = exports.Fieldset = exports.ExpandableBlock = exports.NonIdealState = exports.ErrorPage = exports.DropdownMenu = exports.Dialog = exports.generateLocalizedStrings = exports.DatePicker = exports.ComboBox = exports.ColorPalette = exports.ColorInputPanel = exports.ColorBuilder = exports.ColorSwatch = exports.ColorPicker = exports.Checkbox = exports.Carousel = exports.ButtonGroup = exports.SplitButton = exports.IdeasButton = exports.IconButton = exports.DropdownButton = exports.Button = exports.Breadcrumbs = exports.Badge = exports.Backdrop = exports.UserIconGroup = exports.AvatarGroup = exports.UserIcon = exports.Avatar = exports.Alert = void 0;
|
|
7
|
+
exports.TreeNodeExpander = exports.TreeNode = exports.Tree = exports.Tooltip = exports.ToggleSwitch = exports.ThemeProvider = exports.toaster = exports.TimePicker = exports.Tile = exports.Textarea = exports.TagContainer = exports.Tag = exports.SelectionColumn = exports.ExpanderColumn = exports.ActionColumn = exports.TablePaginator = exports.EditableCell = exports.DefaultCell = exports.FilterButtonBar = exports.BaseFilter = exports.tableFilters = exports.Table = exports.Surface = exports.StatusMessage = exports.Slider = exports.SkipToContentLink = exports.SidenavSubmenuHeader = exports.SidenavSubmenu = exports.SidenavButton = exports.SideNavigation = exports.Select = exports.RadioTileGroup = exports.RadioTile = exports.Radio = exports.ProgressRadial = exports.ProgressLinear = exports.NotificationMarker = exports.ModalContent = exports.ModalButtonBar = exports.Modal = exports.MenuItemSkeleton = exports.MenuExtraContent = exports.MenuDivider = exports.MenuItem = exports.Menu = exports.LabeledTextarea = exports.LabeledSelect = exports.InputGroup = exports.LabeledInput = exports.Label = void 0;
|
|
8
|
+
exports.Flex = exports.Icon = exports.MiddleTextTruncation = exports.ColorValue = exports.useTheme = exports.getUserColor = exports.WorkflowDiagram = exports.Stepper = exports.Wizard = exports.Text = exports.KbdKeys = exports.Kbd = exports.Code = exports.Blockquote = exports.Title = exports.Subheading = exports.Small = exports.Leading = exports.Headline = exports.Body = exports.Anchor = void 0;
|
|
9
9
|
/*---------------------------------------------------------------------------------------------
|
|
10
10
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
11
11
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -61,6 +61,8 @@ Object.defineProperty(exports, "Fieldset", { enumerable: true, get: function ()
|
|
|
61
61
|
var FileUpload_1 = require("./FileUpload");
|
|
62
62
|
Object.defineProperty(exports, "FileUpload", { enumerable: true, get: function () { return FileUpload_1.FileUpload; } });
|
|
63
63
|
Object.defineProperty(exports, "FileUploadTemplate", { enumerable: true, get: function () { return FileUpload_1.FileUploadTemplate; } });
|
|
64
|
+
Object.defineProperty(exports, "FileUploadCard", { enumerable: true, get: function () { return FileUpload_1.FileUploadCard; } });
|
|
65
|
+
Object.defineProperty(exports, "FileEmptyCard", { enumerable: true, get: function () { return FileUpload_1.FileEmptyCard; } });
|
|
64
66
|
var Footer_1 = require("./Footer");
|
|
65
67
|
Object.defineProperty(exports, "Footer", { enumerable: true, get: function () { return Footer_1.Footer; } });
|
|
66
68
|
Object.defineProperty(exports, "defaultFooterElements", { enumerable: true, get: function () { return Footer_1.defaultFooterElements; } });
|
|
@@ -30,3 +30,4 @@ __exportStar(require("./useSafeContext"), exports);
|
|
|
30
30
|
__exportStar(require("./useLatestRef"), exports);
|
|
31
31
|
__exportStar(require("./useIsomorphicLayoutEffect"), exports);
|
|
32
32
|
__exportStar(require("./useIsThemeAlreadySet"), exports);
|
|
33
|
+
__exportStar(require("./useId"), exports);
|
|
@@ -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
|
+
});
|
|
@@ -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;
|
|
@@ -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
|
-
|
|
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).
|