Skip to content

Commit 2bd6e20

Browse files
authored
S2 Card updates (#7053)
1 parent 9e79420 commit 2bd6e20

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

packages/@react-spectrum/s2/src/Card.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let selectionIndicator = style({
215215
},
216216
// Quiet cards with no checkbox have an extra inner stroke
217217
// to distinguish the selection indicator from the preview.
218-
outlineColor: 'gray-25',
218+
outlineColor: lightDark('transparent-white-600', 'transparent-black-600'),
219219
outlineOffset: -4,
220220
outlineStyle: {
221221
default: 'none',
@@ -331,6 +331,13 @@ let content = style({
331331
}
332332
});
333333

334+
let actionMenu = style({
335+
gridArea: 'menu',
336+
// Don't cause the row to expand, preserve gap between title and description text.
337+
// Would use -100% here but it doesn't work in Firefox.
338+
marginY: '[calc(-1 * self(height))]'
339+
});
340+
334341
let footer = style({
335342
display: 'flex',
336343
flexDirection: 'row',
@@ -397,7 +404,7 @@ export const Card = forwardRef(function Card(props: CardProps, ref: DOMRef<HTMLD
397404
isDisabled: isSkeleton,
398405
// @ts-ignore
399406
'data-slot': 'menu',
400-
styles: style({gridArea: 'menu'})
407+
styles: actionMenu
401408
}],
402409
[SkeletonContext, isSkeleton]
403410
]}>

packages/@react-spectrum/s2/src/CardView.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,20 @@ class FlexibleGridLayout<T extends object> extends Layout<Node<T>, GridLayoutOpt
194194
}
195195
}
196196

197+
class WaterfallLayoutInfo extends LayoutInfo {
198+
column = 0;
199+
200+
copy(): WaterfallLayoutInfo {
201+
let res = super.copy() as WaterfallLayoutInfo;
202+
res.column = this.column;
203+
return res;
204+
}
205+
}
206+
197207
class WaterfallLayout<T extends object> extends Layout<Node<T>, GridLayoutOptions> implements LayoutDelegate {
198208
protected contentSize: Size = new Size();
199-
protected layoutInfos: Map<Key, LayoutInfo> = new Map();
209+
protected layoutInfos: Map<Key, WaterfallLayoutInfo> = new Map();
210+
protected numColumns = 0;
200211

201212
update(invalidationContext: InvalidationContext<GridLayoutOptions>): void {
202213
let {
@@ -246,15 +257,18 @@ class WaterfallLayout<T extends object> extends Layout<Node<T>, GridLayoutOption
246257
}
247258

248259
// Figure out which column to place the item in, and compute its position.
249-
let column = columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);
260+
// Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
261+
let prevColumn = numColumns === this.numColumns ? oldLayoutInfo?.column : undefined;
262+
let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);
250263
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing);
251264
let y = columnHeights[column];
252265

253266
let rect = new Rect(x, y, itemWidth, height);
254-
let layoutInfo = new LayoutInfo(node.type, key, rect);
267+
let layoutInfo = new WaterfallLayoutInfo(node.type, key, rect);
255268
layoutInfo.estimatedSize = estimatedSize;
256269
layoutInfo.allowOverflow = true;
257270
layoutInfo.content = node;
271+
layoutInfo.column = column;
258272
newLayoutInfos.set(key, layoutInfo);
259273

260274
columnHeights[column] += layoutInfo.rect.height + minSpace.height;
@@ -283,6 +297,7 @@ class WaterfallLayout<T extends object> extends Layout<Node<T>, GridLayoutOption
283297
let maxHeight = Math.max(...columnHeights);
284298
this.contentSize = new Size(this.virtualizer.visibleRect.width, maxHeight);
285299
this.layoutInfos = newLayoutInfos;
300+
this.numColumns = numColumns;
286301
}
287302

288303
getLayoutInfo(key: Key): LayoutInfo {

0 commit comments

Comments
 (0)