Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 79a6fc5

Browse files
authored
fix: card height with date field (#1106)
1 parent e655745 commit 79a6fc5

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

packages/core/src/components/collections/Collection.classes.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const collectionClasses = generateClassNames('Collection', [
1212
'header-icon',
1313
'header-label',
1414
'new-entry-button',
15+
'new-entry-button-text',
1516
]);
1617

1718
export default collectionClasses;

packages/core/src/components/collections/Collection.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,10 @@
8383

8484
.CMS_Collection_new-entry-button {
8585
@apply hidden
86-
md:flex;
86+
md:flex
87+
min-w-0;
88+
}
89+
90+
.CMS_Collection_new-entry-button-text {
91+
@apply truncate;
8792
}

packages/core/src/components/collections/CollectionHeader.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ const CollectionHeader: FC<CollectionHeaderProps> = ({ collection }) => {
7676
</h2>
7777
{newEntryUrl ? (
7878
<Button to={newEntryUrl} className={collectionClasses['new-entry-button']}>
79-
{t('collection.collectionTop.newButton', {
80-
collectionLabel: collectionLabelSingular ?? pluralLabel,
81-
})}
79+
<div className={collectionClasses['new-entry-button-text']}>
80+
{t('collection.collectionTop.newButton', {
81+
collectionLabel: collectionLabelSingular ?? pluralLabel,
82+
})}
83+
</div>
8284
</Button>
8385
) : null}
8486
</div>

packages/core/src/components/collections/entries/EntryListingCardGrid.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AutoSizer from 'react-virtualized-auto-sizer';
33
import { VariableSizeGrid as Grid } from 'react-window';
44

55
import {
6+
COLLECTION_CARD_DATE_HEIGHT,
67
COLLECTION_CARD_HEIGHT,
78
COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE,
89
COLLECTION_CARD_MARGIN,
@@ -64,7 +65,7 @@ const CardWrapper: FC<GridChildComponentProps<CardGridItemData>> = ({
6465
}
6566
const data = entryData[index];
6667
const cardHeight =
67-
index < cardHeights.length ? cardHeights[index] + COLLECTION_CARD_MARGIN : style.height;
68+
index < cardHeights.length ? cardHeights[index] + COLLECTION_CARD_MARGIN * 2 : style.height;
6869

6970
return (
7071
<div
@@ -114,9 +115,15 @@ const EntryListingCardGrid: FC<EntryListingCardGridProps> = ({
114115
}, []);
115116

116117
const getDefaultHeight = useCallback((data?: CollectionEntryData) => {
117-
return isNotNullish(data?.imageFieldName)
118+
const base = isNotNullish(data?.imageFieldName)
118119
? COLLECTION_CARD_HEIGHT
119120
: COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE;
121+
122+
if (isNotNullish(data?.dateFieldName)) {
123+
return base + COLLECTION_CARD_DATE_HEIGHT;
124+
}
125+
126+
return base;
120127
}, []);
121128

122129
const [prevCardHeights, setPrevCardHeight] = useState<number[]>([]);
@@ -185,12 +192,12 @@ const EntryListingCardGrid: FC<EntryListingCardGridProps> = ({
185192
}
186193

187194
if (cardHeights[i] > rowHeight && cardHeights[i]) {
188-
rowHeight = cardHeights[i] + COLLECTION_CARD_MARGIN;
195+
rowHeight = cardHeights[i] + COLLECTION_CARD_MARGIN * 2;
189196
}
190197
}
191198

192199
if (rowHeight === 0) {
193-
rowHeight = getDefaultHeight() + COLLECTION_CARD_MARGIN;
200+
rowHeight = getDefaultHeight() + COLLECTION_CARD_MARGIN * 2;
194201
}
195202

196203
return rowHeight;

packages/core/src/constants/views.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const COLLECTION_CARD_WIDTH = 240;
88
export const COLLECTION_CARD_HEIGHT = 204;
99
export const COLLECTION_CARD_IMAGE_HEIGHT = 140;
1010
export const COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE = 56;
11+
export const COLLECTION_CARD_DATE_HEIGHT = 24;
1112
export const COLLECTION_CARD_MARGIN = 10;
1213

1314
export const EDITOR_SIZE_COMPACT = 'compact';

0 commit comments

Comments
 (0)