@react-spectrum/card 3.0.0-alpha.0 → 3.0.0-alpha.11
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/dist/main.css +1 -2
- package/dist/main.js +1395 -1580
- package/dist/main.js.map +1 -1
- package/dist/module.js +1385 -1488
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +30 -38
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -21
- package/src/BaseLayout.tsx +13 -1
- package/src/Card.tsx +5 -8
- package/src/CardBase.tsx +24 -64
- package/src/CardView.tsx +52 -23
- package/src/GalleryLayout.tsx +94 -99
- package/src/GridLayout.tsx +40 -29
- package/src/WaterfallLayout.tsx +6 -20
- package/src/index.ts +10 -5
- package/dist/main.css.map +0 -1
- package/src/cardview.css +0 -16
package/dist/types.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, { Key } from "react";
|
|
3
|
-
import { SpectrumCardViewProps } from "@react-types/card";
|
|
1
|
+
import { Direction, KeyboardDelegate, Node, Orientation, DOMRef, DOMRefValue, ItemProps } from "@react-types/shared";
|
|
4
2
|
import { GridCollection } from "@react-stately/grid";
|
|
5
3
|
import { InvalidationContext, Layout, LayoutInfo, Rect, Size } from "@react-stately/virtualizer";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const CardView: <T>(props: SpectrumCardViewProps<T> & {
|
|
10
|
-
ref?: React.Ref<DOMRefValue<HTMLDivElement>>;
|
|
11
|
-
}) => React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)>) | (new (props: any) => React.Component<any, any, any>)>;
|
|
4
|
+
import React, { Key, ReactElement } from "react";
|
|
5
|
+
import { Scale } from "@react-types/provider";
|
|
6
|
+
import { SpectrumCardViewProps, SpectrumCardProps } from "@react-types/card";
|
|
12
7
|
interface BaseLayoutOptions {
|
|
13
8
|
collator?: Intl.Collator;
|
|
9
|
+
scale?: Scale;
|
|
10
|
+
/**
|
|
11
|
+
* The margin around the grid view between the edges and the items.
|
|
12
|
+
* @default 24
|
|
13
|
+
*/
|
|
14
|
+
margin?: number;
|
|
14
15
|
}
|
|
15
16
|
declare class BaseLayout<T> extends Layout<Node<T>> implements KeyboardDelegate {
|
|
16
17
|
protected contentSize: Size;
|
|
@@ -21,6 +22,8 @@ declare class BaseLayout<T> extends Layout<Node<T>> implements KeyboardDelegate
|
|
|
21
22
|
isLoading: boolean;
|
|
22
23
|
disabledKeys: Set<Key>;
|
|
23
24
|
direction: Direction;
|
|
25
|
+
scale: Scale;
|
|
26
|
+
margin: number;
|
|
24
27
|
constructor(options?: BaseLayoutOptions);
|
|
25
28
|
validate(invalidationContext: InvalidationContext<Node<T>, unknown>): void;
|
|
26
29
|
buildCollection(invalidationContext?: InvalidationContext<Node<T>, unknown>): void;
|
|
@@ -40,7 +43,7 @@ declare class BaseLayout<T> extends Layout<Node<T>> implements KeyboardDelegate
|
|
|
40
43
|
getLastKey(): any;
|
|
41
44
|
getKeyPageAbove(key: Key): any;
|
|
42
45
|
getKeyPageBelow(key: Key): any;
|
|
43
|
-
getKeyForSearch(search: string, fromKey?: Key):
|
|
46
|
+
getKeyForSearch(search: string, fromKey?: Key): Key;
|
|
44
47
|
}
|
|
45
48
|
export interface GalleryLayoutOptions extends BaseLayoutOptions {
|
|
46
49
|
/**
|
|
@@ -55,7 +58,7 @@ export interface GalleryLayoutOptions extends BaseLayoutOptions {
|
|
|
55
58
|
itemSpacing?: Size;
|
|
56
59
|
/**
|
|
57
60
|
* The vertical padding for an item.
|
|
58
|
-
* @default
|
|
61
|
+
* @default 78
|
|
59
62
|
*/
|
|
60
63
|
itemPadding?: number;
|
|
61
64
|
/**
|
|
@@ -69,15 +72,9 @@ export interface GalleryLayoutOptions extends BaseLayoutOptions {
|
|
|
69
72
|
* @type {number}
|
|
70
73
|
*/
|
|
71
74
|
threshold?: number;
|
|
72
|
-
/**
|
|
73
|
-
* The margin around the grid view between the edges and the items.
|
|
74
|
-
* @default 24
|
|
75
|
-
*/
|
|
76
|
-
margin?: number;
|
|
77
75
|
}
|
|
78
76
|
export class GalleryLayout<T> extends BaseLayout<T> {
|
|
79
77
|
protected idealRowHeight: number;
|
|
80
|
-
protected margin: number;
|
|
81
78
|
protected itemSpacing: Size;
|
|
82
79
|
itemPadding: number;
|
|
83
80
|
protected minItemSize: Size;
|
|
@@ -95,7 +92,7 @@ export class GalleryLayout<T> extends BaseLayout<T> {
|
|
|
95
92
|
export interface GridLayoutOptions extends BaseLayoutOptions {
|
|
96
93
|
/**
|
|
97
94
|
* The minimum item size.
|
|
98
|
-
* @default 208 x 208
|
|
95
|
+
* @default 208 x 208 for horizontal card orientation. 102 x 102 for vertical card orientation.
|
|
99
96
|
*/
|
|
100
97
|
minItemSize?: Size;
|
|
101
98
|
/**
|
|
@@ -103,11 +100,6 @@ export interface GridLayoutOptions extends BaseLayoutOptions {
|
|
|
103
100
|
* @default Infinity
|
|
104
101
|
*/
|
|
105
102
|
maxItemSize?: Size;
|
|
106
|
-
/**
|
|
107
|
-
* The margin around the grid view between the edges and the items.
|
|
108
|
-
* @default 24
|
|
109
|
-
*/
|
|
110
|
-
margin?: number;
|
|
111
103
|
/**
|
|
112
104
|
* The minimum space required between items.
|
|
113
105
|
* @default 18 x 18
|
|
@@ -119,18 +111,23 @@ export interface GridLayoutOptions extends BaseLayoutOptions {
|
|
|
119
111
|
*/
|
|
120
112
|
maxColumns?: number;
|
|
121
113
|
/**
|
|
122
|
-
* The
|
|
114
|
+
* The additional padding along the card's main axis. Affects the sizing of the content area following the card image.
|
|
123
115
|
* @default 95
|
|
124
116
|
*/
|
|
125
117
|
itemPadding?: number;
|
|
118
|
+
/**
|
|
119
|
+
* The orientation of the cards withn the grid.
|
|
120
|
+
* @default vertical
|
|
121
|
+
*/
|
|
122
|
+
cardOrientation?: Orientation;
|
|
126
123
|
}
|
|
127
124
|
export class GridLayout<T> extends BaseLayout<T> {
|
|
128
125
|
protected minItemSize: Size;
|
|
129
126
|
protected maxItemSize: Size;
|
|
130
|
-
protected margin: number;
|
|
131
127
|
protected minSpace: Size;
|
|
132
128
|
protected maxColumns: number;
|
|
133
129
|
itemPadding: number;
|
|
130
|
+
cardOrientation: Orientation;
|
|
134
131
|
protected itemSize: Size;
|
|
135
132
|
protected numColumns: number;
|
|
136
133
|
protected numRows: number;
|
|
@@ -155,11 +152,6 @@ export interface WaterfallLayoutOptions extends BaseLayoutOptions {
|
|
|
155
152
|
* @default Infinity
|
|
156
153
|
*/
|
|
157
154
|
maxItemSize?: Size;
|
|
158
|
-
/**
|
|
159
|
-
* The margin around the grid view between the edges and the items.
|
|
160
|
-
* @default 24
|
|
161
|
-
*/
|
|
162
|
-
margin?: number;
|
|
163
155
|
/**
|
|
164
156
|
* The minimum space required between items.
|
|
165
157
|
* @default 18 x 18
|
|
@@ -170,19 +162,12 @@ export interface WaterfallLayoutOptions extends BaseLayoutOptions {
|
|
|
170
162
|
* @default Infinity
|
|
171
163
|
*/
|
|
172
164
|
maxColumns?: number;
|
|
173
|
-
/**
|
|
174
|
-
* The vertical padding for an item.
|
|
175
|
-
* @default 56
|
|
176
|
-
*/
|
|
177
|
-
itemPadding?: number;
|
|
178
165
|
}
|
|
179
166
|
export class WaterfallLayout<T> extends BaseLayout<T> implements KeyboardDelegate {
|
|
180
167
|
protected minItemSize: Size;
|
|
181
168
|
protected maxItemSize: Size;
|
|
182
|
-
protected margin: number;
|
|
183
169
|
protected minSpace: Size;
|
|
184
170
|
protected maxColumns: number;
|
|
185
|
-
itemPadding: number;
|
|
186
171
|
protected numColumns: number;
|
|
187
172
|
protected itemWidth: number;
|
|
188
173
|
protected horizontalSpacing: number;
|
|
@@ -196,6 +181,13 @@ export class WaterfallLayout<T> extends BaseLayout<T> implements KeyboardDelegat
|
|
|
196
181
|
getKeyRightOf(key: Key): any;
|
|
197
182
|
getKeyLeftOf(key: Key): any;
|
|
198
183
|
}
|
|
199
|
-
|
|
184
|
+
/**
|
|
185
|
+
* TODO: Add description of component here.
|
|
186
|
+
*/
|
|
187
|
+
export const CardView: <T>(props: SpectrumCardViewProps<T> & {
|
|
188
|
+
ref?: DOMRef<HTMLDivElement>;
|
|
189
|
+
}) => ReactElement;
|
|
190
|
+
export let Card: React.ForwardRefExoticComponent<ItemProps<SpectrumCardProps> & SpectrumCardProps & React.RefAttributes<DOMRefValue<HTMLDivElement>>>;
|
|
191
|
+
export type { SpectrumCardViewProps } from '@react-types/card';
|
|
200
192
|
|
|
201
193
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;AAkBA;IACE,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC;IAEzB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,yBAAwB,CAAC,CAAE,SAAQ,OAAO,KAAK,CAAC,CAAC,CAAE,YAAW,gBAAgB;IAC5E,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC;IAC5B,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC5C,SAAS,CAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC;IAClC,SAAS,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;IAC5C,UAAU,EAAG,eAAe,CAAC,CAAC,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAa;IACnC,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;gBAEH,OAAO,GAAE,iBAAsB;IAS3C,QAAQ,CAAC,mBAAmB,EAAE,oBAAoB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC;IAyBnE,eA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B,EAAC,MAAM,mBAAmB,CAAC","sources":["packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/BaseLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/GalleryLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/GridLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/WaterfallLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/CardViewContext.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/CardBase.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/CardView.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/Card.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/index.ts","packages/@react-spectrum/card/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/// <reference types=\"css-module-types\" />\n\nexport type {GalleryLayoutOptions} from './GalleryLayout';\nexport type {GridLayoutOptions} from './GridLayout';\nexport type {WaterfallLayoutOptions} from './WaterfallLayout';\n\nexport {CardView} from './CardView';\nexport {GalleryLayout} from './GalleryLayout';\nexport {GridLayout} from './GridLayout';\nexport {WaterfallLayout} from './WaterfallLayout';\nexport {Card} from './Card';\nexport type {SpectrumCardViewProps} from '@react-types/card';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/card",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.11",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -32,34 +32,35 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.6.2",
|
|
35
|
-
"@react-aria/focus": "^3.
|
|
36
|
-
"@react-aria/grid": "^3.
|
|
37
|
-
"@react-aria/i18n": "^3.
|
|
38
|
-
"@react-aria/interactions": "^3.
|
|
39
|
-
"@react-aria/utils": "^3.
|
|
40
|
-
"@react-aria/virtualizer": "^3.
|
|
41
|
-
"@react-spectrum/checkbox": "^3.
|
|
42
|
-
"@react-spectrum/divider": "^3.1
|
|
43
|
-
"@react-spectrum/layout": "^3.
|
|
44
|
-
"@react-spectrum/progress": "^3.1
|
|
45
|
-
"@react-spectrum/utils": "^3.
|
|
46
|
-
"@react-stately/collections": "^3.3
|
|
47
|
-
"@react-stately/grid": "^3.
|
|
48
|
-
"@react-stately/list": "^3.3
|
|
49
|
-
"@react-stately/utils": "^3.
|
|
50
|
-
"@react-stately/virtualizer": "^3.
|
|
51
|
-
"@react-types/card": "3.0.0-alpha.
|
|
52
|
-
"@react-types/
|
|
35
|
+
"@react-aria/focus": "^3.8.0",
|
|
36
|
+
"@react-aria/grid": "^3.4.1",
|
|
37
|
+
"@react-aria/i18n": "^3.6.0",
|
|
38
|
+
"@react-aria/interactions": "^3.11.0",
|
|
39
|
+
"@react-aria/utils": "^3.13.3",
|
|
40
|
+
"@react-aria/virtualizer": "^3.5.0",
|
|
41
|
+
"@react-spectrum/checkbox": "^3.5.1",
|
|
42
|
+
"@react-spectrum/divider": "^3.4.1",
|
|
43
|
+
"@react-spectrum/layout": "^3.4.1",
|
|
44
|
+
"@react-spectrum/progress": "^3.3.1",
|
|
45
|
+
"@react-spectrum/utils": "^3.7.3",
|
|
46
|
+
"@react-stately/collections": "^3.4.3",
|
|
47
|
+
"@react-stately/grid": "^3.3.1",
|
|
48
|
+
"@react-stately/list": "^3.5.3",
|
|
49
|
+
"@react-stately/utils": "^3.5.1",
|
|
50
|
+
"@react-stately/virtualizer": "^3.3.0",
|
|
51
|
+
"@react-types/card": "3.0.0-alpha.9",
|
|
52
|
+
"@react-types/provider": "^3.5.3",
|
|
53
|
+
"@react-types/shared": "^3.14.1"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@adobe/spectrum-css-temp": "3.0.0-alpha.1"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
59
|
"@react-spectrum/provider": "^3.0.0",
|
|
59
|
-
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
60
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
60
61
|
},
|
|
61
62
|
"publishConfig": {
|
|
62
63
|
"access": "public"
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "b03ef51e6317547dd0a840f151e59d039b1e1fd3"
|
|
65
66
|
}
|
package/src/BaseLayout.tsx
CHANGED
|
@@ -14,9 +14,17 @@ import {Direction, KeyboardDelegate, Node} from '@react-types/shared';
|
|
|
14
14
|
import {GridCollection} from '@react-stately/grid';
|
|
15
15
|
import {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';
|
|
16
16
|
import {Key} from 'react';
|
|
17
|
+
import {Scale} from '@react-types/provider';
|
|
17
18
|
|
|
18
19
|
export interface BaseLayoutOptions {
|
|
19
|
-
collator?: Intl.Collator
|
|
20
|
+
collator?: Intl.Collator,
|
|
21
|
+
// TODO: is this valid or is scale a spectrum specific thing that should be left out of the layouts?
|
|
22
|
+
scale?: Scale,
|
|
23
|
+
/**
|
|
24
|
+
* The margin around the grid view between the edges and the items.
|
|
25
|
+
* @default 24
|
|
26
|
+
*/
|
|
27
|
+
margin?: number
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
export class BaseLayout<T> extends Layout<Node<T>> implements KeyboardDelegate {
|
|
@@ -28,12 +36,16 @@ export class BaseLayout<T> extends Layout<Node<T>> implements KeyboardDelegate {
|
|
|
28
36
|
isLoading: boolean;
|
|
29
37
|
disabledKeys: Set<Key> = new Set();
|
|
30
38
|
direction: Direction;
|
|
39
|
+
scale: Scale;
|
|
40
|
+
margin: number;
|
|
31
41
|
|
|
32
42
|
constructor(options: BaseLayoutOptions = {}) {
|
|
33
43
|
super();
|
|
34
44
|
this.layoutInfos = new Map();
|
|
35
45
|
this.collator = options.collator;
|
|
36
46
|
this.lastCollection = null;
|
|
47
|
+
this.scale = options.scale || 'medium';
|
|
48
|
+
this.margin = options.margin || 24;
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
validate(invalidationContext: InvalidationContext<Node<T>, unknown>) {
|
package/src/Card.tsx
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
import {CardBase} from './CardBase';
|
|
15
|
-
import {DOMRef} from '@react-types/shared';
|
|
14
|
+
import {DOMRef, DOMRefValue, ItemProps} from '@react-types/shared';
|
|
16
15
|
import {PartialNode} from '@react-stately/collections';
|
|
17
|
-
import React, {forwardRef} from 'react';
|
|
16
|
+
import React, {forwardRef, ForwardRefExoticComponent, PropsWithoutRef, RefAttributes} from 'react';
|
|
18
17
|
import {SpectrumCardProps} from '@react-types/card';
|
|
19
18
|
import {useCardViewContext} from './CardViewContext';
|
|
20
19
|
|
|
20
|
+
|
|
21
21
|
let Card = forwardRef((props: SpectrumCardProps, ref: DOMRef<HTMLDivElement>) => {
|
|
22
22
|
let context = useCardViewContext();
|
|
23
23
|
if (context !== null) {
|
|
@@ -29,10 +29,8 @@ let Card = forwardRef((props: SpectrumCardProps, ref: DOMRef<HTMLDivElement>) =>
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
// TODO: Update the typescript for the below and the export
|
|
33
32
|
// @ts-ignore
|
|
34
|
-
|
|
35
|
-
Card.getCollectionNode = function* getCollectionNode<T>(props, context: any): Generator<PartialNode<T>> {
|
|
33
|
+
Card.getCollectionNode = function* getCollectionNode<T>(props: any): Generator<PartialNode<T>> {
|
|
36
34
|
let {children, textValue} = props;
|
|
37
35
|
|
|
38
36
|
yield {
|
|
@@ -45,6 +43,5 @@ Card.getCollectionNode = function* getCollectionNode<T>(props, context: any): Ge
|
|
|
45
43
|
};
|
|
46
44
|
};
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
let _Card = Card as <T>(props, ref) => JSX.Element;
|
|
46
|
+
let _Card = Card as ForwardRefExoticComponent<ItemProps<SpectrumCardProps> & PropsWithoutRef<SpectrumCardProps> & RefAttributes<DOMRefValue<HTMLDivElement>>>;
|
|
50
47
|
export {_Card as Card};
|
package/src/CardBase.tsx
CHANGED
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
import {AriaCardProps, SpectrumCardProps} from '@react-types/card';
|
|
14
14
|
import {Checkbox} from '@react-spectrum/checkbox';
|
|
15
15
|
import {classNames, SlotProvider, useDOMRef, useHasChild, useStyleProps} from '@react-spectrum/utils';
|
|
16
|
-
import {Divider} from '@react-spectrum/divider';
|
|
17
16
|
import {DOMRef, Node} from '@react-types/shared';
|
|
18
|
-
import {filterDOMProps, mergeProps, useLayoutEffect, useSlotId} from '@react-aria/utils';
|
|
17
|
+
import {filterDOMProps, mergeProps, useLayoutEffect, useResizeObserver, useSlotId} from '@react-aria/utils';
|
|
19
18
|
import {FocusRing} from '@react-aria/focus';
|
|
20
|
-
import
|
|
19
|
+
import {getFocusableTreeWalker} from '@react-aria/focus';
|
|
20
|
+
import React, {HTMLAttributes, useCallback, useMemo, useRef, useState} from 'react';
|
|
21
21
|
import styles from '@adobe/spectrum-css-temp/components/card/vars.css';
|
|
22
22
|
import {useCardViewContext} from './CardViewContext';
|
|
23
23
|
import {useFocusWithin, useHover} from '@react-aria/interactions';
|
|
@@ -30,7 +30,6 @@ interface CardBaseProps<T> extends SpectrumCardProps {
|
|
|
30
30
|
|
|
31
31
|
function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDivElement>) {
|
|
32
32
|
props = useProviderProps(props);
|
|
33
|
-
// TODO: Don't send in articleProps via context (unless we want to make another context for InternalCard)? Pass it in via props since it will only be provided via CardView's InternalCard
|
|
34
33
|
let context = useCardViewContext() || {}; // we can call again here, won't change from Card.tsx
|
|
35
34
|
let {state} = context;
|
|
36
35
|
let manager = state?.selectionManager;
|
|
@@ -39,7 +38,8 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
39
38
|
orientation = 'vertical',
|
|
40
39
|
articleProps = {},
|
|
41
40
|
item,
|
|
42
|
-
layout
|
|
41
|
+
layout,
|
|
42
|
+
children
|
|
43
43
|
} = props;
|
|
44
44
|
|
|
45
45
|
let key = item?.key;
|
|
@@ -51,6 +51,7 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
51
51
|
let {cardProps, titleProps, contentProps} = useCard(props);
|
|
52
52
|
let domRef = useDOMRef(ref);
|
|
53
53
|
let gridRef = useRef<HTMLDivElement>();
|
|
54
|
+
let checkboxRef = useRef(null);
|
|
54
55
|
|
|
55
56
|
// cards are only interactive if there is a selection manager and it allows selection
|
|
56
57
|
let {hoverProps, isHovered} = useHover({isDisabled: manager === undefined || manager?.selectionMode === 'none' || isDisabled});
|
|
@@ -60,8 +61,6 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
60
61
|
isDisabled
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
let hasFooter = useHasChild(`.${styles['spectrum-Card-footer']}`, gridRef);
|
|
64
|
-
|
|
65
64
|
// ToDo: see css for comment about avatar under selector .spectrum-Card--noLayout.spectrum-Card--default
|
|
66
65
|
let hasPreviewImage = useHasChild(`.${styles['spectrum-Card-image']}`, gridRef);
|
|
67
66
|
let hasPreviewIllustration = useHasChild(`.${styles['spectrum-Card-illustration']}`, gridRef);
|
|
@@ -69,13 +68,16 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
69
68
|
|
|
70
69
|
// this is for horizontal cards
|
|
71
70
|
let [height, setHeight] = useState(NaN);
|
|
72
|
-
|
|
71
|
+
let updateHeight = useCallback(() => {
|
|
73
72
|
if (orientation !== 'horizontal') {
|
|
74
73
|
return;
|
|
75
74
|
}
|
|
75
|
+
|
|
76
76
|
let cardHeight = gridRef.current.getBoundingClientRect().height;
|
|
77
77
|
setHeight(cardHeight);
|
|
78
|
-
}, [gridRef, setHeight
|
|
78
|
+
}, [orientation, gridRef, setHeight]);
|
|
79
|
+
useResizeObserver({ref: gridRef, onResize: updateHeight});
|
|
80
|
+
|
|
79
81
|
let aspectRatioEnforce = undefined;
|
|
80
82
|
if (orientation === 'horizontal' && !isNaN(height)) {
|
|
81
83
|
aspectRatioEnforce = {
|
|
@@ -90,63 +92,22 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
90
92
|
avatar: {UNSAFE_className: classNames(styles, 'spectrum-Card-avatar'), size: 'avatar-size-400'},
|
|
91
93
|
heading: {UNSAFE_className: classNames(styles, 'spectrum-Card-heading'), ...titleProps},
|
|
92
94
|
content: {UNSAFE_className: classNames(styles, 'spectrum-Card-content'), ...contentProps},
|
|
93
|
-
detail: {UNSAFE_className: classNames(styles, 'spectrum-Card-detail')}
|
|
94
|
-
actionmenu: {UNSAFE_className: classNames(styles, 'spectrum-Card-actions'), align: 'end', isQuiet: true},
|
|
95
|
-
footer: {UNSAFE_className: classNames(styles, 'spectrum-Card-footer'), isHidden: isQuiet},
|
|
96
|
-
divider: {UNSAFE_className: classNames(styles, 'spectrum-Card-divider'), size: 'S'}
|
|
95
|
+
detail: {UNSAFE_className: classNames(styles, 'spectrum-Card-detail')}
|
|
97
96
|
}), [titleProps, contentProps, height, isQuiet, orientation]);
|
|
98
97
|
|
|
99
|
-
// This is only for quiet grid cards
|
|
100
|
-
let [isCloseToSquare, setIsCloseToSquare] = useState(false);
|
|
101
98
|
useLayoutEffect(() => {
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let height = image.naturalHeight;
|
|
112
|
-
let width = image.naturalWidth;
|
|
113
|
-
/*
|
|
114
|
-
* ToDo: Choose between min-padding and plain ratio
|
|
115
|
-
* Do we want to just do a ratio measurement when it's close to being a square?
|
|
116
|
-
* or do we want to actually figure out min-padding?
|
|
117
|
-
* Min Padding would require us to check that the padding is not less than the min in both Vertical and Horizontal
|
|
118
|
-
* Unfortunately img contain doesn't actually create padding, which is what this math below can figure out
|
|
119
|
-
* Vs the commented out straight ratio check
|
|
120
|
-
* */
|
|
121
|
-
let imgTagHeight = image.clientHeight;
|
|
122
|
-
let imgTagWidth = image.clientWidth;
|
|
123
|
-
let ratio = Math.min(imgTagWidth / width, imgTagHeight / height);
|
|
124
|
-
let trueHeight = ratio * height;
|
|
125
|
-
let trueWidth = ratio * width;
|
|
126
|
-
let paddingVertical = imgTagHeight - trueHeight;
|
|
127
|
-
let paddingHorizontal = imgTagWidth - trueWidth;
|
|
128
|
-
if (paddingVertical < 16 && paddingHorizontal < 16) { // ToDo: does this need to be different per scale?
|
|
129
|
-
setIsCloseToSquare(true);
|
|
130
|
-
} else {
|
|
131
|
-
setIsCloseToSquare(false);
|
|
99
|
+
if (gridRef?.current) {
|
|
100
|
+
let walker = getFocusableTreeWalker(gridRef.current);
|
|
101
|
+
let nextNode = walker.nextNode();
|
|
102
|
+
while (nextNode != null) {
|
|
103
|
+
if (checkboxRef.current && !checkboxRef.current.UNSAFE_getDOMNode().contains(nextNode)) {
|
|
104
|
+
console.warn('Card does not support focusable elements, please contact the team regarding your use case.');
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
nextNode = walker.nextNode();
|
|
132
108
|
}
|
|
133
|
-
|
|
134
|
-
// let ratio = height / width;
|
|
135
|
-
// if (ratio > 0.9 && ratio < 1.1) {
|
|
136
|
-
// setIsCloseToSquare(true);
|
|
137
|
-
// }
|
|
138
|
-
};
|
|
139
|
-
if (image.complete) {
|
|
140
|
-
measure();
|
|
141
|
-
} else {
|
|
142
|
-
image.addEventListener('load', measure);
|
|
143
|
-
return () => {
|
|
144
|
-
image.removeEventListener('load', measure);
|
|
145
|
-
};
|
|
146
109
|
}
|
|
147
|
-
|
|
148
|
-
}, [props.children, setIsCloseToSquare, isQuiet, layout]);
|
|
149
|
-
|
|
110
|
+
}, [children]);
|
|
150
111
|
|
|
151
112
|
return (
|
|
152
113
|
<FocusRing focusRingClass={classNames(styles, 'focus-ring')}>
|
|
@@ -158,7 +119,6 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
158
119
|
'spectrum-Card--default': !isQuiet && orientation !== 'horizontal',
|
|
159
120
|
'spectrum-Card--isQuiet': isQuiet && orientation !== 'horizontal',
|
|
160
121
|
'spectrum-Card--horizontal': orientation === 'horizontal',
|
|
161
|
-
'spectrum-Card--closeToSquare': isCloseToSquare,
|
|
162
122
|
'spectrum-Card--noPreview': !hasPreview,
|
|
163
123
|
'is-hovered': isHovered,
|
|
164
124
|
'is-focused': isFocused,
|
|
@@ -172,6 +132,7 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
172
132
|
{manager && manager.selectionMode !== 'none' && (
|
|
173
133
|
<div className={classNames(styles, 'spectrum-Card-checkboxWrapper')}>
|
|
174
134
|
<Checkbox
|
|
135
|
+
ref={checkboxRef}
|
|
175
136
|
isDisabled={isDisabled}
|
|
176
137
|
excludeFromTabOrder
|
|
177
138
|
isSelected={isSelected}
|
|
@@ -182,8 +143,7 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
|
|
|
182
143
|
</div>
|
|
183
144
|
)}
|
|
184
145
|
<SlotProvider slots={slots}>
|
|
185
|
-
{
|
|
186
|
-
{hasFooter && <Divider />}
|
|
146
|
+
{children}
|
|
187
147
|
</SlotProvider>
|
|
188
148
|
<div className={classNames(styles, 'spectrum-Card-decoration')} />
|
|
189
149
|
</div>
|