@salesforcedevs/dx-components 1.2.21 → 1.3.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/lwc.config.json CHANGED
@@ -47,6 +47,7 @@
47
47
  "dx/iconBadge",
48
48
  "dx/imageAndLabel",
49
49
  "dx/input",
50
+ "dx/interactiveImage",
50
51
  "dx/logo",
51
52
  "dx/modal",
52
53
  "dx/metadataBadge",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.2.21",
3
+ "version": "1.3.0",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -28,5 +28,5 @@
28
28
  "@types/lodash.kebabcase": "^4.1.7",
29
29
  "@types/vimeo__player": "^2.16.2"
30
30
  },
31
- "gitHead": "a2cdce2eb71710ffc534a3e01e74137f09cabc0a"
31
+ "gitHead": "b5d88aa134399d66a9f894d05ecec170843bc30f"
32
32
  }
@@ -0,0 +1,59 @@
1
+ @import "dxHelpers/reset";
2
+ @import "dxHelpers/text";
3
+
4
+ article {
5
+ border: 1px solid var(--dx-g-gray-90);
6
+ border-radius: 0.3125rem;
7
+ }
8
+
9
+ header {
10
+ display: flex;
11
+ align-items: flex-start;
12
+ justify-content: space-between;
13
+ border-radius: 0.3125rem 0.3125rem 0 0;
14
+ background-color: var(--dx-g-gray-95);
15
+ font-family: var(--dx-g-font-sans);
16
+ color: var(--dx-g-gray-10);
17
+ padding: var(--dx-g-spacing-sm);
18
+ }
19
+
20
+ header span {
21
+ padding: var(--dx-g-spacing-sm) var(--dx-g-spacing-md);
22
+ font-size: var(--dx-g-text-sm);
23
+ }
24
+
25
+ footer {
26
+ border-radius: 0 0 0.3125rem 0.3125rem;
27
+ }
28
+
29
+ .body {
30
+ margin: var(--dx-g-spacing-md);
31
+ overflow-x: auto;
32
+ }
33
+
34
+ .body img {
35
+ min-width: 650px;
36
+ }
37
+
38
+ .controls {
39
+ display: flex;
40
+ align-items: center;
41
+ justify-content: flex-end;
42
+ }
43
+
44
+ /* Breakpoints for mobile */
45
+
46
+ @media screen and (max-width: 640px) {
47
+ header {
48
+ flex-direction: column;
49
+ align-items: flex-end;
50
+ }
51
+ }
52
+
53
+ @media screen and (max-width: 320px) {
54
+ .controls,
55
+ .controls dx-dropdown,
56
+ .controls dx-button {
57
+ width: 100%;
58
+ }
59
+ }
@@ -0,0 +1,32 @@
1
+ <template>
2
+ <article>
3
+ <header>
4
+ <span>{title}</span>
5
+ <div class="controls">
6
+ <template if:true={isSingleDownload}>
7
+ <dx-button
8
+ icon-symbol="download"
9
+ href={singleDownloadHref}
10
+ download={singleDownloadFilename}
11
+ >
12
+ {downloadButtonLabel}
13
+ </dx-button>
14
+ </template>
15
+ <template if:false={isSingleDownload}>
16
+ <dx-dropdown
17
+ options={urls}
18
+ onchange={handleDownloadOptionChange}
19
+ placement="bottom-end"
20
+ >
21
+ <dx-button variant="primary" icon-symbol="chevrondown">
22
+ {downloadButtonLabel}
23
+ </dx-button>
24
+ </dx-dropdown>
25
+ </template>
26
+ </div>
27
+ </header>
28
+ <div class="body">
29
+ <img src={featuredSrc} alt={title} />
30
+ </div>
31
+ </article>
32
+ </template>
@@ -0,0 +1,71 @@
1
+ import { LightningElement, api } from "lwc";
2
+
3
+ // Extracts filename and extension from a file URL
4
+ const FILENAME_FROM_URL_REGEX = /(?=\w+\.\w{3,4}$).+/;
5
+ const EXTENSION_FROM_URL_REGEX = /\.([^.]*)$/;
6
+
7
+ export default class InteractiveImage extends LightningElement {
8
+ @api title!: string;
9
+ @api featuredSrc!: string;
10
+
11
+ @api
12
+ set downloadUrls(values: any) {
13
+ // Normalize input values
14
+ let urls;
15
+ if (typeof values === "string") {
16
+ if (values.startsWith("[")) {
17
+ urls = JSON.parse(values);
18
+ } else {
19
+ urls = [values];
20
+ }
21
+ } else {
22
+ urls = values;
23
+ }
24
+ // Ensure that we have some URLs
25
+ if (!urls || urls.length === 0) {
26
+ throw new Error(
27
+ `No download url found for interactive image with title "${this.title}"`
28
+ );
29
+ }
30
+ // Prepare download options with labels
31
+ this.urls = urls.map((url: string) => {
32
+ return {
33
+ label: this.getDownloadLabelFromUrl(url),
34
+ id: url
35
+ };
36
+ });
37
+ }
38
+ get downloadUrls() {
39
+ return this.urls;
40
+ }
41
+
42
+ private urls: { label: string; id: string }[] = [];
43
+
44
+ private get isSingleDownload() {
45
+ return this.urls.length === 1;
46
+ }
47
+
48
+ private get singleDownloadHref() {
49
+ return this.urls[0].id;
50
+ }
51
+
52
+ private get singleDownloadFilename() {
53
+ const pathParts = this.urls[0].id.match(FILENAME_FROM_URL_REGEX);
54
+ return pathParts ? pathParts[0] : "";
55
+ }
56
+
57
+ private get downloadButtonLabel() {
58
+ return this.isSingleDownload ? this.urls[0].label : "Download as...";
59
+ }
60
+
61
+ private handleDownloadOptionChange(event: CustomEvent) {
62
+ window.open(event.detail, "_blank");
63
+ }
64
+
65
+ private getDownloadLabelFromUrl(url: string): string {
66
+ const urlParts = url.match(EXTENSION_FROM_URL_REGEX);
67
+ return urlParts
68
+ ? `Download as ${urlParts[1].toUpperCase()}`
69
+ : "Download";
70
+ }
71
+ }