@aquera/nile-elements 0.1.36 → 0.1.38-beta-1.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/README.md +13 -0
- package/demo/index.html +9 -9
- package/demo/variables.css +13 -0
- package/dist/{fixture-2b5b3aba.esm.js → fixture-add72f26.esm.js} +1 -1
- package/dist/{fixture-7bfb866e.cjs.js → fixture-cb376a7f.cjs.js} +3 -3
- package/dist/fixture-cb376a7f.cjs.js.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/lit-html-39a6718c.esm.js +6 -0
- package/dist/lit-html-9b3af046.cjs.js +6 -0
- package/dist/lit-html-9b3af046.cjs.js.map +1 -0
- package/dist/nile-accordion/nile-accordian.test.cjs.js +1 -1
- package/dist/nile-accordion/nile-accordian.test.esm.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.test.cjs.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.test.cjs.js.map +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.test.esm.js +1 -1
- package/dist/nile-avatar/nile-avatar.test.cjs.js +1 -1
- package/dist/nile-avatar/nile-avatar.test.esm.js +1 -1
- package/dist/nile-badge/nile-badge.test.cjs.js +1 -1
- package/dist/nile-badge/nile-badge.test.esm.js +1 -1
- package/dist/nile-button/nile-button.test.cjs.js +1 -1
- package/dist/nile-button/nile-button.test.esm.js +1 -1
- package/dist/nile-button-toggle-group/nile-button-toggle-group.test.cjs.js +1 -1
- package/dist/nile-button-toggle-group/nile-button-toggle-group.test.esm.js +1 -1
- package/dist/nile-calendar/nile-calendar.test.cjs.js +1 -1
- package/dist/nile-calendar/nile-calendar.test.esm.js +1 -1
- package/dist/nile-card/nile-card.test.cjs.js +1 -1
- package/dist/nile-card/nile-card.test.esm.js +1 -1
- package/dist/nile-checkbox/nile-checkbox.test.cjs.js +1 -1
- package/dist/nile-checkbox/nile-checkbox.test.esm.js +1 -1
- package/dist/nile-chip/nile-chip.test.cjs.js +1 -1
- package/dist/nile-chip/nile-chip.test.esm.js +1 -1
- package/dist/nile-dialog/nile-dialog.test.cjs.js +1 -1
- package/dist/nile-dialog/nile-dialog.test.esm.js +1 -1
- package/dist/nile-drawer/nile-drawer.test.cjs.js +1 -1
- package/dist/nile-drawer/nile-drawer.test.esm.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.test.cjs.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.test.esm.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.test.cjs.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.test.esm.js +1 -1
- package/dist/nile-error-message/nile-error-message.test.cjs.js +1 -1
- package/dist/nile-error-message/nile-error-message.test.esm.js +1 -1
- package/dist/nile-file-preview/index.cjs.js +2 -0
- package/dist/nile-file-preview/index.cjs.js.map +1 -0
- package/dist/nile-file-preview/index.esm.js +1 -0
- package/dist/nile-file-preview/nile-file-preview.cjs.js +2 -0
- package/dist/nile-file-preview/nile-file-preview.cjs.js.map +1 -0
- package/dist/nile-file-preview/nile-file-preview.css.cjs.js +2 -0
- package/dist/nile-file-preview/nile-file-preview.css.cjs.js.map +1 -0
- package/dist/nile-file-preview/nile-file-preview.css.esm.js +510 -0
- package/dist/nile-file-preview/nile-file-preview.esm.js +3 -0
- package/dist/nile-file-preview/nile-file-preview.template.cjs.js +2 -0
- package/dist/nile-file-preview/nile-file-preview.template.cjs.js.map +1 -0
- package/dist/nile-file-preview/nile-file-preview.template.esm.js +179 -0
- package/dist/nile-file-preview/nile-file-preview.test.cjs.js +2 -0
- package/dist/nile-file-preview/nile-file-preview.test.cjs.js.map +1 -0
- package/dist/nile-file-preview/nile-file-preview.test.esm.js +1 -0
- package/dist/nile-file-preview/types/index.cjs.js +2 -0
- package/dist/nile-file-preview/types/index.cjs.js.map +1 -0
- package/dist/nile-file-preview/types/index.esm.js +1 -0
- package/dist/nile-file-preview/types/nile-file-preview.enums.cjs.js +2 -0
- package/dist/nile-file-preview/types/nile-file-preview.enums.cjs.js.map +1 -0
- package/dist/nile-file-preview/types/nile-file-preview.enums.esm.js +1 -0
- package/dist/nile-file-preview/types/nile-file-preview.interface.cjs.js +2 -0
- package/dist/nile-file-preview/types/nile-file-preview.interface.cjs.js.map +1 -0
- package/dist/nile-file-preview/types/nile-file-preview.interface.esm.js +1 -0
- package/dist/nile-file-preview/utils/index.cjs.js +2 -0
- package/dist/nile-file-preview/utils/index.cjs.js.map +1 -0
- package/dist/nile-file-preview/utils/index.esm.js +1 -0
- package/dist/nile-file-preview/utils/nile-file-preview.util.cjs.js +2 -0
- package/dist/nile-file-preview/utils/nile-file-preview.util.cjs.js.map +1 -0
- package/dist/nile-file-preview/utils/nile-file-preview.util.esm.js +1 -0
- package/dist/nile-file-upload/index.cjs.js +2 -0
- package/dist/nile-file-upload/index.cjs.js.map +1 -0
- package/dist/nile-file-upload/index.esm.js +1 -0
- package/dist/nile-file-upload/nile-file-upload.cjs.js +2 -0
- package/dist/nile-file-upload/nile-file-upload.cjs.js.map +1 -0
- package/dist/nile-file-upload/nile-file-upload.css.cjs.js +2 -0
- package/dist/nile-file-upload/nile-file-upload.css.cjs.js.map +1 -0
- package/dist/nile-file-upload/nile-file-upload.css.esm.js +536 -0
- package/dist/nile-file-upload/nile-file-upload.esm.js +3 -0
- package/dist/nile-file-upload/nile-file-upload.template.cjs.js +10 -0
- package/dist/nile-file-upload/nile-file-upload.template.cjs.js.map +1 -0
- package/dist/nile-file-upload/nile-file-upload.template.esm.js +163 -0
- package/dist/nile-file-upload/nile-file-upload.test.cjs.js +2 -0
- package/dist/nile-file-upload/nile-file-upload.test.cjs.js.map +1 -0
- package/dist/nile-file-upload/nile-file-upload.test.esm.js +1 -0
- package/dist/nile-file-upload/types/file-upload.enums.cjs.js +2 -0
- package/dist/nile-file-upload/types/file-upload.enums.cjs.js.map +1 -0
- package/dist/nile-file-upload/types/file-upload.enums.esm.js +1 -0
- package/dist/nile-file-upload/types/file-upload.type.cjs.js +2 -0
- package/dist/nile-file-upload/types/file-upload.type.cjs.js.map +1 -0
- package/dist/nile-file-upload/types/file-upload.type.esm.js +1 -0
- package/dist/nile-file-upload/types/index.cjs.js +2 -0
- package/dist/nile-file-upload/types/index.cjs.js.map +1 -0
- package/dist/nile-file-upload/types/index.esm.js +1 -0
- package/dist/nile-file-upload/utils/drag-drop.util.cjs.js +2 -0
- package/dist/nile-file-upload/utils/drag-drop.util.cjs.js.map +1 -0
- package/dist/nile-file-upload/utils/drag-drop.util.esm.js +1 -0
- package/dist/nile-file-upload/utils/file-validation.util.cjs.js +2 -0
- package/dist/nile-file-upload/utils/file-validation.util.cjs.js.map +1 -0
- package/dist/nile-file-upload/utils/file-validation.util.esm.js +1 -0
- package/dist/nile-filter-chip/index.cjs.js +2 -0
- package/dist/nile-filter-chip/index.cjs.js.map +1 -0
- package/dist/nile-filter-chip/index.esm.js +1 -0
- package/dist/nile-filter-chip/nile-filter-chip.cjs.js +2 -0
- package/dist/nile-filter-chip/nile-filter-chip.cjs.js.map +1 -0
- package/dist/nile-filter-chip/nile-filter-chip.css.cjs.js +2 -0
- package/dist/nile-filter-chip/nile-filter-chip.css.cjs.js.map +1 -0
- package/dist/nile-filter-chip/nile-filter-chip.css.esm.js +121 -0
- package/dist/nile-filter-chip/nile-filter-chip.esm.js +43 -0
- package/dist/nile-filter-chip/nile-filter-chip.test.cjs.js +2 -0
- package/dist/nile-filter-chip/nile-filter-chip.test.cjs.js.map +1 -0
- package/dist/nile-filter-chip/nile-filter-chip.test.esm.js +20 -0
- package/dist/nile-form-group/nile-form-group.test.cjs.js +1 -1
- package/dist/nile-form-group/nile-form-group.test.esm.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.test.cjs.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.test.esm.js +1 -1
- package/dist/nile-hero/nile-hero.test.cjs.js +1 -1
- package/dist/nile-hero/nile-hero.test.esm.js +1 -1
- package/dist/nile-icon/nile-icon.test.cjs.js +1 -1
- package/dist/nile-icon/nile-icon.test.esm.js +1 -1
- package/dist/nile-input/nile-input.test.cjs.js +1 -1
- package/dist/nile-input/nile-input.test.esm.js +1 -1
- package/dist/nile-link/nile-link.test.cjs.js +1 -1
- package/dist/nile-link/nile-link.test.esm.js +1 -1
- package/dist/nile-loader/nile-loader.test.cjs.js +1 -1
- package/dist/nile-loader/nile-loader.test.esm.js +1 -1
- package/dist/nile-popover/index.cjs.js +1 -1
- package/dist/nile-popover/index.esm.js +1 -1
- package/dist/nile-popover/nile-popover.cjs.js +3 -11
- package/dist/nile-popover/nile-popover.cjs.js.map +1 -1
- package/dist/nile-popover/nile-popover.esm.js +7 -13
- package/dist/nile-popover/nile-popover.test.cjs.js +1 -1
- package/dist/nile-popover/nile-popover.test.cjs.js.map +1 -1
- package/dist/nile-popover/nile-popover.test.esm.js +3 -3
- package/dist/nile-popup/nile-popup.test.cjs.js +1 -1
- package/dist/nile-popup/nile-popup.test.esm.js +1 -1
- package/dist/nile-progress-bar/nile-progress-bar.test.cjs.js +1 -1
- package/dist/nile-progress-bar/nile-progress-bar.test.esm.js +1 -1
- package/dist/nile-radio/nile-radio.test.cjs.js +1 -1
- package/dist/nile-radio/nile-radio.test.esm.js +1 -1
- package/dist/nile-radio-group/nile-radio-group.test.cjs.js +1 -1
- package/dist/nile-radio-group/nile-radio-group.test.esm.js +1 -1
- package/dist/nile-select/nile-select.test.cjs.js +1 -1
- package/dist/nile-select/nile-select.test.esm.js +1 -1
- package/dist/nile-slide-toggle/nile-slide-toggle.test.cjs.js +1 -1
- package/dist/nile-slide-toggle/nile-slide-toggle.test.esm.js +1 -1
- package/dist/nile-tab-group/nile-tab-group.test.cjs.js +1 -1
- package/dist/nile-tab-group/nile-tab-group.test.esm.js +1 -1
- package/dist/nile-textarea/nile-textarea.test.cjs.js +1 -1
- package/dist/nile-textarea/nile-textarea.test.esm.js +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/nile-file-preview/nile-file-preview.css.js +32 -43
- package/dist/src/nile-file-preview/nile-file-preview.css.js.map +1 -1
- package/dist/src/nile-file-preview/nile-file-preview.d.ts +3 -1
- package/dist/src/nile-file-preview/nile-file-preview.js +27 -5
- package/dist/src/nile-file-preview/nile-file-preview.js.map +1 -1
- package/dist/src/nile-file-preview/nile-file-preview.template.d.ts +2 -0
- package/dist/src/nile-file-preview/nile-file-preview.template.js +114 -48
- package/dist/src/nile-file-preview/nile-file-preview.template.js.map +1 -1
- package/dist/src/nile-file-preview/types/index.d.ts +2 -2
- package/dist/src/nile-file-preview/types/index.js +2 -2
- package/dist/src/nile-file-preview/types/index.js.map +1 -1
- package/dist/src/nile-file-preview/types/nile-file-preview.enums.d.ts +28 -0
- package/dist/src/nile-file-preview/types/nile-file-preview.enums.js +33 -0
- package/dist/src/nile-file-preview/types/nile-file-preview.enums.js.map +1 -0
- package/dist/src/nile-file-preview/types/nile-file-preview.interface.d.ts +4 -0
- package/dist/src/nile-file-preview/types/nile-file-preview.interface.js +2 -0
- package/dist/src/nile-file-preview/types/nile-file-preview.interface.js.map +1 -0
- package/dist/src/nile-file-preview/utils/index.d.ts +1 -1
- package/dist/src/nile-file-preview/utils/index.js +1 -1
- package/dist/src/nile-file-preview/utils/index.js.map +1 -1
- package/dist/src/nile-file-preview/utils/nile-file-preview.util.d.ts +4 -0
- package/dist/src/nile-file-preview/utils/nile-file-preview.util.js +38 -0
- package/dist/src/nile-file-preview/utils/nile-file-preview.util.js.map +1 -0
- package/dist/src/nile-file-upload/nile-file-upload.css.js +2 -1
- package/dist/src/nile-file-upload/nile-file-upload.css.js.map +1 -1
- package/dist/src/nile-file-upload/nile-file-upload.d.ts +3 -0
- package/dist/src/nile-file-upload/nile-file-upload.js +22 -5
- package/dist/src/nile-file-upload/nile-file-upload.js.map +1 -1
- package/dist/src/nile-file-upload/nile-file-upload.template.js +27 -19
- package/dist/src/nile-file-upload/nile-file-upload.template.js.map +1 -1
- package/dist/src/nile-file-upload/types/file-upload.enums.d.ts +9 -2
- package/dist/src/nile-file-upload/types/file-upload.enums.js +8 -1
- package/dist/src/nile-file-upload/types/file-upload.enums.js.map +1 -1
- package/dist/src/nile-file-upload/utils/drag-drop.util.d.ts +5 -1
- package/dist/src/nile-file-upload/utils/drag-drop.util.js +9 -1
- package/dist/src/nile-file-upload/utils/drag-drop.util.js.map +1 -1
- package/dist/src/nile-file-upload/utils/file-validation.util.d.ts +3 -1
- package/dist/src/nile-file-upload/utils/file-validation.util.js +72 -10
- package/dist/src/nile-file-upload/utils/file-validation.util.js.map +1 -1
- package/dist/src/nile-filter-chip/index.d.ts +1 -0
- package/dist/src/nile-filter-chip/index.js +2 -0
- package/dist/src/nile-filter-chip/index.js.map +1 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.css.d.ts +12 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.css.js +133 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.css.js.map +1 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.d.ts +36 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.js +141 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.js.map +1 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.test.d.ts +1 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.test.js +80 -0
- package/dist/src/nile-filter-chip/nile-filter-chip.test.js.map +1 -0
- package/dist/src/nile-tooltip/nile-tooltip-utils.d.ts +18 -0
- package/dist/src/nile-tooltip/nile-tooltip-utils.js +216 -0
- package/dist/src/nile-tooltip/nile-tooltip-utils.js.map +1 -0
- package/dist/src/nile-tooltip/nile-tooltip.test.d.ts +1 -0
- package/dist/src/nile-tooltip/nile-tooltip.test.js +148 -0
- package/dist/src/nile-tooltip/nile-tooltip.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -1
- package/src/nile-file-preview/index.ts +1 -0
- package/src/nile-file-preview/nile-file-preview.css.ts +524 -0
- package/src/nile-file-preview/nile-file-preview.template.ts +248 -0
- package/src/nile-file-preview/nile-file-preview.test.ts +38 -0
- package/src/nile-file-preview/nile-file-preview.ts +173 -0
- package/src/nile-file-preview/types/index.ts +2 -0
- package/src/nile-file-preview/types/nile-file-preview.enums.ts +31 -0
- package/src/nile-file-preview/types/nile-file-preview.interface.ts +4 -0
- package/src/nile-file-preview/utils/index.ts +1 -0
- package/src/nile-file-preview/utils/nile-file-preview.util.ts +47 -0
- package/src/nile-file-upload/index.ts +1 -0
- package/src/nile-file-upload/nile-file-upload.css.ts +550 -0
- package/src/nile-file-upload/nile-file-upload.template.ts +201 -0
- package/src/nile-file-upload/nile-file-upload.test.ts +38 -0
- package/src/nile-file-upload/nile-file-upload.ts +149 -0
- package/src/nile-file-upload/types/file-upload.enums.ts +39 -0
- package/src/nile-file-upload/types/file-upload.type.ts +5 -0
- package/src/nile-file-upload/types/index.ts +2 -0
- package/src/nile-file-upload/utils/drag-drop.util.ts +106 -0
- package/src/nile-file-upload/utils/file-validation.util.ts +163 -0
- package/src/nile-filter-chip/index.ts +1 -0
- package/src/nile-filter-chip/nile-filter-chip.css.ts +138 -0
- package/src/nile-filter-chip/nile-filter-chip.test.ts +92 -0
- package/src/nile-filter-chip/nile-filter-chip.ts +136 -0
- package/vscode-html-custom-data.json +192 -0
- package/dist/fixture-7bfb866e.cjs.js.map +0 -1
@@ -0,0 +1,163 @@
|
|
1
|
+
import { DragHandler } from "./drag-drop.util";
|
2
|
+
import { FileUploadState, FileUploadError, FileUploadEvent } from "../types";
|
3
|
+
import { NileFileUpload } from "../nile-file-upload";
|
4
|
+
|
5
|
+
// write a function to check for duplicatse in the files name it as areDuplicates
|
6
|
+
export const areDuplicates = (files: File[], uploadedFiles: File[]): boolean => {
|
7
|
+
return files.some(file =>
|
8
|
+
uploadedFiles.some(existing =>
|
9
|
+
file.name === existing.name &&
|
10
|
+
file.size === existing.size &&
|
11
|
+
file.lastModified === existing.lastModified
|
12
|
+
)
|
13
|
+
);
|
14
|
+
};
|
15
|
+
|
16
|
+
// set up the drag handler
|
17
|
+
export const setUpDragHandler = (
|
18
|
+
nileFileUpload: NileFileUpload,
|
19
|
+
dragHandler: DragHandler
|
20
|
+
): void => {
|
21
|
+
dragHandler.onStateChange((newState: FileUploadState) => {
|
22
|
+
nileFileUpload.state = newState;
|
23
|
+
});
|
24
|
+
|
25
|
+
dragHandler.onFileDrop((files: File[]) => {
|
26
|
+
let { allowMultiple, uploadedFiles, errorMessage, requestUpdate } = nileFileUpload;
|
27
|
+
|
28
|
+
if (!allowMultiple) {
|
29
|
+
const total = uploadedFiles.length + files.length;
|
30
|
+
if (total > 1) {
|
31
|
+
errorMessage = FileUploadError.MULTIPLE_NOT_ALLOWED;
|
32
|
+
requestUpdate();
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
let newFiles = files;
|
38
|
+
|
39
|
+
if (!nileFileUpload.allowDuplicates) {
|
40
|
+
newFiles = files.filter(file =>
|
41
|
+
!nileFileUpload.uploadedFiles.some(
|
42
|
+
uploaded =>
|
43
|
+
uploaded.name === file.name &&
|
44
|
+
uploaded.size === file.size &&
|
45
|
+
uploaded.type === file.type
|
46
|
+
)
|
47
|
+
);
|
48
|
+
|
49
|
+
if (newFiles.length === 0) {
|
50
|
+
nileFileUpload.errorMessage = FileUploadError.DUPLICATES_NOT_ALLOWED;
|
51
|
+
nileFileUpload.requestUpdate();
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
nileFileUpload.uploadedFiles = [...nileFileUpload.uploadedFiles, ...newFiles];
|
57
|
+
nileFileUpload.requestUpdate();
|
58
|
+
});
|
59
|
+
|
60
|
+
dragHandler.setErrorMessage((errorMessage: string) => {
|
61
|
+
nileFileUpload.errorMessage = errorMessage;
|
62
|
+
});
|
63
|
+
};
|
64
|
+
|
65
|
+
|
66
|
+
// global listenrers
|
67
|
+
export const addGlobalListeners = (dragHandler: DragHandler): void => {
|
68
|
+
document.addEventListener('dragover', dragHandler.preventDragOver, { passive: false });
|
69
|
+
document.addEventListener('drop', dragHandler.preventDrop, { passive: false });
|
70
|
+
}
|
71
|
+
|
72
|
+
// for hover & dragging functionality
|
73
|
+
export const addInternalListeners = (nileFileUpload: NileFileUpload, dragHandler: DragHandler, uploadRequests: any): void => {
|
74
|
+
nileFileUpload.addEventListener('mouseenter', (e) => handleHoverIn(nileFileUpload.setState, nileFileUpload.state));
|
75
|
+
nileFileUpload.addEventListener('mouseleave', (e) => handleHoverOut(nileFileUpload.setState, nileFileUpload.state));
|
76
|
+
nileFileUpload.addEventListener('dragenter', (e) => dragHandler.dragEnter(e));
|
77
|
+
nileFileUpload.addEventListener('dragleave', (e) => dragHandler.dragLeave(e));
|
78
|
+
nileFileUpload.addEventListener('dragover', (e) => dragHandler.dragOver(e));
|
79
|
+
nileFileUpload.addEventListener('drop', (e) => dragHandler.drop(e));
|
80
|
+
|
81
|
+
cancelFileUpload(nileFileUpload, uploadRequests);
|
82
|
+
}
|
83
|
+
|
84
|
+
export function handleHoverIn(
|
85
|
+
setState: (state: FileUploadState) => void,
|
86
|
+
currentState: FileUploadState
|
87
|
+
): void {
|
88
|
+
if (currentState === FileUploadState.DEFAULT) {
|
89
|
+
setState(FileUploadState.HOVER);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
export function handleHoverOut(
|
94
|
+
setState: (state: FileUploadState) => void,
|
95
|
+
currentState: FileUploadState
|
96
|
+
): void {
|
97
|
+
if (currentState === FileUploadState.HOVER) {
|
98
|
+
setState(FileUploadState.DEFAULT);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
export function uploadFiles(nileFileUpload: NileFileUpload) {
|
103
|
+
const { uploadedFiles, fileUploadUrl, uploadRequests } = nileFileUpload;
|
104
|
+
if (!fileUploadUrl || !uploadedFiles?.length) return;
|
105
|
+
|
106
|
+
for (const file of uploadedFiles) {
|
107
|
+
const formData = new FormData();
|
108
|
+
formData.append('file', file);
|
109
|
+
|
110
|
+
const xhr = new XMLHttpRequest();
|
111
|
+
uploadRequests.set(file, xhr);
|
112
|
+
|
113
|
+
xhr.upload.onprogress = (e) => {
|
114
|
+
const percent = Math.floor((e.loaded / e.total) * 100);
|
115
|
+
nileFileUpload.dispatchEvent(new CustomEvent(FileUploadEvent.NILE_UPLOAD_PROGRESS, {
|
116
|
+
detail: { file, progress: percent }
|
117
|
+
}));
|
118
|
+
};
|
119
|
+
|
120
|
+
xhr.onload = () => {
|
121
|
+
uploadRequests.delete(file);
|
122
|
+
if (xhr.status === 201) {
|
123
|
+
// Remove the successfully uploaded file
|
124
|
+
nileFileUpload.uploadedFiles = nileFileUpload.uploadedFiles.filter(f => f !== file);
|
125
|
+
|
126
|
+
nileFileUpload.dispatchEvent(new CustomEvent(FileUploadEvent.NILE_UPLOAD_SUCCESS, {
|
127
|
+
detail: { file, response: xhr.response }
|
128
|
+
}));
|
129
|
+
} else {
|
130
|
+
nileFileUpload.dispatchEvent(new CustomEvent(FileUploadEvent.SERVER_SIDE_ERROR, {
|
131
|
+
detail: { file, status: xhr.status, response: xhr.response }
|
132
|
+
}));
|
133
|
+
}
|
134
|
+
};
|
135
|
+
|
136
|
+
xhr.onerror = () => {
|
137
|
+
uploadRequests.delete(file);
|
138
|
+
nileFileUpload.dispatchEvent(new CustomEvent(FileUploadEvent.NILE_NETWORK_ERROR, {
|
139
|
+
detail: { file, status: xhr.status, response: xhr.response }
|
140
|
+
}));
|
141
|
+
};
|
142
|
+
|
143
|
+
xhr.open('POST', fileUploadUrl);
|
144
|
+
xhr.send(formData);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
export const cancelFileUpload = (nileFileUpload: NileFileUpload, uploadRequests: Map<File, XMLHttpRequest>) => {
|
149
|
+
document.addEventListener(FileUploadEvent.NILE_CANCEL_UPLOAD, (e: CustomEvent) => {
|
150
|
+
const fileToCancel = e.detail.file;
|
151
|
+
const xhr = uploadRequests.get(fileToCancel);
|
152
|
+
|
153
|
+
if (xhr) {
|
154
|
+
xhr.abort();
|
155
|
+
}
|
156
|
+
uploadRequests.delete(fileToCancel);
|
157
|
+
nileFileUpload.uploadedFiles = nileFileUpload.uploadedFiles.filter(file => file !== fileToCancel);
|
158
|
+
|
159
|
+
nileFileUpload.dispatchEvent(new CustomEvent(FileUploadEvent.NILE_UPLOAD_CANCELLED, {
|
160
|
+
detail: { file: fileToCancel }
|
161
|
+
}));
|
162
|
+
});
|
163
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { NileFilterChip } from './nile-filter-chip';
|
@@ -0,0 +1,138 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright Aquera Inc 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the BSD-3-Clause license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
import {css} from 'lit';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* FilterChip CSS
|
12
|
+
*/
|
13
|
+
|
14
|
+
export const styles = css`
|
15
|
+
|
16
|
+
|
17
|
+
.filter-chips {
|
18
|
+
display: flex;
|
19
|
+
align-items: center;
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
.chip {
|
24
|
+
display: inline-flex;
|
25
|
+
align-items: center;
|
26
|
+
height: 30px;
|
27
|
+
padding: 8px;
|
28
|
+
border: 1px solid var(--nile-filter-chip-chip-border-color-stroke);
|
29
|
+
border-radius: 4px;
|
30
|
+
font-size: 14px;
|
31
|
+
background-color: var(--nile-filter-chip-background-default);
|
32
|
+
color: var(--nile-filter-chip-text-default);
|
33
|
+
transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
|
34
|
+
cursor: pointer;
|
35
|
+
box-sizing: border-box;
|
36
|
+
}
|
37
|
+
|
38
|
+
.chip:hover {
|
39
|
+
background-color: var(--nile-filter-chip-hover-background);
|
40
|
+
}
|
41
|
+
.chip:active {
|
42
|
+
background-color: var(--nile-filter-chip-active-background);
|
43
|
+
border-color: var(--nile-filter-chip-active-border-color-stroke);
|
44
|
+
}
|
45
|
+
:host([active]) .chip {
|
46
|
+
background-color: var(--nile-filter-chip-active-background);
|
47
|
+
border-color: var(--nile-filter-chip-active-border-color-stroke);
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
.icon {
|
52
|
+
color: var(--nile-filter-chip-icon-color-default);
|
53
|
+
display: flex;
|
54
|
+
align-items: center;
|
55
|
+
justify-content: center;
|
56
|
+
vertical-align: middle;
|
57
|
+
position: relative;
|
58
|
+
top: 12px;
|
59
|
+
}
|
60
|
+
|
61
|
+
.label {
|
62
|
+
font-weight: 500;
|
63
|
+
color: var(--nile-filter-chip-label-color-default);
|
64
|
+
}
|
65
|
+
|
66
|
+
nile-badge::part(base) {
|
67
|
+
width: auto;
|
68
|
+
height: 14px;
|
69
|
+
border-radius: 100px;
|
70
|
+
padding: 6px;
|
71
|
+
gap: 10px;
|
72
|
+
font-size: 8px;
|
73
|
+
display: inline-flex;
|
74
|
+
align-items: center;
|
75
|
+
justify-content: center;
|
76
|
+
line-height: 1;
|
77
|
+
}
|
78
|
+
|
79
|
+
.chip-container {
|
80
|
+
display: flex;
|
81
|
+
justify-content: space-between;
|
82
|
+
align-items: center;
|
83
|
+
width: 100%;
|
84
|
+
}
|
85
|
+
|
86
|
+
.clear-all-container {
|
87
|
+
margin-left: 18px;
|
88
|
+
white-space: nowrap;
|
89
|
+
cursor: pointer;
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
.value {
|
94
|
+
color: var(--nile-filter-chip-values-color-default);
|
95
|
+
display: inline-block;
|
96
|
+
overflow: hidden;
|
97
|
+
text-overflow: ellipsis;
|
98
|
+
white-space: nowrap;
|
99
|
+
max-width: 140px;
|
100
|
+
vertical-align: bottom;
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
.close-icon {
|
105
|
+
color: var(--nile-filter-chip-close-icon-color-default);
|
106
|
+
cursor: pointer;
|
107
|
+
display: flex;
|
108
|
+
align-items: center;
|
109
|
+
border-radius: 50%;
|
110
|
+
transition: background-color 0.2s;
|
111
|
+
}
|
112
|
+
|
113
|
+
.close-icon:hover {
|
114
|
+
background-color: var(--nile-filter-chip-close-icon-hover-background);
|
115
|
+
color: var(--nile-filter-chip-close-icon-hover-color);
|
116
|
+
}
|
117
|
+
|
118
|
+
.label-wrapper {
|
119
|
+
margin-right: 4px;
|
120
|
+
}
|
121
|
+
|
122
|
+
::slotted([slot="icon"]) {
|
123
|
+
margin-right: 6px;
|
124
|
+
}
|
125
|
+
|
126
|
+
.value-wrapper {
|
127
|
+
margin-right: 4px;
|
128
|
+
}
|
129
|
+
|
130
|
+
.badge-wrapper {
|
131
|
+
margin-right: 12px;
|
132
|
+
}
|
133
|
+
|
134
|
+
`;
|
135
|
+
|
136
|
+
export default [styles];
|
137
|
+
|
138
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
import { fixture, expect, html, oneEvent } from '@open-wc/testing';
|
2
|
+
import './nile-filter-chip';
|
3
|
+
import { NileFilterChip } from './nile-filter-chip';
|
4
|
+
|
5
|
+
describe('<nile-filter-chip>', () => {
|
6
|
+
afterEach(() => {
|
7
|
+
(NileFilterChip as any).activeChips = [];
|
8
|
+
});
|
9
|
+
|
10
|
+
it('registers and unregisters itself in activeChips', async () => {
|
11
|
+
const el = await fixture<NileFilterChip>(html`
|
12
|
+
<nile-filter-chip label="L" value="T"></nile-filter-chip>
|
13
|
+
`);
|
14
|
+
expect((NileFilterChip as any).activeChips).to.include(el);
|
15
|
+
el.remove();
|
16
|
+
await el.updateComplete;
|
17
|
+
expect((NileFilterChip as any).activeChips).to.not.include(el);
|
18
|
+
});
|
19
|
+
|
20
|
+
it('renders fallback label and value', async () => {
|
21
|
+
const el = await fixture<NileFilterChip>(html`
|
22
|
+
<nile-filter-chip label="MyLabel" value="MyText"></nile-filter-chip>
|
23
|
+
`);
|
24
|
+
const label = el.shadowRoot!.querySelector('.label')! as HTMLElement;
|
25
|
+
const value = el.shadowRoot!.querySelector('.value')! as HTMLElement;
|
26
|
+
expect(label.textContent).to.equal('MyLabel:');
|
27
|
+
expect(value.textContent!.trim()).to.equal('MyText');
|
28
|
+
});
|
29
|
+
|
30
|
+
it('renders slotted label and value over fallback', async () => {
|
31
|
+
const el = await fixture<NileFilterChip>(html`
|
32
|
+
<nile-filter-chip>
|
33
|
+
<span slot="label">SLOT-LBL</span>
|
34
|
+
<span slot="value">SLOT-VAL</span>
|
35
|
+
</nile-filter-chip>
|
36
|
+
`);
|
37
|
+
const slottedLabel = el.querySelector('[slot="label"]')! as HTMLElement;
|
38
|
+
const slottedValue = el.querySelector('[slot="value"]')! as HTMLElement;
|
39
|
+
expect(slottedLabel.textContent).to.equal('SLOT-LBL');
|
40
|
+
expect(slottedValue.textContent).to.equal('SLOT-VAL');
|
41
|
+
});
|
42
|
+
|
43
|
+
it('renders an icon when the `icon` property is set', async () => {
|
44
|
+
const el = await fixture<NileFilterChip>(html`
|
45
|
+
<nile-filter-chip icon="★" label="L" value="T"></nile-filter-chip>
|
46
|
+
`);
|
47
|
+
const iconSpan = el.shadowRoot!.querySelector('.icon')! as HTMLElement;
|
48
|
+
expect(iconSpan).to.exist;
|
49
|
+
expect(iconSpan.textContent).to.equal('★');
|
50
|
+
});
|
51
|
+
|
52
|
+
it('does not render a badge when viewMoreCount is zero', async () => {
|
53
|
+
const el = await fixture<NileFilterChip>(html`
|
54
|
+
<nile-filter-chip viewMoreCount="0" label="L" value="T"></nile-filter-chip>
|
55
|
+
`);
|
56
|
+
expect(el.shadowRoot!.querySelector('nile-badge')).to.be.null;
|
57
|
+
});
|
58
|
+
|
59
|
+
it('renders a +badge when viewMoreCount > 0', async () => {
|
60
|
+
const el = await fixture<NileFilterChip>(html`
|
61
|
+
<nile-filter-chip viewMoreCount="5" label="L" value="T"></nile-filter-chip>
|
62
|
+
`);
|
63
|
+
const badge = el.shadowRoot!.querySelector('nile-badge')! as HTMLElement;
|
64
|
+
expect(badge).to.exist;
|
65
|
+
expect(badge.textContent).to.contain('+5');
|
66
|
+
});
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
it('dispatches `nile-click` on chip click', async () => {
|
71
|
+
const el = await fixture<NileFilterChip>(html`
|
72
|
+
<nile-filter-chip label="L" value="T"></nile-filter-chip>
|
73
|
+
`);
|
74
|
+
const chip = el.shadowRoot!.querySelector('.chip')! as HTMLElement;
|
75
|
+
setTimeout(() => chip.click());
|
76
|
+
const ev = await oneEvent(el, 'nile-click');
|
77
|
+
expect(ev.detail).to.deep.equal({ value: 'T', viewMoreCount: 0 });
|
78
|
+
});
|
79
|
+
|
80
|
+
it('dispatches `nile-close` on close icon click and removes itself', async () => {
|
81
|
+
const el = await fixture<NileFilterChip>(html`
|
82
|
+
<nile-filter-chip closable viewMoreCount="2" value="TT"></nile-filter-chip>
|
83
|
+
`);
|
84
|
+
const closeIcon = el.shadowRoot!.querySelector('.close-icon')! as HTMLElement;
|
85
|
+
setTimeout(() => closeIcon.click());
|
86
|
+
const ev = await oneEvent(el, 'nile-close');
|
87
|
+
expect(ev.detail).to.deep.equal({ value: 'TT', viewMoreCount: 2 });
|
88
|
+
expect(document.body.contains(el)).to.be.false;
|
89
|
+
});
|
90
|
+
|
91
|
+
|
92
|
+
});
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import { LitElement, html, css, CSSResultArray, TemplateResult } from 'lit';
|
2
|
+
import { customElement, property } from 'lit/decorators.js';
|
3
|
+
import NileElement from '../internal/nile-element';
|
4
|
+
import { styles } from './nile-filter-chip.css';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Nile filter-chip component.
|
8
|
+
*
|
9
|
+
* @tag nile-filter-chip
|
10
|
+
*/
|
11
|
+
@customElement('nile-filter-chip')
|
12
|
+
export class NileFilterChip extends NileElement {
|
13
|
+
@property({ type: String }) label = '';
|
14
|
+
@property({ type: String }) value = '';
|
15
|
+
@property({ type: Number }) viewMoreCount: number = 0;
|
16
|
+
@property({ type: Boolean }) editable = false;
|
17
|
+
@property({ type: Boolean }) closable = false;
|
18
|
+
@property({ type: String }) icon = '';
|
19
|
+
@property({ type: String }) removeIcon = '';
|
20
|
+
@property({ type: Boolean, reflect: true }) active = false;
|
21
|
+
|
22
|
+
|
23
|
+
private static activeChips: NileFilterChip[] = [];
|
24
|
+
|
25
|
+
public static get styles(): CSSResultArray {
|
26
|
+
return [styles];
|
27
|
+
}
|
28
|
+
|
29
|
+
connectedCallback() {
|
30
|
+
super.connectedCallback();
|
31
|
+
this.registerChip();
|
32
|
+
}
|
33
|
+
|
34
|
+
disconnectedCallback() {
|
35
|
+
super.disconnectedCallback();
|
36
|
+
this.unregisterChip();
|
37
|
+
}
|
38
|
+
|
39
|
+
private registerChip() {
|
40
|
+
NileFilterChip.activeChips.push(this);
|
41
|
+
}
|
42
|
+
|
43
|
+
private unregisterChip() {
|
44
|
+
NileFilterChip.activeChips = NileFilterChip.activeChips.filter(
|
45
|
+
(chip) => chip !== this
|
46
|
+
);
|
47
|
+
}
|
48
|
+
|
49
|
+
private handleClose(event: Event) {
|
50
|
+
event.stopPropagation();
|
51
|
+
this.dispatchEvent(
|
52
|
+
new CustomEvent('nile-close', { detail: { value: this.value, viewMoreCount: this.viewMoreCount } })
|
53
|
+
);
|
54
|
+
this.remove();
|
55
|
+
}
|
56
|
+
|
57
|
+
private handleClick() {
|
58
|
+
this.dispatchEvent(
|
59
|
+
new CustomEvent('nile-click', { detail: { value: this.value, viewMoreCount: this.viewMoreCount } })
|
60
|
+
);
|
61
|
+
}
|
62
|
+
|
63
|
+
private getLabelSlot(): TemplateResult {
|
64
|
+
return html`
|
65
|
+
<span class="label-wrapper">
|
66
|
+
<slot name="label">
|
67
|
+
<span class="label" part="label">${this.label}:</span>
|
68
|
+
</slot>
|
69
|
+
</span>
|
70
|
+
|
71
|
+
`;
|
72
|
+
}
|
73
|
+
|
74
|
+
private getValueSlot(): TemplateResult {
|
75
|
+
return html`
|
76
|
+
<span class="value-wrapper">
|
77
|
+
<slot name="value">
|
78
|
+
<span class="value" part="value">${this.value}</span>
|
79
|
+
</slot>
|
80
|
+
</span>
|
81
|
+
|
82
|
+
`;
|
83
|
+
}
|
84
|
+
|
85
|
+
private getviewMoreCountSlot(): TemplateResult {
|
86
|
+
return html`
|
87
|
+
<slot name="suffix">
|
88
|
+
${this.viewMoreCount
|
89
|
+
? html`
|
90
|
+
<span class="badge-wrapper">
|
91
|
+
<nile-badge variant="primary" pilltype="pill-color">
|
92
|
+
+${this.viewMoreCount}
|
93
|
+
</nile-badge>
|
94
|
+
</span>
|
95
|
+
|
96
|
+
`
|
97
|
+
: html``}
|
98
|
+
</slot>
|
99
|
+
`;
|
100
|
+
}
|
101
|
+
|
102
|
+
private getCloseIconSlot(): TemplateResult {
|
103
|
+
return html`
|
104
|
+
${this.closable
|
105
|
+
? html`
|
106
|
+
<span class="close-icon" @click="${this.handleClose}">
|
107
|
+
<nile-icon name="${this.removeIcon || 'close'}" size="12"></nile-icon>
|
108
|
+
</span>
|
109
|
+
`
|
110
|
+
: html``}
|
111
|
+
`;
|
112
|
+
}
|
113
|
+
|
114
|
+
public render(): TemplateResult {
|
115
|
+
return html`
|
116
|
+
<div class="chip" @click="${this.handleClick}">
|
117
|
+
<slot name="icon">
|
118
|
+
${this.icon ? html`<span class="icon">${this.icon}</span>` : html``}
|
119
|
+
</slot>
|
120
|
+
${this.getLabelSlot()}
|
121
|
+
<slot name="content"></slot>
|
122
|
+
${this.getValueSlot()}
|
123
|
+
${this.getviewMoreCountSlot()}
|
124
|
+
${this.getCloseIconSlot()}
|
125
|
+
</div>
|
126
|
+
`;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
export default NileFilterChip;
|
131
|
+
|
132
|
+
declare global {
|
133
|
+
interface HTMLElementTagNameMap {
|
134
|
+
'nile-filter-chip': NileFilterChip;
|
135
|
+
}
|
136
|
+
}
|