@usecapsule/core-components 3.0.1 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/css/capsule-core.css +93 -24
- package/css/capsule-core.css.map +1 -1
- package/dist/capsule/capsule.esm.js +1 -1
- package/dist/capsule/capsule.esm.js.map +1 -1
- package/dist/capsule/index.esm.js +1 -1
- package/dist/capsule/index.esm.js.map +1 -1
- package/dist/capsule/p-02072c68.entry.js +2 -0
- package/dist/capsule/p-02072c68.entry.js.map +1 -0
- package/dist/capsule/p-1474c545.entry.js +29 -0
- package/dist/capsule/p-1474c545.entry.js.map +1 -0
- package/dist/capsule/p-2c16694d.entry.js +2 -0
- package/dist/capsule/p-41088cd4.entry.js +2 -0
- package/dist/capsule/{p-fcead80b.entry.js.map → p-41088cd4.entry.js.map} +1 -1
- package/dist/capsule/{p-fa078837.entry.js → p-6dcaee48.entry.js} +2 -2
- package/dist/capsule/p-7dde3172.js +3 -0
- package/dist/capsule/p-7dde3172.js.map +1 -0
- package/dist/capsule/{p-d28b96ba.entry.js → p-a6aaf3f4.entry.js} +2 -2
- package/dist/capsule/{p-0d0a0037.entry.js → p-b976b6f0.entry.js} +2 -2
- package/dist/capsule/p-f2393be6.js +2 -0
- package/dist/capsule/p-f2393be6.js.map +1 -0
- package/dist/cjs/capsule.cjs.js +2 -2
- package/dist/cjs/{constants-0869a780.js → constants-9b1b01bb.js} +3 -3
- package/dist/cjs/{constants-0869a780.js.map → constants-9b1b01bb.js.map} +1 -1
- package/dist/cjs/{cpsl-alert_29.cjs.entry.js → cpsl-alert_33.cjs.entry.js} +662 -87
- package/dist/cjs/cpsl-alert_33.cjs.entry.js.map +1 -0
- package/dist/cjs/cpsl-animation.cjs.entry.js +1 -1
- package/dist/cjs/cpsl-col.cjs.entry.js +1 -1
- package/dist/cjs/cpsl-grid.cjs.entry.js +3 -3
- package/dist/cjs/cpsl-info-box.cjs.entry.js +3 -3
- package/dist/cjs/cpsl-info-box.cjs.entry.js.map +1 -1
- package/dist/cjs/cpsl-modal-v2.cjs.entry.js +55 -0
- package/dist/cjs/cpsl-modal-v2.cjs.entry.js.map +1 -0
- package/dist/cjs/cpsl-row.cjs.entry.js +2 -2
- package/dist/cjs/{index-5733071e.js → index-528f7428.js} +86 -3
- package/dist/cjs/index-528f7428.js.map +1 -0
- package/dist/cjs/index.cjs.js +116 -107
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/assets/icons/chevron-up.svg +2 -2
- package/dist/collection/assets/icons/close.svg +3 -4
- package/dist/collection/assets/icons/cube.svg +3 -0
- package/dist/collection/assets/icons/farcaster-brand.svg +10 -0
- package/dist/collection/assets/icons/farcaster.svg +10 -0
- package/dist/collection/assets/icons/image.svg +3 -0
- package/dist/collection/assets/icons/index.js +9 -1
- package/dist/collection/assets/icons/index.js.map +1 -1
- package/dist/collection/assets/icons/menu.svg +3 -0
- package/dist/collection/assets/icons/refresh.svg +3 -0
- package/dist/collection/assets/icons/stars.svg +4 -0
- package/dist/collection/assets/icons/x.svg +3 -0
- package/dist/collection/collection-manifest.json +5 -0
- package/dist/collection/components/cpsl-alert/cpsl-alert.js +1 -1
- package/dist/collection/components/cpsl-app-bar/cpsl-app-bar.js +20 -4
- package/dist/collection/components/cpsl-app-bar/cpsl-app-bar.js.map +1 -1
- package/dist/collection/components/cpsl-button/cpsl-button.css +113 -17
- package/dist/collection/components/cpsl-button/cpsl-button.js +63 -7
- package/dist/collection/components/cpsl-button/cpsl-button.js.map +1 -1
- package/dist/collection/components/cpsl-button-group/cpsl-button-group.css +1 -0
- package/dist/collection/components/cpsl-card/cpsl-card.css +1 -1
- package/dist/collection/components/cpsl-card/cpsl-card.js +1 -1
- package/dist/collection/components/cpsl-card/cpsl-card.js.map +1 -1
- package/dist/collection/components/cpsl-checkbox/cpsl-checkbox.css +2 -2
- package/dist/collection/components/cpsl-code-input/cpsl-code-input.css +1 -1
- package/dist/collection/components/cpsl-divider/cpsl-divider.css +1 -1
- package/dist/collection/components/cpsl-drawer/cpsl-drawer.js +84 -11
- package/dist/collection/components/cpsl-drawer/cpsl-drawer.js.map +1 -1
- package/dist/collection/components/cpsl-dropdown/cpsl-dropdown.js +1 -1
- package/dist/collection/components/cpsl-dropdown/cpsl-dropdown.js.map +1 -1
- package/dist/collection/components/cpsl-file-upload/cpsl-file-upload.css +211 -0
- package/dist/collection/components/cpsl-file-upload/cpsl-file-upload.js +406 -0
- package/dist/collection/components/cpsl-file-upload/cpsl-file-upload.js.map +1 -0
- package/dist/collection/components/cpsl-file-upload/test/cpsl-file-upload.e2e.js +29 -0
- package/dist/collection/components/cpsl-file-upload/test/cpsl-file-upload.e2e.js.map +1 -0
- package/dist/collection/components/cpsl-file-upload/test/cpsl-file-upload.spec.js +37 -0
- package/dist/collection/components/cpsl-file-upload/test/cpsl-file-upload.spec.js.map +1 -0
- package/dist/collection/components/cpsl-grid/cpsl-grid.js +2 -2
- package/dist/collection/components/cpsl-icon/cpsl-icon.js +2 -2
- package/dist/collection/components/cpsl-info-box/cpsl-info-box.css +1 -1
- package/dist/collection/components/cpsl-info-box/cpsl-info-box.js +1 -1
- package/dist/collection/components/cpsl-input/cpsl-input.css +7 -6
- package/dist/collection/components/cpsl-input/cpsl-input.js +3 -8
- package/dist/collection/components/cpsl-input/cpsl-input.js.map +1 -1
- package/dist/collection/components/cpsl-modal/cpsl-modal.css +4 -4
- package/dist/collection/components/cpsl-modal/cpsl-modal.js +1 -0
- package/dist/collection/components/cpsl-modal/cpsl-modal.js.map +1 -1
- package/dist/collection/components/cpsl-modal-v2/cpsl-modal-v2.css +91 -0
- package/dist/collection/components/cpsl-modal-v2/cpsl-modal-v2.js +224 -0
- package/dist/collection/components/cpsl-modal-v2/cpsl-modal-v2.js.map +1 -0
- package/dist/collection/components/cpsl-modal-v2/test/cpsl-modal-v2.e2e.js +29 -0
- package/dist/collection/components/cpsl-modal-v2/test/cpsl-modal-v2.e2e.js.map +1 -0
- package/dist/collection/components/cpsl-modal-v2/test/cpsl-modal-v2.spec.js +37 -0
- package/dist/collection/components/cpsl-modal-v2/test/cpsl-modal-v2.spec.js.map +1 -0
- package/dist/collection/components/cpsl-nav-button-group/cpsl-nav-button-group.js +1 -1
- package/dist/collection/components/cpsl-overlay/cpsl-overlay.css +1 -1
- package/dist/collection/components/cpsl-overlay/cpsl-overlay.js +1 -1
- package/dist/collection/components/cpsl-pagination/cpsl-pagination.css +4 -0
- package/dist/collection/components/cpsl-pagination/cpsl-pagination.js +1 -1
- package/dist/collection/components/cpsl-pagination/cpsl-pagination.js.map +1 -1
- package/dist/collection/components/cpsl-pill/cpsl-pill.css +1 -1
- package/dist/collection/components/cpsl-pill/cpsl-pill.js +1 -1
- package/dist/collection/components/cpsl-popover/cpsl-popover.css +98 -0
- package/dist/collection/components/cpsl-popover/cpsl-popover.js +511 -0
- package/dist/collection/components/cpsl-popover/cpsl-popover.js.map +1 -0
- package/dist/collection/components/cpsl-popover/test/cpsl-popover.e2e.js +29 -0
- package/dist/collection/components/cpsl-popover/test/cpsl-popover.e2e.js.map +1 -0
- package/dist/collection/components/cpsl-popover/test/cpsl-popover.spec.js +37 -0
- package/dist/collection/components/cpsl-popover/test/cpsl-popover.spec.js.map +1 -0
- package/dist/collection/components/cpsl-progress-indicator/cpsl-progress-indicator.css +3 -3
- package/dist/collection/components/cpsl-qr-code/cpsl-qr-code.css +1 -1
- package/dist/collection/components/cpsl-qr-code/cpsl-qr-code.js +1 -1
- package/dist/collection/components/cpsl-radio/cpsl-radio.css +2 -2
- package/dist/collection/components/cpsl-radio/cpsl-radio.js +1 -1
- package/dist/collection/components/cpsl-row/cpsl-row.js +1 -1
- package/dist/collection/components/cpsl-select/cpsl-select.css +229 -0
- package/dist/collection/components/cpsl-select/cpsl-select.js +409 -0
- package/dist/collection/components/cpsl-select/cpsl-select.js.map +1 -0
- package/dist/collection/components/cpsl-select/test/cpsl-select.e2e.js +29 -0
- package/dist/collection/components/cpsl-select/test/cpsl-select.e2e.js.map +1 -0
- package/dist/collection/components/cpsl-select/test/cpsl-select.spec.js +37 -0
- package/dist/collection/components/cpsl-select/test/cpsl-select.spec.js.map +1 -0
- package/dist/collection/components/cpsl-select-item/cpsl-select-item.css +114 -0
- package/dist/collection/components/cpsl-select-item/cpsl-select-item.js +85 -0
- package/dist/collection/components/cpsl-select-item/cpsl-select-item.js.map +1 -0
- package/dist/collection/components/cpsl-select-item/test/cpsl-select-item.e2e.js +29 -0
- package/dist/collection/components/cpsl-select-item/test/cpsl-select-item.e2e.js.map +1 -0
- package/dist/collection/components/cpsl-select-item/test/cpsl-select-item.spec.js +37 -0
- package/dist/collection/components/cpsl-select-item/test/cpsl-select-item.spec.js.map +1 -0
- package/dist/collection/components/cpsl-slide-button/cpsl-slide-button.css +3 -3
- package/dist/collection/components/cpsl-slide-button/cpsl-slide-button.js +3 -3
- package/dist/collection/components/cpsl-spinner/cpsl-spinner.js +2 -2
- package/dist/collection/components/cpsl-switch/cpsl-switch.css +4 -4
- package/dist/collection/components/cpsl-switch/cpsl-switch.js +1 -1
- package/dist/collection/components/cpsl-tab/cpsl-tab.js +1 -1
- package/dist/collection/components/cpsl-table/cpsl-table.css +40 -60
- package/dist/collection/components/cpsl-table/cpsl-table.js +40 -58
- package/dist/collection/components/cpsl-table/cpsl-table.js.map +1 -1
- package/dist/collection/components/cpsl-tabs/cpsl-tabs.css +2 -2
- package/dist/collection/components/cpsl-tabs/cpsl-tabs.js +1 -1
- package/dist/collection/components/cpsl-text/cpsl-text.css +4 -0
- package/dist/collection/components/cpsl-text/cpsl-text.js +5 -4
- package/dist/collection/components/cpsl-text/cpsl-text.js.map +1 -1
- package/dist/collection/components/cpsl-tile-button/cpsl-tile-button.css +1 -1
- package/dist/collection/components/cpsl-tile-button/cpsl-tile-button.js +2 -2
- package/dist/collection/constants.js +2 -2
- package/dist/collection/constants.js.map +1 -1
- package/dist/collection/interface.js.map +1 -1
- package/dist/collection/utils/theme/generateBorderRadii.js +40 -39
- package/dist/collection/utils/theme/generateBorderRadii.js.map +1 -1
- package/dist/collection/utils/theme/generatePalette.js +11 -3
- package/dist/collection/utils/theme/generatePalette.js.map +1 -1
- package/dist/collection/utils/theme/generateTheme.js +2 -2
- package/dist/collection/utils/theme/generateTheme.js.map +1 -1
- package/dist/collection/utils/theme/utils.js +1 -0
- package/dist/collection/utils/theme/utils.js.map +1 -1
- package/dist/esm/capsule.js +3 -3
- package/dist/esm/{constants-6acf4ea8.js → constants-fce138fa.js} +3 -3
- package/dist/esm/{constants-6acf4ea8.js.map → constants-fce138fa.js.map} +1 -1
- package/dist/esm/{cpsl-alert_29.entry.js → cpsl-alert_33.entry.js} +659 -88
- package/dist/esm/cpsl-alert_33.entry.js.map +1 -0
- package/dist/esm/cpsl-animation.entry.js +1 -1
- package/dist/esm/cpsl-col.entry.js +1 -1
- package/dist/esm/cpsl-grid.entry.js +3 -3
- package/dist/esm/cpsl-info-box.entry.js +3 -3
- package/dist/esm/cpsl-info-box.entry.js.map +1 -1
- package/dist/esm/cpsl-modal-v2.entry.js +51 -0
- package/dist/esm/cpsl-modal-v2.entry.js.map +1 -0
- package/dist/esm/cpsl-row.entry.js +2 -2
- package/dist/esm/{index-8fe9f35e.js → index-b188f201.js} +86 -4
- package/dist/esm/index-b188f201.js.map +1 -0
- package/dist/esm/index.js +116 -107
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/types/assets/icons/index.d.ts +8 -0
- package/dist/types/components/cpsl-app-bar/cpsl-app-bar.d.ts +1 -0
- package/dist/types/components/cpsl-button/cpsl-button.d.ts +4 -1
- package/dist/types/components/cpsl-drawer/cpsl-drawer.d.ts +10 -1
- package/dist/types/components/cpsl-file-upload/cpsl-file-upload.d.ts +34 -0
- package/dist/types/components/cpsl-input/cpsl-input.d.ts +1 -1
- package/dist/types/components/cpsl-modal-v2/cpsl-modal-v2.d.ts +17 -0
- package/dist/types/components/cpsl-popover/cpsl-popover.d.ts +35 -0
- package/dist/types/components/cpsl-select/cpsl-select.d.ts +38 -0
- package/dist/types/components/cpsl-select-item/cpsl-select-item.d.ts +8 -0
- package/dist/types/components/cpsl-table/cpsl-table.d.ts +8 -3
- package/dist/types/components/cpsl-text/cpsl-text.d.ts +1 -1
- package/dist/types/components.d.ts +596 -28
- package/dist/types/constants.d.ts +2 -2
- package/dist/types/interface.d.ts +68 -1
- package/dist/types/utils/theme/generateBorderRadii.d.ts +1 -1
- package/dist/types/utils/theme/generateTheme.d.ts +1 -1
- package/dist/types/utils/theme/utils.d.ts +4 -1
- package/package.json +2 -2
- package/dist/capsule/p-107e1ff5.entry.js +0 -29
- package/dist/capsule/p-107e1ff5.entry.js.map +0 -1
- package/dist/capsule/p-86e48e61.js +0 -3
- package/dist/capsule/p-86e48e61.js.map +0 -1
- package/dist/capsule/p-ad14a817.entry.js +0 -2
- package/dist/capsule/p-b6b38e73.js +0 -2
- package/dist/capsule/p-b6b38e73.js.map +0 -1
- package/dist/capsule/p-fcead80b.entry.js +0 -2
- package/dist/cjs/cpsl-alert_29.cjs.entry.js.map +0 -1
- package/dist/cjs/index-5733071e.js.map +0 -1
- package/dist/collection/components/cpsl-table/table-interface.js +0 -2
- package/dist/collection/components/cpsl-table/table-interface.js.map +0 -1
- package/dist/esm/cpsl-alert_29.entry.js.map +0 -1
- package/dist/esm/index-8fe9f35e.js.map +0 -1
- package/dist/types/components/cpsl-table/table-interface.d.ts +0 -19
- /package/dist/capsule/{p-ad14a817.entry.js.map → p-2c16694d.entry.js.map} +0 -0
- /package/dist/capsule/{p-fa078837.entry.js.map → p-6dcaee48.entry.js.map} +0 -0
- /package/dist/capsule/{p-d28b96ba.entry.js.map → p-a6aaf3f4.entry.js.map} +0 -0
- /package/dist/capsule/{p-0d0a0037.entry.js.map → p-b976b6f0.entry.js.map} +0 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
/**
|
2
|
+
* Convert a font size to a dynamic font size.
|
3
|
+
* Fonts that participate in Dynamic Type should use
|
4
|
+
* dynamic font sizes.
|
5
|
+
* @param size - The initial font size including the unit (i.e. px or pt)
|
6
|
+
* @param unit (optional) - The unit to convert to. Use this if you want to
|
7
|
+
* convert to a unit other than $baselineUnit.
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* Convert a font size to a dynamic font size but impose
|
11
|
+
* a maximum font size.
|
12
|
+
* @param size - The initial font size including the unit (i.e. px or pt)
|
13
|
+
* @param maxScale - The maximum scale of the font (i.e. 2.5 for a maximum 250% scale).
|
14
|
+
* @param unit (optional) - The unit to convert the initial font size to. Use this if you want to
|
15
|
+
* convert to a unit other than $baselineUnit.
|
16
|
+
*/
|
17
|
+
/**
|
18
|
+
* Convert a font size to a dynamic font size but impose
|
19
|
+
* a minimum font size.
|
20
|
+
* @param size - The initial font size including the unit (i.e. px or pt)
|
21
|
+
* @param minScale - The minimum scale of the font (i.e. 0.8 for a minimum 80% scale).
|
22
|
+
* @param unit (optional) - The unit to convert the initial font size to. Use this if you want to
|
23
|
+
* convert to a unit other than $baselineUnit.
|
24
|
+
*/
|
25
|
+
/**
|
26
|
+
* Convert a font size to a dynamic font size but impose
|
27
|
+
* maximum and minimum font sizes.
|
28
|
+
* @param size - The initial font size including the unit (i.e. px or pt)
|
29
|
+
* @param minScale - The minimum scale of the font (i.e. 0.8 for a minimum 80% scale).
|
30
|
+
* @param maxScale - The maximum scale of the font (i.e. 2.5 for a maximum 250% scale).
|
31
|
+
* @param unit (optional) - The unit to convert the initial font size to. Use this if you want to
|
32
|
+
* convert to a unit other than $baselineUnit.
|
33
|
+
*/
|
34
|
+
/**
|
35
|
+
* A heuristic that applies CSS to tablet
|
36
|
+
* viewports.
|
37
|
+
*
|
38
|
+
* Usage:
|
39
|
+
* @include tablet-viewport() {
|
40
|
+
* :host {
|
41
|
+
* background-color: green;
|
42
|
+
* }
|
43
|
+
* }
|
44
|
+
*/
|
45
|
+
/**
|
46
|
+
* A heuristic that applies CSS to mobile
|
47
|
+
* viewports (i.e. phones, not tablets).
|
48
|
+
*
|
49
|
+
* Usage:
|
50
|
+
* @include mobile-viewport() {
|
51
|
+
* :host {
|
52
|
+
* background-color: blue;
|
53
|
+
* }
|
54
|
+
* }
|
55
|
+
*/
|
56
|
+
:host {
|
57
|
+
--container-box-shadow: none;
|
58
|
+
--container-box-shadow-color: var(--cpsl-color-file-border-placeholder);
|
59
|
+
--container-border-color: var(--cpsl-color-file-border-placeholder);
|
60
|
+
--container-border-color-error: var(--cpsl-color-file-border-error);
|
61
|
+
--container-background-color: var(--cpsl-color-file-surface-default);
|
62
|
+
--container-background-color-disabled: var(--cpsl-color-file-surface-disabled);
|
63
|
+
--container-background-color-drag: var(--cpsl-color-file-surface-drag);
|
64
|
+
--container-border-width: 1px;
|
65
|
+
--container-border-radius: var(--cpsl-border-radius-file);
|
66
|
+
--container-padding-top: 12px;
|
67
|
+
--container-padding-bottom: 12px;
|
68
|
+
--container-padding-end: 12px;
|
69
|
+
--container-padding-start: 12px;
|
70
|
+
--container-height: 48px;
|
71
|
+
--container-gap: 8px;
|
72
|
+
--optional-label-color: var(--cpsl-color-text-secondary);
|
73
|
+
--label-color: var(--cpsl-color-text-primary);
|
74
|
+
--label-font-size: var(--cpsl-font-size-body-s);
|
75
|
+
--label-margin-bottom: 0px;
|
76
|
+
--helper-text-color: var(--cpsl-color-text-secondary);
|
77
|
+
--helper-text-error-color: var(--cpsl-color-text-error);
|
78
|
+
--helper-text-icon-color: var(--cpsl-color-text-secondary);
|
79
|
+
--helper-text-icon-error-color: var(--cpsl-color-text-error);
|
80
|
+
--helper-text-icon-size: 16px;
|
81
|
+
--helper-text-font-size: var(--cpsl-font-size-body-xs);
|
82
|
+
--helper-text-margin-top: 0px;
|
83
|
+
--sample-img-height: 40px;
|
84
|
+
--sample-img-width: 40px;
|
85
|
+
--sample-img-border-radius: 8px;
|
86
|
+
display: flex;
|
87
|
+
flex-direction: column;
|
88
|
+
gap: 4px;
|
89
|
+
font-family: var(--cpsl-font-family, inherit);
|
90
|
+
}
|
91
|
+
|
92
|
+
.container {
|
93
|
+
-webkit-padding-start: var(--container-padding-start);
|
94
|
+
padding-inline-start: var(--container-padding-start);
|
95
|
+
-webkit-padding-end: var(--container-padding-end);
|
96
|
+
padding-inline-end: var(--container-padding-end);
|
97
|
+
padding-top: var(--container-padding-top);
|
98
|
+
padding-bottom: var(--container-padding-bottom);
|
99
|
+
display: flex;
|
100
|
+
align-items: center;
|
101
|
+
box-sizing: border-box;
|
102
|
+
flex-wrap: wrap;
|
103
|
+
width: 100%;
|
104
|
+
gap: var(--container-gap);
|
105
|
+
cursor: pointer;
|
106
|
+
position: relative;
|
107
|
+
border-style: solid;
|
108
|
+
border-width: var(--container-border-width);
|
109
|
+
border-color: var(--container-border-color);
|
110
|
+
border-radius: var(--container-border-radius);
|
111
|
+
background: var(--container-background-color);
|
112
|
+
box-shadow: var(--container-box-shadow);
|
113
|
+
}
|
114
|
+
.container.drag, .container:active {
|
115
|
+
background: var(--container-background-color-drag);
|
116
|
+
}
|
117
|
+
.container.drag-error {
|
118
|
+
cursor: no-drop;
|
119
|
+
}
|
120
|
+
.container.error {
|
121
|
+
border-color: var(--container-border-color-error);
|
122
|
+
}
|
123
|
+
|
124
|
+
input {
|
125
|
+
position: absolute;
|
126
|
+
width: 100%;
|
127
|
+
height: 100%;
|
128
|
+
top: 0;
|
129
|
+
left: 0;
|
130
|
+
margin: 0px;
|
131
|
+
opacity: 0;
|
132
|
+
cursor: pointer;
|
133
|
+
}
|
134
|
+
|
135
|
+
.sample-img {
|
136
|
+
height: var(--sample-img-height);
|
137
|
+
width: var(--sample-img-width);
|
138
|
+
border-radius: var(--sample-img-border-radius);
|
139
|
+
object-fit: contain;
|
140
|
+
}
|
141
|
+
|
142
|
+
.sample-image-name-container {
|
143
|
+
display: flex;
|
144
|
+
gap: 4px;
|
145
|
+
align-items: center;
|
146
|
+
text-align: center;
|
147
|
+
}
|
148
|
+
.sample-image-name-container cpsl-icon {
|
149
|
+
z-index: 10000;
|
150
|
+
--height: 16px;
|
151
|
+
--width: 16px;
|
152
|
+
}
|
153
|
+
|
154
|
+
.inline-text {
|
155
|
+
display: inline-block;
|
156
|
+
}
|
157
|
+
|
158
|
+
.sample-image-name {
|
159
|
+
display: inline-block;
|
160
|
+
color: var(--cpsl-color-text-tertiary);
|
161
|
+
}
|
162
|
+
|
163
|
+
.label-container {
|
164
|
+
flex: 1;
|
165
|
+
}
|
166
|
+
|
167
|
+
.file-container {
|
168
|
+
display: flex;
|
169
|
+
flex-direction: column;
|
170
|
+
flex: 1;
|
171
|
+
gap: 8px;
|
172
|
+
justify-content: center;
|
173
|
+
align-items: center;
|
174
|
+
}
|
175
|
+
|
176
|
+
.label {
|
177
|
+
display: inline-block;
|
178
|
+
color: var(--label-color);
|
179
|
+
font-size: var(--label-font-size);
|
180
|
+
font-weight: 500;
|
181
|
+
margin-bottom: var(--label-margin-bottom);
|
182
|
+
}
|
183
|
+
|
184
|
+
.optional-label {
|
185
|
+
display: inline-block;
|
186
|
+
color: var(--optional-label-color);
|
187
|
+
font-size: var(--label-font-size);
|
188
|
+
font-weight: 500;
|
189
|
+
}
|
190
|
+
|
191
|
+
.helper-text-container {
|
192
|
+
display: flex;
|
193
|
+
align-items: center;
|
194
|
+
gap: 4px;
|
195
|
+
color: var(--helper-text-color);
|
196
|
+
font-size: var(--helper-text-font-size);
|
197
|
+
font-weight: 500;
|
198
|
+
margin-top: var(--helper-text-margin-top);
|
199
|
+
}
|
200
|
+
.helper-text-container cpsl-icon {
|
201
|
+
--height: var(--helper-text-icon-size);
|
202
|
+
--width: var(--helper-text-icon-size);
|
203
|
+
--icon-color: var(--helper-text-icon-color);
|
204
|
+
}
|
205
|
+
|
206
|
+
.error-text {
|
207
|
+
color: var(--helper-text-error-color);
|
208
|
+
}
|
209
|
+
.error-text cpsl-icon {
|
210
|
+
--icon-color: var(--helper-text-icon-error-color);
|
211
|
+
}
|
@@ -0,0 +1,406 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try {
|
5
|
+
step(generator.next(value));
|
6
|
+
}
|
7
|
+
catch (e) {
|
8
|
+
reject(e);
|
9
|
+
} }
|
10
|
+
function rejected(value) { try {
|
11
|
+
step(generator["throw"](value));
|
12
|
+
}
|
13
|
+
catch (e) {
|
14
|
+
reject(e);
|
15
|
+
} }
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
18
|
+
});
|
19
|
+
};
|
20
|
+
import { Host, h, Fragment } from "@stencil/core";
|
21
|
+
export class CpslFileUpload {
|
22
|
+
constructor() {
|
23
|
+
this.inputId = `cpsl-file-upload-${inputIds++}`;
|
24
|
+
this.handleDrop = (ev) => __awaiter(this, void 0, void 0, function* () {
|
25
|
+
var _a;
|
26
|
+
ev.preventDefault();
|
27
|
+
const item = (_a = Array.from(ev.dataTransfer.items)) === null || _a === void 0 ? void 0 : _a[0];
|
28
|
+
if (item && this.isValidFile(item.type)) {
|
29
|
+
const file = item.getAsFile();
|
30
|
+
yield this.addFile(file);
|
31
|
+
}
|
32
|
+
this.dragOver = false;
|
33
|
+
this.dragError = false;
|
34
|
+
this.cpslOnDrop.emit(ev);
|
35
|
+
});
|
36
|
+
this.handleDragEnter = (ev) => {
|
37
|
+
var _a;
|
38
|
+
ev.preventDefault();
|
39
|
+
this.dragOver = true;
|
40
|
+
const item = (_a = Array.from(ev.dataTransfer.items)) === null || _a === void 0 ? void 0 : _a[0];
|
41
|
+
if (item && this.isValidFile(item.type)) {
|
42
|
+
this.dragError = true;
|
43
|
+
}
|
44
|
+
this.cpslOnDragEnter.emit(ev);
|
45
|
+
};
|
46
|
+
this.handleDragLeave = (ev) => {
|
47
|
+
ev.preventDefault();
|
48
|
+
this.dragOver = false;
|
49
|
+
this.dragError = false;
|
50
|
+
this.cpslOnDragLeave.emit(ev);
|
51
|
+
};
|
52
|
+
this.handleInputChange = (ev) => __awaiter(this, void 0, void 0, function* () {
|
53
|
+
ev.preventDefault();
|
54
|
+
const input = this.inputEl;
|
55
|
+
if (Boolean(input.files.length)) {
|
56
|
+
const file = input.files[0];
|
57
|
+
if (this.isValidFile(file.type)) {
|
58
|
+
yield this.addFile(file);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
});
|
62
|
+
this.isValidFile = (type) => {
|
63
|
+
var _a;
|
64
|
+
if (Boolean((_a = this.fileTypes) === null || _a === void 0 ? void 0 : _a.length) ? !this.fileTypes.includes(type) : false) {
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
return true;
|
68
|
+
};
|
69
|
+
this.addFile = (file) => __awaiter(this, void 0, void 0, function* () {
|
70
|
+
this.file = file;
|
71
|
+
this.cpslFileChange.emit(file);
|
72
|
+
this.uploadError = false;
|
73
|
+
this.isUploading = true;
|
74
|
+
const uploadSuccess = Boolean(this.uploadFile) ? yield this.uploadFile(file) : true;
|
75
|
+
if (!uploadSuccess) {
|
76
|
+
this.uploadError = true;
|
77
|
+
const input = this.inputEl;
|
78
|
+
input.value = '';
|
79
|
+
}
|
80
|
+
this.isUploading = false;
|
81
|
+
});
|
82
|
+
this.removeFile = (e) => {
|
83
|
+
e.preventDefault();
|
84
|
+
this.file = undefined;
|
85
|
+
const input = this.inputEl;
|
86
|
+
input.value = '';
|
87
|
+
this.cpslFileRemoved.emit();
|
88
|
+
};
|
89
|
+
this.file = undefined;
|
90
|
+
this.dragOver = undefined;
|
91
|
+
this.dragError = undefined;
|
92
|
+
this.isUploading = undefined;
|
93
|
+
this.uploadError = undefined;
|
94
|
+
this.errorText = undefined;
|
95
|
+
this.externalFilename = undefined;
|
96
|
+
this.externalSrc = undefined;
|
97
|
+
this.fileTypes = undefined;
|
98
|
+
this.helperText = undefined;
|
99
|
+
this.label = undefined;
|
100
|
+
this.required = false;
|
101
|
+
this.showOptionalLabel = false;
|
102
|
+
this.uploadFile = undefined;
|
103
|
+
}
|
104
|
+
get inputEl() {
|
105
|
+
return this.el.shadowRoot.getElementById(this.inputId);
|
106
|
+
}
|
107
|
+
get FileContent() {
|
108
|
+
var _a;
|
109
|
+
const hasFile = Boolean(this.file) || Boolean(this.externalSrc);
|
110
|
+
const isUploading = this.isUploading;
|
111
|
+
const error = this.uploadError;
|
112
|
+
const text = !hasFile ? (h(Fragment, null, 'Drag file here or ', h("cpsl-text", { class: "inline-text", variant: "bodyXS" }, "upload file"))) : isUploading ? (`${this.file.name} is uploading`) : error ? ('Upload Failed') : (((_a = this.file) === null || _a === void 0 ? void 0 : _a.name) || this.externalFilename || '');
|
113
|
+
const TopElement = !hasFile ? (h("cpsl-icon", { icon: "image" })) : isUploading ? (h("cpsl-spinner", null)) : error ? (h("cpsl-icon", { icon: "close" })) : (h("img", { class: "sample-img", src: Boolean(this.file) ? URL.createObjectURL(this.file) : this.externalSrc, alt: "Sample Image" }));
|
114
|
+
return (h(Fragment, null, TopElement, h("span", { class: "sample-image-name-container" }, h("cpsl-text", { class: "sample-image-name", variant: "bodyXS" }, text), hasFile && !error && !isUploading && h("cpsl-icon", { icon: "close", onClick: this.removeFile }))));
|
115
|
+
}
|
116
|
+
render() {
|
117
|
+
var _a, _b, _c;
|
118
|
+
return (h(Host, { key: '71d945bcac5d443719737781fd9ec5166952760d' }, this.label && (h("label", { class: "label", htmlFor: this.inputId }, this.label, this.required ? '*' : ' ', !this.required && this.showOptionalLabel ? h("span", { class: "optional-label" }, "(optional)") : '')), h("slot", { key: '63786e91e0a230d85344da507d0508ac1524cc88', name: "label" }), h("div", { key: '74e7296a0c8ef732094c0e7fab3e0a7db916694b', class: { 'container': true, 'error': Boolean(this.errorText), 'drag': this.dragOver, 'drag-error': this.dragError } }, h("div", { key: '1a3030a828d8e7a742f3dfbff784e213f845859e', class: { 'label-container': true } }, h("slot", { key: '1f77e4c6566deffe7cd830fccb96d21c22daee4b', name: "left-content" })), h("div", { key: '3dc0a113348d15d52aae929792de6ee48da795ca', class: { 'file-container': true } }, this.FileContent), h("input", { key: 'a6fc37d212b5e4284f4eeec56dc4e7a32ff8374b', id: this.inputId, type: "file", accept: (_b = (_a = this.fileTypes) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : '*', files: Boolean(this.file) ? [this.file] : undefined, onDrop: this.handleDrop, onDragEnter: this.handleDragEnter, onDragLeave: this.handleDragLeave, onChange: this.handleInputChange })), (this.errorText || this.helperText) && (h("div", { class: { 'helper-text-container': true, 'error-text': Boolean(this.errorText) } }, h("span", null, (_c = this.errorText) !== null && _c !== void 0 ? _c : this.helperText)))));
|
119
|
+
}
|
120
|
+
static get is() { return "cpsl-file-upload"; }
|
121
|
+
static get encapsulation() { return "shadow"; }
|
122
|
+
static get originalStyleUrls() {
|
123
|
+
return {
|
124
|
+
"$": ["cpsl-file-upload.scss"]
|
125
|
+
};
|
126
|
+
}
|
127
|
+
static get styleUrls() {
|
128
|
+
return {
|
129
|
+
"$": ["cpsl-file-upload.css"]
|
130
|
+
};
|
131
|
+
}
|
132
|
+
static get properties() {
|
133
|
+
return {
|
134
|
+
"errorText": {
|
135
|
+
"type": "string",
|
136
|
+
"mutable": false,
|
137
|
+
"complexType": {
|
138
|
+
"original": "string",
|
139
|
+
"resolved": "string",
|
140
|
+
"references": {}
|
141
|
+
},
|
142
|
+
"required": false,
|
143
|
+
"optional": true,
|
144
|
+
"docs": {
|
145
|
+
"tags": [],
|
146
|
+
"text": "Error text to show below the input. If this is provided the input will enter an error state."
|
147
|
+
},
|
148
|
+
"attribute": "error-text",
|
149
|
+
"reflect": false
|
150
|
+
},
|
151
|
+
"externalFilename": {
|
152
|
+
"type": "string",
|
153
|
+
"mutable": false,
|
154
|
+
"complexType": {
|
155
|
+
"original": "string",
|
156
|
+
"resolved": "string",
|
157
|
+
"references": {}
|
158
|
+
},
|
159
|
+
"required": false,
|
160
|
+
"optional": true,
|
161
|
+
"docs": {
|
162
|
+
"tags": [],
|
163
|
+
"text": "Filename for the external source of the selected file."
|
164
|
+
},
|
165
|
+
"attribute": "external-filename",
|
166
|
+
"reflect": false
|
167
|
+
},
|
168
|
+
"externalSrc": {
|
169
|
+
"type": "string",
|
170
|
+
"mutable": false,
|
171
|
+
"complexType": {
|
172
|
+
"original": "string",
|
173
|
+
"resolved": "string",
|
174
|
+
"references": {}
|
175
|
+
},
|
176
|
+
"required": false,
|
177
|
+
"optional": true,
|
178
|
+
"docs": {
|
179
|
+
"tags": [],
|
180
|
+
"text": "External source for the selected file."
|
181
|
+
},
|
182
|
+
"attribute": "external-src",
|
183
|
+
"reflect": false
|
184
|
+
},
|
185
|
+
"fileTypes": {
|
186
|
+
"type": "unknown",
|
187
|
+
"mutable": false,
|
188
|
+
"complexType": {
|
189
|
+
"original": "string[]",
|
190
|
+
"resolved": "string[]",
|
191
|
+
"references": {}
|
192
|
+
},
|
193
|
+
"required": false,
|
194
|
+
"optional": true,
|
195
|
+
"docs": {
|
196
|
+
"tags": [],
|
197
|
+
"text": "Valid file types."
|
198
|
+
}
|
199
|
+
},
|
200
|
+
"helperText": {
|
201
|
+
"type": "string",
|
202
|
+
"mutable": false,
|
203
|
+
"complexType": {
|
204
|
+
"original": "string",
|
205
|
+
"resolved": "string",
|
206
|
+
"references": {}
|
207
|
+
},
|
208
|
+
"required": false,
|
209
|
+
"optional": true,
|
210
|
+
"docs": {
|
211
|
+
"tags": [],
|
212
|
+
"text": "Helper text to show below the input. If `\"errorText\"` is provided that will take precedence."
|
213
|
+
},
|
214
|
+
"attribute": "helper-text",
|
215
|
+
"reflect": false
|
216
|
+
},
|
217
|
+
"label": {
|
218
|
+
"type": "string",
|
219
|
+
"mutable": false,
|
220
|
+
"complexType": {
|
221
|
+
"original": "string",
|
222
|
+
"resolved": "string",
|
223
|
+
"references": {}
|
224
|
+
},
|
225
|
+
"required": false,
|
226
|
+
"optional": true,
|
227
|
+
"docs": {
|
228
|
+
"tags": [],
|
229
|
+
"text": "The label for the input."
|
230
|
+
},
|
231
|
+
"attribute": "label",
|
232
|
+
"reflect": false
|
233
|
+
},
|
234
|
+
"required": {
|
235
|
+
"type": "boolean",
|
236
|
+
"mutable": false,
|
237
|
+
"complexType": {
|
238
|
+
"original": "boolean",
|
239
|
+
"resolved": "boolean",
|
240
|
+
"references": {}
|
241
|
+
},
|
242
|
+
"required": false,
|
243
|
+
"optional": false,
|
244
|
+
"docs": {
|
245
|
+
"tags": [],
|
246
|
+
"text": "If `true`, the user must fill in a value before submitting a form."
|
247
|
+
},
|
248
|
+
"attribute": "required",
|
249
|
+
"reflect": false,
|
250
|
+
"defaultValue": "false"
|
251
|
+
},
|
252
|
+
"showOptionalLabel": {
|
253
|
+
"type": "boolean",
|
254
|
+
"mutable": false,
|
255
|
+
"complexType": {
|
256
|
+
"original": "boolean",
|
257
|
+
"resolved": "boolean",
|
258
|
+
"references": {}
|
259
|
+
},
|
260
|
+
"required": false,
|
261
|
+
"optional": false,
|
262
|
+
"docs": {
|
263
|
+
"tags": [],
|
264
|
+
"text": "If `true`, the label will display an \"optional\" tag."
|
265
|
+
},
|
266
|
+
"attribute": "show-optional-label",
|
267
|
+
"reflect": false,
|
268
|
+
"defaultValue": "false"
|
269
|
+
},
|
270
|
+
"uploadFile": {
|
271
|
+
"type": "unknown",
|
272
|
+
"mutable": false,
|
273
|
+
"complexType": {
|
274
|
+
"original": "(file: File) => Promise<boolean>",
|
275
|
+
"resolved": "(file: File) => Promise<boolean>",
|
276
|
+
"references": {
|
277
|
+
"File": {
|
278
|
+
"location": "global",
|
279
|
+
"id": "global::File"
|
280
|
+
},
|
281
|
+
"Promise": {
|
282
|
+
"location": "global",
|
283
|
+
"id": "global::Promise"
|
284
|
+
}
|
285
|
+
}
|
286
|
+
},
|
287
|
+
"required": false,
|
288
|
+
"optional": true,
|
289
|
+
"docs": {
|
290
|
+
"tags": [],
|
291
|
+
"text": "Function to trigger file upload to server.\nReturns: boolean indicating success or failure."
|
292
|
+
}
|
293
|
+
}
|
294
|
+
};
|
295
|
+
}
|
296
|
+
static get states() {
|
297
|
+
return {
|
298
|
+
"file": {},
|
299
|
+
"dragOver": {},
|
300
|
+
"dragError": {},
|
301
|
+
"isUploading": {},
|
302
|
+
"uploadError": {}
|
303
|
+
};
|
304
|
+
}
|
305
|
+
static get events() {
|
306
|
+
return [{
|
307
|
+
"method": "cpslOnDrop",
|
308
|
+
"name": "cpslOnDrop",
|
309
|
+
"bubbles": true,
|
310
|
+
"cancelable": true,
|
311
|
+
"composed": true,
|
312
|
+
"docs": {
|
313
|
+
"tags": [],
|
314
|
+
"text": "Emitted when the file is dropped in the input."
|
315
|
+
},
|
316
|
+
"complexType": {
|
317
|
+
"original": "DragEvent",
|
318
|
+
"resolved": "DragEvent",
|
319
|
+
"references": {
|
320
|
+
"DragEvent": {
|
321
|
+
"location": "global",
|
322
|
+
"id": "global::DragEvent"
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}, {
|
327
|
+
"method": "cpslOnDragEnter",
|
328
|
+
"name": "cpslOnDragEnter",
|
329
|
+
"bubbles": true,
|
330
|
+
"cancelable": true,
|
331
|
+
"composed": true,
|
332
|
+
"docs": {
|
333
|
+
"tags": [],
|
334
|
+
"text": "Emitted when the file drag enters the input."
|
335
|
+
},
|
336
|
+
"complexType": {
|
337
|
+
"original": "DragEvent",
|
338
|
+
"resolved": "DragEvent",
|
339
|
+
"references": {
|
340
|
+
"DragEvent": {
|
341
|
+
"location": "global",
|
342
|
+
"id": "global::DragEvent"
|
343
|
+
}
|
344
|
+
}
|
345
|
+
}
|
346
|
+
}, {
|
347
|
+
"method": "cpslOnDragLeave",
|
348
|
+
"name": "cpslOnDragLeave",
|
349
|
+
"bubbles": true,
|
350
|
+
"cancelable": true,
|
351
|
+
"composed": true,
|
352
|
+
"docs": {
|
353
|
+
"tags": [],
|
354
|
+
"text": "Emitted when the file drag leaves the input."
|
355
|
+
},
|
356
|
+
"complexType": {
|
357
|
+
"original": "DragEvent",
|
358
|
+
"resolved": "DragEvent",
|
359
|
+
"references": {
|
360
|
+
"DragEvent": {
|
361
|
+
"location": "global",
|
362
|
+
"id": "global::DragEvent"
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|
366
|
+
}, {
|
367
|
+
"method": "cpslFileChange",
|
368
|
+
"name": "cpslFileChange",
|
369
|
+
"bubbles": true,
|
370
|
+
"cancelable": true,
|
371
|
+
"composed": true,
|
372
|
+
"docs": {
|
373
|
+
"tags": [],
|
374
|
+
"text": "Emitted when the file changes."
|
375
|
+
},
|
376
|
+
"complexType": {
|
377
|
+
"original": "File",
|
378
|
+
"resolved": "File",
|
379
|
+
"references": {
|
380
|
+
"File": {
|
381
|
+
"location": "global",
|
382
|
+
"id": "global::File"
|
383
|
+
}
|
384
|
+
}
|
385
|
+
}
|
386
|
+
}, {
|
387
|
+
"method": "cpslFileRemoved",
|
388
|
+
"name": "cpslFileRemoved",
|
389
|
+
"bubbles": true,
|
390
|
+
"cancelable": true,
|
391
|
+
"composed": true,
|
392
|
+
"docs": {
|
393
|
+
"tags": [],
|
394
|
+
"text": "Emitted when the file is removed."
|
395
|
+
},
|
396
|
+
"complexType": {
|
397
|
+
"original": "void",
|
398
|
+
"resolved": "void",
|
399
|
+
"references": {}
|
400
|
+
}
|
401
|
+
}];
|
402
|
+
}
|
403
|
+
static get elementRef() { return "el"; }
|
404
|
+
}
|
405
|
+
let inputIds = 0;
|
406
|
+
//# sourceMappingURL=cpsl-file-upload.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cpsl-file-upload.js","sourceRoot":"","sources":["../../../../src/components/cpsl-file-upload/cpsl-file-upload.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAgB,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAOxG,MAAM,OAAO,cAAc;;QAGjB,YAAO,GAAG,oBAAoB,QAAQ,EAAE,EAAE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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF;AAED,IAAI,QAAQ,GAAG,CAAC,CAAC","sourcesContent":["import { Component, Host, Prop, Event, h, EventEmitter, State, Fragment, Element } from '@stencil/core';\n\n@Component({\n tag: 'cpsl-file-upload',\n styleUrl: 'cpsl-file-upload.scss',\n shadow: true,\n})\nexport class CpslFileUpload {\n @Element() el!: HTMLCpslFileUploadElement;\n\n private inputId = `cpsl-file-upload-${inputIds++}`;\n\n @State() file?: File;\n @State() dragOver?: boolean;\n @State() dragError?: boolean;\n @State() isUploading?: boolean;\n @State() uploadError?: boolean;\n\n /**\n * Error text to show below the input. If this is provided the input will enter an error state.\n */\n @Prop() errorText?: string;\n\n /**\n * Filename for the external source of the selected file.\n */\n @Prop() externalFilename?: string;\n\n /**\n * External source for the selected file.\n */\n @Prop() externalSrc?: string;\n\n /**\n * Valid file types.\n */\n @Prop() fileTypes?: string[];\n\n /**\n * Helper text to show below the input. If `\"errorText\"` is provided that will take precedence.\n */\n @Prop() helperText?: string;\n\n /**\n * The label for the input.\n */\n @Prop() label?: string;\n\n /**\n * If `true`, the user must fill in a value before submitting a form.\n */\n @Prop() required = false;\n\n /**\n * If `true`, the label will display an \"optional\" tag.\n */\n @Prop() showOptionalLabel = false;\n\n /**\n * Function to trigger file upload to server.\n * Returns: boolean indicating success or failure.\n */\n @Prop() uploadFile?: (file: File) => Promise<boolean>;\n\n /**\n * Emitted when the file is dropped in the input.\n */\n @Event() cpslOnDrop!: EventEmitter<DragEvent>;\n\n /**\n * Emitted when the file drag enters the input.\n */\n @Event() cpslOnDragEnter!: EventEmitter<DragEvent>;\n\n /**\n * Emitted when the file drag leaves the input.\n */\n @Event() cpslOnDragLeave!: EventEmitter<DragEvent>;\n\n /**\n * Emitted when the file changes.\n */\n @Event() cpslFileChange!: EventEmitter<File>;\n\n /**\n * Emitted when the file is removed.\n */\n @Event() cpslFileRemoved!: EventEmitter<void>;\n\n private handleDrop = async (ev: DragEvent) => {\n ev.preventDefault();\n\n const item = Array.from(ev.dataTransfer.items)?.[0];\n\n if (item && this.isValidFile(item.type)) {\n const file = item.getAsFile();\n await this.addFile(file);\n }\n\n this.dragOver = false;\n this.dragError = false;\n\n this.cpslOnDrop.emit(ev);\n };\n\n private handleDragEnter = (ev: DragEvent) => {\n ev.preventDefault();\n\n this.dragOver = true;\n\n const item = Array.from(ev.dataTransfer.items)?.[0];\n\n if (item && this.isValidFile(item.type)) {\n this.dragError = true;\n }\n\n this.cpslOnDragEnter.emit(ev);\n };\n\n private handleDragLeave = (ev: DragEvent) => {\n ev.preventDefault();\n\n this.dragOver = false;\n this.dragError = false;\n\n this.cpslOnDragLeave.emit(ev);\n };\n\n private handleInputChange = async (ev: Event) => {\n ev.preventDefault();\n\n const input = this.inputEl;\n\n if (Boolean(input.files.length)) {\n const file = input.files[0];\n\n if (this.isValidFile(file.type)) {\n await this.addFile(file);\n }\n }\n };\n\n private isValidFile = (type: string) => {\n if (Boolean(this.fileTypes?.length) ? !this.fileTypes.includes(type) : false) {\n return false;\n }\n\n return true;\n };\n\n private addFile = async (file: File) => {\n this.file = file;\n this.cpslFileChange.emit(file);\n this.uploadError = false;\n this.isUploading = true;\n const uploadSuccess = Boolean(this.uploadFile) ? await this.uploadFile(file) : true;\n if (!uploadSuccess) {\n this.uploadError = true;\n const input = this.inputEl;\n input.value = '';\n }\n this.isUploading = false;\n };\n\n private removeFile = (e: MouseEvent) => {\n e.preventDefault();\n\n this.file = undefined;\n\n const input = this.inputEl;\n input.value = '';\n\n this.cpslFileRemoved.emit();\n };\n\n get inputEl() {\n return this.el.shadowRoot.getElementById(this.inputId) as HTMLInputElement;\n }\n\n get FileContent() {\n const hasFile = Boolean(this.file) || Boolean(this.externalSrc);\n const isUploading = this.isUploading;\n const error = this.uploadError;\n\n const text = !hasFile ? (\n <Fragment>\n {'Drag file here or '}\n <cpsl-text class=\"inline-text\" variant=\"bodyXS\">\n upload file\n </cpsl-text>\n </Fragment>\n ) : isUploading ? (\n `${this.file.name} is uploading`\n ) : error ? (\n 'Upload Failed'\n ) : (\n this.file?.name || this.externalFilename || ''\n );\n const TopElement = !hasFile ? (\n <cpsl-icon icon=\"image\" />\n ) : isUploading ? (\n <cpsl-spinner />\n ) : error ? (\n <cpsl-icon icon=\"close\" />\n ) : (\n <img class=\"sample-img\" src={Boolean(this.file) ? URL.createObjectURL(this.file) : this.externalSrc} alt=\"Sample Image\" />\n );\n\n return (\n <Fragment>\n {TopElement}\n <span class=\"sample-image-name-container\">\n <cpsl-text class=\"sample-image-name\" variant=\"bodyXS\">\n {text}\n </cpsl-text>\n {hasFile && !error && !isUploading && <cpsl-icon icon=\"close\" onClick={this.removeFile} />}\n </span>\n </Fragment>\n );\n }\n\n render() {\n return (\n <Host>\n {this.label && (\n <label class=\"label\" htmlFor={this.inputId}>\n {this.label}\n {this.required ? '*' : ' '}\n {!this.required && this.showOptionalLabel ? <span class=\"optional-label\">(optional)</span> : ''}\n </label>\n )}\n <slot name=\"label\"></slot>\n <div class={{ 'container': true, 'error': Boolean(this.errorText), 'drag': this.dragOver, 'drag-error': this.dragError }}>\n <div class={{ 'label-container': true }}>\n <slot name=\"left-content\"></slot>\n </div>\n <div class={{ 'file-container': true }}>{this.FileContent}</div>\n <input\n id={this.inputId}\n type=\"file\"\n accept={this.fileTypes?.join(', ') ?? '*'}\n files={Boolean(this.file) ? [this.file] : undefined}\n onDrop={this.handleDrop}\n onDragEnter={this.handleDragEnter}\n onDragLeave={this.handleDragLeave}\n onChange={this.handleInputChange}\n />\n </div>\n {(this.errorText || this.helperText) && (\n <div class={{ 'helper-text-container': true, 'error-text': Boolean(this.errorText) }}>\n <span>{this.errorText ?? this.helperText}</span>\n </div>\n )}\n </Host>\n );\n }\n}\n\nlet inputIds = 0;\n"]}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try {
|
5
|
+
step(generator.next(value));
|
6
|
+
}
|
7
|
+
catch (e) {
|
8
|
+
reject(e);
|
9
|
+
} }
|
10
|
+
function rejected(value) { try {
|
11
|
+
step(generator["throw"](value));
|
12
|
+
}
|
13
|
+
catch (e) {
|
14
|
+
reject(e);
|
15
|
+
} }
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
18
|
+
});
|
19
|
+
};
|
20
|
+
import { newE2EPage } from "@stencil/core/testing";
|
21
|
+
describe('cpsl-file-upload', () => {
|
22
|
+
it('renders', () => __awaiter(void 0, void 0, void 0, function* () {
|
23
|
+
const page = yield newE2EPage();
|
24
|
+
yield page.setContent('<cpsl-file-upload></cpsl-file-upload>');
|
25
|
+
const element = yield page.find('cpsl-file-upload');
|
26
|
+
expect(element).toHaveClass('hydrated');
|
27
|
+
}));
|
28
|
+
});
|
29
|
+
//# sourceMappingURL=cpsl-file-upload.e2e.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cpsl-file-upload.e2e.js","sourceRoot":"","sources":["../../../../../src/components/cpsl-file-upload/test/cpsl-file-upload.e2e.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,SAAS,EAAE,GAAS,EAAE;QACvB,MAAM,IAAI,GAAG,MAAM,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,CAAC,UAAU,CAAC,uCAAuC,CAAC,CAAC;QAE/D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACpD,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { newE2EPage } from '@stencil/core/testing';\n\ndescribe('cpsl-file-upload', () => {\n it('renders', async () => {\n const page = await newE2EPage();\n await page.setContent('<cpsl-file-upload></cpsl-file-upload>');\n\n const element = await page.find('cpsl-file-upload');\n expect(element).toHaveClass('hydrated');\n });\n});\n"]}
|