|
11 | 11 | */ |
12 | 12 |
|
13 | 13 | import { CSSResultArray, html, TemplateResult } from 'lit'; |
| 14 | +import { classMap } from 'lit/directives/class-map.js'; |
14 | 15 |
|
15 | 16 | import { AssetBase } from '@spectrum-web-components/core/components/asset'; |
16 | 17 |
|
17 | 18 | import styles from './asset.css'; |
18 | 19 |
|
19 | 20 | const file = (label: string): TemplateResult => html` |
20 | 21 | <svg |
21 | | - class="file" |
| 22 | + class="spectrum-Asset-file" |
22 | 23 | role="img" |
23 | 24 | viewBox="0 0 128 128" |
24 | 25 | aria-label=${label || 'File'} |
25 | 26 | > |
26 | 27 | <path |
27 | | - class="fileBackground" |
| 28 | + class="spectrum-Asset-fileBackground" |
28 | 29 | d="M24,126c-5.5,0-10-4.5-10-10V12c0-5.5,4.5-10,10-10h61.5c2.1,0,4.1,0.8,5.6,2.3l20.5,20.4c1.5,1.5,2.4,3.5,2.4,5.7V116c0,5.5-4.5,10-10,10H24z" |
29 | 30 | ></path> |
30 | 31 | <path |
31 | | - class="fileOutline" |
| 32 | + class="spectrum-Asset-fileOutline" |
32 | 33 | d="M113.1,23.3L92.6,2.9C90.7,1,88.2,0,85.5,0H24c-6.6,0-12,5.4-12,12v104c0,6.6,5.4,12,12,12h80c6.6,0,12-5.4,12-12V30.4C116,27.8,114.9,25.2,113.1,23.3z M90,6l20.1,20H92c-1.1,0-2-0.9-2-2V6z M112,116c0,4.4-3.6,8-8,8H24c-4.4,0-8-3.6-8-8V12c0-4.4,3.6-8,8-8h61.5c0.2,0,0.3,0,0.5,0v20c0,3.3,2.7,6,6,6h20c0,0.1,0,0.3,0,0.4V116z" |
33 | 34 | ></path> |
34 | 35 | </svg> |
35 | 36 | `; |
36 | 37 |
|
37 | 38 | const folder = (label: string): TemplateResult => html` |
38 | 39 | <svg |
39 | | - class="folder" |
| 40 | + class="spectrum-Asset-folder" |
40 | 41 | role="img" |
41 | 42 | viewBox="0 0 32 32" |
42 | 43 | aria-label=${label || 'Folder'} |
43 | 44 | > |
44 | 45 | <path |
45 | | - class="folderBackground" |
| 46 | + class="spectrum-Asset-folderBackground" |
46 | 47 | d="M3,29.5c-1.4,0-2.5-1.1-2.5-2.5V5c0-1.4,1.1-2.5,2.5-2.5h10.1c0.5,0,1,0.2,1.4,0.6l3.1,3.1c0.2,0.2,0.4,0.3,0.7,0.3H29c1.4,0,2.5,1.1,2.5,2.5v18c0,1.4-1.1,2.5-2.5,2.5H3z" |
47 | 48 | ></path> |
48 | 49 | <path |
49 | | - class="folderOutline" |
| 50 | + class="spectrum-Asset-folderOutline" |
50 | 51 | d="M29,6H18.3c-0.1,0-0.2,0-0.4-0.2l-3.1-3.1C14.4,2.3,13.8,2,13.1,2H3C1.3,2,0,3.3,0,5v22c0,1.6,1.3,3,3,3h26c1.7,0,3-1.4,3-3V9C32,7.3,30.7,6,29,6z M31,27c0,1.1-0.9,2-2,2H3c-1.1,0-2-0.9-2-2V7h28c1.1,0,2,0.9,2,2V27z" |
51 | 52 | ></path> |
52 | 53 | </svg> |
53 | 54 | `; |
54 | 55 |
|
55 | 56 | /** |
| 57 | + * Use an asset element to visually represent a file, folder, or image. |
| 58 | + * File and folder representations center themselves within the available space. |
| 59 | + * Images are contained to the element’s size and centered. |
| 60 | + * |
56 | 61 | * @element swc-asset |
57 | | - * @slot - content to be displayed in the asset when an acceptable value for `file` is not present |
| 62 | + * @slot - content to be displayed when no `variant` is set (typically an <img>) |
| 63 | + * |
| 64 | + * @example |
| 65 | + * <swc-asset style="block-size: 128px"> |
| 66 | + * <img class="spectrum-Asset-image" src="example.png" alt="Example image" /> |
| 67 | + * </swc-asset> |
| 68 | + * |
| 69 | + * @example |
| 70 | + * <swc-asset variant="file" style="min-inline-size: 150px; block-size: 128px"></swc-asset> |
| 71 | + * |
| 72 | + * @example |
| 73 | + * <swc-asset variant="folder" style="min-inline-size: 150px; block-size: 128px"></swc-asset> |
58 | 74 | */ |
59 | 75 | export class Asset extends AssetBase { |
| 76 | + // ────────────────────────────── |
| 77 | + // RENDERING & STYLING |
| 78 | + // ────────────────────────────── |
| 79 | + |
60 | 80 | public static override get styles(): CSSResultArray { |
61 | 81 | return [styles]; |
62 | 82 | } |
63 | 83 |
|
64 | 84 | protected override render(): TemplateResult { |
65 | | - if (this.variant === 'file') { |
66 | | - return file(this.label); |
67 | | - } else if (this.variant === 'folder') { |
68 | | - return folder(this.label); |
69 | | - } |
70 | | - return html` <slot></slot> `; |
| 85 | + return html` |
| 86 | + <div |
| 87 | + class=${classMap({ |
| 88 | + ['spectrum-Asset']: true, |
| 89 | + })} |
| 90 | + > |
| 91 | + ${this.variant === 'file' |
| 92 | + ? file(this.label) |
| 93 | + : this.variant === 'folder' |
| 94 | + ? folder(this.label) |
| 95 | + : html` <slot></slot> `} |
| 96 | + </div> |
| 97 | + `; |
71 | 98 | } |
72 | 99 | } |
0 commit comments