@spectrum-web-components/card 0.0.0-20241209155954

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 ADDED
@@ -0,0 +1,291 @@
1
+ ## Description
2
+
3
+ An `<sp-card>` represents a rectangular card that contains
4
+ a variety of text and image layouts. Cards are typically used
5
+ to encapsulate units of a data set, such as a gallery of
6
+ image/caption pairs.
7
+
8
+ ### Usage
9
+
10
+ [![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/card?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/card)
11
+ [![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/card?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/card)
12
+ [![Try it on webcomponents.dev](https://img.shields.io/badge/Try%20it%20on-webcomponents.dev-green?style=for-the-badge)](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/0lwluuJO4nR1daE9dyRw/src/index.stories.js)
13
+
14
+ ```
15
+ yarn add @spectrum-web-components/card
16
+ ```
17
+
18
+ Import the side effectful registration of `<sp-card>` via:
19
+
20
+ ```
21
+ import '@spectrum-web-components/card/sp-card.js';
22
+ ```
23
+
24
+ When looking to leverage the `Card` base class as a type and/or for extension purposes, do so via:
25
+
26
+ ```
27
+ import { Card } from '@spectrum-web-components/card';
28
+ ```
29
+
30
+ ## Example
31
+
32
+ ```html demo
33
+ <sp-card heading="Card Heading" subheading="JPG Photo">
34
+ <img
35
+ slot="cover-photo"
36
+ src="https://picsum.photos/200/300"
37
+ alt="Demo Image"
38
+ />
39
+ <div slot="footer">Footer</div>
40
+ </sp-card>
41
+ ```
42
+
43
+ ```html demo
44
+ <sp-card heading="Card Title" subheading="JPG">
45
+ <img slot="preview" src="https://picsum.photos/200/300" alt="Demo Image" />
46
+ <div slot="footer">Footer</div>
47
+ </sp-card>
48
+ ```
49
+
50
+ ## Heading
51
+
52
+ By default, the heading for an `<sp-card>` is applied via the `heading` attribute, which is restricted to string content only. For HTML content, use the `heading` slot instead.
53
+
54
+ ```html demo
55
+ <sp-card
56
+ subheading="JPG Photo"
57
+ style="--spectrum-card-body-header-height: auto;"
58
+ >
59
+ <h1 slot="heading">Card Heading</h1>
60
+ <img alt="" slot="cover-photo" src="https://picsum.photos/200/300" />
61
+ <div slot="footer">Footer</div>
62
+ </sp-card>
63
+ ```
64
+
65
+ ## Linking
66
+
67
+ An `<sp-card>` can be provided with an `href` attribute in order for it to act as one large anchor element. When leveraging the `href` attribute, the `download`, `target` and `rel` attributes customize the card's linking behavior. Use them as follows:
68
+
69
+ <!-- prettier-ignore -->
70
+ ```html
71
+ <sp-card
72
+ heading="Card Title"
73
+ subheading="JPG"
74
+ href="https://opensource.adobe.com/spectrum-web-components"
75
+ target="_blank"
76
+ >
77
+ <img slot="cover-photo" src="https://picsum.photos/200/300" alt="Demo Image" />
78
+ </sp-card>
79
+ ```
80
+
81
+ ## Variants
82
+
83
+ There are multiple card variants to choose from in Spectrum. The `variant`
84
+ attribute controls the main variant of the card.
85
+
86
+ ### Normal
87
+
88
+ Normal cards can contain a heading, a subheading, a cover photo, and a footer.
89
+
90
+ ```html
91
+ <sp-card heading="Card Heading">
92
+ <img alt="" slot="cover-photo" src="https://picsum.photos/200/300" />
93
+ <span slot="subheading">JPG photo</span>
94
+ <div slot="footer">Footer</div>
95
+ </sp-card>
96
+ ```
97
+
98
+ ### Actions
99
+
100
+ Cards can be supplied an `actions` via a names slot.
101
+
102
+ ```html
103
+ <sp-card heading="Card Heading" subheading="JPG Photo">
104
+ <img
105
+ slot="cover-photo"
106
+ src="https://picsum.photos/200/300"
107
+ alt="Demo Image"
108
+ />
109
+ <div slot="footer">Footer</div>
110
+ <sp-action-menu
111
+ label="More Actions"
112
+ slot="actions"
113
+ placement="bottom-end"
114
+ quiet
115
+ >
116
+ <sp-menu-item>Deselect</sp-menu-item>
117
+ <sp-menu-item>Select Inverse</sp-menu-item>
118
+ <sp-menu-item>Feather...</sp-menu-item>
119
+ <sp-menu-item>Select and Mask...</sp-menu-item>
120
+ <sp-menu-divider></sp-menu-divider>
121
+ <sp-menu-item>Save Selection</sp-menu-item>
122
+ <sp-menu-item disabled>Make Work Path</sp-menu-item>
123
+ </sp-action-menu>
124
+ </sp-card>
125
+ ```
126
+
127
+ ### No Preview Image
128
+
129
+ Cards with no preview image can contain a heading, a subheading, and a footer.
130
+
131
+ ```html demo
132
+ <sp-card heading="Card Title" subheading="No Preview Image">
133
+ <div slot="footer">Footer</div>
134
+ </sp-card>
135
+ ```
136
+
137
+ ### Quiet
138
+
139
+ Quiet cards can contain a heading, a subheading, a cover photo, a description, and a footer.
140
+
141
+ ```html
142
+ <div style="width: 208px; height: 264px">
143
+ <sp-card variant="quiet" heading="Card Heading" subheading="JPG Photo">
144
+ <img alt="" slot="preview" src="https://picsum.photos/200/300" />
145
+ <div slot="description">10/15/18</div>
146
+ <div slot="footer">Footer</div>
147
+ </sp-card>
148
+ </div>
149
+ ```
150
+
151
+ When leveraging the `asset` attribute, a card can be declared as representing a `file`:
152
+
153
+ ```html
154
+ <div style="width: 208px; height: 264px">
155
+ <sp-card
156
+ variant="quiet"
157
+ heading="Card Heading"
158
+ subheading="JPG Photo"
159
+ asset="file"
160
+ >
161
+ <img alt="" slot="preview" src="https://picsum.photos/200/300" />
162
+ <div slot="heading">File Name</div>
163
+ <div slot="description">10/15/18</div>
164
+ <div slot="footer">Footer</div>
165
+ </sp-card>
166
+ </div>
167
+ ```
168
+
169
+ Or a `folder`:
170
+
171
+ ```html
172
+ <div style="width: 208px; height: 264px">
173
+ <sp-card variant="quiet" subheading="JPG Photo" asset="folder">
174
+ <img alt="" slot="preview" src="https://picsum.photos/200/300" />
175
+ <div slot="heading">Folder Name</div>
176
+ <div slot="description">10/15/18</div>
177
+ <div slot="footer">Footer</div>
178
+ </sp-card>
179
+ </div>
180
+ ```
181
+
182
+ Quiet cards will also accept `actions` via a named slot.
183
+
184
+ ```html
185
+ <div style="width: 208px; height: 264px">
186
+ <sp-card variant="quiet" heading="Card Heading" subheading="JPG Photo">
187
+ <img alt="" slot="preview" src="https://picsum.photos/200/300" />
188
+ <div slot="description">10/15/18</div>
189
+ <sp-action-menu
190
+ label="More Actions"
191
+ slot="actions"
192
+ placement="bottom-end"
193
+ quiet
194
+ >
195
+ <sp-menu-item>Deselect</sp-menu-item>
196
+ <sp-menu-item>Select Inverse</sp-menu-item>
197
+ <sp-menu-item>Feather...</sp-menu-item>
198
+ <sp-menu-item>Select and Mask...</sp-menu-item>
199
+ <sp-menu-divider></sp-menu-divider>
200
+ <sp-menu-item>Save Selection</sp-menu-item>
201
+ <sp-menu-item disabled>Make Work Path</sp-menu-item>
202
+ </sp-action-menu>
203
+ </sp-card>
204
+ </div>
205
+ ```
206
+
207
+ ### Gallery
208
+
209
+ Gallery cards can contain a heading, a subheading, an image preview, a description, and a footer.
210
+
211
+ ```html
212
+ <div style="width: 532px; max-width: 100%; height: 224px">
213
+ <sp-card variant="gallery" heading="Card Heading" subheading="JPG Photo">
214
+ <img alt="" slot="preview" src="https://picsum.photos/532/192" />
215
+ <div slot="description">10/15/18</div>
216
+ <div slot="footer">Footer</div>
217
+ </sp-card>
218
+ </div>
219
+ ```
220
+
221
+ ### Size
222
+
223
+ `size="s"` will delivery the `<sp-card>` element at a "small" size. It can be leveraged with a standard card:
224
+
225
+ ```html demo
226
+ <div style="width: 208px; height: 264px">
227
+ <sp-card size="s" heading="Card Heading" subheading="JPG Photo">
228
+ <img
229
+ slot="cover-photo"
230
+ alt="Demo Image"
231
+ src="https://picsum.photos/110"
232
+ />
233
+ <div slot="footer">Footer</div>
234
+ </sp-card>
235
+ </div>
236
+ ```
237
+
238
+ A `horizontal` card:
239
+
240
+ ```html demo
241
+ <div style="color: var(--spectrum-neutral-content-color-default);">
242
+ <sp-card size="s" horizontal heading="Card Heading" subheading="JPG Photo">
243
+ <sp-icon slot="preview" style="width: 36px; height: 36px;">
244
+ <svg
245
+ xmlns="http://www.w3.org/2000/svg"
246
+ viewBox="0 0 36 36"
247
+ aria-hidden="true"
248
+ role="img"
249
+ fill="currentColor"
250
+ >
251
+ <path d="M20 2v10h10L20 2z" />
252
+ <path
253
+ d="M19 14a1 1 0 01-1-1V2H7a1 1 0 00-1 1v30a1 1 0 001 1h22a1 1 0 001-1V14zm7 15.5a.5.5 0 01-.5.5h-15a.5.5 0 01-.5-.5v-1a.5.5 0 01.5-.5h15a.5.5 0 01.5.5zm0-4a.5.5 0 01-.5.5h-15a.5.5 0 01-.5-.5v-1a.5.5 0 01.5-.5h15a.5.5 0 01.5.5zm0-4a.5.5 0 01-.5.5h-15a.5.5 0 01-.5-.5v-1a.5.5 0 01.5-.5h15a.5.5 0 01.5.5z"
254
+ />
255
+ </svg>
256
+ </sp-icon>
257
+ </sp-card>
258
+ </div>
259
+ ```
260
+
261
+ Or a `quiet` card:
262
+
263
+ ```html demo
264
+ <div
265
+ style="color: var(--spectrum-neutral-content-color-default); width: 110px;"
266
+ >
267
+ <sp-card
268
+ size="s"
269
+ heading="Card Heading"
270
+ subheading="JPG Photo"
271
+ variant="quiet"
272
+ >
273
+ <img src="https://picsum.photos/110" alt="Demo Image" slot="preview" />
274
+ <div slot="footer">Footer</div>
275
+ <sp-action-menu
276
+ label="More Actions"
277
+ slot="actions"
278
+ placement="bottom-end"
279
+ quiet
280
+ >
281
+ <sp-menu-item>Deselect</sp-menu-item>
282
+ <sp-menu-item>Select Inverse</sp-menu-item>
283
+ <sp-menu-item>Feather...</sp-menu-item>
284
+ <sp-menu-item>Select and Mask...</sp-menu-item>
285
+ <sp-menu-divider></sp-menu-divider>
286
+ <sp-menu-item>Save Selection</sp-menu-item>
287
+ <sp-menu-item disabled>Make Work Path</sp-menu-item>
288
+ </sp-action-menu>
289
+ </sp-card>
290
+ </div>
291
+ ```
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@spectrum-web-components/card",
3
+ "version": "0.0.0-20241209155954",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "",
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/adobe/spectrum-web-components.git",
12
+ "directory": "packages/card"
13
+ },
14
+ "author": "",
15
+ "homepage": "https://opensource.adobe.com/spectrum-web-components/components/card",
16
+ "bugs": {
17
+ "url": "https://github.com/adobe/spectrum-web-components/issues"
18
+ },
19
+ "main": "./src/index.js",
20
+ "module": "./src/index.js",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "development": "./src/index.dev.js",
25
+ "default": "./src/index.js"
26
+ },
27
+ "./package.json": "./package.json",
28
+ "./src/Card.js": {
29
+ "development": "./src/Card.dev.js",
30
+ "default": "./src/Card.js"
31
+ },
32
+ "./src/card-overrides.css.js": "./src/card-overrides.css.js",
33
+ "./src/card.css.js": "./src/card.css.js",
34
+ "./src/index.js": {
35
+ "development": "./src/index.dev.js",
36
+ "default": "./src/index.js"
37
+ },
38
+ "./sp-card.js": {
39
+ "development": "./sp-card.dev.js",
40
+ "default": "./sp-card.js"
41
+ }
42
+ },
43
+ "scripts": {
44
+ "test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
45
+ },
46
+ "files": [
47
+ "**/*.d.ts",
48
+ "**/*.js",
49
+ "**/*.js.map",
50
+ "custom-elements.json",
51
+ "!stories/",
52
+ "!test/"
53
+ ],
54
+ "keywords": [
55
+ "spectrum css",
56
+ "web components",
57
+ "lit-element",
58
+ "lit-html"
59
+ ],
60
+ "dependencies": {
61
+ "@spectrum-web-components/asset": "0.0.0-20241209155954",
62
+ "@spectrum-web-components/base": "0.0.0-20241209155954",
63
+ "@spectrum-web-components/checkbox": "0.0.0-20241209155954",
64
+ "@spectrum-web-components/divider": "0.0.0-20241209155954",
65
+ "@spectrum-web-components/icons-workflow": "0.0.0-20241209155954",
66
+ "@spectrum-web-components/shared": "0.0.0-20241209155954",
67
+ "@spectrum-web-components/styles": "0.0.0-20241209155954"
68
+ },
69
+ "devDependencies": {
70
+ "@spectrum-css/card": "^10.0.0-s2-foundations.20"
71
+ },
72
+ "types": "./src/index.d.ts",
73
+ "customElements": "custom-elements.json",
74
+ "sideEffects": [
75
+ "./sp-*.js",
76
+ "./**/*.dev.js"
77
+ ]
78
+ }
package/sp-card.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Card } from './src/Card.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'sp-card': Card;
5
+ }
6
+ }
package/sp-card.dev.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ import { Card } from "./src/Card.dev.js";
3
+ import { defineElement } from "@spectrum-web-components/base/src/define-element.js";
4
+ defineElement("sp-card", Card);
5
+ //# sourceMappingURL=sp-card.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["sp-card.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Card } from './src/Card.dev.js'\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-card', Card);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-card': Card;\n }\n}\n"],
5
+ "mappings": ";AAYA,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAE9B,cAAc,WAAW,IAAI;",
6
+ "names": []
7
+ }
package/sp-card.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";import{Card as e}from"./src/Card.js";import{defineElement as a}from"@spectrum-web-components/base/src/define-element.js";a("sp-card",e);
2
+ //# sourceMappingURL=sp-card.js.map
package/sp-card.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["sp-card.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Card } from './src/Card.js';\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-card', Card);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-card': Card;\n }\n}\n"],
5
+ "mappings": "aAYA,OAAS,QAAAA,MAAY,gBACrB,OAAS,iBAAAC,MAAqB,sDAE9BA,EAAc,UAAWD,CAAI",
6
+ "names": ["Card", "defineElement"]
7
+ }
package/src/Card.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
2
+ import '@spectrum-web-components/asset/sp-asset.js';
3
+ import '@spectrum-web-components/checkbox/sp-checkbox.js';
4
+ import '@spectrum-web-components/popover/sp-popover.js';
5
+ import '@spectrum-web-components/divider/sp-divider.js';
6
+ declare const Card_base: typeof SpectrumElement & {
7
+ new (...args: any[]): import("@spectrum-web-components/shared/src/observe-slot-presence.js").SlotPresenceObservingInterface;
8
+ prototype: import("@spectrum-web-components/shared/src/observe-slot-presence.js").SlotPresenceObservingInterface;
9
+ } & {
10
+ new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
11
+ prototype: import("@spectrum-web-components/base").SizedElementInterface;
12
+ } & {
13
+ new (...args: any[]): import("@spectrum-web-components/shared/src/like-anchor.js").LikeAnchorInterface;
14
+ prototype: import("@spectrum-web-components/shared/src/like-anchor.js").LikeAnchorInterface;
15
+ };
16
+ /**
17
+ * @element sp-card
18
+ *
19
+ * @fires change - Announces a change in the `selected` property of a card
20
+ * @slot preview - This is the preview image for Gallery Cards
21
+ * @slot cover-photo - This is the cover photo for Default and Quiet Cards
22
+ * @slot heading - HTML content to be listed as the heading
23
+ * @slot subheading - HTML content to be listed as the subheading
24
+ * @slot description - A description of the card
25
+ * @slot actions - an `sp-action-menu` element outlining actions to take on the represened object
26
+ * @slot footer - Footer text
27
+ */
28
+ export declare class Card extends Card_base {
29
+ static get styles(): CSSResultArray;
30
+ asset?: 'file' | 'folder';
31
+ variant: 'standard' | 'gallery' | 'quiet';
32
+ get selected(): boolean;
33
+ set selected(selected: boolean);
34
+ private _selected;
35
+ heading: string;
36
+ horizontal: boolean;
37
+ private likeAnchor?;
38
+ focused: boolean;
39
+ toggles: boolean;
40
+ value: string;
41
+ subheading: string;
42
+ protected get hasCoverPhoto(): boolean;
43
+ protected get hasPreview(): boolean;
44
+ click(): void;
45
+ private handleFocusin;
46
+ private handleFocusout;
47
+ private handleKeydown;
48
+ private handleSelectedChange;
49
+ toggleSelected(): void;
50
+ private announceChange;
51
+ private stopPropagationOnHref;
52
+ private handlePointerdown;
53
+ protected get renderHeading(): TemplateResult;
54
+ protected get renderPreviewImage(): TemplateResult;
55
+ protected get renderCoverImage(): TemplateResult;
56
+ protected get images(): TemplateResult[];
57
+ private renderImage;
58
+ private get renderSubtitleAndDescription();
59
+ protected render(): TemplateResult;
60
+ protected firstUpdated(changes: PropertyValues): void;
61
+ }
62
+ export {};