@heymantle/litho 0.0.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.
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cjs/components/ActionList.js +267 -0
- package/dist/cjs/components/AnnouncementBar.js +73 -0
- package/dist/cjs/components/AppProvider.js +245 -0
- package/dist/cjs/components/Autocomplete.js +351 -0
- package/dist/cjs/components/Badge.js +234 -0
- package/dist/cjs/components/Banner.js +264 -0
- package/dist/cjs/components/Box.js +247 -0
- package/dist/cjs/components/Button.js +1018 -0
- package/dist/cjs/components/ButtonGroup.js +196 -0
- package/dist/cjs/components/Card.js +593 -0
- package/dist/cjs/components/Checkbox.js +175 -0
- package/dist/cjs/components/ChoiceList.js +160 -0
- package/dist/cjs/components/Collapsible.js +42 -0
- package/dist/cjs/components/ColorField.js +159 -0
- package/dist/cjs/components/ContextualSaveBar.js +53 -0
- package/dist/cjs/components/DatePicker.js +547 -0
- package/dist/cjs/components/Divider.js +50 -0
- package/dist/cjs/components/DropZone.js +547 -0
- package/dist/cjs/components/EmptyState.js +111 -0
- package/dist/cjs/components/Filters.js +874 -0
- package/dist/cjs/components/FooterHelp.js +48 -0
- package/dist/cjs/components/Form.js +44 -0
- package/dist/cjs/components/Frame.js +386 -0
- package/dist/cjs/components/FrameSaveBar.js +239 -0
- package/dist/cjs/components/Grid.js +151 -0
- package/dist/cjs/components/HorizontalStack.js +180 -0
- package/dist/cjs/components/Icon.js +346 -0
- package/dist/cjs/components/Image.js +191 -0
- package/dist/cjs/components/InlineError.js +57 -0
- package/dist/cjs/components/Label.js +78 -0
- package/dist/cjs/components/Layout.js +228 -0
- package/dist/cjs/components/LayoutSection.js +133 -0
- package/dist/cjs/components/Link.js +128 -0
- package/dist/cjs/components/List.js +69 -0
- package/dist/cjs/components/Listbox.js +211 -0
- package/dist/cjs/components/Loading.js +103 -0
- package/dist/cjs/components/Modal.js +449 -0
- package/dist/cjs/components/Navigation.js +331 -0
- package/dist/cjs/components/Page.js +529 -0
- package/dist/cjs/components/Pagination.js +109 -0
- package/dist/cjs/components/Pane.js +128 -0
- package/dist/cjs/components/Popover.js +365 -0
- package/dist/cjs/components/PopoverManager.js +34 -0
- package/dist/cjs/components/ProgressBar.js +124 -0
- package/dist/cjs/components/RadioButton.js +172 -0
- package/dist/cjs/components/RadioButtonCard.js +193 -0
- package/dist/cjs/components/RangeSlider.js +235 -0
- package/dist/cjs/components/ResourceList.js +105 -0
- package/dist/cjs/components/Select.js +300 -0
- package/dist/cjs/components/SkeletonText.js +130 -0
- package/dist/cjs/components/Spinner.js +72 -0
- package/dist/cjs/components/Table.js +1184 -0
- package/dist/cjs/components/Tabs.js +421 -0
- package/dist/cjs/components/Tag.js +165 -0
- package/dist/cjs/components/Text.js +274 -0
- package/dist/cjs/components/TextField.js +584 -0
- package/dist/cjs/components/Thumbnail.js +73 -0
- package/dist/cjs/components/TimePicker.js +23 -0
- package/dist/cjs/components/Tip.js +220 -0
- package/dist/cjs/components/Tooltip.js +431 -0
- package/dist/cjs/components/TopBar.js +210 -0
- package/dist/cjs/components/VerticalStack.js +161 -0
- package/dist/cjs/index.js +308 -0
- package/dist/cjs/styles/Table.js +591 -0
- package/dist/cjs/utilities/dates.js +339 -0
- package/dist/cjs/utilities/useIndexResourceState.js +175 -0
- package/dist/cjs/utilities/useMounted.js +67 -0
- package/dist/cjs/utilities/useTableScrollState.js +142 -0
- package/dist/esm/components/ActionList.js +216 -0
- package/dist/esm/components/AnnouncementBar.js +63 -0
- package/dist/esm/components/AppProvider.js +185 -0
- package/dist/esm/components/Autocomplete.js +300 -0
- package/dist/esm/components/Badge.js +225 -0
- package/dist/esm/components/Banner.js +254 -0
- package/dist/esm/components/Box.js +238 -0
- package/dist/esm/components/Button.js +967 -0
- package/dist/esm/components/ButtonGroup.js +137 -0
- package/dist/esm/components/Card.js +537 -0
- package/dist/esm/components/Checkbox.js +165 -0
- package/dist/esm/components/ChoiceList.js +145 -0
- package/dist/esm/components/Collapsible.js +32 -0
- package/dist/esm/components/ColorField.js +149 -0
- package/dist/esm/components/ContextualSaveBar.js +43 -0
- package/dist/esm/components/DatePicker.js +532 -0
- package/dist/esm/components/Divider.js +41 -0
- package/dist/esm/components/DropZone.js +537 -0
- package/dist/esm/components/EmptyState.js +101 -0
- package/dist/esm/components/Filters.js +823 -0
- package/dist/esm/components/FooterHelp.js +38 -0
- package/dist/esm/components/Form.js +35 -0
- package/dist/esm/components/Frame.js +376 -0
- package/dist/esm/components/FrameSaveBar.js +229 -0
- package/dist/esm/components/Grid.js +142 -0
- package/dist/esm/components/HorizontalStack.js +171 -0
- package/dist/esm/components/Icon.js +296 -0
- package/dist/esm/components/Image.js +141 -0
- package/dist/esm/components/InlineError.js +43 -0
- package/dist/esm/components/Label.js +63 -0
- package/dist/esm/components/Layout.js +164 -0
- package/dist/esm/components/LayoutSection.js +82 -0
- package/dist/esm/components/Link.js +119 -0
- package/dist/esm/components/List.js +61 -0
- package/dist/esm/components/Listbox.js +201 -0
- package/dist/esm/components/Loading.js +93 -0
- package/dist/esm/components/Modal.js +390 -0
- package/dist/esm/components/Navigation.js +321 -0
- package/dist/esm/components/Page.js +473 -0
- package/dist/esm/components/Pagination.js +99 -0
- package/dist/esm/components/Pane.js +118 -0
- package/dist/esm/components/Popover.js +350 -0
- package/dist/esm/components/PopoverManager.js +24 -0
- package/dist/esm/components/ProgressBar.js +114 -0
- package/dist/esm/components/RadioButton.js +157 -0
- package/dist/esm/components/RadioButtonCard.js +178 -0
- package/dist/esm/components/RangeSlider.js +225 -0
- package/dist/esm/components/ResourceList.js +95 -0
- package/dist/esm/components/Select.js +285 -0
- package/dist/esm/components/SkeletonText.js +120 -0
- package/dist/esm/components/Spinner.js +63 -0
- package/dist/esm/components/Table.js +1129 -0
- package/dist/esm/components/Tabs.js +366 -0
- package/dist/esm/components/Tag.js +151 -0
- package/dist/esm/components/Text.js +265 -0
- package/dist/esm/components/TextField.js +533 -0
- package/dist/esm/components/Thumbnail.js +63 -0
- package/dist/esm/components/TimePicker.js +13 -0
- package/dist/esm/components/Tip.js +169 -0
- package/dist/esm/components/Tooltip.js +380 -0
- package/dist/esm/components/TopBar.js +200 -0
- package/dist/esm/components/VerticalStack.js +152 -0
- package/dist/esm/index.js +61 -0
- package/dist/esm/styles/Table.js +581 -0
- package/dist/esm/utilities/dates.js +289 -0
- package/dist/esm/utilities/useIndexResourceState.js +158 -0
- package/dist/esm/utilities/useMounted.js +57 -0
- package/dist/esm/utilities/useTableScrollState.js +132 -0
- package/index.css +1137 -0
- package/package.json +53 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_with_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return arr;
|
|
9
|
+
}
|
|
10
|
+
function _array_without_holes(arr) {
|
|
11
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
+
}
|
|
13
|
+
function _iterable_to_array(iter) {
|
|
14
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
15
|
+
}
|
|
16
|
+
function _iterable_to_array_limit(arr, i) {
|
|
17
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
18
|
+
if (_i == null) return;
|
|
19
|
+
var _arr = [];
|
|
20
|
+
var _n = true;
|
|
21
|
+
var _d = false;
|
|
22
|
+
var _s, _e;
|
|
23
|
+
try {
|
|
24
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
25
|
+
_arr.push(_s.value);
|
|
26
|
+
if (i && _arr.length === i) break;
|
|
27
|
+
}
|
|
28
|
+
} catch (err) {
|
|
29
|
+
_d = true;
|
|
30
|
+
_e = err;
|
|
31
|
+
} finally{
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
34
|
+
} finally{
|
|
35
|
+
if (_d) throw _e;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return _arr;
|
|
39
|
+
}
|
|
40
|
+
function _non_iterable_rest() {
|
|
41
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
42
|
+
}
|
|
43
|
+
function _non_iterable_spread() {
|
|
44
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
45
|
+
}
|
|
46
|
+
function _sliced_to_array(arr, i) {
|
|
47
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
48
|
+
}
|
|
49
|
+
function _to_consumable_array(arr) {
|
|
50
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
51
|
+
}
|
|
52
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
53
|
+
if (!o) return;
|
|
54
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
55
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
56
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
57
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
58
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
59
|
+
}
|
|
60
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
61
|
+
import { useEffect, useRef, useState } from "react";
|
|
62
|
+
import { tv } from "tailwind-variants";
|
|
63
|
+
import { Button, Icon, InlineError, Label, Link, SkeletonText, Spinner, Text } from "../index.js";
|
|
64
|
+
import { CancelMajor, CircleAlertMajor, FileMinor, ImageMajor, ImagesMajor } from "@shopify/polaris-icons";
|
|
65
|
+
var dropZoneStyles = tv({
|
|
66
|
+
base: "Litho-DropZone w-full flex items-center justify-center p-4 border border-form-border border-dashed rounded-md focus:outline-hidden",
|
|
67
|
+
variants: {
|
|
68
|
+
uploading: {
|
|
69
|
+
true: "bg-form-bg-disabled",
|
|
70
|
+
false: ""
|
|
71
|
+
},
|
|
72
|
+
disabled: {
|
|
73
|
+
true: "pointer-events-none user-select-none",
|
|
74
|
+
false: "cursor-pointer bg-form-bg hover:bg-form-bg-hover"
|
|
75
|
+
},
|
|
76
|
+
hasFocusWithin: {
|
|
77
|
+
true: "ring ring-form-focus border-form-border-focus",
|
|
78
|
+
false: ""
|
|
79
|
+
},
|
|
80
|
+
dragOver: {
|
|
81
|
+
true: "bg-form-bg-hover border-form-border-focus ring ring-form-focus",
|
|
82
|
+
false: ""
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
defaultVariants: {
|
|
86
|
+
disabled: false,
|
|
87
|
+
uploading: false,
|
|
88
|
+
dragOver: false
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* DropZone component for handling file uploads with previews.
|
|
93
|
+
*
|
|
94
|
+
* @param {Object} props - Component props.
|
|
95
|
+
* @param {string} [props.id] - The ID for the DropZone input.
|
|
96
|
+
* @param {string} [props.label] - Label for the DropZone.
|
|
97
|
+
* @param {boolean} [props.labelHidden] - Whether the label is hidden.
|
|
98
|
+
* @param {Object} [props.labelAction] - Action for the label, including `onAction` and `content`.
|
|
99
|
+
* @param {string} [props.tooltip] - Tooltip for the label.
|
|
100
|
+
* @param {string} [props.labelVariant] - Variant for the label styling.
|
|
101
|
+
* @param {string} [props.type="file"] - The type of files accepted (e.g., "file", "image").
|
|
102
|
+
* @param {string|string[]} [props.accept] - Accepted file types.
|
|
103
|
+
* @param {boolean} [props.allowMultiple=false] - Whether multiple files can be uploaded.
|
|
104
|
+
* @param {boolean} [props.showDropZoneWhenDisabled=true] - Whether the DropZone is shown when disabled.
|
|
105
|
+
* @param {boolean} [props.disabled] - Whether the DropZone is disabled.
|
|
106
|
+
* @param {Function} [props.onDrop] - Callback for when files are dropped.
|
|
107
|
+
* @param {Function} [props.onDropAccepted] - Callback for accepted files.
|
|
108
|
+
* @param {Function} [props.onDropRejected] - Callback for rejected files.
|
|
109
|
+
* @param {string} [props.helpText] - Help text displayed below the DropZone.
|
|
110
|
+
* @param {string} [props.error] - Error message to display.
|
|
111
|
+
* @param {boolean} [props.uploading=false] - Whether a file upload is in progress.
|
|
112
|
+
* @param {Array} [props.uploadedFiles=[]] - Array of uploaded files.
|
|
113
|
+
* @param {string} [props.uploadLabel="Drag and drop files or click to upload"] - Label for upload prompt.
|
|
114
|
+
* @param {string} [props.uploadingLabel="Uploading..."] - Label shown during file uploads.
|
|
115
|
+
* @param {string} [props.dragLabel="Release to upload"] - Label for the drag area.
|
|
116
|
+
* @param {boolean} [props.showFilePreview=true] - Whether file previews are displayed.
|
|
117
|
+
* @param {boolean} [props.previewLoading] - Whether file previews are loading.
|
|
118
|
+
* @param {number} [props.previewRows=2] - Number of preview rows to display.
|
|
119
|
+
* @param {Function} [props.onRemove] - Callback for removing a file.
|
|
120
|
+
* @param {Function} [props.onFilePreviewClick] - Callback for clicking a file preview.
|
|
121
|
+
* @param {string} [props.filename] - Name of the file being uploaded.
|
|
122
|
+
* @returns {JSX.Element} DropZone component.
|
|
123
|
+
*/ function DropZone() {
|
|
124
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
125
|
+
var id = props.id, label = props.label, labelHidden = props.labelHidden, labelAction = props.labelAction, tooltip = props.tooltip, labelVariant = props.labelVariant, _props_type = props.type, type = _props_type === void 0 ? "file" : _props_type, _props_accept = props.accept, accept = _props_accept === void 0 ? typeof props.accept === "string" ? [
|
|
126
|
+
props.accept
|
|
127
|
+
] : props.accept : _props_accept, _props_allowMultiple = props.allowMultiple, allowMultiple = _props_allowMultiple === void 0 ? false : _props_allowMultiple, _props_showDropZoneWhenDisabled = props.showDropZoneWhenDisabled, showDropZoneWhenDisabled = _props_showDropZoneWhenDisabled === void 0 ? true : _props_showDropZoneWhenDisabled, _disabled = props.disabled, onDrop = props.onDrop, onDropAccepted = props.onDropAccepted, onDropRejected = props.onDropRejected, helpText = props.helpText, error = props.error, _props_uploading = props.uploading, uploading = _props_uploading === void 0 ? false : _props_uploading, _props_uploadedFiles = props.uploadedFiles, uploadedFiles = _props_uploadedFiles === void 0 ? [] : _props_uploadedFiles, _props_uploadLabel = props.uploadLabel, uploadLabel = _props_uploadLabel === void 0 ? "Drag and drop files or click to upload" : _props_uploadLabel, _props_uploadingLabel = props.uploadingLabel, uploadingLabel = _props_uploadingLabel === void 0 ? "Uploading..." : _props_uploadingLabel, _props_dragLabel = props.dragLabel, dragLabel = _props_dragLabel === void 0 ? "Release to upload" : _props_dragLabel, tmp = props.showFilePreview, _showFilePreview = tmp === void 0 ? true : tmp, previewLoading = props.previewLoading, _props_previewRows = props.previewRows, previewRows = _props_previewRows === void 0 ? 2 : _props_previewRows, onRemove = props.onRemove, onFilePreviewClick = props.onFilePreviewClick, filename = props.filename;
|
|
128
|
+
var inputRef = useRef(null);
|
|
129
|
+
var _useState = _sliced_to_array(useState(false), 2), hasFocusWithin = _useState[0], setHasFocusWithin = _useState[1];
|
|
130
|
+
var _useState1 = _sliced_to_array(useState(false), 2), isDraggingOver = _useState1[0], setIsDraggingOver = _useState1[1];
|
|
131
|
+
var _useState2 = _sliced_to_array(useState(0), 2), dragFileCount = _useState2[0], setDragFileCount = _useState2[1];
|
|
132
|
+
var showFilePreview = _showFilePreview && (uploadedFiles.length > 0 || previewLoading);
|
|
133
|
+
var getTypeSettings = function(type) {
|
|
134
|
+
switch(type){
|
|
135
|
+
case "image":
|
|
136
|
+
return {
|
|
137
|
+
accept: accept.length > 0 ? accept : [
|
|
138
|
+
"image/*"
|
|
139
|
+
],
|
|
140
|
+
icon: allowMultiple ? ImagesMajor : ImageMajor
|
|
141
|
+
};
|
|
142
|
+
case "video":
|
|
143
|
+
return {
|
|
144
|
+
accept: accept.length > 0 ? accept : [
|
|
145
|
+
"video/*"
|
|
146
|
+
],
|
|
147
|
+
icon: allowMultiple ? ImagesMajor : ImageMajor
|
|
148
|
+
};
|
|
149
|
+
default:
|
|
150
|
+
return {
|
|
151
|
+
accept: accept.length > 0 ? accept : [
|
|
152
|
+
"*/*"
|
|
153
|
+
],
|
|
154
|
+
icon: FileMinor
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var _getTypeSettings = getTypeSettings(type), typeAccept = _getTypeSettings.accept, typeIcon = _getTypeSettings.icon;
|
|
159
|
+
var disabled = _disabled || uploading || allowMultiple === false && uploadedFiles && uploadedFiles.length > 0;
|
|
160
|
+
var showDropZone = !previewLoading && (uploading || !disabled || showDropZoneWhenDisabled);
|
|
161
|
+
var dropAreaClasses = dropZoneStyles({
|
|
162
|
+
uploading: uploading,
|
|
163
|
+
disabled: disabled,
|
|
164
|
+
hasFocusWithin: hasFocusWithin && !disabled,
|
|
165
|
+
dragOver: isDraggingOver && !disabled
|
|
166
|
+
});
|
|
167
|
+
var handleDragOver = function(event) {
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
event.stopPropagation();
|
|
170
|
+
if (!disabled) {
|
|
171
|
+
setIsDraggingOver(true);
|
|
172
|
+
setDragFileCount(event.dataTransfer.items.length);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var handleDragLeave = function(event) {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
event.stopPropagation();
|
|
178
|
+
setIsDraggingOver(false);
|
|
179
|
+
setDragFileCount(0);
|
|
180
|
+
};
|
|
181
|
+
var handleDrop = function(event) {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
setIsDraggingOver(false);
|
|
185
|
+
setDragFileCount(0);
|
|
186
|
+
if (disabled) return;
|
|
187
|
+
var droppedFiles = Array.from(event.dataTransfer.files);
|
|
188
|
+
var acceptedFiles = [];
|
|
189
|
+
var rejectedFiles = [];
|
|
190
|
+
droppedFiles.forEach(function(file) {
|
|
191
|
+
var isValidType = typeAccept.length === 0 || typeAccept.some(function(type) {
|
|
192
|
+
if (type.endsWith("/*")) {
|
|
193
|
+
return file.type.startsWith("".concat(type.split("/")[0], "/"));
|
|
194
|
+
}
|
|
195
|
+
return file.type === type;
|
|
196
|
+
});
|
|
197
|
+
var isValid = isValidType;
|
|
198
|
+
if (isValid) {
|
|
199
|
+
acceptedFiles.push(file);
|
|
200
|
+
} else {
|
|
201
|
+
rejectedFiles.push(file);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
if (onDrop) {
|
|
205
|
+
onDrop(droppedFiles);
|
|
206
|
+
}
|
|
207
|
+
if (onDropAccepted && acceptedFiles.length > 0) {
|
|
208
|
+
onDropAccepted(acceptedFiles);
|
|
209
|
+
}
|
|
210
|
+
if (onDropRejected && rejectedFiles.length > 0) {
|
|
211
|
+
onDropRejected(rejectedFiles);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var handleFileChange = function(event) {
|
|
215
|
+
var selectedFiles = Array.from(event.target.files);
|
|
216
|
+
var acceptedFiles = [];
|
|
217
|
+
var rejectedFiles = [];
|
|
218
|
+
selectedFiles.forEach(function(file) {
|
|
219
|
+
var isValidType = typeAccept.length === 0 || typeAccept.some(function(type) {
|
|
220
|
+
if (type.endsWith("/*")) {
|
|
221
|
+
return file.type.startsWith("".concat(type.split("/")[0], "/"));
|
|
222
|
+
}
|
|
223
|
+
return file.type === type;
|
|
224
|
+
});
|
|
225
|
+
var isValid = isValidType;
|
|
226
|
+
if (isValid) {
|
|
227
|
+
acceptedFiles.push(file);
|
|
228
|
+
} else {
|
|
229
|
+
rejectedFiles.push(file);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (onDrop) {
|
|
233
|
+
onDrop(selectedFiles);
|
|
234
|
+
}
|
|
235
|
+
if (onDropAccepted && acceptedFiles.length > 0) {
|
|
236
|
+
onDropAccepted(acceptedFiles);
|
|
237
|
+
}
|
|
238
|
+
if (onDropRejected && rejectedFiles.length > 0) {
|
|
239
|
+
onDropRejected(rejectedFiles);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
var handleKeyDown = function(event) {
|
|
243
|
+
if (event.key === "Enter") {
|
|
244
|
+
event.preventDefault();
|
|
245
|
+
if (inputRef.current) {
|
|
246
|
+
inputRef.current.click();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
251
|
+
className: "Litho-DropZone flex flex-col gap-2",
|
|
252
|
+
children: [
|
|
253
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
254
|
+
className: "flex flex-col gap-1",
|
|
255
|
+
children: [
|
|
256
|
+
label && !labelHidden && /*#__PURE__*/ _jsxs("div", {
|
|
257
|
+
className: "flex justify-between items-end",
|
|
258
|
+
children: [
|
|
259
|
+
/*#__PURE__*/ _jsx(Label, {
|
|
260
|
+
id: id,
|
|
261
|
+
hidden: labelHidden,
|
|
262
|
+
disabled: disabled,
|
|
263
|
+
tooltip: tooltip,
|
|
264
|
+
variant: labelVariant,
|
|
265
|
+
children: label
|
|
266
|
+
}),
|
|
267
|
+
labelAction && /*#__PURE__*/ _jsx(Link, {
|
|
268
|
+
onClick: labelAction.onAction,
|
|
269
|
+
removeUnderline: true,
|
|
270
|
+
children: labelAction.content
|
|
271
|
+
})
|
|
272
|
+
]
|
|
273
|
+
}),
|
|
274
|
+
showDropZone && /*#__PURE__*/ _jsxs("div", {
|
|
275
|
+
className: "flex flex-col gap-1",
|
|
276
|
+
children: [
|
|
277
|
+
/*#__PURE__*/ _jsxs("label", {
|
|
278
|
+
className: dropAreaClasses,
|
|
279
|
+
tabIndex: 0,
|
|
280
|
+
onFocus: function() {
|
|
281
|
+
return setHasFocusWithin(true);
|
|
282
|
+
},
|
|
283
|
+
onBlur: function() {
|
|
284
|
+
return setHasFocusWithin(false);
|
|
285
|
+
},
|
|
286
|
+
onKeyDown: function(e) {
|
|
287
|
+
return handleKeyDown(e);
|
|
288
|
+
},
|
|
289
|
+
onDragOver: handleDragOver,
|
|
290
|
+
onDragLeave: handleDragLeave,
|
|
291
|
+
onDrop: handleDrop,
|
|
292
|
+
children: [
|
|
293
|
+
/*#__PURE__*/ _jsx("input", {
|
|
294
|
+
ref: inputRef,
|
|
295
|
+
id: id,
|
|
296
|
+
type: "file",
|
|
297
|
+
accept: typeAccept,
|
|
298
|
+
multiple: allowMultiple,
|
|
299
|
+
disabled: disabled || uploading,
|
|
300
|
+
className: "hidden",
|
|
301
|
+
onBlur: function() {
|
|
302
|
+
return setHasFocusWithin(false);
|
|
303
|
+
},
|
|
304
|
+
onChange: handleFileChange
|
|
305
|
+
}),
|
|
306
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
307
|
+
className: "flex items-center justify-center gap-2",
|
|
308
|
+
children: [
|
|
309
|
+
uploading ? /*#__PURE__*/ _jsx(Spinner, {
|
|
310
|
+
size: "small"
|
|
311
|
+
}) : /*#__PURE__*/ _jsx(Icon, {
|
|
312
|
+
source: typeIcon,
|
|
313
|
+
color: disabled ? "disabled" : "subdued"
|
|
314
|
+
}),
|
|
315
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
316
|
+
fontWeight: "medium",
|
|
317
|
+
color: disabled ? "disabled" : "subdued",
|
|
318
|
+
children: uploading ? uploadingLabel : isDraggingOver ? "".concat(dragLabel, " ").concat(dragFileCount, " file").concat(dragFileCount !== 1 ? "s" : "") : uploadLabel
|
|
319
|
+
})
|
|
320
|
+
]
|
|
321
|
+
})
|
|
322
|
+
]
|
|
323
|
+
}),
|
|
324
|
+
error && /*#__PURE__*/ _jsx(InlineError, {
|
|
325
|
+
message: error,
|
|
326
|
+
icon: CircleAlertMajor
|
|
327
|
+
}),
|
|
328
|
+
helpText && /*#__PURE__*/ _jsx(Text, {
|
|
329
|
+
color: "subdued",
|
|
330
|
+
children: helpText
|
|
331
|
+
})
|
|
332
|
+
]
|
|
333
|
+
})
|
|
334
|
+
]
|
|
335
|
+
}),
|
|
336
|
+
showFilePreview && /*#__PURE__*/ _jsx(FilePreview, {
|
|
337
|
+
files: uploadedFiles,
|
|
338
|
+
loading: previewLoading,
|
|
339
|
+
previewRows: allowMultiple ? previewRows : 1,
|
|
340
|
+
onRemove: onRemove,
|
|
341
|
+
filename: filename,
|
|
342
|
+
onClick: onFilePreviewClick
|
|
343
|
+
})
|
|
344
|
+
]
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
var previewContainerStyles = tv({
|
|
348
|
+
base: "flex flex-col",
|
|
349
|
+
variants: {
|
|
350
|
+
onClick: {
|
|
351
|
+
true: "",
|
|
352
|
+
false: "gap-2"
|
|
353
|
+
},
|
|
354
|
+
display: {
|
|
355
|
+
column: "",
|
|
356
|
+
row: "@lg:flex-row @lg:overflow-x-auto"
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
var previewStyles = tv({
|
|
361
|
+
base: "flex gap-2 items-center shrink",
|
|
362
|
+
variants: {
|
|
363
|
+
onClick: {
|
|
364
|
+
true: "cursor-pointer p-1 pr-3 rounded-md hover"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
/**
|
|
369
|
+
* FilePreview component for displaying file preview thumbnails.
|
|
370
|
+
*
|
|
371
|
+
* @param {Object} props - Component props.
|
|
372
|
+
* @param {Array} [props.files] - Array of file objects to preview.
|
|
373
|
+
* @param {boolean} [props.loading] - Whether the file previews are loading.
|
|
374
|
+
* @param {number} [props.previewRows=2] - Number of preview rows to display.
|
|
375
|
+
* @param {Function} [props.onRemove] - Callback for removing a file.
|
|
376
|
+
* @param {Function} [props.onClick] - Callback for clicking a file preview.
|
|
377
|
+
* @param {string} [props.filename] - Name of the file being uploaded.
|
|
378
|
+
* @returns {JSX.Element} FilePreview component.
|
|
379
|
+
*/ function FilePreview() {
|
|
380
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
381
|
+
var files = props.files, onRemove = props.onRemove, loading = props.loading, _props_previewRows = props.previewRows, previewRows = _props_previewRows === void 0 ? 2 : _props_previewRows, onClick = props.onClick, filename = props.filename, _props_display = props.display, display = _props_display === void 0 ? "column" : _props_display;
|
|
382
|
+
var previewContainerClasses = previewContainerStyles({
|
|
383
|
+
onClick: !!onClick,
|
|
384
|
+
display: display
|
|
385
|
+
});
|
|
386
|
+
var previewClasses = previewStyles({
|
|
387
|
+
onClick: !!onClick
|
|
388
|
+
});
|
|
389
|
+
if (loading) {
|
|
390
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
391
|
+
className: "flex flex-col gap-2",
|
|
392
|
+
children: _to_consumable_array(Array(previewRows)).map(function(_, index) {
|
|
393
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
394
|
+
className: "flex justify-between items-center gap-2",
|
|
395
|
+
children: [
|
|
396
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
397
|
+
className: "flex gap-2 items-center shrink",
|
|
398
|
+
children: [
|
|
399
|
+
/*#__PURE__*/ _jsx(FileThumbnail, {
|
|
400
|
+
loading: true
|
|
401
|
+
}),
|
|
402
|
+
/*#__PURE__*/ _jsx("div", {
|
|
403
|
+
className: "w-20",
|
|
404
|
+
children: /*#__PURE__*/ _jsx(SkeletonText, {
|
|
405
|
+
lines: 2,
|
|
406
|
+
gap: "small"
|
|
407
|
+
})
|
|
408
|
+
})
|
|
409
|
+
]
|
|
410
|
+
}),
|
|
411
|
+
onRemove && /*#__PURE__*/ _jsx(Button, {
|
|
412
|
+
size: "small",
|
|
413
|
+
icon: CancelMajor,
|
|
414
|
+
disabled: true,
|
|
415
|
+
className: "shrink-0 opacity-30"
|
|
416
|
+
})
|
|
417
|
+
]
|
|
418
|
+
}, index);
|
|
419
|
+
})
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
423
|
+
className: previewContainerClasses,
|
|
424
|
+
children: files.map(function(file, index) {
|
|
425
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
426
|
+
className: "flex justify-between items-center gap-2",
|
|
427
|
+
children: [
|
|
428
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
429
|
+
className: previewClasses,
|
|
430
|
+
onClick: onClick ? function() {
|
|
431
|
+
return onClick(file);
|
|
432
|
+
} : undefined,
|
|
433
|
+
children: [
|
|
434
|
+
/*#__PURE__*/ _jsx(FileThumbnail, {
|
|
435
|
+
file: file
|
|
436
|
+
}),
|
|
437
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
438
|
+
className: display === "row" ? "@lg:max-w-32" : "",
|
|
439
|
+
children: [
|
|
440
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
441
|
+
fontWeight: "medium",
|
|
442
|
+
truncate: true,
|
|
443
|
+
children: filename || file.fileName
|
|
444
|
+
}),
|
|
445
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
446
|
+
color: "subdued",
|
|
447
|
+
truncate: true,
|
|
448
|
+
variant: "bodySm",
|
|
449
|
+
children: formatFileSize(file.fileSize)
|
|
450
|
+
})
|
|
451
|
+
]
|
|
452
|
+
})
|
|
453
|
+
]
|
|
454
|
+
}),
|
|
455
|
+
onRemove && /*#__PURE__*/ _jsx(Button, {
|
|
456
|
+
size: "small",
|
|
457
|
+
icon: CancelMajor,
|
|
458
|
+
tooltip: "Remove",
|
|
459
|
+
onClick: function() {
|
|
460
|
+
return onRemove(file.fileKey);
|
|
461
|
+
},
|
|
462
|
+
className: "shrink-0"
|
|
463
|
+
})
|
|
464
|
+
]
|
|
465
|
+
}, "file-".concat(index));
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
DropZone.FilePreview = FilePreview;
|
|
470
|
+
var thumbnailSizeStyles = tv({
|
|
471
|
+
base: "Litho-FileThumbnail h-9 w-9 shrink-0 flex items-center justify-center rounded-md bg-tint-2 dark:bg-tint-alt-2 overflow-hidden bg-cover bg-center border border-tint-4 dark:border-tint-alt-4"
|
|
472
|
+
});
|
|
473
|
+
/**
|
|
474
|
+
* FileThumbnail component for displaying a file thumbnail or spinner.
|
|
475
|
+
*
|
|
476
|
+
* @param {Object} props - Component props.
|
|
477
|
+
* @param {Object} [props.file] - File object to display.
|
|
478
|
+
* @param {boolean} [props.loading] - Whether the thumbnail is loading.
|
|
479
|
+
* @returns {JSX.Element} FileThumbnail component.
|
|
480
|
+
*/ function FileThumbnail() {
|
|
481
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
482
|
+
var _file_fileType, _file_fileType1;
|
|
483
|
+
var file = props.file, loading = props.loading;
|
|
484
|
+
var _useState = _sliced_to_array(useState(file === null || file === void 0 ? void 0 : file.url), 2), imagePreview = _useState[0], setImagePreview = _useState[1];
|
|
485
|
+
var thumbnailClasses = thumbnailSizeStyles();
|
|
486
|
+
useEffect(function() {
|
|
487
|
+
var _file_fileType;
|
|
488
|
+
if (file && !imagePreview && !file.url && ((_file_fileType = file.fileType) === null || _file_fileType === void 0 ? void 0 : _file_fileType.startsWith("image"))) {
|
|
489
|
+
var reader = new FileReader();
|
|
490
|
+
reader.onloadend = function() {
|
|
491
|
+
setImagePreview(reader.result);
|
|
492
|
+
};
|
|
493
|
+
reader.readAsDataURL(file.file);
|
|
494
|
+
}
|
|
495
|
+
}, [
|
|
496
|
+
file
|
|
497
|
+
]);
|
|
498
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
499
|
+
className: thumbnailClasses,
|
|
500
|
+
style: (file === null || file === void 0 ? void 0 : (_file_fileType = file.fileType) === null || _file_fileType === void 0 ? void 0 : _file_fileType.startsWith("image")) ? {
|
|
501
|
+
backgroundImage: "url(".concat(imagePreview, ")")
|
|
502
|
+
} : {},
|
|
503
|
+
children: loading ? /*#__PURE__*/ _jsx(Spinner, {
|
|
504
|
+
size: "small",
|
|
505
|
+
color: "subdued"
|
|
506
|
+
}) : file && !((_file_fileType1 = file.fileType) === null || _file_fileType1 === void 0 ? void 0 : _file_fileType1.startsWith("image")) && /*#__PURE__*/ _jsx(Icon, {
|
|
507
|
+
source: FileMinor,
|
|
508
|
+
color: "subdued"
|
|
509
|
+
})
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
DropZone.FileThumbnail = FileThumbnail;
|
|
513
|
+
/**
|
|
514
|
+
* Formats a file size into a human-readable string.
|
|
515
|
+
*
|
|
516
|
+
* @param {number} fileSize - Size of the file in bytes.
|
|
517
|
+
* @returns {string} Formatted file size (e.g., "1.2 MB").
|
|
518
|
+
*/ var formatFileSize = function(fileSize) {
|
|
519
|
+
if (typeof fileSize !== "number" || isNaN(fileSize)) {
|
|
520
|
+
return "0 Bytes";
|
|
521
|
+
}
|
|
522
|
+
var units = [
|
|
523
|
+
"Bytes",
|
|
524
|
+
"KB",
|
|
525
|
+
"MB",
|
|
526
|
+
"GB",
|
|
527
|
+
"TB"
|
|
528
|
+
];
|
|
529
|
+
var index = 0;
|
|
530
|
+
while(fileSize >= 1024 && index < units.length - 1){
|
|
531
|
+
fileSize /= 1024;
|
|
532
|
+
index++;
|
|
533
|
+
}
|
|
534
|
+
return "".concat(fileSize.toFixed(1), " ").concat(units[index]);
|
|
535
|
+
};
|
|
536
|
+
DropZone.formatFileSize = formatFileSize;
|
|
537
|
+
export default DropZone;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Image, Text, ProgressBar } from "../index.js";
|
|
3
|
+
import { tv } from "tailwind-variants";
|
|
4
|
+
var styles = tv({
|
|
5
|
+
base: "Litho-EmptyState py-16 px-4 flex flex-col items-center text-center gap-6"
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* EmptyState component for displaying a structured layout with a title, description,
|
|
9
|
+
* icon, and action buttons when no content is available.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} props - The properties to customize the EmptyState component.
|
|
12
|
+
* @param {string} [props.description] - Text description to display in the empty state.
|
|
13
|
+
* @param {React.ReactNode} [props.icon] - React node to render a custom icon.
|
|
14
|
+
* @param {string} [props.iconSource] - Image source URL to display an icon.
|
|
15
|
+
* @param {Object} [props.primaryAction] - Primary action button configuration.
|
|
16
|
+
* @param {string} props.primaryAction.content - Label for the primary button.
|
|
17
|
+
* @param {function} props.primaryAction.onAction - Callback function for the primary action button click.
|
|
18
|
+
* @param {boolean} [props.primaryAction.disabled=false] - Disable state for the primary action button.
|
|
19
|
+
* @param {boolean} [props.primaryAction.loading=false] - Loading state for the primary action button.
|
|
20
|
+
* @param {boolean} [props.primaryAction.external=false] - Whether the primary action button should open in a new tab.
|
|
21
|
+
* @param {Object} [props.secondaryAction] - Secondary action button configuration.
|
|
22
|
+
* @param {string} props.secondaryAction.content - Label for the secondary button.
|
|
23
|
+
* @param {function} props.secondaryAction.onAction - Callback function for the secondary action button click.
|
|
24
|
+
* @param {boolean} [props.secondaryAction.disabled=false] - Disable state for the secondary action button.
|
|
25
|
+
* @param {boolean} [props.secondaryAction.loading=false] - Loading state for the secondary action button.
|
|
26
|
+
* @param {boolean} [props.secondaryAction.external=false] - Whether the secondary action button should open in a new tab.
|
|
27
|
+
* @param {string} [props.title] - Title text to display in the empty state.
|
|
28
|
+
* @param {string} [props.titleVariant="headingXl"] - Typography variant for the title, default is "headingXl".
|
|
29
|
+
* @param {string} [props.descriptionVariant="bodyLg"] - Typography variant for the description, default is "bodyLg".
|
|
30
|
+
* @param {number} [props.progress] - Progress value to display in the empty state.
|
|
31
|
+
*
|
|
32
|
+
* @returns {JSX.Element} The rendered EmptyState component.
|
|
33
|
+
*/ function EmptyState() {
|
|
34
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
35
|
+
var description = props.description, icon = props.icon, iconSource = props.iconSource, primaryAction = props.primaryAction, secondaryAction = props.secondaryAction, title = props.title, _props_titleVariant = props.titleVariant, titleVariant = _props_titleVariant === void 0 ? "headingXl" : _props_titleVariant, _props_descriptionVariant = props.descriptionVariant, descriptionVariant = _props_descriptionVariant === void 0 ? "bodyLg" : _props_descriptionVariant, progress = props.progress;
|
|
36
|
+
var classes = styles();
|
|
37
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
38
|
+
className: classes,
|
|
39
|
+
children: [
|
|
40
|
+
iconSource && /*#__PURE__*/ _jsx("div", {
|
|
41
|
+
className: "flex items-center justify-center w-16 h-16",
|
|
42
|
+
children: /*#__PURE__*/ _jsx(Image, {
|
|
43
|
+
source: iconSource
|
|
44
|
+
})
|
|
45
|
+
}),
|
|
46
|
+
icon && /*#__PURE__*/ _jsx("div", {
|
|
47
|
+
className: "flex items-center justify-center",
|
|
48
|
+
children: icon
|
|
49
|
+
}),
|
|
50
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
51
|
+
className: "flex flex-col items-center gap-4",
|
|
52
|
+
children: [
|
|
53
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
54
|
+
className: "flex flex-col items-center gap-2 max-w-112",
|
|
55
|
+
children: [
|
|
56
|
+
title && /*#__PURE__*/ _jsx(Text, {
|
|
57
|
+
variant: titleVariant,
|
|
58
|
+
children: title
|
|
59
|
+
}),
|
|
60
|
+
description && /*#__PURE__*/ _jsx(Text, {
|
|
61
|
+
variant: descriptionVariant,
|
|
62
|
+
color: "subdued",
|
|
63
|
+
children: description
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
}),
|
|
67
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
68
|
+
className: "flex gap-3",
|
|
69
|
+
children: [
|
|
70
|
+
primaryAction && /*#__PURE__*/ _jsx(Button, {
|
|
71
|
+
primary: true,
|
|
72
|
+
onClick: primaryAction.onAction,
|
|
73
|
+
disabled: primaryAction.disabled,
|
|
74
|
+
url: primaryAction.url,
|
|
75
|
+
external: primaryAction.external,
|
|
76
|
+
loading: primaryAction.loading,
|
|
77
|
+
children: primaryAction.content
|
|
78
|
+
}),
|
|
79
|
+
secondaryAction && /*#__PURE__*/ _jsx(Button, {
|
|
80
|
+
onClick: secondaryAction.onAction,
|
|
81
|
+
url: secondaryAction.url,
|
|
82
|
+
external: secondaryAction.external,
|
|
83
|
+
disabled: secondaryAction.disabled,
|
|
84
|
+
loading: secondaryAction.loading,
|
|
85
|
+
children: secondaryAction.content
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
}),
|
|
89
|
+
progress !== undefined && progress !== null && /*#__PURE__*/ _jsx("div", {
|
|
90
|
+
className: "w-full",
|
|
91
|
+
children: /*#__PURE__*/ _jsx(ProgressBar, {
|
|
92
|
+
animated: true,
|
|
93
|
+
progress: progress
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export default EmptyState;
|